From 38c42725fe9ad6f50cd45e32a408e5fda370971c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 14 Jul 2002 23:48:42 +0000 Subject: Check in tests that have been in my tree for a long time git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2906 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CFrontend/2002-07-14-MiscListTests.c | 69 +++++++++++ test/CFrontend/2002-07-14-MiscTests.c | 55 +++++++++ test/CFrontend/2002-07-14-MiscTests2.c | 11 ++ test/CFrontend/2002-07-14-MiscTests3.c | 185 ++++++++++++++++++++++++++++++ 4 files changed, 320 insertions(+) create mode 100644 test/CFrontend/2002-07-14-MiscListTests.c create mode 100644 test/CFrontend/2002-07-14-MiscTests.c create mode 100644 test/CFrontend/2002-07-14-MiscTests2.c create mode 100644 test/CFrontend/2002-07-14-MiscTests3.c (limited to 'test/CFrontend') diff --git a/test/CFrontend/2002-07-14-MiscListTests.c b/test/CFrontend/2002-07-14-MiscListTests.c new file mode 100644 index 0000000..34edea1 --- /dev/null +++ b/test/CFrontend/2002-07-14-MiscListTests.c @@ -0,0 +1,69 @@ +// Test list stuff + +void *malloc(unsigned); + +// Test opaque structure support. the list type is defined later +struct list; + +struct list *PassThroughList(struct list *L) { + return L; +} + + +// Recursive data structure tests... + +typedef struct list { + int Data; + struct list *Next; +} list; + +list *Data; + +void foo() { + static int Foo = 0; // Test static local variable + Foo += 1; // Increment static variable + + Data = (list*)malloc(12); // This is not a proper list allocation +} + +extern list ListNode1; +list ListNode3 = { 4, 0 }; +list ListNode2 = { 3, &ListNode3 }; +list ListNode0 = { 1, &ListNode1 }; +list ListNode1 = { 2, &ListNode2 }; + + +list ListArray[10]; + +// Iterative insert fn +void InsertIntoListTail(list **L, int Data) { + while (*L) + L = &(*L)->Next; + *L = (list*)malloc(sizeof(list)); + (*L)->Data = Data; + (*L)->Next = 0; +} + +// Recursive list search fn +list *FindData(list *L, int Data) { + if (L == 0) return 0; + if (L->Data == Data) return L; + return FindData(L->Next, Data); +} + +void foundIt(void); + +// Driver fn... +void DoListStuff() { + list *MyList = 0; + InsertIntoListTail(&MyList, 100); + InsertIntoListTail(&MyList, 12); + InsertIntoListTail(&MyList, 42); + InsertIntoListTail(&MyList, 1123); + InsertIntoListTail(&MyList, 1213); + + if (FindData(MyList, 75)) foundIt(); + if (FindData(MyList, 42)) foundIt(); + if (FindData(MyList, 700)) foundIt(); +} + diff --git a/test/CFrontend/2002-07-14-MiscTests.c b/test/CFrontend/2002-07-14-MiscTests.c new file mode 100644 index 0000000..980a8a4 --- /dev/null +++ b/test/CFrontend/2002-07-14-MiscTests.c @@ -0,0 +1,55 @@ +/* These are random tests that I used when working on the GCC frontend + originally. */ + +// test floating point comparison! +int floatcomptest(double *X, double *Y, float *x, float *y) { + return *X < *Y || *x < *y; +} + +extern void *malloc(unsigned); + +// Exposed a bug +void *memset_impl(void *dstpp, int c, unsigned len) { + long long int dstp = (long long int) dstpp; + + while (dstp % 4 != 0) + { + ((unsigned char *) dstp)[0] = c; + dstp += 1; + len -= 1; + } + return dstpp; +} + +// TEST problem with signed/unsigned versions of the same constants being shared +// incorrectly! +// +static char *temp; +static int remaining; +static char *localmalloc(int size) { + char *blah; + + if (size>remaining) + { + temp = (char *) malloc(32768); + remaining = 32768; + return temp; + } + return 0; +} + +typedef struct { double X; double Y; int Z; } PBVTest; + +PBVTest testRetStruct(float X, double Y, int Z) { + PBVTest T = { X, Y, Z }; + return T; +} +PBVTest testRetStruct2(void); // external func no inlining + + +double CallRetStruct(float X, double Y, int Z) { + PBVTest T = testRetStruct2(); + return T.X+X+Y+Z; +} + + diff --git a/test/CFrontend/2002-07-14-MiscTests2.c b/test/CFrontend/2002-07-14-MiscTests2.c new file mode 100644 index 0000000..b7b3d5c --- /dev/null +++ b/test/CFrontend/2002-07-14-MiscTests2.c @@ -0,0 +1,11 @@ + +// Test ?: in function calls +extern fp(int, char*); +char *Ext; +void +__bb_exit_func (void) +{ + fp (12, Ext ? Ext : ""); +} + + diff --git a/test/CFrontend/2002-07-14-MiscTests3.c b/test/CFrontend/2002-07-14-MiscTests3.c new file mode 100644 index 0000000..95a0045 --- /dev/null +++ b/test/CFrontend/2002-07-14-MiscTests3.c @@ -0,0 +1,185 @@ + + +void *malloc(unsigned); + +//#include +int puts(const char *s); + +struct FunStructTest { + int Test1; + char *Pointer; + int Array[12]; +}; + +struct SubStruct { + short X, Y; +}; + +struct Quad { + int w; + struct SubStruct SS; + struct SubStruct *SSP; + char c; + int y; +}; + +struct Quad GlobalQuad = { 4, {1, 2}, 0, 3, 156 }; + +typedef int (*FuncPtr)(int); + +unsigned PtrFunc(int (*Func)(int), int X) { + return Func(X); +} + +char PtrFunc2(FuncPtr FuncTab[30], int Num) { + return FuncTab[Num]('b'); +} + +extern char SmallArgs2(char w, char x, long long Zrrk, char y, char z); +extern int SomeFunc(void); +char SmallArgs(char w, char x, char y, char z) { + SomeFunc(); + return SmallArgs2(w-1, x+1, y, z, w); +} + +static int F0(struct Quad Q, int i) { /* Pass Q by value */ + struct Quad R; + if (i) R.SS = Q.SS; + Q.SSP = &R.SS; + Q.w = Q.y = Q.c = 1; + return Q.SS.Y + i + R.y - Q.c; +} + +int F1(struct Quad *Q, int i) { /* Pass Q by address */ + struct Quad R; +#if 0 + if (i) R.SS = Q->SS; +#else + if (i) R = *Q; +#endif + Q->w = Q->y = Q->c = 1; + return Q->SS.Y+i+R.y-Q->c; +} + + +int BadFunc(float Val) { + int Result; + if (Val > 12.345) Result = 4; + return Result; /* Test use of undefined value */ +} + +int RealFunc(void) { + return SomeUndefinedFunction(1, 4, 5); +} + +extern int EF1(int *, char *, int *); + +int Func(int Param, long long Param2) { + int Result = Param; + + {{{{ + char c; int X; + EF1(&Result, &c, &X); + }}} + + { // c & X are duplicate names! + char c; int X; + EF1(&Result, &c, &X); + } + + } + return Result; +} + + +short FunFunc(long long x, char z) { + return x+z; +} + +unsigned castTest(int X) { return X; } + +double TestAdd(double X, float Y) { + return X+Y+.5; +} + +int func(int i, int j) { + while (i != 20) + i += 2; + + j += func(2, i); + return (i * 3 + j*2)*j; +} + +int SumArray(int Array[], int Num) { + int i, Result = 0; + for (i = 0; i < Num; ++i) + Result += Array[i]; + + return Result; +} + +int ArrayParam(int Values[100]) { + return EF1((int*)Values[50], (char*)1, &Values[50]); +} + +int ArrayToSum(void) { + int A[100], i; + for (i = 0; i < 100; ++i) + A[i] = i*4; + + return A[A[0]]; //SumArray(A, 100); +} + + +int ExternFunc(long long, unsigned*, short, unsigned char); + +int main(int argc, char *argv[]) { + unsigned i; + puts("Hello world!\n"); + + ExternFunc(-1, 0, (short)argc, 2); + //func(argc, argc); + + for (i = 0; i < 10; i++) + puts(argv[3]); + return 0; +} + +double MathFunc(double X, double Y, double Z, + double AA, double BB, double CC, double DD, + double EE, double FF, double GG, double HH, + double aAA, double aBB, double aCC, double aDD, + double aEE, double aFF) { + return X + Y + Z + AA + BB + CC + DD + EE + FF + GG + HH + + aAA + aBB + aCC + aDD + aEE + aFF; +} + + + +void strcpy(char *s1, char *s2) { + while (*s1++ = *s2++); +} + +void strcat(char *s1, char *s2) { + while (*s1++); + s1--; + while (*s1++ = *s2++); +} + +int strcmp(char *s1, char *s2) { + while (*s1++ == *s2++); + if (*s1 == 0) { + if (*s2 == 0) { + return 0; + } else { + return -1; + } + } else { + if (*s2 == 0) { + return 1; + } else { + return (*(--s1) - *(--s2)); + } + } +} + -- cgit v1.1