diff options
Diffstat (limited to 'test/CodeGen')
362 files changed, 6067 insertions, 370 deletions
diff --git a/test/CodeGen/2002-01-23-LoadQISIReloadFailure.c b/test/CodeGen/2002-01-23-LoadQISIReloadFailure.c new file mode 100644 index 000000000000..ec454c826835 --- /dev/null +++ b/test/CodeGen/2002-01-23-LoadQISIReloadFailure.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* Regression test. Just compile .c -> .ll to test */ +int foo(void) { + unsigned char *pp; + unsigned w_cnt; + + w_cnt += *pp; + + return w_cnt; +} diff --git a/test/CodeGen/2002-01-24-ComplexSpaceInType.c b/test/CodeGen/2002-01-24-ComplexSpaceInType.c new file mode 100644 index 000000000000..9af533dfa414 --- /dev/null +++ b/test/CodeGen/2002-01-24-ComplexSpaceInType.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +// This caused generation of the following type name: +// %Array = uninitialized global [10 x %complex int] +// +// which caused problems because of the space int the complex int type +// + +struct { int X, Y; } Array[10]; + +void foo() {} diff --git a/test/CodeGen/2002-01-24-HandleCallInsnSEGV.c b/test/CodeGen/2002-01-24-HandleCallInsnSEGV.c new file mode 100644 index 000000000000..739a841bbdff --- /dev/null +++ b/test/CodeGen/2002-01-24-HandleCallInsnSEGV.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +void *dlclose(void*); + +void ap_os_dso_unload(void *handle) +{ + dlclose(handle); + return; /* This return triggers the bug: Weird */ +} diff --git a/test/CodeGen/2002-02-13-ConditionalInCall.c b/test/CodeGen/2002-02-13-ConditionalInCall.c new file mode 100644 index 000000000000..d389371dd323 --- /dev/null +++ b/test/CodeGen/2002-02-13-ConditionalInCall.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* Test problem where bad code was generated with a ?: statement was + in a function call argument */ + +void foo(int, double, float); + +void bar(int x) { + foo(x, x ? 1.0 : 12.5, 1.0f); +} + diff --git a/test/CodeGen/2002-02-13-ReloadProblem.c b/test/CodeGen/2002-02-13-ReloadProblem.c new file mode 100644 index 000000000000..da7f5e4fe00c --- /dev/null +++ b/test/CodeGen/2002-02-13-ReloadProblem.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* This triggered a problem in reload, fixed by disabling most of the + * steps of compilation in GCC. Before this change, the code went through + * the entire backend of GCC, even though it was unnecessary for LLVM output + * now it is skipped entirely, and since reload doesn't run, it can't cause + * a problem. + */ + +extern int tolower(int); + +const char *rangematch(const char *pattern, int test, int c) { + + if ((c <= test) | (tolower(c) <= tolower((unsigned char)test))) + return 0; + + return pattern; +} diff --git a/test/CodeGen/2002-02-13-TypeVarNameCollision.c b/test/CodeGen/2002-02-13-TypeVarNameCollision.c new file mode 100644 index 000000000000..c76aef05109f --- /dev/null +++ b/test/CodeGen/2002-02-13-TypeVarNameCollision.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* This testcase causes a symbol table collision. Type names and variable + * names should be in distinct namespaces + */ + +typedef struct foo { + int X, Y; +} FOO; + +static FOO foo[100]; + +int test() { + return foo[4].Y; +} + diff --git a/test/CodeGen/2002-02-13-UnnamedLocal.c b/test/CodeGen/2002-02-13-UnnamedLocal.c new file mode 100644 index 000000000000..58a9f5ab1c0b --- /dev/null +++ b/test/CodeGen/2002-02-13-UnnamedLocal.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* Testcase for a problem where GCC allocated xqic to a register, + * and did not have a VAR_DECL that explained the stack slot to LLVM. + * Now the LLVM code synthesizes a stack slot if one is presented that + * has not been previously recognized. This is where alloca's named + * 'local' come from now. + */ + +typedef struct { + short x; +} foostruct; + +int foo(foostruct ic); + +void test() { + foostruct xqic; + foo(xqic); +} + + diff --git a/test/CodeGen/2002-02-14-EntryNodePreds.c b/test/CodeGen/2002-02-14-EntryNodePreds.c new file mode 100644 index 000000000000..60d1104f9667 --- /dev/null +++ b/test/CodeGen/2002-02-14-EntryNodePreds.c @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* GCC Used to generate code that contained a branch to the entry node of + * the do_merge function. This is illegal LLVM code. To fix this, GCC now + * inserts an entry node regardless of whether or not it has to insert allocas. + */ + +struct edge_rec +{ + struct VERTEX *v; + struct edge_rec *next; + int wasseen; + int more_data; +}; + +typedef struct edge_rec *QUAD_EDGE; + +typedef struct { + QUAD_EDGE left, right; +} EDGE_PAIR; + +struct EDGE_STACK { + int ptr; + QUAD_EDGE *elts; + int stack_size; +}; + +int do_merge(QUAD_EDGE ldo, QUAD_EDGE rdo) { + int lvalid; + QUAD_EDGE basel,rcand; + while (1) { + if (!lvalid) { + return (int)basel->next; + } + } +} + diff --git a/test/CodeGen/2002-02-16-RenamingTest.c b/test/CodeGen/2002-02-16-RenamingTest.c new file mode 100644 index 000000000000..bb23e680f25a --- /dev/null +++ b/test/CodeGen/2002-02-16-RenamingTest.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* test that locals are renamed with . notation */ + +void abc(void *); + +void Test5(double X) { + abc(&X); + { + int X; + abc(&X); + { + float X; + abc(&X); + } + } +} + diff --git a/test/CodeGen/2002-02-17-ArgumentAddress.c b/test/CodeGen/2002-02-17-ArgumentAddress.c new file mode 100644 index 000000000000..d1ad6a885ee1 --- /dev/null +++ b/test/CodeGen/2002-02-17-ArgumentAddress.c @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +int test(int X) { + return X; +} + +void abc(int *X); +int def(int Y, int Z) { + abc(&Z); + return Y; +} + +struct Test { short X, x; int Y, Z; }; + +int Testing(struct Test *A) { + return A->X+A->Y; +} + +int Test2(int X, struct Test A, int Y) { + return X+Y+A.X+A.Y; +} +int Test3(struct Test A, struct Test B) { + return A.X+A.Y+B.Y+B.Z; +} + +struct Test Test4(struct Test A) { + return A; +} + +int Test6() { + int B[200]; + return B[4]; +} + +struct STest2 { int X; short Y[4]; double Z; }; + +struct STest2 Test7(struct STest2 X) { + return X; +} diff --git a/test/CodeGen/2002-02-18-64bitConstant.c b/test/CodeGen/2002-02-18-64bitConstant.c new file mode 100644 index 000000000000..95da72dc30a3 --- /dev/null +++ b/test/CodeGen/2002-02-18-64bitConstant.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* GCC wasn't handling 64 bit constants right fixed */ + +int printf(const char * restrict format, ...); + +int main() { + long long Var = 123455678902ll; + printf("%lld\n", Var); +} diff --git a/test/CodeGen/2002-02-18-StaticData.c b/test/CodeGen/2002-02-18-StaticData.c new file mode 100644 index 000000000000..d0cf52477252 --- /dev/null +++ b/test/CodeGen/2002-02-18-StaticData.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +double FOO = 17; +double BAR = 12.0; +float XX = 12.0f; + +static char *procnames[] = { + "EXIT" +}; + +void *Data[] = { &FOO, &BAR, &XX }; + diff --git a/test/CodeGen/2002-03-11-LargeCharInString.c b/test/CodeGen/2002-03-11-LargeCharInString.c new file mode 100644 index 000000000000..927087349bcb --- /dev/null +++ b/test/CodeGen/2002-03-11-LargeCharInString.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +int strcmp(const char *s1, const char *s2); + +int test(char *X) { + /* LLVM-GCC used to emit: + %.LC0 = internal global [3 x sbyte] c"\1F\FFFFFF8B\00" + */ + return strcmp(X, "\037\213"); +} diff --git a/test/CodeGen/2002-03-12-ArrayInitialization.c b/test/CodeGen/2002-03-12-ArrayInitialization.c new file mode 100644 index 000000000000..f05b83861bab --- /dev/null +++ b/test/CodeGen/2002-03-12-ArrayInitialization.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* GCC would generate bad code if not enough initializers are + specified for an array. + */ + +int a[10] = { 0, 2}; + +char str[10] = "x"; + +void *Arr[5] = { 0, 0 }; + +float F[12] = { 1.23f, 34.7f }; + +struct Test { int X; double Y; }; + +struct Test Array[10] = { { 2, 12.0 }, { 3, 24.0 } }; + +int B[4][4] = { { 1, 2, 3, 4}, { 5, 6, 7 }, { 8, 9 } }; diff --git a/test/CodeGen/2002-03-12-StructInitialize.c b/test/CodeGen/2002-03-12-StructInitialize.c new file mode 100644 index 000000000000..1316fbbd0e4a --- /dev/null +++ b/test/CodeGen/2002-03-12-StructInitialize.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +typedef struct Connection_Type { + long to; + char type[10]; + long length; +} Connection; + +Connection link[3] += { {1, "link1", 10}, + {2, "link2", 20}, + {3, "link3", 30} }; + diff --git a/test/CodeGen/2002-03-12-StructInitializer.c b/test/CodeGen/2002-03-12-StructInitializer.c new file mode 100644 index 000000000000..a65675b13786 --- /dev/null +++ b/test/CodeGen/2002-03-12-StructInitializer.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* GCC was not emitting string constants of the correct length when + * embedded into a structure field like this. It thought the strlength + * was -1. + */ + +typedef struct Connection_Type { + long to; + char type[10]; + long length; +} Connection; + +Connection link[3] += { {1, "link1", 10}, + {2, "link2", 20}, + {3, "link3", 30} }; + diff --git a/test/CodeGen/2002-03-14-BrokenPHINode.c b/test/CodeGen/2002-03-14-BrokenPHINode.c new file mode 100644 index 000000000000..eb058598c505 --- /dev/null +++ b/test/CodeGen/2002-03-14-BrokenPHINode.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* GCC was generating PHI nodes with an arity < #pred of the basic block the + * PHI node lived in. This was breaking LLVM because the number of entries + * in a PHI node must equal the number of predecessors for a basic block. + */ + +int trys(char *s, int x) +{ + int asa; + double Val; + int LLS; + if (x) { + asa = LLS + asa; + } else { + } + return asa+(int)Val; +} + diff --git a/test/CodeGen/2002-03-14-BrokenSSA.c b/test/CodeGen/2002-03-14-BrokenSSA.c new file mode 100644 index 000000000000..65e5cfad815e --- /dev/null +++ b/test/CodeGen/2002-03-14-BrokenSSA.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* This code used to break GCC's SSA computation code. It would create + uses of B & C that are not dominated by their definitions. See: + http://gcc.gnu.org/ml/gcc/2002-03/msg00697.html + */ +int bar(); +int foo() +{ + int a,b,c; + + a = b + c; + b = bar(); + c = bar(); + return a + b + c; +} + diff --git a/test/CodeGen/2002-03-14-QuotesInStrConst.c b/test/CodeGen/2002-03-14-QuotesInStrConst.c new file mode 100644 index 000000000000..de4bdd658078 --- /dev/null +++ b/test/CodeGen/2002-03-14-QuotesInStrConst.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* GCC was not escaping quotes in string constants correctly, so this would + * get emitted: + * %.LC1 = internal global [32 x sbyte] c"*** Word "%s" on line %d is not\00" + */ + +const char *Foo() { + return "*** Word \"%s\" on line %d is not"; +} diff --git a/test/CodeGen/2002-04-07-SwitchStmt.c b/test/CodeGen/2002-04-07-SwitchStmt.c new file mode 100644 index 000000000000..cf1ec79b08a5 --- /dev/null +++ b/test/CodeGen/2002-04-07-SwitchStmt.c @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +int printf(const char *, ...); +int foo(); + +int main() { + while (foo()) { + switch (foo()) { + case 0: + case 1: + case 2: + case 3: + printf("3"); + case 4: printf("4"); + case 5: + case 6: + default: + break; + } + } + return 0; +} diff --git a/test/CodeGen/2002-04-08-LocalArray.c b/test/CodeGen/2002-04-08-LocalArray.c new file mode 100644 index 000000000000..9b5ef7921456 --- /dev/null +++ b/test/CodeGen/2002-04-08-LocalArray.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* GCC is not outputting the static array to the LLVM backend, so bad things + * happen. Note that if this is defined static, everything seems fine. + */ +double test(unsigned X) { + double student_t[30]={0.0 , 12.706 , 4.303 , 3.182 , 2.776 , 2.571 , + 2.447 , 2.365 , 2.306 , 2.262 , 2.228 , + 2.201 , 2.179 , 2.160 , 2.145 , 2.131 , + 2.120 , 2.110 , 2.101 , 2.093 , 2.086 , + 2.080 , 2.074 , 2.069 , 2.064 , 2.060 , + 2.056 , 2.052 , 2.048 , 2.045 }; + return student_t[X]; +} diff --git a/test/CodeGen/2002-04-09-StructRetVal.c b/test/CodeGen/2002-04-09-StructRetVal.c new file mode 100644 index 000000000000..f043ab721095 --- /dev/null +++ b/test/CodeGen/2002-04-09-StructRetVal.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct S { + int i; + short s1, s2; +}; + +struct S func_returning_struct(void); + +void loop(void) { + func_returning_struct(); +} diff --git a/test/CodeGen/2002-04-10-StructParameters.c b/test/CodeGen/2002-04-10-StructParameters.c new file mode 100644 index 000000000000..72cebc64481f --- /dev/null +++ b/test/CodeGen/2002-04-10-StructParameters.c @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +typedef struct { + char p; + short q; + char r; + int X; + short Y, Z; + int Q; +} foo; + +int test(foo X, float); +int testE(char,short,char,int,int,float); +void test3(foo *X) { + X->q = 1; +} + +void test2(foo Y) { + testE(Y.p, Y.q, Y.r, Y.X, Y.Y, 0.1f); + test(Y, 0.1f); + test2(Y); + test3(&Y); +} + diff --git a/test/CodeGen/2002-05-23-StaticValues.c b/test/CodeGen/2002-05-23-StaticValues.c new file mode 100644 index 000000000000..b8c25b73c71f --- /dev/null +++ b/test/CodeGen/2002-05-23-StaticValues.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* Make sure the frontend is correctly marking static stuff as internal! */ + +int X; +static int Y = 12; + +static void foo(int Z) { + Y = Z; +} + +void *test() { + foo(12); + return &Y; +} diff --git a/test/CodeGen/2002-05-23-TypeNameCollision.c b/test/CodeGen/2002-05-23-TypeNameCollision.c new file mode 100644 index 000000000000..c15c952e7797 --- /dev/null +++ b/test/CodeGen/2002-05-23-TypeNameCollision.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* Testcase for when struct tag conflicts with typedef name... grr */ + +typedef struct foo { + struct foo *X; + int Y; +} * foo; + +foo F1; +struct foo *F2; + +enum bar { test1, test2 }; + +typedef float bar; + +enum bar B1; +bar B2; + diff --git a/test/CodeGen/2002-05-24-Alloca.c b/test/CodeGen/2002-05-24-Alloca.c new file mode 100644 index 000000000000..30ba8bb8e218 --- /dev/null +++ b/test/CodeGen/2002-05-24-Alloca.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +typedef __SIZE_TYPE__ size_t; +void *alloca(size_t size); +char *strcpy(char *restrict s1, const char *restrict s2); +int puts(const char *s); +int main(int argc, char **argv) { + char *C = (char*)alloca(argc); + strcpy(C, argv[0]); + puts(C); +} diff --git a/test/CodeGen/2002-06-25-FWriteInterfaceFailure.c b/test/CodeGen/2002-06-25-FWriteInterfaceFailure.c new file mode 100644 index 000000000000..24c67d1520a1 --- /dev/null +++ b/test/CodeGen/2002-06-25-FWriteInterfaceFailure.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +typedef struct _IO_FILE FILE; +extern FILE *stderr; +int fprintf(FILE * restrict stream, const char * restrict format, ...); + +void test() { + fprintf(stderr, "testing\n"); +} diff --git a/test/CodeGen/2002-07-14-MiscListTests.c b/test/CodeGen/2002-07-14-MiscListTests.c new file mode 100644 index 000000000000..901701a17654 --- /dev/null +++ b/test/CodeGen/2002-07-14-MiscListTests.c @@ -0,0 +1,71 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +// 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/CodeGen/2002-07-14-MiscTests.c b/test/CodeGen/2002-07-14-MiscTests.c new file mode 100644 index 000000000000..2a651248b55c --- /dev/null +++ b/test/CodeGen/2002-07-14-MiscTests.c @@ -0,0 +1,57 @@ +// RUN: %clang_cc1 -w -emit-llvm %s -o /dev/null + +/* 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/CodeGen/2002-07-14-MiscTests2.c b/test/CodeGen/2002-07-14-MiscTests2.c new file mode 100644 index 000000000000..ad1301766d3a --- /dev/null +++ b/test/CodeGen/2002-07-14-MiscTests2.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +// Test ?: in function calls +extern fp(int, char*); +char *Ext; +void +__bb_exit_func (void) +{ + fp (12, Ext ? Ext : "<none>"); +} + + diff --git a/test/CodeGen/2002-07-14-MiscTests3.c b/test/CodeGen/2002-07-14-MiscTests3.c new file mode 100644 index 000000000000..f7ded4e720de --- /dev/null +++ b/test/CodeGen/2002-07-14-MiscTests3.c @@ -0,0 +1,182 @@ +// RUN: %clang_cc1 -w -emit-llvm %s -o /dev/null + +void *malloc(unsigned); +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)); + } + } +} diff --git a/test/CodeGen/2002-07-16-HardStringInit.c b/test/CodeGen/2002-07-16-HardStringInit.c new file mode 100644 index 000000000000..b307359b0fc9 --- /dev/null +++ b/test/CodeGen/2002-07-16-HardStringInit.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + char auto_kibitz_list[100][20] = { + {"diepx"}, + {"ferret"}, + {"knightc"}, + {"knightcap"}}; + diff --git a/test/CodeGen/2002-07-17-StringConstant.c b/test/CodeGen/2002-07-17-StringConstant.c new file mode 100644 index 000000000000..5b86a5b7dff6 --- /dev/null +++ b/test/CodeGen/2002-07-17-StringConstant.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +char * foo() { return "\\begin{"; } diff --git a/test/CodeGen/2002-07-30-SubregSetAssertion.c b/test/CodeGen/2002-07-30-SubregSetAssertion.c new file mode 100644 index 000000000000..39e97b3b4aec --- /dev/null +++ b/test/CodeGen/2002-07-30-SubregSetAssertion.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +union X { + void *B; +}; + +union X foo() { + union X A; + A.B = (void*)123; + return A; +} diff --git a/test/CodeGen/2002-07-30-UnionTest.c b/test/CodeGen/2002-07-30-UnionTest.c new file mode 100644 index 000000000000..d5b92e710657 --- /dev/null +++ b/test/CodeGen/2002-07-30-UnionTest.c @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +union X; +struct Empty {}; +union F {}; +union Q { union Q *X; }; +union X { + char C; + int A, Z; + long long B; + void *b1; + struct { int A; long long Z; } Q; +}; + +union X foo(union X A) { + A.C = 123; + A.A = 39249; + //A.B = (void*)123040123321; + A.B = 12301230123123LL; + A.Z = 1; + return A; +} diff --git a/test/CodeGen/2002-07-30-VarArgsCallFailure.c b/test/CodeGen/2002-07-30-VarArgsCallFailure.c new file mode 100644 index 000000000000..784305d6d3b6 --- /dev/null +++ b/test/CodeGen/2002-07-30-VarArgsCallFailure.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +int tcount; +void test(char *, const char*, int); +void foo() { + char Buf[10]; + test(Buf, "n%%%d", tcount++); +} diff --git a/test/CodeGen/2002-07-31-BadAssert.c b/test/CodeGen/2002-07-31-BadAssert.c new file mode 100644 index 000000000000..512a63a09a29 --- /dev/null +++ b/test/CodeGen/2002-07-31-BadAssert.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +typedef struct +{ + unsigned char type; /* Indicates, NORMAL, SUBNORMAL, etc. */ +} InternalFPF; + + +static void SetInternalFPFZero(InternalFPF *dest) { + dest->type=0; +} + +void denormalize(InternalFPF *ptr) { + SetInternalFPFZero(ptr); +} + diff --git a/test/CodeGen/2002-07-31-SubregFailure.c b/test/CodeGen/2002-07-31-SubregFailure.c new file mode 100644 index 000000000000..5c7f38f00579 --- /dev/null +++ b/test/CodeGen/2002-07-31-SubregFailure.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +typedef union { + long (*ap)[4]; +} ptrs; + +void DoAssignIteration() { + ptrs abase; + abase.ap+=27; + Assignment(*abase.ap); +} + + diff --git a/test/CodeGen/2002-08-02-UnionTest.c b/test/CodeGen/2002-08-02-UnionTest.c new file mode 100644 index 000000000000..2be149909be5 --- /dev/null +++ b/test/CodeGen/2002-08-02-UnionTest.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* In this testcase, the return value of foo() is being promoted to a register + * which breaks stuff + */ +int printf(const char * restrict format, ...); + +union X { char X; void *B; int a, b, c, d;}; + +union X foo() { + union X Global; + Global.B = (void*)123; /* Interesting part */ + return Global; +} + +int main() { + union X test = foo(); + printf("0x%p", test.B); +} diff --git a/test/CodeGen/2002-08-19-RecursiveLocals.c b/test/CodeGen/2002-08-19-RecursiveLocals.c new file mode 100644 index 000000000000..89c67bad663a --- /dev/null +++ b/test/CodeGen/2002-08-19-RecursiveLocals.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* This testcase doesn't actually test a bug, it's just the result of me + * figuring out the syntax for forward declaring a static variable. */ +struct list { + int x; + struct list *Next; +}; + +static struct list B; /* Forward declare static */ +static struct list A = { 7, &B }; +static struct list B = { 8, &A }; + +extern struct list D; /* forward declare normal var */ + +struct list C = { 7, &D }; +struct list D = { 8, &C }; + diff --git a/test/CodeGen/2002-09-08-PointerShifts.c b/test/CodeGen/2002-09-08-PointerShifts.c new file mode 100644 index 000000000000..7d1ba6e90fe4 --- /dev/null +++ b/test/CodeGen/2002-09-08-PointerShifts.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +int foo(int *A, unsigned X) { + return A[X]; +} diff --git a/test/CodeGen/2002-09-18-UnionProblem.c b/test/CodeGen/2002-09-18-UnionProblem.c new file mode 100644 index 000000000000..d299c19009ca --- /dev/null +++ b/test/CodeGen/2002-09-18-UnionProblem.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +struct DWstruct { + char high, low; +}; + +typedef union { + struct DWstruct s; + short ll; +} DWunion; + +short __udivmodhi4 (char n1, char bm) { + DWunion rr; + + if (bm == 0) + { + rr.s.high = n1; + } + else + { + rr.s.high = bm; + } + + return rr.ll; +} diff --git a/test/CodeGen/2002-09-19-StarInLabel.c b/test/CodeGen/2002-09-19-StarInLabel.c new file mode 100644 index 000000000000..e046e2b00297 --- /dev/null +++ b/test/CodeGen/2002-09-19-StarInLabel.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +extern void start() __asm__("start"); +extern void _start() __asm__("_start"); +extern void __start() __asm__("__start"); +void start() {} +void _start() {} +void __start() {} + diff --git a/test/CodeGen/2002-10-12-TooManyArguments.c b/test/CodeGen/2002-10-12-TooManyArguments.c new file mode 100644 index 000000000000..2324c2aa4662 --- /dev/null +++ b/test/CodeGen/2002-10-12-TooManyArguments.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +void foo() {} + +void bar() { + foo(1, 2, 3); /* Too many arguments passed */ +} diff --git a/test/CodeGen/2002-12-15-GlobalBoolTest.c b/test/CodeGen/2002-12-15-GlobalBoolTest.c new file mode 100644 index 000000000000..3c4133f4be73 --- /dev/null +++ b/test/CodeGen/2002-12-15-GlobalBoolTest.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +_Bool X = 0; + diff --git a/test/CodeGen/2002-12-15-GlobalConstantTest.c b/test/CodeGen/2002-12-15-GlobalConstantTest.c new file mode 100644 index 000000000000..8203f569625d --- /dev/null +++ b/test/CodeGen/2002-12-15-GlobalConstantTest.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +const char *W = "foo"; +const int X = 7; +int Y = 8; +const char * const Z = "bar"; + diff --git a/test/CodeGen/2002-12-15-GlobalRedefinition.c b/test/CodeGen/2002-12-15-GlobalRedefinition.c new file mode 100644 index 000000000000..646e91ec3dfa --- /dev/null +++ b/test/CodeGen/2002-12-15-GlobalRedefinition.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +extern char algbrfile[9]; +char algbrfile[9] = "abcdefgh"; + diff --git a/test/CodeGen/2002-12-15-StructParameters.c b/test/CodeGen/2002-12-15-StructParameters.c new file mode 100644 index 000000000000..f6b59de7f0a6 --- /dev/null +++ b/test/CodeGen/2002-12-15-StructParameters.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +typedef struct +{ + void *stack; + unsigned size; + unsigned avail; +} compile_stack_type; + +void foo(void*); +void bar(compile_stack_type T, unsigned); + +void test() { + compile_stack_type CST; + foo(&CST); + + bar(CST, 12); +} diff --git a/test/CodeGen/2003-01-30-UnionInit.c b/test/CodeGen/2003-01-30-UnionInit.c new file mode 100644 index 000000000000..98aee727b4ec --- /dev/null +++ b/test/CodeGen/2003-01-30-UnionInit.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +union foo { + struct { char A, B; } X; + int C; +}; + +union foo V = { {1, 2} }; diff --git a/test/CodeGen/2003-03-03-DeferredType.c b/test/CodeGen/2003-03-03-DeferredType.c new file mode 100644 index 000000000000..a7a4ce38e635 --- /dev/null +++ b/test/CodeGen/2003-03-03-DeferredType.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + + + +struct foo A; + +struct foo { + int x; +double D; +}; + diff --git a/test/CodeGen/2003-06-22-UnionCrash.c b/test/CodeGen/2003-06-22-UnionCrash.c new file mode 100644 index 000000000000..eb5014c37e7d --- /dev/null +++ b/test/CodeGen/2003-06-22-UnionCrash.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct Blend_Map_Entry { + union { + float Colour[5]; + double Point_Slope[2]; + } Vals; +}; + +void test(struct Blend_Map_Entry* Foo) +{ +} + diff --git a/test/CodeGen/2003-06-23-GCC-fold-infinite-recursion.c b/test/CodeGen/2003-06-23-GCC-fold-infinite-recursion.c new file mode 100644 index 000000000000..51d4824681a8 --- /dev/null +++ b/test/CodeGen/2003-06-23-GCC-fold-infinite-recursion.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +double Test(double A, double B, double C, double D) { + return -(A-B) - (C-D); +} + diff --git a/test/CodeGen/2003-06-26-CFECrash.c b/test/CodeGen/2003-06-26-CFECrash.c new file mode 100644 index 000000000000..dd874b7b4547 --- /dev/null +++ b/test/CodeGen/2003-06-26-CFECrash.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +typedef struct min_info { + long offset; + unsigned file_attr; +} min_info; + +typedef struct Globals { + char answerbuf; + min_info info[1]; + min_info *pInfo; +} Uz_Globs; + +extern Uz_Globs G; + +int extract_or_test_files() { + G.pInfo = G.info; +} + diff --git a/test/CodeGen/2003-06-29-MultipleFunctionDefinition.c b/test/CodeGen/2003-06-29-MultipleFunctionDefinition.c new file mode 100644 index 000000000000..99b3a7f5ba36 --- /dev/null +++ b/test/CodeGen/2003-06-29-MultipleFunctionDefinition.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -std=gnu89 -emit-llvm %s -o /dev/null + +/* This is apparently legal C. + */ +extern __inline__ void test() { } + +void test() { +} diff --git a/test/CodeGen/2003-07-22-ArrayAccessTypeSafety.c b/test/CodeGen/2003-07-22-ArrayAccessTypeSafety.c new file mode 100644 index 000000000000..d0703ef5e914 --- /dev/null +++ b/test/CodeGen/2003-07-22-ArrayAccessTypeSafety.c @@ -0,0 +1,7 @@ +/* RUN: %clang_cc1 %s -emit-llvm -o - | grep -v alloca | not grep bitcast + */ + +void test(int* array, long long N) { + array[N] = N[array] = 33; +} + diff --git a/test/CodeGen/2003-08-06-BuiltinSetjmpLongjmp.c b/test/CodeGen/2003-08-06-BuiltinSetjmpLongjmp.c new file mode 100644 index 000000000000..12bce268cfac --- /dev/null +++ b/test/CodeGen/2003-08-06-BuiltinSetjmpLongjmp.c @@ -0,0 +1,14 @@ +/* RUN: %clang_cc1 %s -emit-llvm -o - | not grep __builtin_ + * + * __builtin_longjmp/setjmp should get transformed into llvm.setjmp/longjmp + * just like explicit setjmp/longjmp calls are. + */ + +void jumpaway(int *ptr) { + __builtin_longjmp(ptr,1); +} + +int main(void) { + __builtin_setjmp(0); + jumpaway(0); +} diff --git a/test/CodeGen/2003-08-17-DeadCodeShortCircuit.c b/test/CodeGen/2003-08-17-DeadCodeShortCircuit.c new file mode 100644 index 000000000000..031b530672a3 --- /dev/null +++ b/test/CodeGen/2003-08-17-DeadCodeShortCircuit.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -x c %s -emit-llvm -o /dev/null + +int test(_Bool pos, _Bool color) { + return 0; + return (pos && color); +} diff --git a/test/CodeGen/2003-08-18-SigSetJmp.c b/test/CodeGen/2003-08-18-SigSetJmp.c new file mode 100644 index 000000000000..1b1b18f6eecc --- /dev/null +++ b/test/CodeGen/2003-08-18-SigSetJmp.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o /dev/null + +#define _JBLEN ((9 * 2) + 3 + 16) +typedef int sigjmp_buf[_JBLEN + 1]; +int sigsetjmp(sigjmp_buf env, int savemask); +sigjmp_buf B; +int foo() { + sigsetjmp(B, 1); + bar(); +} diff --git a/test/CodeGen/2003-08-18-StructAsValue.c b/test/CodeGen/2003-08-18-StructAsValue.c new file mode 100644 index 000000000000..9b8b5a2b1c19 --- /dev/null +++ b/test/CodeGen/2003-08-18-StructAsValue.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +typedef struct { + int op; +} event_t; + +event_t test(int X) { + event_t foo = { 1 }, bar = { 2 }; + return X ? foo : bar; +} diff --git a/test/CodeGen/2003-08-20-BadBitfieldRef.c b/test/CodeGen/2003-08-20-BadBitfieldRef.c new file mode 100644 index 000000000000..a001546fb55d --- /dev/null +++ b/test/CodeGen/2003-08-20-BadBitfieldRef.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +void foo() +{ + char *ap; + ap[1] == '-' && ap[2] == 0; +} + diff --git a/test/CodeGen/2003-08-20-PrototypeMismatch.c b/test/CodeGen/2003-08-20-PrototypeMismatch.c new file mode 100644 index 000000000000..fa42ca581a0a --- /dev/null +++ b/test/CodeGen/2003-08-20-PrototypeMismatch.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + + +static int foo(int); + +static int foo(C) +char C; +{ + return C; +} + +void test() { + foo(7); +} diff --git a/test/CodeGen/2003-08-20-vfork-bug.c b/test/CodeGen/2003-08-20-vfork-bug.c new file mode 100644 index 000000000000..7ec0048828c1 --- /dev/null +++ b/test/CodeGen/2003-08-20-vfork-bug.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +extern int vfork(void); +test() { + vfork(); +} diff --git a/test/CodeGen/2003-08-21-BinOp-Type-Mismatch.c b/test/CodeGen/2003-08-21-BinOp-Type-Mismatch.c new file mode 100644 index 000000000000..d86b0244e17b --- /dev/null +++ b/test/CodeGen/2003-08-21-BinOp-Type-Mismatch.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct bar; + +void foo() +{ + unsigned int frame, focus; + (struct bar *) focus == (focus ? ((struct bar *) frame) : 0); +} + diff --git a/test/CodeGen/2003-08-21-StmtExpr.c b/test/CodeGen/2003-08-21-StmtExpr.c new file mode 100644 index 000000000000..39db694400d8 --- /dev/null +++ b/test/CodeGen/2003-08-21-StmtExpr.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +typedef struct { + unsigned long val; +} structty; + +void bar(structty new_mask); +static void foo() { + bar(({ structty mask; mask; })); +} + diff --git a/test/CodeGen/2003-08-21-WideString.c b/test/CodeGen/2003-08-21-WideString.c new file mode 100644 index 000000000000..4071d17c7970 --- /dev/null +++ b/test/CodeGen/2003-08-21-WideString.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +// This bit is taken from Sema/wchar.c so we can avoid the wchar.h include. +typedef __WCHAR_TYPE__ wchar_t; +#if defined(_WIN32) || defined(_M_IX86) || defined(__CYGWIN__) \ + || defined(_M_X64) || defined(SHORT_WCHAR) + #define WCHAR_T_TYPE unsigned short +#elif defined(__sun) || defined(__AuroraUX__) + #define WCHAR_T_TYPE long +#else /* Solaris or AuroraUX. */ + #define WCHAR_T_TYPE int +#endif + +struct { + wchar_t *name; +} syms = { L"NUL" }; diff --git a/test/CodeGen/2003-08-23-LocalUnionTest.c b/test/CodeGen/2003-08-23-LocalUnionTest.c new file mode 100644 index 000000000000..50b01e425878 --- /dev/null +++ b/test/CodeGen/2003-08-23-LocalUnionTest.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + + +union foo { int X; }; + +int test(union foo* F) { + { + union foo { float X; } A; + } +} diff --git a/test/CodeGen/2003-08-29-BitFieldStruct.c b/test/CodeGen/2003-08-29-BitFieldStruct.c new file mode 100644 index 000000000000..d8995eab3df9 --- /dev/null +++ b/test/CodeGen/2003-08-29-BitFieldStruct.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct Word { + short bar; + short baz; + int final:1; + short quux; +} *word_limit; + +void foo () +{ + word_limit->final = (word_limit->final && word_limit->final); +} diff --git a/test/CodeGen/2003-08-29-HugeCharConst.c b/test/CodeGen/2003-08-29-HugeCharConst.c new file mode 100644 index 000000000000..cd3eb54b31d4 --- /dev/null +++ b/test/CodeGen/2003-08-29-HugeCharConst.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +void foo() { + unsigned char int_latin1[] = "f\200\372b\200\343\200\340"; +} diff --git a/test/CodeGen/2003-08-29-StructLayoutBug.c b/test/CodeGen/2003-08-29-StructLayoutBug.c new file mode 100644 index 000000000000..0f45fc94e340 --- /dev/null +++ b/test/CodeGen/2003-08-29-StructLayoutBug.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct foo { + unsigned int I:1; + unsigned char J[1]; + unsigned int K:1; + }; + +void test(struct foo *X) {} + diff --git a/test/CodeGen/2003-08-30-AggregateInitializer.c b/test/CodeGen/2003-08-30-AggregateInitializer.c new file mode 100644 index 000000000000..5beb14e5f8f0 --- /dev/null +++ b/test/CodeGen/2003-08-30-AggregateInitializer.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct istruct { + unsigned char C; +}; + +struct foo { + unsigned int I:1; + struct istruct J; + unsigned char L[1]; + unsigned int K:1; +}; + +struct foo F = { 1, { 7 }, { 123 } , 1 }; + + diff --git a/test/CodeGen/2003-08-30-LargeIntegerBitfieldMember.c b/test/CodeGen/2003-08-30-LargeIntegerBitfieldMember.c new file mode 100644 index 000000000000..483cb668a28b --- /dev/null +++ b/test/CodeGen/2003-08-30-LargeIntegerBitfieldMember.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct foo { + unsigned int I:1; + unsigned char J[1][123]; + unsigned int K:1; + }; + +struct foo F; diff --git a/test/CodeGen/2003-09-18-BitfieldTests.c b/test/CodeGen/2003-09-18-BitfieldTests.c new file mode 100644 index 000000000000..6807f5a1fa4d --- /dev/null +++ b/test/CodeGen/2003-09-18-BitfieldTests.c @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -w -emit-llvm %s -o /dev/null + + +typedef struct BF { + int A : 1; + char B; + int C : 13; +} BF; + +char *test1(BF *b) { + return &b->B; // Must be able to address non-bitfield +} + +void test2(BF *b) { // Increment and decrement operators + b->A++; + --b->C; +} + +void test3(BF *b) { + b->C = 12345; // Store +} + +int test4(BF *b) { + return b->C; // Load +} + +void test5(BF *b, int i) { // array ref + b[i].C = 12345; +} + diff --git a/test/CodeGen/2003-09-30-StructLayout.c b/test/CodeGen/2003-09-30-StructLayout.c new file mode 100644 index 000000000000..45ef69ce60f8 --- /dev/null +++ b/test/CodeGen/2003-09-30-StructLayout.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +enum En { + ENUM_VAL +}; + +struct St { + unsigned char A; + enum En B; + unsigned char C; + enum En D; + float E; +}; + + +void func(struct St* A) { + A->D = ENUM_VAL; +} diff --git a/test/CodeGen/2003-10-02-UnionLValueError.c b/test/CodeGen/2003-10-02-UnionLValueError.c new file mode 100644 index 000000000000..180eb1080be9 --- /dev/null +++ b/test/CodeGen/2003-10-02-UnionLValueError.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +int sprintf(char * restrict str, const char * restrict format, ...); +union U{ + int i[8]; + char s[80]; +}; + +void format_message(char *buffer, union U *u) { + sprintf(buffer, u->s); +} diff --git a/test/CodeGen/2003-10-06-NegateExprType.c b/test/CodeGen/2003-10-06-NegateExprType.c new file mode 100644 index 000000000000..6d692c1323de --- /dev/null +++ b/test/CodeGen/2003-10-06-NegateExprType.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +extern int A[10]; +void Func(int *B) { + B - &A[5]; +} + diff --git a/test/CodeGen/2003-10-09-UnionInitializerBug.c b/test/CodeGen/2003-10-09-UnionInitializerBug.c new file mode 100644 index 000000000000..a14fd084c699 --- /dev/null +++ b/test/CodeGen/2003-10-09-UnionInitializerBug.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct Foo { + unsigned a; + unsigned b; + unsigned c; +}; + +struct Bar { + union { + void **a; + struct Foo b; + }u; +}; + +struct Bar test = {0}; + diff --git a/test/CodeGen/2003-10-28-ident.c b/test/CodeGen/2003-10-28-ident.c new file mode 100644 index 000000000000..d1e54476b9ad --- /dev/null +++ b/test/CodeGen/2003-10-28-ident.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +#ident "foo" diff --git a/test/CodeGen/2003-10-29-AsmRename.c b/test/CodeGen/2003-10-29-AsmRename.c new file mode 100644 index 000000000000..d0f19af32276 --- /dev/null +++ b/test/CodeGen/2003-10-29-AsmRename.c @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-apple-darwin -o /dev/null + + +struct foo { int X; }; +struct bar { int Y; }; + +extern int Func(struct foo*) __asm__("Func64"); +extern int Func64(struct bar*); + +int Func(struct foo *F) { + return 1; +} + +int Func64(struct bar* B) { + return 0; +} + + +int test() { + Func(0); /* should be renamed to call Func64 */ + Func64(0); +} diff --git a/test/CodeGen/2003-11-01-C99-CompoundLiteral.c b/test/CodeGen/2003-11-01-C99-CompoundLiteral.c new file mode 100644 index 000000000000..f4d3824fa647 --- /dev/null +++ b/test/CodeGen/2003-11-01-C99-CompoundLiteral.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +typedef struct { int foo; } spinlock_t; +typedef struct wait_queue_head_t { spinlock_t lock; } wait_queue_head_t; +void call_usermodehelper(void) { + struct wait_queue_head_t work = { lock: (spinlock_t) { 0 }, }; +} + diff --git a/test/CodeGen/2003-11-01-EmptyStructCrash.c b/test/CodeGen/2003-11-01-EmptyStructCrash.c new file mode 100644 index 000000000000..e0f231af5994 --- /dev/null +++ b/test/CodeGen/2003-11-01-EmptyStructCrash.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +typedef struct { } the_coolest_struct_in_the_world; +extern the_coolest_struct_in_the_world xyzzy; +void *foo() { return &xyzzy; } + diff --git a/test/CodeGen/2003-11-01-GlobalUnionInit.c b/test/CodeGen/2003-11-01-GlobalUnionInit.c new file mode 100644 index 000000000000..8290379494b6 --- /dev/null +++ b/test/CodeGen/2003-11-01-GlobalUnionInit.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +union bdflush_param { + struct { int x; } b_un; + int y[1]; +} bdf_prm = {{30}}; + diff --git a/test/CodeGen/2003-11-03-AddrArrayElement.c b/test/CodeGen/2003-11-03-AddrArrayElement.c new file mode 100644 index 000000000000..50e81d6fd86a --- /dev/null +++ b/test/CodeGen/2003-11-03-AddrArrayElement.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// This should be turned into a tasty getelementptr instruction, not a nasty +// series of casts and address arithmetic. + +char Global[100]; + +char *test1(unsigned i) { + // CHECK: getelementptr + return &Global[i]; +} diff --git a/test/CodeGen/2003-11-04-EmptyStruct.c b/test/CodeGen/2003-11-04-EmptyStruct.c new file mode 100644 index 000000000000..e771b8830070 --- /dev/null +++ b/test/CodeGen/2003-11-04-EmptyStruct.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +typedef struct { } rwlock_t; +struct fs_struct { rwlock_t lock; int umask; }; +void __copy_fs_struct(struct fs_struct *fs) { fs->lock = (rwlock_t) { }; } + diff --git a/test/CodeGen/2003-11-04-OutOfMemory.c b/test/CodeGen/2003-11-04-OutOfMemory.c new file mode 100644 index 000000000000..579c93daae58 --- /dev/null +++ b/test/CodeGen/2003-11-04-OutOfMemory.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +void schedule_timeout(signed long timeout) +{ + switch (timeout) + { + case ((long)(~0UL>>1)): break; + } +} diff --git a/test/CodeGen/2003-11-08-PointerSubNotGetelementptr.c b/test/CodeGen/2003-11-08-PointerSubNotGetelementptr.c new file mode 100644 index 000000000000..9a9c642f11a5 --- /dev/null +++ b/test/CodeGen/2003-11-08-PointerSubNotGetelementptr.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +char *test(char* C) { + // CHECK: getelementptr + return C-1; // Should turn into a GEP +} + +int *test2(int* I) { + return I-1; +} diff --git a/test/CodeGen/2003-11-12-VoidString.c b/test/CodeGen/2003-11-12-VoidString.c new file mode 100644 index 000000000000..d22e9f45cbd1 --- /dev/null +++ b/test/CodeGen/2003-11-12-VoidString.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +void query_newnamebuf(void) { ((void)"query_newnamebuf"); } + diff --git a/test/CodeGen/2003-11-13-TypeSafety.c b/test/CodeGen/2003-11-13-TypeSafety.c new file mode 100644 index 000000000000..b9add6c175a3 --- /dev/null +++ b/test/CodeGen/2003-11-13-TypeSafety.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | grep getelementptr + +int *test(int *X, int Y) { + return X + Y; +} diff --git a/test/CodeGen/2003-11-16-StaticArrayInit.c b/test/CodeGen/2003-11-16-StaticArrayInit.c new file mode 100644 index 000000000000..8a11c05d08db --- /dev/null +++ b/test/CodeGen/2003-11-16-StaticArrayInit.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +void bar () { + static char x[10]; + static char *xend = x + 10; +} + + diff --git a/test/CodeGen/2003-11-18-CondExprLValue.c b/test/CodeGen/2003-11-18-CondExprLValue.c new file mode 100644 index 000000000000..62968e5fbfc9 --- /dev/null +++ b/test/CodeGen/2003-11-18-CondExprLValue.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +typedef struct { unsigned long pgprot; } pgprot_t; + +void split_large_page(unsigned long addr, pgprot_t prot) +{ + (addr ? prot : ((pgprot_t) { 0x001 } )).pgprot; +} + diff --git a/test/CodeGen/2003-11-19-AddressOfRegister.c b/test/CodeGen/2003-11-19-AddressOfRegister.c new file mode 100644 index 000000000000..e80ff654cff2 --- /dev/null +++ b/test/CodeGen/2003-11-19-AddressOfRegister.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -emit-llvm -o /dev/null + +struct item { + short delta[4]; +}; + +int TEST(int nt) { + register struct item *aa; + aa[nt].delta; + return 1; +} diff --git a/test/CodeGen/2003-11-19-BitFieldArray.c b/test/CodeGen/2003-11-19-BitFieldArray.c new file mode 100644 index 000000000000..841156306193 --- /dev/null +++ b/test/CodeGen/2003-11-19-BitFieldArray.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct _GIOChannel { + int write_buf; + char partial_write_buf[6]; + int d :1; +}; + +void g_io_channel_init (struct _GIOChannel *channel) { + channel->partial_write_buf[0]; +} + diff --git a/test/CodeGen/2003-11-20-Bitfields.c b/test/CodeGen/2003-11-20-Bitfields.c new file mode 100644 index 000000000000..5284cde4a946 --- /dev/null +++ b/test/CodeGen/2003-11-20-Bitfields.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct face_cachel { + unsigned int reverse :1; + unsigned char font_specified[1]; +}; + +void +ensure_face_cachel_contains_charset (struct face_cachel *cachel) { + cachel->font_specified[0] = 0; +} + diff --git a/test/CodeGen/2003-11-20-ComplexDivision.c b/test/CodeGen/2003-11-20-ComplexDivision.c new file mode 100644 index 000000000000..ecd780b9b3f8 --- /dev/null +++ b/test/CodeGen/2003-11-20-ComplexDivision.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +int test() { + __complex__ double C; + double D; + C / D; +} diff --git a/test/CodeGen/2003-11-20-UnionBitfield.c b/test/CodeGen/2003-11-20-UnionBitfield.c new file mode 100644 index 000000000000..6ffe76a17197 --- /dev/null +++ b/test/CodeGen/2003-11-20-UnionBitfield.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct printf_spec { + unsigned int minus_flag:1; + char converter; +}; + +void parse_doprnt_spec () { + struct printf_spec spec; + spec.minus_flag = 1; +} + diff --git a/test/CodeGen/2003-11-26-PointerShift.c b/test/CodeGen/2003-11-26-PointerShift.c new file mode 100644 index 000000000000..530759eb0c10 --- /dev/null +++ b/test/CodeGen/2003-11-26-PointerShift.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +unsigned long do_csum(const unsigned char *buff, int len, unsigned long result) { + if (2 & (unsigned long) buff) result += 1; + return result; +} diff --git a/test/CodeGen/2003-11-27-ConstructorCast.c b/test/CodeGen/2003-11-27-ConstructorCast.c new file mode 100644 index 000000000000..f04fa213b94a --- /dev/null +++ b/test/CodeGen/2003-11-27-ConstructorCast.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct i387_soft_struct { + long cwd; +}; +union i387_union { + struct i387_soft_struct soft; +}; +struct thread_struct { + union i387_union i387; +}; +void _init_task_union(void) { + struct thread_struct thread = (struct thread_struct) { {{0}} }; +} diff --git a/test/CodeGen/2003-11-27-UnionCtorInitialization.c b/test/CodeGen/2003-11-27-UnionCtorInitialization.c new file mode 100644 index 000000000000..ca80173bfdc7 --- /dev/null +++ b/test/CodeGen/2003-11-27-UnionCtorInitialization.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +struct i387_soft_struct { + long cwd; + long twd; + long fip; +}; +union i387_union { + struct i387_soft_struct soft; +}; +struct thread_struct { + union i387_union i387; +}; +void _init_task_union(void) { + struct thread_struct thread = (struct thread_struct) { {{0}} }; +} diff --git a/test/CodeGen/2003-12-14-ExternInlineSupport.c b/test/CodeGen/2003-12-14-ExternInlineSupport.c new file mode 100644 index 000000000000..eb3859c38092 --- /dev/null +++ b/test/CodeGen/2003-12-14-ExternInlineSupport.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -std=gnu89 %s -emit-llvm -o - | not grep dead_function + +extern __inline__ void dead_function() {} diff --git a/test/CodeGen/2004-01-01-UnknownInitSize.c b/test/CodeGen/2004-01-01-UnknownInitSize.c new file mode 100644 index 000000000000..25ddebddccb0 --- /dev/null +++ b/test/CodeGen/2004-01-01-UnknownInitSize.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +/* + * This regression test ensures that the C front end can compile initializers + * even when it cannot determine the size (as below). +*/ +struct one +{ + int a; + int values []; +}; + +struct one hobbit = {5, {1, 2, 3}}; + diff --git a/test/CodeGen/2004-01-08-ExternInlineRedefine.c b/test/CodeGen/2004-01-08-ExternInlineRedefine.c new file mode 100644 index 000000000000..358a9c28f775 --- /dev/null +++ b/test/CodeGen/2004-01-08-ExternInlineRedefine.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -std=gnu89 -emit-llvm %s -o /dev/null + + +extern __inline long int +__strtol_l (int a) +{ + return 0; +} + +long int +__strtol_l (int a) +{ + return 0; +} diff --git a/test/CodeGen/2004-02-12-LargeAggregateCopy.c b/test/CodeGen/2004-02-12-LargeAggregateCopy.c new file mode 100644 index 000000000000..811ee8e3f641 --- /dev/null +++ b/test/CodeGen/2004-02-12-LargeAggregateCopy.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +struct X { int V[10000]; }; +struct X Global1, Global2; +void test() { + // CHECK: llvm.memcpy + Global2 = Global1; +} diff --git a/test/CodeGen/2004-02-13-BuiltinFrameReturnAddress.c b/test/CodeGen/2004-02-13-BuiltinFrameReturnAddress.c new file mode 100644 index 000000000000..8c0b7ba8fff0 --- /dev/null +++ b/test/CodeGen/2004-02-13-BuiltinFrameReturnAddress.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +void *test1() { + // CHECK: call i8* @llvm.returnaddress + return __builtin_return_address(1); +} +void *test2() { + // CHECK: call i8* @llvm.frameaddress + return __builtin_frame_address(0); +} diff --git a/test/CodeGen/2004-02-13-IllegalVararg.c b/test/CodeGen/2004-02-13-IllegalVararg.c new file mode 100644 index 000000000000..cbc9151ec631 --- /dev/null +++ b/test/CodeGen/2004-02-13-IllegalVararg.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -w -emit-llvm -o - + +float test(int X, ...) { + __builtin_va_list ap; + float F; + __builtin_va_start(ap, X); + F = __builtin_va_arg(ap, float); + return F; +} diff --git a/test/CodeGen/2004-02-13-Memset.c b/test/CodeGen/2004-02-13-Memset.c new file mode 100644 index 000000000000..23a4d3b99a45 --- /dev/null +++ b/test/CodeGen/2004-02-13-Memset.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | grep llvm.memset | count 3 + +typedef __SIZE_TYPE__ size_t; +void *memset(void*, int, size_t); +void bzero(void*, size_t); + +void test(int* X, char *Y) { + // CHECK: call i8* llvm.memset + memset(X, 4, 1000); + // CHECK: call void bzero + bzero(Y, 100); +} diff --git a/test/CodeGen/2004-02-14-ZeroInitializer.c b/test/CodeGen/2004-02-14-ZeroInitializer.c new file mode 100644 index 000000000000..3379a06c6284 --- /dev/null +++ b/test/CodeGen/2004-02-14-ZeroInitializer.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// CHECK: zeroinitializer +int X[1000]; diff --git a/test/CodeGen/2004-02-20-Builtins.c b/test/CodeGen/2004-02-20-Builtins.c new file mode 100644 index 000000000000..9be0523b4afd --- /dev/null +++ b/test/CodeGen/2004-02-20-Builtins.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | not grep builtin +double sqrt(double x); +void zsqrtxxx(float num) { + num = sqrt(num); +} diff --git a/test/CodeGen/2004-03-07-ComplexDivEquals.c b/test/CodeGen/2004-03-07-ComplexDivEquals.c new file mode 100644 index 000000000000..e2cd539a80ab --- /dev/null +++ b/test/CodeGen/2004-03-07-ComplexDivEquals.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +void test(__complex__ double D, double X) { + D /= X; +} diff --git a/test/CodeGen/2004-03-07-ExternalConstant.c b/test/CodeGen/2004-03-07-ExternalConstant.c new file mode 100644 index 000000000000..2de3a69bd679 --- /dev/null +++ b/test/CodeGen/2004-03-07-ExternalConstant.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// CHECK: @a = external constan +extern const int a[]; // 'a' should be marked constant even though it's external! +int foo () { + return a[0]; +} diff --git a/test/CodeGen/2004-03-09-LargeArrayInitializers.c b/test/CodeGen/2004-03-09-LargeArrayInitializers.c new file mode 100644 index 000000000000..b34af0d29907 --- /dev/null +++ b/test/CodeGen/2004-03-09-LargeArrayInitializers.c @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +// Test that these initializers are handled efficiently + +int test(int x) { + const int XX[1000] = { 0, 0 }; + const char S [1000] = "foo"; + + const int array[] = { + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, + }; + return array[x]; +} diff --git a/test/CodeGen/2004-03-15-SimpleIndirectGoto.c b/test/CodeGen/2004-03-15-SimpleIndirectGoto.c new file mode 100644 index 000000000000..93fb59ff142e --- /dev/null +++ b/test/CodeGen/2004-03-15-SimpleIndirectGoto.c @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +int code[]={0,0,0,0,1}; +void foo(int x) { + volatile int b; + b = 0xffffffff; +} +void bar(int *pc) { + static const void *l[] = {&&lab0, &&end}; + + foo(0); + goto *l[*pc]; + lab0: + foo(0); + pc++; + goto *l[*pc]; + end: + return; +} +int main() { + bar(code); + return 0; +} diff --git a/test/CodeGen/2004-03-16-AsmRegisterCrash.c b/test/CodeGen/2004-03-16-AsmRegisterCrash.c new file mode 100644 index 000000000000..515d2436b1a8 --- /dev/null +++ b/test/CodeGen/2004-03-16-AsmRegisterCrash.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null +// XFAIL: * +// XTARGET: arm, i386, i686, x86_64 + +int foo() { +#ifdef __arm__ + register int X __asm__("r1"); +#else + register int X __asm__("ebx"); +#endif + return X; +} diff --git a/test/CodeGen/2004-05-07-VarArrays.c b/test/CodeGen/2004-05-07-VarArrays.c new file mode 100644 index 000000000000..1ef5cf32e0b7 --- /dev/null +++ b/test/CodeGen/2004-05-07-VarArrays.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +int foo(int len, char arr[][len], int X) { + return arr[X][0]; +} diff --git a/test/CodeGen/2004-05-21-IncompleteEnum.c b/test/CodeGen/2004-05-21-IncompleteEnum.c new file mode 100644 index 000000000000..41652d11a4fe --- /dev/null +++ b/test/CodeGen/2004-05-21-IncompleteEnum.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -w -emit-llvm %s -o /dev/null + +void test(enum foo *X) { +} + diff --git a/test/CodeGen/2004-06-08-OpaqueStructArg.c b/test/CodeGen/2004-06-08-OpaqueStructArg.c new file mode 100644 index 000000000000..cec44591f398 --- /dev/null +++ b/test/CodeGen/2004-06-08-OpaqueStructArg.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + struct fu; + void foo(struct fu); + void bar() { + foo; + } diff --git a/test/CodeGen/2004-06-17-UnorderedBuiltins.c b/test/CodeGen/2004-06-17-UnorderedBuiltins.c new file mode 100644 index 000000000000..90360c4b58c0 --- /dev/null +++ b/test/CodeGen/2004-06-17-UnorderedBuiltins.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +_Bool A, B, C, D, E, F, G, H; +void TestF(float X, float Y) { + A = __builtin_isgreater(X, Y); + B = __builtin_isgreaterequal(X, Y); + C = __builtin_isless(X, Y); + D = __builtin_islessequal(X, Y); + E = __builtin_islessgreater(X, Y); + F = __builtin_isunordered(X, Y); + //G = __builtin_isordered(X, Y); // Our current snapshot of GCC doesn't include this builtin + H = __builtin_isunordered(X, Y); +} +void TestD(double X, double Y) { + A = __builtin_isgreater(X, Y); + B = __builtin_isgreaterequal(X, Y); + C = __builtin_isless(X, Y); + D = __builtin_islessequal(X, Y); + E = __builtin_islessgreater(X, Y); + F = __builtin_isunordered(X, Y); + //G = __builtin_isordered(X, Y); // Our current snapshot doesn't include this builtin. FIXME + H = __builtin_isunordered(X, Y); +} diff --git a/test/CodeGen/2004-06-17-UnorderedCompares.c b/test/CodeGen/2004-06-17-UnorderedCompares.c new file mode 100644 index 000000000000..7d2ba9614741 --- /dev/null +++ b/test/CodeGen/2004-06-17-UnorderedCompares.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -std=c99 %s -emit-llvm -o - | grep -v llvm.isunordered | not grep call + +_Bool A, B, C, D, E, F; +void TestF(float X, float Y) { + A = __builtin_isgreater(X, Y); + B = __builtin_isgreaterequal(X, Y); + C = __builtin_isless(X, Y); + D = __builtin_islessequal(X, Y); + E = __builtin_islessgreater(X, Y); + F = __builtin_isunordered(X, Y); +} +void TestD(double X, double Y) { + A = __builtin_isgreater(X, Y); + B = __builtin_isgreaterequal(X, Y); + C = __builtin_isless(X, Y); + D = __builtin_islessequal(X, Y); + E = __builtin_islessgreater(X, Y); + F = __builtin_isunordered(X, Y); +} diff --git a/test/CodeGen/2004-06-18-VariableLengthArrayOfStructures.c b/test/CodeGen/2004-06-18-VariableLengthArrayOfStructures.c new file mode 100644 index 000000000000..abf78fb09556 --- /dev/null +++ b/test/CodeGen/2004-06-18-VariableLengthArrayOfStructures.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +struct S { }; + +int xxxx(int a) { + struct S comps[a]; + comps[0]; +} + diff --git a/test/CodeGen/2004-07-06-FunctionCast.c b/test/CodeGen/2004-07-06-FunctionCast.c new file mode 100644 index 000000000000..32931e2fce71 --- /dev/null +++ b/test/CodeGen/2004-07-06-FunctionCast.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +static int unused_func(void) { + return 1; +} + +int foo(void) { + (void)unused_func; /* avoid compiler warning */ + return 2; +} diff --git a/test/CodeGen/2004-08-06-LargeStructTest.c b/test/CodeGen/2004-08-06-LargeStructTest.c new file mode 100644 index 000000000000..ee57f0b5af80 --- /dev/null +++ b/test/CodeGen/2004-08-06-LargeStructTest.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + + +#define A(X) int X; +#define B(X) A(X##0) A(X##1) A(X##2) A(X##3) A(X##4) A(X##5) A(X##6) A(X##7) \ + A(X##8) A(X##9) A(X##A) A(X##B) A(X##C) A(X##D) A(X##E) A(X##F) +#define C(X) B(X##0) B(X##1) B(X##2) B(X##3) B(X##4) B(X##5) B(X##6) B(X##7) \ + B(X##8) B(X##9) B(X##A) B(X##B) B(X##C) B(X##D) B(X##E) B(X##F) + +struct foo { + C(x); // 256 + C(y); // 256 + C(z); +}; + + +int test(struct foo *F) { + return F->xA1 + F->yFF + F->zC4; +} diff --git a/test/CodeGen/2004-11-25-UnnamedBitfieldPadding.c b/test/CodeGen/2004-11-25-UnnamedBitfieldPadding.c new file mode 100644 index 000000000000..a6af2a574411 --- /dev/null +++ b/test/CodeGen/2004-11-25-UnnamedBitfieldPadding.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null +// This is a testcase for PR461 +typedef struct { + unsigned min_align: 1; + unsigned : 1; +} addr_diff_vec_flags; + +addr_diff_vec_flags X; diff --git a/test/CodeGen/2004-11-27-InvalidConstantExpr.c b/test/CodeGen/2004-11-27-InvalidConstantExpr.c new file mode 100644 index 000000000000..431dccffc1a1 --- /dev/null +++ b/test/CodeGen/2004-11-27-InvalidConstantExpr.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | not grep {foo\\* sub} +// This should not produce a subtrace constantexpr of a pointer +struct foo { + int Y; + char X[100]; +} F; + +int test(char *Y) { + return Y - F.X; +} diff --git a/test/CodeGen/2004-11-27-StaticFunctionRedeclare.c b/test/CodeGen/2004-11-27-StaticFunctionRedeclare.c new file mode 100644 index 000000000000..55efa86865de --- /dev/null +++ b/test/CodeGen/2004-11-27-StaticFunctionRedeclare.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | \ +// RUN: opt -std-compile-opts -emit-llvm | not grep {declare i32.*func} + +// There should not be an unresolved reference to func here. Believe it or not, +// the "expected result" is a function named 'func' which is internal and +// referenced by bar(). + +// This is PR244 + +static int func(); +void bar() { + int func(); + foo(func); +} +static int func(char** A, char ** B) {} diff --git a/test/CodeGen/2005-01-02-ConstantInits.c b/test/CodeGen/2005-01-02-ConstantInits.c new file mode 100644 index 000000000000..d85f5198650d --- /dev/null +++ b/test/CodeGen/2005-01-02-ConstantInits.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +// This tests all kinds of hard cases with initializers and +// array subscripts. This corresponds to PR487. + +struct X { int a[2]; }; + +int test() { + static int i23 = (int) &(((struct X *)0)->a[1]); + return i23; +} + +int i = (int) &( ((struct X *)0) -> a[1]); + +int Arr[100]; + +int foo(int i) { return bar(&Arr[49])+bar(&Arr[i]); } +int foo2(int i) { + static const int *X = &Arr[49]; + static int i23 = (int) &( ((struct X *)0) -> a[0]); + int *P = Arr; + ++P; + return bar(Arr+i); +} diff --git a/test/CodeGen/2005-01-02-PointerDifference.c b/test/CodeGen/2005-01-02-PointerDifference.c new file mode 100644 index 000000000000..1114ef5c25de --- /dev/null +++ b/test/CodeGen/2005-01-02-PointerDifference.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// CHECK: sdiv exact +int Diff(int *P, int *Q) { return P-Q; } diff --git a/test/CodeGen/2005-01-02-VAArgError-ICE.c b/test/CodeGen/2005-01-02-VAArgError-ICE.c new file mode 100644 index 000000000000..06377c23d2aa --- /dev/null +++ b/test/CodeGen/2005-01-02-VAArgError-ICE.c @@ -0,0 +1,9 @@ +// This file is erroneous, but should not cause the compiler to ICE. +// PR481 +// RUN: %clang_cc1 %s -emit-llvm -o /dev/null + +int flags(int a, int b, ...) { + __builtin_va_list args; + __builtin_va_start(args,a); // not the last named arg + foo(args); +} diff --git a/test/CodeGen/2005-02-20-AggregateSAVEEXPR.c b/test/CodeGen/2005-02-20-AggregateSAVEEXPR.c new file mode 100644 index 000000000000..99efb1bf79f3 --- /dev/null +++ b/test/CodeGen/2005-02-20-AggregateSAVEEXPR.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 %s -o /dev/null -emit-llvm + +int foo(__complex float c) { + return creal(c); +} diff --git a/test/CodeGen/2005-02-27-MarkGlobalConstant.c b/test/CodeGen/2005-02-27-MarkGlobalConstant.c new file mode 100644 index 000000000000..dc2cdbfa726f --- /dev/null +++ b/test/CodeGen/2005-02-27-MarkGlobalConstant.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s +// PR10414 + +// The synthetic global made by the CFE for big initializer should be marked +// constant. + +void bar(); +void foo() { + // CHECK: private unnamed_addr constant + char Blah[] = "asdlfkajsdlfkajsd;lfkajds;lfkjasd;flkajsd;lkfja;sdlkfjasd"; + bar(Blah); +} diff --git a/test/CodeGen/2005-03-05-OffsetOfHack.c b/test/CodeGen/2005-03-05-OffsetOfHack.c new file mode 100644 index 000000000000..442098107504 --- /dev/null +++ b/test/CodeGen/2005-03-05-OffsetOfHack.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +struct s { + unsigned long int field[0]; +}; + +#define OFFS \ + (((char *) &((struct s *) 0)->field[0]) - (char *) 0) + +int foo[OFFS]; + + diff --git a/test/CodeGen/2005-03-06-OffsetOfStructCrash.c b/test/CodeGen/2005-03-06-OffsetOfStructCrash.c new file mode 100644 index 000000000000..46968bb8db64 --- /dev/null +++ b/test/CodeGen/2005-03-06-OffsetOfStructCrash.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +struct Y {}; +struct XXX { + struct Y F; +}; + +void test1() { + (int)&((struct XXX*)(((void *)0)))->F; +} + +void test2() { + &((struct XXX*)(((void *)0)))->F; +} diff --git a/test/CodeGen/2005-03-11-Prefetch.c b/test/CodeGen/2005-03-11-Prefetch.c new file mode 100644 index 000000000000..8d7d12edcbd2 --- /dev/null +++ b/test/CodeGen/2005-03-11-Prefetch.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +void foo(int *P) { + // CHECK: llvm.prefetch + __builtin_prefetch(P); + __builtin_prefetch(P, 1); +} diff --git a/test/CodeGen/2005-04-09-ComplexOps.c b/test/CodeGen/2005-04-09-ComplexOps.c new file mode 100644 index 000000000000..23716d362c9a --- /dev/null +++ b/test/CodeGen/2005-04-09-ComplexOps.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +#define I 1.0iF + +double __complex test(double X) { return ~-(X*I); } + +_Bool EQ(double __complex A, double __complex B) { return A == B; } +_Bool NE(double __complex A, double __complex B) { return A != B; } diff --git a/test/CodeGen/2005-05-06-CountBuiltins.c b/test/CodeGen/2005-05-06-CountBuiltins.c new file mode 100644 index 000000000000..4c12100dc50c --- /dev/null +++ b/test/CodeGen/2005-05-06-CountBuiltins.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -emit-llvm -o %t +// RUN: not grep call*__builtin %t + +int G, H, I; +void foo(int P) { + G = __builtin_clz(P); + H = __builtin_ctz(P); + I = __builtin_popcount(P); +} + +long long g, h, i; +void fooll(float P) { + g = __builtin_clzll(P); + g = __builtin_clzll(P); + h = __builtin_ctzll(P); + i = __builtin_popcountll(P); +} diff --git a/test/CodeGen/2005-05-10-GlobalUnionInit.c b/test/CodeGen/2005-05-10-GlobalUnionInit.c new file mode 100644 index 000000000000..ddd7f5e92475 --- /dev/null +++ b/test/CodeGen/2005-05-10-GlobalUnionInit.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +union A { // { uint } + union B { double *C; } D; +} E = { { (double*)12312 } }; + diff --git a/test/CodeGen/2005-06-15-ExpandGotoInternalProblem.c b/test/CodeGen/2005-06-15-ExpandGotoInternalProblem.c new file mode 100644 index 000000000000..dd1acc54bc1d --- /dev/null +++ b/test/CodeGen/2005-06-15-ExpandGotoInternalProblem.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -std=c99 %s -emit-llvm -o - | \ +// RUN: opt -std-compile-opts -disable-output +// PR580 + +int X, Y; +int foo() { + int i; + for (i=0; i<100; i++ ) + { + break; + i = ( X || Y ) ; + } +} + diff --git a/test/CodeGen/2005-07-20-SqrtNoErrno.c b/test/CodeGen/2005-07-20-SqrtNoErrno.c new file mode 100644 index 000000000000..f40f61d27f31 --- /dev/null +++ b/test/CodeGen/2005-07-20-SqrtNoErrno.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s +// llvm.sqrt has undefined behavior on negative inputs, so it is +// inappropriate to translate C/C++ sqrt to this. +float sqrtf(float x); +float foo(float X) { + // CHECK: foo + // CHECK: call float @sqrtf(float % + // Check that this is marked readonly when errno is ignored. + return sqrtf(X); +} diff --git a/test/CodeGen/2005-07-26-UnionInitCrash.c b/test/CodeGen/2005-07-26-UnionInitCrash.c new file mode 100644 index 000000000000..557224018123 --- /dev/null +++ b/test/CodeGen/2005-07-26-UnionInitCrash.c @@ -0,0 +1,3 @@ +// PR607 +// RUN: %clang_cc1 %s -emit-llvm -o - +union { char bytes[8]; double alignment; }EQ1 = {0,0,0,0,0,0,0,0}; diff --git a/test/CodeGen/2005-07-28-IncorrectWeakGlobal.c b/test/CodeGen/2005-07-28-IncorrectWeakGlobal.c new file mode 100644 index 000000000000..cbacf2253911 --- /dev/null +++ b/test/CodeGen/2005-07-28-IncorrectWeakGlobal.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | grep TheGlobal | not grep weak + +extern int TheGlobal; +int foo() { return TheGlobal; } +int TheGlobal = 1; diff --git a/test/CodeGen/2005-09-20-ComplexConstants.c b/test/CodeGen/2005-09-20-ComplexConstants.c new file mode 100644 index 000000000000..a23ccee0de2e --- /dev/null +++ b/test/CodeGen/2005-09-20-ComplexConstants.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -emit-llvm -o /dev/null + +const double _Complex x[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + diff --git a/test/CodeGen/2005-09-24-AsmUserPrefix.c b/test/CodeGen/2005-09-24-AsmUserPrefix.c new file mode 100644 index 000000000000..16283130beb0 --- /dev/null +++ b/test/CodeGen/2005-09-24-AsmUserPrefix.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | opt -std-compile-opts | llc | \ +// RUN: not grep _foo2 + +void foo() __asm__("foo2"); + +void bar() { + foo(); +} diff --git a/test/CodeGen/2005-09-24-BitFieldCrash.c b/test/CodeGen/2005-09-24-BitFieldCrash.c new file mode 100644 index 000000000000..d687d2f39d26 --- /dev/null +++ b/test/CodeGen/2005-09-24-BitFieldCrash.c @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +struct tree_common {}; + +struct tree_int_cst { + struct tree_common common; + struct tree_int_cst_lowhi { + unsigned long long low; + long long high; + } int_cst; +}; + +enum XXX { yyy }; + +struct tree_function_decl { + struct tree_common common; + long long locus, y; + __extension__ enum XXX built_in_class : 2; + +}; + + +union tree_node { + struct tree_int_cst int_cst; + struct tree_function_decl function_decl; +}; + + +void foo (union tree_node * decl) { + decl->function_decl.built_in_class != 0; +} + + diff --git a/test/CodeGen/2005-12-04-AttributeUsed.c b/test/CodeGen/2005-12-04-AttributeUsed.c new file mode 100644 index 000000000000..4be6b798fd43 --- /dev/null +++ b/test/CodeGen/2005-12-04-AttributeUsed.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// CHECK: @llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* @foo to i8*), i8* bitcast (i32* @X to i8*)], section "llvm.metadata" +int X __attribute__((used)); +int Y; + +__attribute__((used)) void foo() {} diff --git a/test/CodeGen/2005-12-04-DeclarationLineNumbers.c b/test/CodeGen/2005-12-04-DeclarationLineNumbers.c new file mode 100644 index 000000000000..596d3eed24fc --- /dev/null +++ b/test/CodeGen/2005-12-04-DeclarationLineNumbers.c @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 %s -emit-llvm -g -o - | grep DW_TAG_compile_unit | count 1 +// PR664: ensure that line #'s are emitted for declarations + + +short test(short br_data_0, +short br_data_1, +short br_data_2, +short br_data_3, +short br_data_4, +short br_data_5, +short br_data_6, +short br_data_7) { + +short sm07 = br_data_0 + br_data_7; +short sm16 = br_data_1 + br_data_6; +short sm25 = br_data_2 + br_data_5; +short sm34 = br_data_3 + br_data_4; +short s0734 = sm07 + sm34; +short s1625 = sm16 + sm25; + +return s0734 + s1625; +} + diff --git a/test/CodeGen/2006-01-13-Includes.c b/test/CodeGen/2006-01-13-Includes.c new file mode 100644 index 000000000000..9cc45cec55ef --- /dev/null +++ b/test/CodeGen/2006-01-13-Includes.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 %s -g -emit-llvm -o - | FileCheck %s +// PR676 + +int printf(const char * restrict format, ...); + +void test() { + printf("Hello World\n"); +} + +// CHECK: test{{[\\/]}}CodeGen diff --git a/test/CodeGen/2006-01-13-StackSave.c b/test/CodeGen/2006-01-13-StackSave.c new file mode 100644 index 000000000000..7c506b31f2a0 --- /dev/null +++ b/test/CodeGen/2006-01-13-StackSave.c @@ -0,0 +1,11 @@ +// PR691 +// RUN: %clang_cc1 %s -emit-llvm -o - | opt -std-compile-opts | \ +// RUN: llvm-dis | grep llvm.stacksave + +void test(int N) { + int i; + for (i = 0; i < N; ++i) { + int VLA[i]; + external(VLA); + } +} diff --git a/test/CodeGen/2006-01-16-BitCountIntrinsicsUnsigned.c b/test/CodeGen/2006-01-16-BitCountIntrinsicsUnsigned.c new file mode 100644 index 000000000000..ba7820a0db6c --- /dev/null +++ b/test/CodeGen/2006-01-16-BitCountIntrinsicsUnsigned.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s + +unsigned t2(unsigned X) { + // CHECK: t2 + // CHECK: llvm.ctlz.i32 + return __builtin_clz(X); +} +int t1(int X) { + // CHECK: t1 + // CHECK: llvm.ctlz.i32 + return __builtin_clz(X); +} diff --git a/test/CodeGen/2006-01-23-FileScopeAsm.c b/test/CodeGen/2006-01-23-FileScopeAsm.c new file mode 100644 index 000000000000..472b46496710 --- /dev/null +++ b/test/CodeGen/2006-01-23-FileScopeAsm.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// CHECK: module asm "foo1" +__asm__ ("foo1"); +// CHECK: module asm "foo2" +__asm__ ("foo2"); +// CHECK: module asm "foo3" +__asm__ ("foo3"); +// CHECK: module asm "foo4" +__asm__ ("foo4"); +// CHECK: module asm "foo5" +__asm__ ("foo5"); diff --git a/test/CodeGen/2006-03-03-MissingInitializer.c b/test/CodeGen/2006-03-03-MissingInitializer.c new file mode 100644 index 000000000000..d2317d3acc41 --- /dev/null +++ b/test/CodeGen/2006-03-03-MissingInitializer.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +struct X { int *XX; int Y;}; + +void foo() { + // CHECK: @foo.nate = internal global i32 0 + static int nate = 0; + struct X bob = { &nate, 14 }; + bar(&bob); +} diff --git a/test/CodeGen/2006-03-16-VectorCtor.c b/test/CodeGen/2006-03-16-VectorCtor.c new file mode 100644 index 000000000000..c04d4b977a2e --- /dev/null +++ b/test/CodeGen/2006-03-16-VectorCtor.c @@ -0,0 +1,10 @@ +// Test that basic generic vector support works +// RUN: %clang_cc1 %s -emit-llvm -o - + +typedef int v4si __attribute__ ((__vector_size__ (16))); +void test(v4si *P, v4si *Q, float X) { + *P = (v4si){ X, X, X, X } * *Q; +} + +v4si G = (v4si){ 0.1, 1.2, 4.2, 17.2 }; + diff --git a/test/CodeGen/2006-03-17-KnRMismatch.c b/test/CodeGen/2006-03-17-KnRMismatch.c new file mode 100644 index 000000000000..f678e9f11d81 --- /dev/null +++ b/test/CodeGen/2006-03-17-KnRMismatch.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +void regnode(int op); + +void regnode(op) +char op; +{ +} diff --git a/test/CodeGen/2006-05-19-SingleEltReturn.c b/test/CodeGen/2006-05-19-SingleEltReturn.c new file mode 100644 index 000000000000..819237ce53be --- /dev/null +++ b/test/CodeGen/2006-05-19-SingleEltReturn.c @@ -0,0 +1,23 @@ +// Test returning a single element aggregate value containing a double. +// RUN: %clang_cc1 %s -emit-llvm -o - + +struct X { + double D; +}; + +struct Y { + struct X x; +}; + +struct Y bar(); + +void foo(struct Y *P) { + *P = bar(); +} + +struct Y bar() { + struct Y a; + a.x.D = 0; + return a; +} + diff --git a/test/CodeGen/2006-07-31-PR854.c b/test/CodeGen/2006-07-31-PR854.c new file mode 100644 index 000000000000..b3b4d8eb616c --- /dev/null +++ b/test/CodeGen/2006-07-31-PR854.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple i686-linux-gnu -w %s -emit-llvm -o - + +// PR854 + struct kernel_symbol { + unsigned long value; + }; + unsigned long loops_per_jiffy = (1<<12); + static const char __kstrtab_loops_per_jiffy[] +__attribute__((section("__ksymtab_strings"))) = "loops_per_jiffy"; + static const struct kernel_symbol __ksymtab_loops_per_jiffy +__attribute__((__used__)) __attribute__((section("__ksymtab"))) = { (unsigned +long)&loops_per_jiffy, __kstrtab_loops_per_jiffy }; diff --git a/test/CodeGen/2006-09-11-BitfieldRefCrash.c b/test/CodeGen/2006-09-11-BitfieldRefCrash.c new file mode 100644 index 000000000000..3d45d8bfd202 --- /dev/null +++ b/test/CodeGen/2006-09-11-BitfieldRefCrash.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - +// PR906 + +struct state_struct { + unsigned long long phys_frame: 50; + unsigned valid : 2; +} s; + +int mem_access(struct state_struct *p) { + return p->valid; +} + diff --git a/test/CodeGen/2006-09-18-fwrite-cast-crash.c b/test/CodeGen/2006-09-18-fwrite-cast-crash.c new file mode 100644 index 000000000000..a12fd0befe11 --- /dev/null +++ b/test/CodeGen/2006-09-18-fwrite-cast-crash.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -o /dev/null +// PR910 + +struct l_struct_2E_FILE { char x; }; +unsigned fwrite(signed char *, unsigned , unsigned , signed char *); +static signed char str301[39]; +static void Usage(signed char *ltmp_611_6) { + struct l_struct_2E_FILE *ltmp_6202_16; + unsigned ltmp_6203_92; + ltmp_6203_92 = /*tail*/ ((unsigned (*) (signed char *, unsigned , unsigned , +struct l_struct_2E_FILE *))(void*)fwrite)((&(str301[0u])), 38u, 1u, ltmp_6202_16); +} diff --git a/test/CodeGen/2006-09-21-IncompleteElementType.c b/test/CodeGen/2006-09-21-IncompleteElementType.c new file mode 100644 index 000000000000..1c71ea1ee9fa --- /dev/null +++ b/test/CodeGen/2006-09-21-IncompleteElementType.c @@ -0,0 +1,3 @@ +// RUN: not %clang_cc1 %s -emit-llvm -o /dev/null + +struct A X[(927 - 37) / sizeof(struct A)]; diff --git a/test/CodeGen/2006-09-25-DebugFilename.c b/test/CodeGen/2006-09-25-DebugFilename.c new file mode 100644 index 000000000000..2edb63f84dd8 --- /dev/null +++ b/test/CodeGen/2006-09-25-DebugFilename.c @@ -0,0 +1,4 @@ +// RUN: not %clang_cc1 %s -emit-llvm -o /dev/null +#include "2006-09-25-DebugFilename.h" +int func1() { return hfunc1(); } +int func2() { fluffy; return hfunc1(); } // expected-error {{use of undeclared identifier 'fluffy'}} diff --git a/test/CodeGen/2006-09-25-DebugFilename.h b/test/CodeGen/2006-09-25-DebugFilename.h new file mode 100644 index 000000000000..9b03666b3c27 --- /dev/null +++ b/test/CodeGen/2006-09-25-DebugFilename.h @@ -0,0 +1,6 @@ +extern int exfunc(int a); + +static inline int hfunc1() +{ + return exfunc(1); +} diff --git a/test/CodeGen/2006-09-28-SimpleAsm.c b/test/CodeGen/2006-09-28-SimpleAsm.c new file mode 100644 index 000000000000..c3983af5c98d --- /dev/null +++ b/test/CodeGen/2006-09-28-SimpleAsm.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s +// PR924 + +void bar() { + // Extended asm + // CHECK: call void asm sideeffect "ext: xorl %eax, eax; movl eax, fs; movl eax, gs %blah + asm volatile ("ext: xorl %%eax, eax; movl eax, fs; movl eax, gs %%blah %= %\ +% " : : "r"(1)); + // CHECK: call void asm sideeffect "nonext: xorl %eax, %eax; movl %eax, %fs; movl %eax, %gs %%blah %= %% + // Non-extended asm. + asm volatile ("nonext: xorl %eax, %eax; movl %eax, %fs; movl %eax, %gs %%blah %= %% "); +} diff --git a/test/CodeGen/2006-10-30-ArrayCrash.c b/test/CodeGen/2006-10-30-ArrayCrash.c new file mode 100644 index 000000000000..67446fd0567b --- /dev/null +++ b/test/CodeGen/2006-10-30-ArrayCrash.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -O3 -emit-llvm -o - %s +// PR954, PR911 + +extern void foo(); + +struct S { + short f1[3]; + unsigned int f2 : 1; +}; + +void bar() +{ + struct S *A; + + if (A->f2) + foo(); +} diff --git a/test/CodeGen/2006-12-14-ordered_expr.c b/test/CodeGen/2006-12-14-ordered_expr.c new file mode 100644 index 000000000000..c46ba8578941 --- /dev/null +++ b/test/CodeGen/2006-12-14-ordered_expr.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -O3 -emit-llvm %s -o - | FileCheck %s + +int test2(float X, float Y) { + // CHECK: fcmp ord float %X, %Y + return !__builtin_isunordered(X, Y); +} diff --git a/test/CodeGen/2007-01-06-KNR-Proto.c b/test/CodeGen/2007-01-06-KNR-Proto.c new file mode 100644 index 000000000000..d56a786fce53 --- /dev/null +++ b/test/CodeGen/2007-01-06-KNR-Proto.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s +// PR1083 + +int svc_register (void (*dispatch) (int)); + +int svc_register (dispatch) + void (*dispatch) (); +{ +} + diff --git a/test/CodeGen/2007-01-20-VectorICE.c b/test/CodeGen/2007-01-20-VectorICE.c new file mode 100644 index 000000000000..286b8a1b3de0 --- /dev/null +++ b/test/CodeGen/2007-01-20-VectorICE.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +typedef float __m128 __attribute__((__vector_size__(16))); +typedef long long __v2di __attribute__((__vector_size__(16))); +typedef int __v4si __attribute__((__vector_size__(16))); + +__v2di bar(void); +void foo(int X, __v4si *P) { + *P = X == 2 ? bar() : bar(); +} + diff --git a/test/CodeGen/2007-01-24-InlineAsmCModifier.c b/test/CodeGen/2007-01-24-InlineAsmCModifier.c new file mode 100644 index 000000000000..5158898f5dc8 --- /dev/null +++ b/test/CodeGen/2007-01-24-InlineAsmCModifier.c @@ -0,0 +1,12 @@ +// Verify that the %c modifier works and strips off any prefixes from +// immediates. +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s + +void foo() { + // CHECK: i32 789514 + __asm__ volatile("/* " "pickANumber" ": %c0 */"::"i"(0xC0C0A)); + + // Check that non-c modifiers work also + // CHECK: i32 123 + __asm__ volatile("/* " "pickANumber2 " ": %0 */"::"i"(123)); +} diff --git a/test/CodeGen/2007-02-04-AddrLValue-2.c b/test/CodeGen/2007-02-04-AddrLValue-2.c new file mode 100644 index 000000000000..bc44d1465f47 --- /dev/null +++ b/test/CodeGen/2007-02-04-AddrLValue-2.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 %s -O3 -emit-llvm -o - +// PR1173 + +struct S { char s; }; +struct T { struct S t; }; + +struct S *const p = &((struct T * const) (0x4000))->t; + +void +foo (void) +{ + p->s = 0; +} diff --git a/test/CodeGen/2007-02-04-AddrLValue.c b/test/CodeGen/2007-02-04-AddrLValue.c new file mode 100644 index 000000000000..400dcb60a73c --- /dev/null +++ b/test/CodeGen/2007-02-04-AddrLValue.c @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 %s -O3 -emit-llvm -o - +// PR1176 + +typedef struct +{ + char *key; + char *value; +} T1; + +typedef struct +{ + long type; + char *value; +} T3; + +T1 a[] = +{ + { + "", + ((char *)&((T3) {1, (char *) 1})) + } +}; + diff --git a/test/CodeGen/2007-02-04-EmptyStruct.c b/test/CodeGen/2007-02-04-EmptyStruct.c new file mode 100644 index 000000000000..2b2896f6d11a --- /dev/null +++ b/test/CodeGen/2007-02-04-EmptyStruct.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -O3 -emit-llvm -o - +// PR1175 + +struct empty { }; + +void foo(struct empty *p) { + p++; +} + diff --git a/test/CodeGen/2007-02-07-AddrLabel.c b/test/CodeGen/2007-02-07-AddrLabel.c new file mode 100644 index 000000000000..25eb89433679 --- /dev/null +++ b/test/CodeGen/2007-02-07-AddrLabel.c @@ -0,0 +1,10 @@ +// PR947 +// RUN: %clang_cc1 %s -emit-llvm -o - + +void foo() { + void *ptr; + label: + ptr = &&label; + + goto *ptr; + } diff --git a/test/CodeGen/2007-02-16-VoidPtrDiff.c b/test/CodeGen/2007-02-16-VoidPtrDiff.c new file mode 100644 index 000000000000..c9f6714c253c --- /dev/null +++ b/test/CodeGen/2007-02-16-VoidPtrDiff.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +void foo(void *ptr, int test) { + (ptr - ((void *) test + 0x2000)); +} diff --git a/test/CodeGen/2007-02-25-C-DotDotDot.c b/test/CodeGen/2007-02-25-C-DotDotDot.c new file mode 100644 index 000000000000..7b2e418f4918 --- /dev/null +++ b/test/CodeGen/2007-02-25-C-DotDotDot.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -O0 %s -emit-llvm -o - | FileCheck %s + +// Make sure the call to foo is compiled as: +// call float @foo() +// not +// call float (...)* bitcast (float ()* @foo to float (...)*)( ) + +static float foo() { return 0.0; } +// CHECK: call float @foo +float bar() { return foo()*10.0;} diff --git a/test/CodeGen/2007-03-01-VarSizeArrayIdx.c b/test/CodeGen/2007-03-01-VarSizeArrayIdx.c new file mode 100644 index 000000000000..7a9f89a66e26 --- /dev/null +++ b/test/CodeGen/2007-03-01-VarSizeArrayIdx.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -O3 -emit-llvm -o - | grep mul +// PR1233 + +float foo(int w, float A[][w], int g, int h) { + return A[g][0]; +} + diff --git a/test/CodeGen/2007-03-05-DataLayout.c b/test/CodeGen/2007-03-05-DataLayout.c new file mode 100644 index 000000000000..751962457379 --- /dev/null +++ b/test/CodeGen/2007-03-05-DataLayout.c @@ -0,0 +1,55 @@ +// Testcase for PR1242 +// RUN: %clang_cc1 -emit-llvm %s -o - | grep datalayout | \ +// RUN: not grep {"\[Ee\]-p:\[36\]\[24\]:\[36\]\[24\]"} +// END. + +typedef __SIZE_TYPE__ size_t; +void * malloc(size_t size); +#define NDIM 3 +#define BODY 01 +typedef double vector[NDIM]; +typedef struct bnode* bodyptr; +// { i16, double, [3 x double], i32, i32, [3 x double], [3 x double], [3 x +// double], double, \2 *, \2 * } +struct bnode { + short int type; + double mass; + vector pos; + int proc; + int new_proc; + vector vel; + vector acc; + vector new_acc; + double phi; + bodyptr next; + bodyptr proc_next; +} body; + +#define Type(x) ((x)->type) +#define Mass(x) ((x)->mass) +#define Pos(x) ((x)->pos) +#define Proc(x) ((x)->proc) +#define New_Proc(x) ((x)->new_proc) +#define Vel(x) ((x)->vel) +#define Acc(x) ((x)->acc) +#define New_Acc(x) ((x)->new_acc) +#define Phi(x) ((x)->phi) +#define Next(x) ((x)->next) +#define Proc_Next(x) ((x)->proc_next) + +bodyptr ubody_alloc(int p) +{ + register bodyptr tmp; + tmp = (bodyptr)malloc(sizeof(body)); + + Type(tmp) = BODY; + Proc(tmp) = p; + Proc_Next(tmp) = NULL; + New_Proc(tmp) = p; + return tmp; +} + +int main(int argc, char** argv) { + bodyptr b = ubody_alloc(17); + return 0; +} diff --git a/test/CodeGen/2007-03-26-BitfieldAfterZeroWidth.c b/test/CodeGen/2007-03-26-BitfieldAfterZeroWidth.c new file mode 100644 index 000000000000..b4a42d989294 --- /dev/null +++ b/test/CodeGen/2007-03-26-BitfieldAfterZeroWidth.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - +struct W {}; +struct Y { + struct W w; + int i:1; +} __attribute__ ((packed)) y; diff --git a/test/CodeGen/2007-03-26-ZeroWidthBitfield.c b/test/CodeGen/2007-03-26-ZeroWidthBitfield.c new file mode 100644 index 000000000000..0bf42ad4f954 --- /dev/null +++ b/test/CodeGen/2007-03-26-ZeroWidthBitfield.c @@ -0,0 +1,2 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - +struct Z { int :0; } z; diff --git a/test/CodeGen/2007-03-27-VarLengthArray.c b/test/CodeGen/2007-03-27-VarLengthArray.c new file mode 100644 index 000000000000..ec11f55e6725 --- /dev/null +++ b/test/CodeGen/2007-03-27-VarLengthArray.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s + +// CHECK: getelementptr inbounds i32* %{{vla|[0-9]}} +extern void f(int *); +int e(int m, int n) { + int x[n]; + f(x); + return x[m]; +} diff --git a/test/CodeGen/2007-04-05-PackedBitFields-2.c b/test/CodeGen/2007-04-05-PackedBitFields-2.c new file mode 100644 index 000000000000..41e6b7def91e --- /dev/null +++ b/test/CodeGen/2007-04-05-PackedBitFields-2.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +# define pck __attribute__((packed)) + + +struct pck F { + unsigned long long i : 12, + j : 23, + k : 27, + l; +}; +struct F f1; + +void foo() { + f1.l = 5; +} diff --git a/test/CodeGen/2007-04-05-PackedBitFields.c b/test/CodeGen/2007-04-05-PackedBitFields.c new file mode 100644 index 000000000000..5c824a3e08f1 --- /dev/null +++ b/test/CodeGen/2007-04-05-PackedBitFields.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +# define pck __attribute__((packed)) + + +struct pck E { + unsigned long long l, + i : 12, + j : 23, + k : 29; }; + +struct E e1; + +void foo() { + e1.k = 5; +} diff --git a/test/CodeGen/2007-04-05-PackedStruct.c b/test/CodeGen/2007-04-05-PackedStruct.c new file mode 100644 index 000000000000..1e9171e4235e --- /dev/null +++ b/test/CodeGen/2007-04-05-PackedStruct.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +#pragma pack(push, 2) + +enum { + tA = 0, + tB = 1 +}; + +struct MyStruct { + unsigned long A; + char C; + void * B; +}; + +void bar(){ +struct MyStruct MS = { tB, 0 }; +} diff --git a/test/CodeGen/2007-04-05-PadBeforeZeroLengthField.c b/test/CodeGen/2007-04-05-PadBeforeZeroLengthField.c new file mode 100644 index 000000000000..f3005b5adaac --- /dev/null +++ b/test/CodeGen/2007-04-05-PadBeforeZeroLengthField.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - +struct c__ { unsigned int type:4; }; +union A { struct c__ c; } __attribute__((aligned(8))); +struct B { + unsigned int retainCount; + union A objects[]; +}; +void foo(union A * objects, struct B *array, unsigned long k) +{ array->objects[k] = objects[k]; } diff --git a/test/CodeGen/2007-04-05-UnPackedStruct.c b/test/CodeGen/2007-04-05-UnPackedStruct.c new file mode 100644 index 000000000000..e7a8df623947 --- /dev/null +++ b/test/CodeGen/2007-04-05-UnPackedStruct.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + + +enum { + tA = 0, + tB = 1 +}; + +struct MyStruct { + unsigned long A; + void * B; +}; + +void bar(){ +struct MyStruct MS = { tB, 0 }; +} diff --git a/test/CodeGen/2007-04-11-InlineAsmStruct.c b/test/CodeGen/2007-04-11-InlineAsmStruct.c new file mode 100644 index 000000000000..d617feeed9f9 --- /dev/null +++ b/test/CodeGen/2007-04-11-InlineAsmStruct.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +struct V { short X, Y; }; +int bar() { + struct V bar; + __asm__ volatile("foo %0\n" : "=r"(bar)); + return bar.X; +} diff --git a/test/CodeGen/2007-04-11-InlineAsmUnion.c b/test/CodeGen/2007-04-11-InlineAsmUnion.c new file mode 100644 index 000000000000..6d24d938abb3 --- /dev/null +++ b/test/CodeGen/2007-04-11-InlineAsmUnion.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +union U { int x; float p; }; +void foo() { + union U bar; + __asm__ volatile("foo %0\n" : "=r"(bar)); +} diff --git a/test/CodeGen/2007-04-11-PR1321.c b/test/CodeGen/2007-04-11-PR1321.c new file mode 100644 index 000000000000..6207ecc1161f --- /dev/null +++ b/test/CodeGen/2007-04-11-PR1321.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -o /dev/null + +struct X { + unsigned int e0 : 17; + unsigned int e1 : 17; + unsigned int e2 : 17; + unsigned int e3 : 17; + unsigned int e4 : 17; + unsigned int e5 : 17; + unsigned int e6 : 17; + unsigned int e7 : 17; +} __attribute__((packed)) x; diff --git a/test/CodeGen/2007-04-13-InlineAsmStruct2.c b/test/CodeGen/2007-04-13-InlineAsmStruct2.c new file mode 100644 index 000000000000..c9a87ffd55fb --- /dev/null +++ b/test/CodeGen/2007-04-13-InlineAsmStruct2.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +struct V { short X, Y; }; +int bar() { + struct V bar; + // CHECK: call void asm + __asm__ volatile("foo %0\n" :: "r"(bar)); + return bar.X; +} diff --git a/test/CodeGen/2007-04-13-InlineAsmUnion2.c b/test/CodeGen/2007-04-13-InlineAsmUnion2.c new file mode 100644 index 000000000000..a8983b61d71f --- /dev/null +++ b/test/CodeGen/2007-04-13-InlineAsmUnion2.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +union U { int x; char* p; }; +void foo() { + union U bar; + // CHECK: call void asm + __asm__ volatile("foo %0\n" :: "r"(bar)); +} diff --git a/test/CodeGen/2007-04-14-FNoBuiltin.c b/test/CodeGen/2007-04-14-FNoBuiltin.c new file mode 100644 index 000000000000..a5fda6306f28 --- /dev/null +++ b/test/CodeGen/2007-04-14-FNoBuiltin.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm %s -O2 -fno-builtin -o - | grep call.*printf +// Check that -fno-builtin is honored. + +extern int printf(const char*, ...); +void foo(const char *msg) { + printf("%s\n",msg); +} diff --git a/test/CodeGen/2007-04-17-ZeroSizeBitFields.c b/test/CodeGen/2007-04-17-ZeroSizeBitFields.c new file mode 100644 index 000000000000..91b45828dbb6 --- /dev/null +++ b/test/CodeGen/2007-04-17-ZeroSizeBitFields.c @@ -0,0 +1,4 @@ +// PR 1332 +// RUN: %clang_cc1 %s -emit-llvm -o /dev/null + +struct Z { int a:1; int :0; int c:1; } z; diff --git a/test/CodeGen/2007-04-24-VolatileStructCopy.c b/test/CodeGen/2007-04-24-VolatileStructCopy.c new file mode 100644 index 000000000000..5eeecce99d29 --- /dev/null +++ b/test/CodeGen/2007-04-24-VolatileStructCopy.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s +// PR1352 + +struct foo { + int x; +}; + +void copy(volatile struct foo *p, struct foo *q) { + // CHECK: call void @llvm.memcpy + *p = *q; +} diff --git a/test/CodeGen/2007-04-24-bit-not-expr.c b/test/CodeGen/2007-04-24-bit-not-expr.c new file mode 100644 index 000000000000..9d99caffb536 --- /dev/null +++ b/test/CodeGen/2007-04-24-bit-not-expr.c @@ -0,0 +1,7 @@ +// PR 1346 +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null +extern bar(void *); + +void f(void *cd) { + bar(((void *)((unsigned long)(cd) ^ -1))); +} diff --git a/test/CodeGen/2007-04-24-str-const.c b/test/CodeGen/2007-04-24-str-const.c new file mode 100644 index 000000000000..1d86d1c251d3 --- /dev/null +++ b/test/CodeGen/2007-04-24-str-const.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null +static char *str; + +static const struct { + const char *name; + unsigned type; +} scan_special[] = { + {"shift", 1}, + {0, 0} +}; + +static void +sb(void) +{ + while (*str == ' ' || *str == '\t') + str++; +} diff --git a/test/CodeGen/2007-05-07-PaddingElements.c b/test/CodeGen/2007-05-07-PaddingElements.c new file mode 100644 index 000000000000..574a37760a38 --- /dev/null +++ b/test/CodeGen/2007-05-07-PaddingElements.c @@ -0,0 +1,12 @@ +// PR 1278 +// RUN: %clang_cc1 %s -emit-llvm -O0 -o - | grep {struct.s} | not grep "4 x i8] zeroinitializer" +// RUN: %clang_cc1 %s -emit-llvm -O0 -o - | not grep "i32 0, i32 2" +struct s { + double d1; + int s1; +}; + +struct s foo(void) { + struct s S = {1.1, 2}; + return S; +} diff --git a/test/CodeGen/2007-05-08-PCH.c b/test/CodeGen/2007-05-08-PCH.c new file mode 100644 index 000000000000..c45d57c42f6f --- /dev/null +++ b/test/CodeGen/2007-05-08-PCH.c @@ -0,0 +1,7 @@ +// PR 1400 +// RUN: %clang_cc1 -x c-header %s -o /dev/null + +int main() { + return 0; +} + diff --git a/test/CodeGen/2007-05-11-str-const.c b/test/CodeGen/2007-05-11-str-const.c new file mode 100644 index 000000000000..731496d34686 --- /dev/null +++ b/test/CodeGen/2007-05-11-str-const.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -emit-llvm -g %s -o /dev/null + +static unsigned char out[]={0,1}; +static const unsigned char str1[]="1"; + diff --git a/test/CodeGen/2007-05-15-PaddingElement.c b/test/CodeGen/2007-05-15-PaddingElement.c new file mode 100644 index 000000000000..5aa4f2e091ce --- /dev/null +++ b/test/CodeGen/2007-05-15-PaddingElement.c @@ -0,0 +1,23 @@ +// PR 1419 + +// RUN: %clang_cc1 -O2 %s -emit-llvm -o - | grep "ret i32 1" +struct A { + short x; + long long :0; +}; + +struct B { + char a; + char b; + unsigned char i; +}; + +union X { struct A a; struct B b; }; + +int check(void) { + union X x, y; + + y.b.i = 0xff; + x = y; + return (x.b.i == 0xff); +} diff --git a/test/CodeGen/2007-05-16-EmptyStruct.c b/test/CodeGen/2007-05-16-EmptyStruct.c new file mode 100644 index 000000000000..14aaff007ebd --- /dev/null +++ b/test/CodeGen/2007-05-16-EmptyStruct.c @@ -0,0 +1,5 @@ +// PR 1417 +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// CHECK: global %struct.anon* null +struct { } *X; diff --git a/test/CodeGen/2007-05-29-UnionCopy.c b/test/CodeGen/2007-05-29-UnionCopy.c new file mode 100644 index 000000000000..9f71687b40a5 --- /dev/null +++ b/test/CodeGen/2007-05-29-UnionCopy.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | grep memcpy +// PR1421 + +struct A { + char c; + int i; +}; + +struct B { + int c; + unsigned char x; +}; + +union U { struct A a; struct B b; }; + +void check(union U *u, union U *v) { + *u = *v; +} diff --git a/test/CodeGen/2007-06-05-NoInlineAttribute.c b/test/CodeGen/2007-06-05-NoInlineAttribute.c new file mode 100644 index 000000000000..26aad88e8146 --- /dev/null +++ b/test/CodeGen/2007-06-05-NoInlineAttribute.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -O2 -emit-llvm %s -o - | grep call + +static int bar(int x, int y) __attribute__((noinline)); + +static int bar(int x, int y) +{ + return x + y; +} + +int foo(int a, int b) { + return bar(b, a); +} + diff --git a/test/CodeGen/2007-06-15-AnnotateAttribute.c b/test/CodeGen/2007-06-15-AnnotateAttribute.c new file mode 100644 index 000000000000..de34866783ba --- /dev/null +++ b/test/CodeGen/2007-06-15-AnnotateAttribute.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | grep llvm.global.annotations +// RUN: %clang_cc1 -emit-llvm %s -o - | grep llvm.var.annotation | count 3 + +/* Global variable with attribute */ +int X __attribute__((annotate("GlobalValAnnotation"))); + +/* Function with attribute */ +int foo(int y) __attribute__((annotate("GlobalValAnnotation"))) + __attribute__((noinline)); + +int foo(int y __attribute__((annotate("LocalValAnnotation")))) { + int x __attribute__((annotate("LocalValAnnotation"))); + x = 34; + return y + x; +} + +int main() { + static int a __attribute__((annotate("GlobalValAnnotation"))); + a = foo(2); + return 0; +} diff --git a/test/CodeGen/2007-06-18-SextAttrAggregate.c b/test/CodeGen/2007-06-18-SextAttrAggregate.c new file mode 100644 index 000000000000..27ae6a9b76a6 --- /dev/null +++ b/test/CodeGen/2007-06-18-SextAttrAggregate.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -o - -emit-llvm | FileCheck %s +// PR1513 + +struct s{ +long a; +long b; +}; + +void f(struct s a, char *b, signed char C) { + // CHECK: i8 signext + +} diff --git a/test/CodeGen/2007-07-29-RestrictPtrArg.c b/test/CodeGen/2007-07-29-RestrictPtrArg.c new file mode 100644 index 000000000000..b6d61a714a69 --- /dev/null +++ b/test/CodeGen/2007-07-29-RestrictPtrArg.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | grep noalias + +void foo(int * __restrict myptr1, int * myptr2) { + myptr1[0] = 0; + myptr2[0] = 0; +} diff --git a/test/CodeGen/2007-08-01-LoadStoreAlign.c b/test/CodeGen/2007-08-01-LoadStoreAlign.c new file mode 100644 index 000000000000..87cf163d4d9b --- /dev/null +++ b/test/CodeGen/2007-08-01-LoadStoreAlign.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +struct p { + char a; + int b; +} __attribute__ ((packed)); + +struct p t = { 1, 10 }; +struct p u; + +int main () { + // CHECK: align 1 + // CHECK: align 1 + int tmp = t.b; + u.b = tmp; + return tmp; + +} diff --git a/test/CodeGen/2007-08-21-ComplexCst.c b/test/CodeGen/2007-08-21-ComplexCst.c new file mode 100644 index 000000000000..cd9ceb198baa --- /dev/null +++ b/test/CodeGen/2007-08-21-ComplexCst.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -O2 -emit-llvm %s -o /dev/null +void f(_Complex float z); +void g() { f(1.0i); } diff --git a/test/CodeGen/2007-08-22-CTTZ.c b/test/CodeGen/2007-08-22-CTTZ.c new file mode 100644 index 000000000000..9067c5a767e3 --- /dev/null +++ b/test/CodeGen/2007-08-22-CTTZ.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +int bork(unsigned long long x) { + // CHECK: llvm.cttz.i64 + // CHECK: llvm.cttz.i64 + // CHECK-NOT: lshr + return __builtin_ctzll(x); +} diff --git a/test/CodeGen/2007-09-05-ConstCtor.c b/test/CodeGen/2007-09-05-ConstCtor.c new file mode 100644 index 000000000000..138b81887560 --- /dev/null +++ b/test/CodeGen/2007-09-05-ConstCtor.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -Os -emit-llvm %s -o /dev/null +// PR1641 + +struct A { + unsigned long l; +}; + +void bar(struct A *a); + +void bork() { + const unsigned long vcgt = 1234; + struct A a = { vcgt }; + bar(&a); +} diff --git a/test/CodeGen/2007-09-12-PragmaPack.c b/test/CodeGen/2007-09-12-PragmaPack.c new file mode 100644 index 000000000000..71c7537e9dca --- /dev/null +++ b/test/CodeGen/2007-09-12-PragmaPack.c @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; + +#pragma pack(push, 1) +typedef struct +{ + uint32_t a; +} foo; + +typedef struct { + uint8_t major; + uint8_t minor; + uint16_t build; +} VERSION; + +typedef struct { + uint8_t a[5]; + VERSION version; + uint8_t b; + foo d; + uint32_t guard; +} bar; +#pragma pack(pop) + + +unsigned barsize(void) { + // CHECK: ret i32 18 + return sizeof(bar); +} diff --git a/test/CodeGen/2007-09-14-NegatePointer.c b/test/CodeGen/2007-09-14-NegatePointer.c new file mode 100644 index 000000000000..52367e6c667b --- /dev/null +++ b/test/CodeGen/2007-09-14-NegatePointer.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - +// PR1662 + +int foo(unsigned char *test) { + return 0U - (unsigned int )test; +} + diff --git a/test/CodeGen/2007-09-17-WeakRef.c b/test/CodeGen/2007-09-17-WeakRef.c new file mode 100644 index 000000000000..3047b7f954ef --- /dev/null +++ b/test/CodeGen/2007-09-17-WeakRef.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -O1 -emit-llvm %s -o - | grep icmp +// PR1678 + +extern void B (void); +static __typeof(B) A __attribute__ ((__weakref__("B"))); +int active (void) +{ + static void *const p = __extension__ (void *) &A; + return p != 0; +} diff --git a/test/CodeGen/2007-09-26-Alignment.c b/test/CodeGen/2007-09-26-Alignment.c new file mode 100644 index 000000000000..8ab130b0a708 --- /dev/null +++ b/test/CodeGen/2007-09-26-Alignment.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s +extern p(int *); +int q(void) { + // CHECK: alloca i32, align 16 + int x __attribute__ ((aligned (16))); + p(&x); + return x; +} diff --git a/test/CodeGen/2007-09-27-ComplexIntCompare.c b/test/CodeGen/2007-09-27-ComplexIntCompare.c new file mode 100644 index 000000000000..d07aa0cf7c36 --- /dev/null +++ b/test/CodeGen/2007-09-27-ComplexIntCompare.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - +// PR1708 + +void __attribute__((noreturn)) abort(void); + +struct s { _Complex unsigned short x; }; +struct s gs = { 100 + 200i }; +struct s __attribute__((noinline)) foo (void) { return gs; } + +int main () +{ + if (foo ().x != gs.x) + abort (); + exit (0); +} diff --git a/test/CodeGen/2007-09-28-PackedUnionMember.c b/test/CodeGen/2007-09-28-PackedUnionMember.c new file mode 100644 index 000000000000..943480e4d882 --- /dev/null +++ b/test/CodeGen/2007-09-28-PackedUnionMember.c @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +#pragma pack(push, 2) +struct H { + unsigned long f1; + unsigned long f2; + union { + struct opaque1 *f3; + struct opaque2 *f4; + struct { + struct opaque3 *f5; + unsigned short f6; + } f7; + } f8; +}; +#pragma pack(pop) + +struct E { + unsigned long f1; + unsigned long f2; +}; + +typedef long (*FuncPtr) (); + +extern long bork(FuncPtr handler, const struct E *list); + +static long hndlr() +{ + struct H cmd = { 4, 412 }; + return 0; +} +void foo(void *inWindow) { + static const struct E events[] = { + { 123124, 1 } + }; + bork(hndlr, events); +} + diff --git a/test/CodeGen/2007-10-02-VolatileArray.c b/test/CodeGen/2007-10-02-VolatileArray.c new file mode 100644 index 000000000000..b1dcb7ea7d0b --- /dev/null +++ b/test/CodeGen/2007-10-02-VolatileArray.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | grep volatile +// PR1647 + +void foo(volatile int *p) +{ +p[0] = 0; +} diff --git a/test/CodeGen/2007-10-15-VoidPtr.c b/test/CodeGen/2007-10-15-VoidPtr.c new file mode 100644 index 000000000000..0bbff3da318d --- /dev/null +++ b/test/CodeGen/2007-10-15-VoidPtr.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null +void bork(void **data) { + (*(unsigned short *) (&(data[37])[927]) = 0); +} diff --git a/test/CodeGen/2007-10-30-Volatile.c b/test/CodeGen/2007-10-30-Volatile.c new file mode 100644 index 000000000000..17aac1a987c2 --- /dev/null +++ b/test/CodeGen/2007-10-30-Volatile.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null -Wall -Werror +void bork() { + char * volatile p = 0; + volatile int cc = 0; + p += cc; +} diff --git a/test/CodeGen/2007-11-07-AlignedMemcpy.c b/test/CodeGen/2007-11-07-AlignedMemcpy.c new file mode 100644 index 000000000000..829b60cb0ef0 --- /dev/null +++ b/test/CodeGen/2007-11-07-AlignedMemcpy.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null +void bork() { + int Qux[33] = {0}; +} diff --git a/test/CodeGen/2007-11-07-CopyAggregateAlign.c b/test/CodeGen/2007-11-07-CopyAggregateAlign.c new file mode 100644 index 000000000000..08d97702e69a --- /dev/null +++ b/test/CodeGen/2007-11-07-CopyAggregateAlign.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s +struct A { char s, t, u, v; short a; }; +// CHECK: %a = alloca %struct.A, align 2 +// CHECK: %b = alloca %struct.A, align 2 +// CHECK: call void @llvm.memcpy.p0i8.p0i8.{{.*}}, i32 2, i1 false) + +void q() { struct A a, b; a = b; } diff --git a/test/CodeGen/2007-11-07-ZeroAggregateAlign.c b/test/CodeGen/2007-11-07-ZeroAggregateAlign.c new file mode 100644 index 000000000000..b059607ba586 --- /dev/null +++ b/test/CodeGen/2007-11-07-ZeroAggregateAlign.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s +struct A { short s; short t; int i; }; +// CHECK: %a = alloca %struct.A, align 4 +// CHECK: call void @llvm.memset.p0i8.{{.*}}i32 4, i1 false) +void q() { struct A a = {0}; } diff --git a/test/CodeGen/2007-11-28-GlobalInitializer.c b/test/CodeGen/2007-11-28-GlobalInitializer.c new file mode 100644 index 000000000000..a79ccddbe9e4 --- /dev/null +++ b/test/CodeGen/2007-11-28-GlobalInitializer.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - +// PR1744 +typedef struct foo { int x; char *p; } FOO; +extern FOO yy[]; + +int *y = &((yy + 1)->x); +void *z = &((yy + 1)->x); + diff --git a/test/CodeGen/2007-12-16-AsmNoUnwind.c b/test/CodeGen/2007-12-16-AsmNoUnwind.c new file mode 100644 index 000000000000..de078a28dd48 --- /dev/null +++ b/test/CodeGen/2007-12-16-AsmNoUnwind.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | grep nounwind + +void bar() { asm (""); } diff --git a/test/CodeGen/2008-01-04-WideBitfield.c b/test/CodeGen/2008-01-04-WideBitfield.c new file mode 100644 index 000000000000..e1c7a38a12e6 --- /dev/null +++ b/test/CodeGen/2008-01-04-WideBitfield.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s +// PR1386 +typedef unsigned long long uint64_t; +struct X { + unsigned char pad : 4; + uint64_t a : 64; +} __attribute__((packed)) x; + +uint64_t f(void) +{ + return x.a; +} diff --git a/test/CodeGen/2008-01-07-UnusualIntSize.c b/test/CodeGen/2008-01-07-UnusualIntSize.c new file mode 100644 index 000000000000..bf0ca5575a6a --- /dev/null +++ b/test/CodeGen/2008-01-07-UnusualIntSize.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s +// PR1721 + +struct s { + unsigned long long u33: 33; +} a, b; + +// This should have %0 and %1 truncated to 33 bits before any operation. +// This can be done using i33 or an explicit and. +_Bool test(void) { + // CHECK: and i64 %[[TMP1:[0-9]+]], 8589934591 + // CHECK-NOT: and i64 [[TMP1]], 8589934591 + // CHECK: and i64 %{{[0-9]}}, 8589934591 + return a.u33 + b.u33 != 0; +} diff --git a/test/CodeGen/2008-01-11-ChainConsistency.c b/test/CodeGen/2008-01-11-ChainConsistency.c new file mode 100644 index 000000000000..9ae021f6da58 --- /dev/null +++ b/test/CodeGen/2008-01-11-ChainConsistency.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -fnested-functions | not grep nest + +void n1(void) { void a(void) { a(); } a(); } diff --git a/test/CodeGen/2008-01-21-PackedBitFields.c b/test/CodeGen/2008-01-21-PackedBitFields.c new file mode 100644 index 000000000000..a649475e8df2 --- /dev/null +++ b/test/CodeGen/2008-01-21-PackedBitFields.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +typedef double Al1Double __attribute__((aligned(1))); +struct x { int a:23; Al1Double v; }; +struct x X = { 5, 3.0 }; +double foo() { return X.v; } + diff --git a/test/CodeGen/2008-01-21-PackedStructField.c b/test/CodeGen/2008-01-21-PackedStructField.c new file mode 100644 index 000000000000..aa1bee4abbe1 --- /dev/null +++ b/test/CodeGen/2008-01-21-PackedStructField.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +struct X { long double b; unsigned char c; double __attribute__((packed)) d; }; +struct X x = { 3.0L, 5, 3.0 }; + + +struct S2504 { + int e:17; + __attribute__((packed)) unsigned long long int f; +} ; +int fails; + extern struct S2504 s2504; +void check2504va (int z) { + struct S2504 arg, *p; + long long int i = 0; + arg.f = i; +} + diff --git a/test/CodeGen/2008-01-24-StructAlignAndBitFields.c b/test/CodeGen/2008-01-24-StructAlignAndBitFields.c new file mode 100644 index 000000000000..eae48b3cad90 --- /dev/null +++ b/test/CodeGen/2008-01-24-StructAlignAndBitFields.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +struct U { char a; short b; int c:25; char d; } u; + diff --git a/test/CodeGen/2008-01-25-ByValReadNone.c b/test/CodeGen/2008-01-25-ByValReadNone.c new file mode 100644 index 000000000000..06ad1eef00f1 --- /dev/null +++ b/test/CodeGen/2008-01-25-ByValReadNone.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | not grep readonly +// RUN: %clang_cc1 -emit-llvm -o - %s | not grep readnone + +// XFAIL: arm + +// The struct being passed byval means that we cannot mark the +// function readnone. Readnone would allow stores to the arg to +// be deleted in the caller. We also don't allow readonly since +// the callee might write to the byval parameter. The inliner +// would have to assume the worse and introduce an explicit +// temporary when inlining such a function, which is costly for +// the common case in which the byval argument is not written. +struct S { int A[1000]; }; +int __attribute__ ((const)) f(struct S x) { x.A[1] = 0; return x.A[0]; } +int g(struct S x) __attribute__ ((pure)); +int h(struct S x) { return g(x); } diff --git a/test/CodeGen/2008-01-25-ZeroSizedAggregate.c b/test/CodeGen/2008-01-25-ZeroSizedAggregate.c new file mode 100644 index 000000000000..d9059856254f --- /dev/null +++ b/test/CodeGen/2008-01-25-ZeroSizedAggregate.c @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +// Aggregates of size zero should be dropped from argument list. +typedef long int Tlong; +struct S2411 { + __attribute__((aligned)) Tlong:0; +}; + +extern struct S2411 a2411[5]; +extern void checkx2411(struct S2411); +void test2411(void) { + checkx2411(a2411[0]); +} + +// Proper handling of zero sized fields during type conversion. +typedef unsigned long long int Tal2ullong __attribute__((aligned(2))); +struct S2525 { + Tal2ullong: 0; + struct { + } e; +}; +struct S2525 s2525; + +struct { + signed char f; + char :0; + struct{}h; + char * i[5]; +} data; + +// Taking address of a zero sized field. +struct Z {}; +struct Y { + int i; + struct Z z; +}; +void *f(struct Y *y) { + return &y->z; +} diff --git a/test/CodeGen/2008-01-28-PragmaMark.c b/test/CodeGen/2008-01-28-PragmaMark.c new file mode 100644 index 000000000000..399af958fcf1 --- /dev/null +++ b/test/CodeGen/2008-01-28-PragmaMark.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -Werror -emit-llvm %s -o /dev/null +#pragma mark LLVM's world +#ifdef DO_ERROR +#error LLVM's world +#endif +int i; diff --git a/test/CodeGen/2008-01-28-UnionSize.c b/test/CodeGen/2008-01-28-UnionSize.c new file mode 100644 index 000000000000..14f363dbc05c --- /dev/null +++ b/test/CodeGen/2008-01-28-UnionSize.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - +// PR 1861 + +typedef unsigned char __u8; +typedef unsigned int __u32; +typedef unsigned short u16; +typedef __u32 __le32; +struct bcm43xx_plcp_hdr6 { + union { + __le32 data; + __u8 raw[6]; + } + __attribute__((__packed__)); +} + __attribute__((__packed__)); +struct bcm43xx_txhdr { + union { + struct { + struct bcm43xx_plcp_hdr6 plcp; + }; + }; +} + __attribute__((__packed__)); +static void bcm43xx_generate_rts(struct bcm43xx_txhdr *txhdr ) { } diff --git a/test/CodeGen/2008-03-03-CtorAttrType.c b/test/CodeGen/2008-03-03-CtorAttrType.c new file mode 100644 index 000000000000..dbd7bc0a7270 --- /dev/null +++ b/test/CodeGen/2008-03-03-CtorAttrType.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | grep llvm.global_ctors +int __attribute__((constructor)) foo(void) { + return 0; +} +void __attribute__((constructor)) bar(void) {} + diff --git a/test/CodeGen/2008-03-05-syncPtr.c b/test/CodeGen/2008-03-05-syncPtr.c new file mode 100644 index 000000000000..784295ce6890 --- /dev/null +++ b/test/CodeGen/2008-03-05-syncPtr.c @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +int* foo(int** a, int* b, int* c) { +return __sync_val_compare_and_swap (a, b, c); +} +// CHECK: define i32* @foo +// CHECK: cmpxchg + +int foo2(int** a, int* b, int* c) { +return __sync_bool_compare_and_swap (a, b, c); +} +// CHECK: define i32 @foo2 +// CHECK: cmpxchg + +int* foo3(int** a, int b) { + return __sync_fetch_and_add (a, b); +} +// CHECK: define i32* @foo3 +// CHECK: atomicrmw add + + +int* foo4(int** a, int b) { + return __sync_fetch_and_sub (a, b); +} +// CHECK: define i32* @foo4 +// CHECK: atomicrmw sub + + +int* foo5(int** a, int* b) { + return __sync_lock_test_and_set (a, b); +} +// CHECK: define i32* @foo5 +// CHECK: atomicrmw xchg + + +int* foo6(int** a, int*** b) { + return __sync_lock_test_and_set (a, b); +} +// CHECK: define i32* @foo6 +// CHECK: atomicrmw xchg diff --git a/test/CodeGen/2008-03-24-BitField-And-Alloca.c b/test/CodeGen/2008-03-24-BitField-And-Alloca.c new file mode 100644 index 000000000000..cb80d76e0596 --- /dev/null +++ b/test/CodeGen/2008-03-24-BitField-And-Alloca.c @@ -0,0 +1,89 @@ +// RUN: %clang_cc1 -O2 -emit-llvm %s -o - | not grep alloca +// RUN: %clang_cc1 -m32 -O2 -emit-llvm %s -o - | not grep {store } + +enum { + PP_C, + PP_D, + PP_R, + PP_2D, + PP_1D, + PP_SR, + PP_S2D, + PP_S1D, + PP_SC +}; + +enum { + G_VP, + G_FP, + G_VS, + G_GS, + G_FS +}; + +enum { + G_NONE, + G_B, + G_R +}; + +typedef union _Key { + struct { + unsigned int count : 2; + unsigned int Aconst : 1; + unsigned int Bconst : 1; + unsigned int Cconst : 1; + unsigned int Xused : 1; + unsigned int Yused : 1; + unsigned int Zused : 1; + unsigned int Wused : 1; + unsigned int ttype : 3; + unsigned int scalar : 1; + unsigned int AType : 4; + unsigned int BType : 4; + unsigned int CType : 4; + unsigned int RType : 4; + unsigned int Size : 2; + unsigned int prec : 1; + + unsigned int ASize : 2; + unsigned int BSize : 2; + unsigned int CSize : 2; + unsigned int tTex : 4; + unsigned int proj : 1; + unsigned int lod : 2; + unsigned int dvts : 1; + unsigned int uipad : 18; + } key_io; + struct { + unsigned int key0; + unsigned int key1; + } key; + unsigned long long lkey; +} Key; + +static void foo(const Key iospec, int* ret) +{ + *ret=0; + if(((iospec.key_io.lod == G_B) && + (iospec.key_io.ttype != G_VS) && + (iospec.key_io.ttype != G_GS) && + (iospec.key_io.ttype != G_FS)) || + + (((iospec.key_io.tTex == PP_C) || + (iospec.key_io.tTex == PP_SC)) && + ((iospec.key_io.tTex == PP_SR) || + (iospec.key_io.tTex == PP_S2D) || + (iospec.key_io.tTex == PP_S1D) || + (iospec.key_io.tTex == PP_SC)))) + *ret=1; +} + + +extern int bar(unsigned long long key_token2) +{ + int ret; + __attribute__ ((unused)) Key iospec = (Key) key_token2; + foo(iospec, &ret); + return ret; +} diff --git a/test/CodeGen/2008-03-26-PackedBitFields.c b/test/CodeGen/2008-03-26-PackedBitFields.c new file mode 100644 index 000000000000..72e5cb17de2e --- /dev/null +++ b/test/CodeGen/2008-03-26-PackedBitFields.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + + +struct S1757 { + long double c; + long int __attribute__((packed)) e:28; +} x; diff --git a/test/CodeGen/2008-04-08-NoExceptions.c b/test/CodeGen/2008-04-08-NoExceptions.c new file mode 100644 index 000000000000..6d5d20ff8541 --- /dev/null +++ b/test/CodeGen/2008-04-08-NoExceptions.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +void f(void); +void g(void) { + // CHECK: define void @g() nounwind + // CHECK-NOT: call void @f() nounwind + f(); +} + +// CHECK-NOT: declare void @f() nounwind diff --git a/test/CodeGen/2008-05-06-CFECrash.c b/test/CodeGen/2008-05-06-CFECrash.c new file mode 100644 index 000000000000..11775673a7cc --- /dev/null +++ b/test/CodeGen/2008-05-06-CFECrash.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -emit-llvm -O2 %s -o /dev/null +// PR2292. +__inline__ __attribute__ ((__pure__)) int g (void) {} +void f (int k) { k = g (); } diff --git a/test/CodeGen/2008-05-12-TempUsedBeforeDef.c b/test/CodeGen/2008-05-12-TempUsedBeforeDef.c new file mode 100644 index 000000000000..bc2886effc20 --- /dev/null +++ b/test/CodeGen/2008-05-12-TempUsedBeforeDef.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -w -emit-llvm -o /dev/null %s +// PR2264. +unsigned foo = 8L; +unsigned bar = 0L; +volatile unsigned char baz = 6L; +int test() { + char qux = 1L; + for (; baz >= -29; baz--) + bork(bar && foo, qux); +} diff --git a/test/CodeGen/2008-05-19-AlwaysInline.c b/test/CodeGen/2008-05-19-AlwaysInline.c new file mode 100644 index 000000000000..73a7691aed76 --- /dev/null +++ b/test/CodeGen/2008-05-19-AlwaysInline.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -fno-unit-at-a-time -O0 -o - | not grep sabrina +// RUN: %clang_cc1 %s -emit-llvm -funit-at-a-time -O0 -o - | not grep sabrina + +static inline int sabrina (void) __attribute__((always_inline)); +static inline int sabrina (void) +{ + return 13; +} +int bar (void) +{ + return sabrina () + 68; +} diff --git a/test/CodeGen/2008-08-07-AlignPadding1.c b/test/CodeGen/2008-08-07-AlignPadding1.c new file mode 100644 index 000000000000..2bb2e61be0db --- /dev/null +++ b/test/CodeGen/2008-08-07-AlignPadding1.c @@ -0,0 +1,32 @@ +/* RUN: %clang_cc1 %s -emit-llvm -triple x86_64-apple-darwin -o - | FileCheck %s + +The FE must generate padding here both at the end of each PyG_Head and +between array elements. Reduced from Python. */ + +typedef union _gc_head { + struct { + union _gc_head *gc_next; + union _gc_head *gc_prev; + long gc_refs; + } gc; + int dummy __attribute__((aligned(16))); +} PyGC_Head; + +struct gc_generation { + PyGC_Head head; + int threshold; + int count; +}; + +#define GEN_HEAD(n) (&generations[n].head) + +// The idea is that there are 6 undefs in this structure initializer to cover +// the padding between elements. +// CHECK: @generations = global [3 x %struct.gc_generation] [%struct.gc_generation { %union._gc_head { %struct.anon { %union._gc_head* getelementptr inbounds ([3 x %struct.gc_generation]* @generations, i32 0, i32 0, i32 0), %union._gc_head* getelementptr inbounds ([3 x %struct.gc_generation]* @generations, i32 0, i32 0, i32 0), i64 0 }, [8 x i8] undef }, i32 700, i32 0, [8 x i8] undef }, %struct.gc_generation { %union._gc_head { %struct.anon { %union._gc_head* bitcast (i8* getelementptr (i8* bitcast ([3 x %struct.gc_generation]* @generations to i8*), i64 48) to %union._gc_head*), %union._gc_head* bitcast (i8* getelementptr (i8* bitcast ([3 x %struct.gc_generation]* @generations to i8*), i64 48) to %union._gc_head*), i64 0 }, [8 x i8] undef }, i32 10, i32 0, [8 x i8] undef }, %struct.gc_generation { %union._gc_head { %struct.anon { %union._gc_head* bitcast (i8* getelementptr (i8* bitcast ([3 x %struct.gc_generation]* @generations to i8*), i64 96) to %union._gc_head*), %union._gc_head* bitcast (i8* getelementptr (i8* bitcast ([3 x %struct.gc_generation]* @generations to i8*), i64 96) to %union._gc_head*), i64 0 }, [8 x i8] undef }, i32 10, i32 0, [8 x i8] undef }] +/* linked lists of container objects */ +struct gc_generation generations[3] = { + /* PyGC_Head, threshold, count */ + {{{GEN_HEAD(0), GEN_HEAD(0), 0}}, 700, 0}, + {{{GEN_HEAD(1), GEN_HEAD(1), 0}}, 10, 0}, + {{{GEN_HEAD(2), GEN_HEAD(2), 0}}, 10, 0}, +}; diff --git a/test/CodeGen/2008-08-07-AlignPadding2.c b/test/CodeGen/2008-08-07-AlignPadding2.c new file mode 100644 index 000000000000..ecf28dd72de0 --- /dev/null +++ b/test/CodeGen/2008-08-07-AlignPadding2.c @@ -0,0 +1,18 @@ +/* RUN: %clang_cc1 %s -emit-llvm -o - -O0 | grep zeroinitializer | count 1 + +The FE must not generate padding here between array elements. PR 2533. */ + +typedef struct { + const char *name; + int flags; + union { + int x; + } u; +} OptionDef; + +const OptionDef options[] = { + /* main options */ + { "a", 0, {3} }, + { "b", 0, {4} }, + { 0, }, +}; diff --git a/test/CodeGen/2008-08-07-GEPIntToPtr.c b/test/CodeGen/2008-08-07-GEPIntToPtr.c new file mode 100644 index 000000000000..6892be033a98 --- /dev/null +++ b/test/CodeGen/2008-08-07-GEPIntToPtr.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s +// PR2603 + +struct A { + char num_fields; +}; + +struct B { + char a, b[1]; +}; + +const struct A Foo = { + // CHECK: i8 1 + (char *)(&( (struct B *)(16) )->b[0]) - (char *)(16) +}; diff --git a/test/CodeGen/2008-09-03-WeakAlias.c b/test/CodeGen/2008-09-03-WeakAlias.c new file mode 100644 index 000000000000..4712a0138cb6 --- /dev/null +++ b/test/CodeGen/2008-09-03-WeakAlias.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-llvm -O1 -o - %s | grep icmp +// PR1678 +extern void B (void); +static __typeof(B) A __attribute__ ((__weakref__("B"))); +int active (void) +{ + static void *const p = __extension__ (void *) &A; + return p != 0; +} diff --git a/test/CodeGen/2008-10-13-FrontendCrash.c b/test/CodeGen/2008-10-13-FrontendCrash.c new file mode 100644 index 000000000000..cdd122970583 --- /dev/null +++ b/test/CodeGen/2008-10-13-FrontendCrash.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - +// PR2797 + +unsigned int +func_48 (signed char p_49) +{ + signed char l_340; + func_44 (1&((1 ^ 1 == (lshift_u_s (1)) != (l_340 < 1)) & 1L)); +} diff --git a/test/CodeGen/2008-10-30-ZeroPlacement.c b/test/CodeGen/2008-10-30-ZeroPlacement.c new file mode 100644 index 000000000000..f3806d499d52 --- /dev/null +++ b/test/CodeGen/2008-10-30-ZeroPlacement.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - +// PR2987 +struct S2045 +{ + unsigned short int a; + union { } b; + union __attribute__ ((aligned (4))) { } c[0]; +}; +struct S2045 s2045; diff --git a/test/CodeGen/2008-11-02-WeakAlias.c b/test/CodeGen/2008-11-02-WeakAlias.c new file mode 100644 index 000000000000..63fd4e15eac9 --- /dev/null +++ b/test/CodeGen/2008-11-02-WeakAlias.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple=i686-pc-linux-gnu -emit-llvm -o - %s | FileCheck %s +// PR2691 + +// CHECK: weak +void init_IRQ(void) __attribute__((weak, alias("native_init_IRQ"))); +void native_init_IRQ(void) {} diff --git a/test/CodeGen/2008-11-08-InstCombineSelect.c b/test/CodeGen/2008-11-08-InstCombineSelect.c new file mode 100644 index 000000000000..3f4428e572ee --- /dev/null +++ b/test/CodeGen/2008-11-08-InstCombineSelect.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -emit-llvm -O2 -o - +// PR3028 + +int g_187; +int g_204; +int g_434; + +int func_89 (void) +{ + return 1; +} + +void func_20 (int p_22) +{ + if (1 & p_22 | g_204 & (1 < g_187) - func_89 ()) + g_434 = 1; +} diff --git a/test/CodeGen/2008-12-23-AsmIntPointerTie.c b/test/CodeGen/2008-12-23-AsmIntPointerTie.c new file mode 100644 index 000000000000..df646b7801f7 --- /dev/null +++ b/test/CodeGen/2008-12-23-AsmIntPointerTie.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -O1 -o - + +typedef long intptr_t; +int test(void *b) { + intptr_t a; + __asm__ __volatile__ ("%0 %1 " : "=r" (a): "0" (b)); + return a; +} diff --git a/test/CodeGen/2009-01-05-BlockInlining.c b/test/CodeGen/2009-01-05-BlockInlining.c new file mode 100644 index 000000000000..2ae9b70bb8fd --- /dev/null +++ b/test/CodeGen/2009-01-05-BlockInlining.c @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 %s -emit-llvm -fblocks -o - | FileCheck %s +// rdar://5865221 + +// These will be inlined by the optimizers provided the block descriptors +// and block literals are internal constants. +// CHECK: @__block_descriptor_tmp = internal constant +// CHECK: @__block_literal_global = internal constant +// CHECK: @__block_descriptor_tmp1 = internal constant +// CHECK: @__block_literal_global2 = internal constant +static int fun(int x) { + return x+1; +} + +static int block(int x) { + return (^(int x){return x+1;})(x); +} + +static void print(int result) { + printf("%d\n", result); +} + +int main (int argc, const char * argv[]) { + int x = argc-1; + print(fun(x)); + print(block(x)); + int (^block_inline)(int) = ^(int x){return x+1;}; + print(block_inline(x)); + return 0; +} diff --git a/test/CodeGen/2009-01-21-InvalidIterator.c b/test/CodeGen/2009-01-21-InvalidIterator.c new file mode 100644 index 000000000000..f857b4d8bd00 --- /dev/null +++ b/test/CodeGen/2009-01-21-InvalidIterator.c @@ -0,0 +1,74 @@ +// RUN: %clang_cc1 %s -emit-llvm -g -o /dev/null + +typedef long unsigned int size_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long int uint64_t; +typedef uint16_t Elf64_Half; +typedef uint32_t Elf64_Word; +typedef uint64_t Elf64_Xword; +typedef uint64_t Elf64_Addr; +typedef uint64_t Elf64_Off; +typedef struct +{ + Elf64_Word p_type; + Elf64_Off p_offset; + Elf64_Addr p_vaddr; + Elf64_Xword p_align; +} +Elf64_Phdr; +struct dl_phdr_info +{ + const char *dlpi_name; + const Elf64_Phdr *dlpi_phdr; + Elf64_Half dlpi_phnum; + unsigned long long int dlpi_adds; +}; +typedef unsigned _Unwind_Ptr; +struct object +{ + union + { + const struct dwarf_fde *single; + struct dwarf_fde **array; + struct fde_vector *sort; + } + u; + union + { + struct + { + } + b; + } + s; + struct object *next; +}; +typedef int sword; +typedef unsigned int uword; +struct dwarf_fde +{ + uword length; + sword CIE_delta; + unsigned char pc_begin[]; +}; +typedef struct dwarf_fde fde; +struct unw_eh_callback_data +{ + const fde *ret; + struct frame_hdr_cache_element *link; +} +frame_hdr_cache[8]; + +_Unwind_Ptr +base_from_cb_data (struct unw_eh_callback_data *data) +{ +} + +void +_Unwind_IteratePhdrCallback (struct dl_phdr_info *info, size_t size, void *ptr) +{ + const unsigned char *p; + const struct unw_eh_frame_hdr *hdr; + struct object ob; +} diff --git a/test/CodeGen/2009-02-13-zerosize-union-field-ppc.c b/test/CodeGen/2009-02-13-zerosize-union-field-ppc.c new file mode 100644 index 000000000000..21b47052813e --- /dev/null +++ b/test/CodeGen/2009-02-13-zerosize-union-field-ppc.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 %s -m32 -emit-llvm -o - | grep {i32 32} | count 3 +// XFAIL: * +// XTARGET: powerpc +// Every printf has 'i32 0' for the GEP of the string; no point counting those. +typedef unsigned int Foo __attribute__((aligned(32))); +typedef union{Foo:0;}a; +typedef union{int x; Foo:0;}b; +extern int printf(const char*, ...); +main() { + printf("%ld\n", sizeof(a)); + printf("%ld\n", __alignof__(a)); + printf("%ld\n", sizeof(b)); + printf("%ld\n", __alignof__(b)); +} diff --git a/test/CodeGen/2009-02-13-zerosize-union-field.c b/test/CodeGen/2009-02-13-zerosize-union-field.c new file mode 100644 index 000000000000..b39a231c65e1 --- /dev/null +++ b/test/CodeGen/2009-02-13-zerosize-union-field.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -triple i686-apple-darwin -emit-llvm -o - | FileCheck %s +// Every printf has 'i32 0' for the GEP of the string; no point counting those. +typedef unsigned int Foo __attribute__((aligned(32))); +typedef union{Foo:0;}a; +typedef union{int x; Foo:0;}b; +extern int printf(const char*, ...); +int main() { + // CHECK: getelementptr inbounds ([5 x i8]* @.str, i32 0, i32 0), i32 0 + printf("%ld\n", sizeof(a)); + // CHECK: getelementptr inbounds ([5 x i8]* @.str, i32 0, i32 0), i32 1 + printf("%ld\n", __alignof__(a)); + // CHECK: getelementptr inbounds ([5 x i8]* @.str, i32 0, i32 0), i32 4 + printf("%ld\n", sizeof(b)); + // CHECK: getelementptr inbounds ([5 x i8]* @.str, i32 0, i32 0), i32 4 + printf("%ld\n", __alignof__(b)); +} diff --git a/test/CodeGen/2009-03-01-MallocNoAlias.c b/test/CodeGen/2009-03-01-MallocNoAlias.c new file mode 100644 index 000000000000..1c4878a8189c --- /dev/null +++ b/test/CodeGen/2009-03-01-MallocNoAlias.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | grep noalias + +void * __attribute__ ((malloc)) foo (void) { return 0; } diff --git a/test/CodeGen/2009-03-08-ZeroEltStructCrash.c b/test/CodeGen/2009-03-08-ZeroEltStructCrash.c new file mode 100644 index 000000000000..b530eb7ce1e5 --- /dev/null +++ b/test/CodeGen/2009-03-08-ZeroEltStructCrash.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - +// PR3744 +struct Empty {}; +struct Union { + union { + int zero_arr[0]; + } contents; +}; +static inline void Foo(struct Union *u) { + int *array = u->contents.zero_arr; +} +static void Bar(struct Union *u) { + Foo(u); +} diff --git a/test/CodeGen/2009-03-13-dbg.c b/test/CodeGen/2009-03-13-dbg.c new file mode 100644 index 000000000000..8f48830e8e2f --- /dev/null +++ b/test/CodeGen/2009-03-13-dbg.c @@ -0,0 +1,2 @@ +// RUN: %clang_cc1 %s -emit-llvm -g -o /dev/null +void foo() {} diff --git a/test/CodeGen/2009-04-28-UnionArrayCrash.c b/test/CodeGen/2009-04-28-UnionArrayCrash.c new file mode 100644 index 000000000000..4296b918cbcc --- /dev/null +++ b/test/CodeGen/2009-04-28-UnionArrayCrash.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - +// PR4082 +union U { + int I; + double F; +}; + +union U arr[] = { { .I = 4 }, { .F = 123.} }; +union U *P = &arr[0]; + + diff --git a/test/CodeGen/2009-05-04-EnumInreg.c b/test/CodeGen/2009-05-04-EnumInreg.c new file mode 100644 index 000000000000..2abc747caf27 --- /dev/null +++ b/test/CodeGen/2009-05-04-EnumInreg.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm -triple i686-apple-darwin -mregparm 3 %s -o - | FileCheck %s +// PR3967 + +enum kobject_action { + KOBJ_ADD, + KOBJ_REMOVE, + KOBJ_CHANGE, + KOBJ_MOVE, + KOBJ_ONLINE, + KOBJ_OFFLINE, + KOBJ_MAX +}; + +struct kobject; + +// CHECK: i32 inreg %action +int kobject_uevent(struct kobject *kobj, enum kobject_action action) {} diff --git a/test/CodeGen/2009-06-14-HighlyAligned.c b/test/CodeGen/2009-06-14-HighlyAligned.c new file mode 100644 index 000000000000..b5a7f5e733ff --- /dev/null +++ b/test/CodeGen/2009-06-14-HighlyAligned.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -o /dev/null +// PR4332 + +static int highly_aligned __attribute__((aligned(4096))); + +int f() { + return highly_aligned; +} diff --git a/test/CodeGen/2009-06-18-StaticInitTailPadPack.c b/test/CodeGen/2009-06-18-StaticInitTailPadPack.c new file mode 100644 index 000000000000..be103ec8e347 --- /dev/null +++ b/test/CodeGen/2009-06-18-StaticInitTailPadPack.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - +// rdar://6983634 + + typedef struct A *Foo; +#pragma pack(push, 2) + struct Bar { + Foo f1; + unsigned short f2; + float f3; + }; + struct Baz { + struct Bar f1; + struct Bar f2; + }; + struct Qux { + unsigned long f1; + struct Baz f2; + }; +extern const struct Qux Bork; +const struct Qux Bork = { + 0, + { + {0}, + {0} + } +}; diff --git a/test/CodeGen/2009-07-14-VoidPtr.c b/test/CodeGen/2009-07-14-VoidPtr.c new file mode 100644 index 000000000000..5e8b23d3aab6 --- /dev/null +++ b/test/CodeGen/2009-07-14-VoidPtr.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - +// PR4556 + +extern void foo; +void *bar = &foo; + diff --git a/test/CodeGen/2009-07-15-pad-wchar_t-array.c b/test/CodeGen/2009-07-15-pad-wchar_t-array.c new file mode 100644 index 000000000000..df12cae90ea0 --- /dev/null +++ b/test/CodeGen/2009-07-15-pad-wchar_t-array.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +// This bit is taken from Sema/wchar.c so we can avoid the wchar.h include. +typedef __WCHAR_TYPE__ wchar_t; +#if defined(_WIN32) || defined(_M_IX86) || defined(__CYGWIN__) \ + || defined(_M_X64) || defined(SHORT_WCHAR) + #define WCHAR_T_TYPE unsigned short +#elif defined(__sun) || defined(__AuroraUX__) + #define WCHAR_T_TYPE long +#else /* Solaris or AuroraUX. */ + #define WCHAR_T_TYPE int +#endif + +signed short _iodbcdm_sqlerror( ) +{ + wchar_t _sqlState[6] = { L"\0" }; +} diff --git a/test/CodeGen/2009-07-22-StructLayout.c b/test/CodeGen/2009-07-22-StructLayout.c new file mode 100644 index 000000000000..7b7b82c40a5f --- /dev/null +++ b/test/CodeGen/2009-07-22-StructLayout.c @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 %s -triple i686-pc-linux-gnu -emit-llvm -o /dev/null +// PR4590 + +typedef unsigned char __u8; +typedef unsigned int __le32; +typedef unsigned int __u32; +typedef unsigned short __le16; +typedef unsigned short __u16; + +struct usb_cdc_ether_desc { + __u8 bLength; + __u8 bDescriptorType; + __u8 bDescriptorSubType; + + __u8 iMACAddress; + __le32 bmEthernetStatistics; + __le16 wMaxSegmentSize; + __le16 wNumberMCFilters; + __u8 bNumberPowerFilters; +} __attribute__ ((packed)); + + +static struct usb_cdc_ether_desc ecm_desc __attribute__ ((__section__(".init.data"))) = { + .bLength = sizeof ecm_desc, + .bDescriptorType = ((0x01 << 5) | 0x04), + .bDescriptorSubType = 0x0f, + + + + .bmEthernetStatistics = (( __le32)(__u32)(0)), + .wMaxSegmentSize = (( __le16)(__u16)(1514)), + .wNumberMCFilters = (( __le16)(__u16)(0)), + .bNumberPowerFilters = 0, +}; diff --git a/test/CodeGen/2009-09-24-SqrtErrno.c b/test/CodeGen/2009-09-24-SqrtErrno.c new file mode 100644 index 000000000000..b4a04ff6b6ab --- /dev/null +++ b/test/CodeGen/2009-09-24-SqrtErrno.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -fmath-errno | FileCheck %s +// llvm.sqrt has undefined behavior on negative inputs, so it is +// inappropriate to translate C/C++ sqrt to this. + +float sqrtf(float x); +float foo(float X) { +// CHECK: foo +// CHECK-NOT: readonly +// CHECK: call float @sqrtf + // Check that this is not marked readonly when errno is used. + return sqrtf(X); +} diff --git a/test/CodeGen/2009-12-07-BitFieldAlignment.c b/test/CodeGen/2009-12-07-BitFieldAlignment.c new file mode 100644 index 000000000000..72c30e13c955 --- /dev/null +++ b/test/CodeGen/2009-12-07-BitFieldAlignment.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple i686-apple-darwin %s -emit-llvm -o - | FileCheck %s +// Set alignment on bitfield accesses. + +struct S { + int a, b; + void *c; + unsigned d : 8; + unsigned e : 8; +}; + +void f0(struct S *a) { +// CHECK: load {{.*}}, align 4 +// CHECK: store {{.*}}, align 4 + a->e = 0; +} diff --git a/test/CodeGen/2010-01-13-MemBarrier.c b/test/CodeGen/2010-01-13-MemBarrier.c new file mode 100644 index 000000000000..c2b0acdab3cb --- /dev/null +++ b/test/CodeGen/2010-01-13-MemBarrier.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s +// XFAIL: sparc +// rdar://7536390 + +typedef unsigned __INT32_TYPE__ uint32_t; + +unsigned t(uint32_t *ptr, uint32_t val) { + // CHECK: @t + // CHECK: atomicrmw xchg i32* {{.*}} seq_cst + return __sync_lock_test_and_set(ptr, val); +} diff --git a/test/CodeGen/2010-01-14-FnType-DebugInfo.c b/test/CodeGen/2010-01-14-FnType-DebugInfo.c new file mode 100644 index 000000000000..964c031d27c0 --- /dev/null +++ b/test/CodeGen/2010-01-14-FnType-DebugInfo.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -emit-llvm -g -o /dev/null +typedef void (*sigcatch_t)( struct sigcontext *); +sigcatch_t sigcatch[50] = {(sigcatch_t) 0}; + diff --git a/test/CodeGen/2010-01-18-Inlined-Debug.c b/test/CodeGen/2010-01-18-Inlined-Debug.c new file mode 100644 index 000000000000..cf00be7752cf --- /dev/null +++ b/test/CodeGen/2010-01-18-Inlined-Debug.c @@ -0,0 +1,12 @@ +// PR: 6058 +// RUN: %clang_cc1 -g -emit-llvm %s -O0 -o /dev/null + +static inline int foo(double) __attribute__ ((always_inline)); +static inline int foo(double __x) { return __x; } + +void bar(double x) { + foo(x); +} + + + diff --git a/test/CodeGen/2010-02-10-PointerName.c b/test/CodeGen/2010-02-10-PointerName.c new file mode 100644 index 000000000000..910dd30fc603 --- /dev/null +++ b/test/CodeGen/2010-02-10-PointerName.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -emit-llvm -g -o - | grep DW_TAG_pointer_type | grep -v char + +char i = 1; +void foo() { + char *cp = &i; +} + diff --git a/test/CodeGen/2010-02-15-DbgStaticVar.c b/test/CodeGen/2010-02-15-DbgStaticVar.c new file mode 100644 index 000000000000..facd14e03ee6 --- /dev/null +++ b/test/CodeGen/2010-02-15-DbgStaticVar.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -g -emit-llvm %s -o - | grep "metadata ..b., metadata ..b., metadata ...," +// Test to check intentionally empty linkage name for a static variable. +// Radar 7651244. +static int foo(int a) +{ + static int b = 1; + return b+a; +} + +int main() { + int j = foo(1); + return 0; +} diff --git a/test/CodeGen/2010-03-5-LexicalScope.c b/test/CodeGen/2010-03-5-LexicalScope.c new file mode 100644 index 000000000000..0f63ff6914b2 --- /dev/null +++ b/test/CodeGen/2010-03-5-LexicalScope.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm -O0 -g %s -o - | grep DW_TAG_lexical_block | count 3 +int foo(int i) { + if (i) { + int j = 2; + } + else { + int j = 3; + } + return i; +} diff --git a/test/CodeGen/2010-05-26-AsmSideEffect.c b/test/CodeGen/2010-05-26-AsmSideEffect.c new file mode 100644 index 000000000000..7dd86aeb54d7 --- /dev/null +++ b/test/CodeGen/2010-05-26-AsmSideEffect.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -emit-llvm -triple arm-apple-darwin -o - | FileCheck %s +// Radar 8026855 + +int test (void *src) { + register int w0 asm ("0"); + // CHECK: call i32 asm "ldr $0, [$1]", "={r0}{{.*}}(i8* + asm ("ldr %0, [%1]": "=r" (w0): "r" (src)); + return w0; +} diff --git a/test/CodeGen/2010-06-11-SaveExpr.c b/test/CodeGen/2010-06-11-SaveExpr.c new file mode 100644 index 000000000000..bfe0f35e269c --- /dev/null +++ b/test/CodeGen/2010-06-11-SaveExpr.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - +// Test case by Eric Postpischil! +void foo(void) +{ + char a[1]; + int t = 1; + ((char (*)[t]) a)[0][0] = 0; +} diff --git a/test/CodeGen/2010-06-17-asmcrash.c b/test/CodeGen/2010-06-17-asmcrash.c new file mode 100644 index 000000000000..8e9485bba9b8 --- /dev/null +++ b/test/CodeGen/2010-06-17-asmcrash.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | llc -mtriple=x86_64-apple-darwin | FileCheck %s +// XFAIL: * +// XTARGET: x86,i386,i686 + +typedef long long int64_t; +typedef unsigned char uint8_t; +typedef int64_t x86_reg; + +void avg_pixels8_mmx2(uint8_t *block, const uint8_t *pixels, int line_size, int h) +{ + __asm__ volatile("# %0 %1 %2 %3" + :"+g"(h), "+S"(pixels), "+D"(block) + :"r" ((x86_reg)line_size) + :"%""rax", "memory"); +// CHECK: # %ecx %rsi %rdi %rdx + } diff --git a/test/CodeGen/2010-07-08-DeclDebugLineNo.c b/test/CodeGen/2010-07-08-DeclDebugLineNo.c new file mode 100644 index 000000000000..1637a4936747 --- /dev/null +++ b/test/CodeGen/2010-07-08-DeclDebugLineNo.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm -O0 -g %s -o - | FileCheck %s +// Insure that dbg.declare lines for locals refer to correct line number records. +// Radar 8152866. +void foo() { + int l = 0; // line #4: CHECK: {{call.*llvm.dbg.declare.*%l.*\!dbg }}[[variable_l:![0-9]+]] + int p = 0; // line #5: CHECK: {{call.*llvm.dbg.declare.*%p.*\!dbg }}[[variable_p:![0-9]+]] +} +// Now match the line number records: +// CHECK: {{^}}[[variable_l]]{{ = metadata ![{]i32 5,}} +// CHECK: {{^}}[[variable_p]]{{ = metadata ![{]i32 6,}} diff --git a/test/CodeGen/2010-07-14-overconservative-align.c b/test/CodeGen/2010-07-14-overconservative-align.c new file mode 100644 index 000000000000..5c8c05645178 --- /dev/null +++ b/test/CodeGen/2010-07-14-overconservative-align.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 %s -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s +// PR 5995 +struct s { + int word; + struct { + int filler __attribute__ ((aligned (8))); + }; +}; + +void func (struct s *s) +{ + // CHECK: load %struct.s**{{.*}}align 8 + s->word = 0; +} diff --git a/test/CodeGen/2010-07-14-ref-off-end.c b/test/CodeGen/2010-07-14-ref-off-end.c new file mode 100644 index 000000000000..580ae889d8f2 --- /dev/null +++ b/test/CodeGen/2010-07-14-ref-off-end.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 %s -emit-llvm -triple i386-apple-darwin -o - | FileCheck %s +extern void abort(); +extern void exit(int); +struct T +{ +unsigned i:8; +unsigned c:24; +}; +f(struct T t) +{ +struct T s[1]; +s[0]=t; +return(char)s->c; +} +main() +{ +// CHECK: getelementptr inbounds [1 x %struct.T]* %s, i32 0, i32 0 +// CHECK: getelementptr inbounds [1 x %struct.T]* %s, i32 0, i32 0 +struct T t; +t.i=0xff; +t.c=0xffff11; +if(f(t)!=0x11)abort(); +exit(0); +} diff --git a/test/CodeGen/2010-08-12-asm-aggr-arg.c b/test/CodeGen/2010-08-12-asm-aggr-arg.c new file mode 100644 index 000000000000..5ddc4122d60f --- /dev/null +++ b/test/CodeGen/2010-08-12-asm-aggr-arg.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -emit-llvm -O0 -o - | FileCheck %s +// Radar 8288710: A small aggregate can be passed as an integer. Make sure +// we don't get an error with "input constraint with a matching output +// constraint of incompatible type!" + +struct wrapper { + int i; +}; + +// CHECK: xyz +int test(int i) { + struct wrapper w; + w.i = i; + __asm__("xyz" : "=r" (w) : "0" (w)); + return w.i; +} diff --git a/test/CodeGen/2010-12-01-CommonGlobal.c b/test/CodeGen/2010-12-01-CommonGlobal.c new file mode 100644 index 000000000000..5eadbae6e3a6 --- /dev/null +++ b/test/CodeGen/2010-12-01-CommonGlobal.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null +// Don't crash on a common-linkage constant global. +extern const int kABSourceTypeProperty; +int foo(void) { + return kABSourceTypeProperty; +} +const int kABSourceTypeProperty; diff --git a/test/CodeGen/2011-02-21-DATA-common.c b/test/CodeGen/2011-02-21-DATA-common.c new file mode 100644 index 000000000000..5079561c868c --- /dev/null +++ b/test/CodeGen/2011-02-21-DATA-common.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null +struct rtxc_snapshot { + int a, b, c, d; +}; +__attribute__ ((section("__DATA, __common"))) static struct rtxc_snapshot rtxc_log_A[4]; diff --git a/test/CodeGen/2011-03-02-UnionInitializer.c b/test/CodeGen/2011-03-02-UnionInitializer.c new file mode 100644 index 000000000000..3c112e0a47f0 --- /dev/null +++ b/test/CodeGen/2011-03-02-UnionInitializer.c @@ -0,0 +1,2 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - +union { int :3; double f; } u17_017 = {17.17}; diff --git a/test/CodeGen/2011-03-08-ZeroFieldUnionInitializer.c b/test/CodeGen/2011-03-08-ZeroFieldUnionInitializer.c new file mode 100644 index 000000000000..ff570d8abb42 --- /dev/null +++ b/test/CodeGen/2011-03-08-ZeroFieldUnionInitializer.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null +typedef struct { + union { + struct { } __attribute((packed)); + }; +} fenv_t; +const fenv_t _FE_DFL_ENV = {{{ 0, 0, 0, 0 }}}; diff --git a/test/CodeGen/2011-03-31-ArrayRefFolding.c b/test/CodeGen/2011-03-31-ArrayRefFolding.c new file mode 100644 index 000000000000..31c0a681a4dc --- /dev/null +++ b/test/CodeGen/2011-03-31-ArrayRefFolding.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -emit-llvm -o - -triple i386-apple-darwin %s | FileCheck %s +// PR9571 + +struct t { + int x; +}; + +extern struct t *cfun; + +int f(void) { + if (!(cfun + 0)) + // CHECK: icmp ne %struct.t* + return 0; + return cfun->x; +} diff --git a/test/CodeGen/Atomics.c b/test/CodeGen/Atomics.c new file mode 100644 index 000000000000..c440b6c1909e --- /dev/null +++ b/test/CodeGen/Atomics.c @@ -0,0 +1,203 @@ +// Test frontend handling of __sync builtins. +// Modified from a gcc testcase. +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s + +signed char sc; +unsigned char uc; +signed short ss; +unsigned short us; +signed int si; +unsigned int ui; +signed long long sll; +unsigned long long ull; + +void test_op_ignore (void) // CHECK: define void @test_op_ignore +{ + (void) __sync_fetch_and_add (&sc, 1); // CHECK: atomicrmw add i8 + (void) __sync_fetch_and_add (&uc, 1); // CHECK: atomicrmw add i8 + (void) __sync_fetch_and_add (&ss, 1); // CHECK: atomicrmw add i16 + (void) __sync_fetch_and_add (&us, 1); // CHECK: atomicrmw add i16 + (void) __sync_fetch_and_add (&si, 1); // CHECK: atomicrmw add i32 + (void) __sync_fetch_and_add (&ui, 1); // CHECK: atomicrmw add i32 + (void) __sync_fetch_and_add (&sll, 1); // CHECK: atomicrmw add i64 + (void) __sync_fetch_and_add (&ull, 1); // CHECK: atomicrmw add i64 + + (void) __sync_fetch_and_sub (&sc, 1); // CHECK: atomicrmw sub i8 + (void) __sync_fetch_and_sub (&uc, 1); // CHECK: atomicrmw sub i8 + (void) __sync_fetch_and_sub (&ss, 1); // CHECK: atomicrmw sub i16 + (void) __sync_fetch_and_sub (&us, 1); // CHECK: atomicrmw sub i16 + (void) __sync_fetch_and_sub (&si, 1); // CHECK: atomicrmw sub i32 + (void) __sync_fetch_and_sub (&ui, 1); // CHECK: atomicrmw sub i32 + (void) __sync_fetch_and_sub (&sll, 1); // CHECK: atomicrmw sub i64 + (void) __sync_fetch_and_sub (&ull, 1); // CHECK: atomicrmw sub i64 + + (void) __sync_fetch_and_or (&sc, 1); // CHECK: atomicrmw or i8 + (void) __sync_fetch_and_or (&uc, 1); // CHECK: atomicrmw or i8 + (void) __sync_fetch_and_or (&ss, 1); // CHECK: atomicrmw or i16 + (void) __sync_fetch_and_or (&us, 1); // CHECK: atomicrmw or i16 + (void) __sync_fetch_and_or (&si, 1); // CHECK: atomicrmw or i32 + (void) __sync_fetch_and_or (&ui, 1); // CHECK: atomicrmw or i32 + (void) __sync_fetch_and_or (&sll, 1); // CHECK: atomicrmw or i64 + (void) __sync_fetch_and_or (&ull, 1); // CHECK: atomicrmw or i64 + + (void) __sync_fetch_and_xor (&sc, 1); // CHECK: atomicrmw xor i8 + (void) __sync_fetch_and_xor (&uc, 1); // CHECK: atomicrmw xor i8 + (void) __sync_fetch_and_xor (&ss, 1); // CHECK: atomicrmw xor i16 + (void) __sync_fetch_and_xor (&us, 1); // CHECK: atomicrmw xor i16 + (void) __sync_fetch_and_xor (&si, 1); // CHECK: atomicrmw xor i32 + (void) __sync_fetch_and_xor (&ui, 1); // CHECK: atomicrmw xor i32 + (void) __sync_fetch_and_xor (&sll, 1); // CHECK: atomicrmw xor i64 + (void) __sync_fetch_and_xor (&ull, 1); // CHECK: atomicrmw xor i64 + + (void) __sync_fetch_and_and (&sc, 1); // CHECK: atomicrmw and i8 + (void) __sync_fetch_and_and (&uc, 1); // CHECK: atomicrmw and i8 + (void) __sync_fetch_and_and (&ss, 1); // CHECK: atomicrmw and i16 + (void) __sync_fetch_and_and (&us, 1); // CHECK: atomicrmw and i16 + (void) __sync_fetch_and_and (&si, 1); // CHECK: atomicrmw and i32 + (void) __sync_fetch_and_and (&ui, 1); // CHECK: atomicrmw and i32 + (void) __sync_fetch_and_and (&sll, 1); // CHECK: atomicrmw and i64 + (void) __sync_fetch_and_and (&ull, 1); // CHECK: atomicrmw and i64 + +} + +void test_fetch_and_op (void) // CHECK: define void @test_fetch_and_op +{ + sc = __sync_fetch_and_add (&sc, 11); // CHECK: atomicrmw add + uc = __sync_fetch_and_add (&uc, 11); // CHECK: atomicrmw add + ss = __sync_fetch_and_add (&ss, 11); // CHECK: atomicrmw add + us = __sync_fetch_and_add (&us, 11); // CHECK: atomicrmw add + si = __sync_fetch_and_add (&si, 11); // CHECK: atomicrmw add + ui = __sync_fetch_and_add (&ui, 11); // CHECK: atomicrmw add + sll = __sync_fetch_and_add (&sll, 11); // CHECK: atomicrmw add + ull = __sync_fetch_and_add (&ull, 11); // CHECK: atomicrmw add + + sc = __sync_fetch_and_sub (&sc, 11); // CHECK: atomicrmw sub + uc = __sync_fetch_and_sub (&uc, 11); // CHECK: atomicrmw sub + ss = __sync_fetch_and_sub (&ss, 11); // CHECK: atomicrmw sub + us = __sync_fetch_and_sub (&us, 11); // CHECK: atomicrmw sub + si = __sync_fetch_and_sub (&si, 11); // CHECK: atomicrmw sub + ui = __sync_fetch_and_sub (&ui, 11); // CHECK: atomicrmw sub + sll = __sync_fetch_and_sub (&sll, 11); // CHECK: atomicrmw sub + ull = __sync_fetch_and_sub (&ull, 11); // CHECK: atomicrmw sub + + sc = __sync_fetch_and_or (&sc, 11); // CHECK: atomicrmw or + uc = __sync_fetch_and_or (&uc, 11); // CHECK: atomicrmw or + ss = __sync_fetch_and_or (&ss, 11); // CHECK: atomicrmw or + us = __sync_fetch_and_or (&us, 11); // CHECK: atomicrmw or + si = __sync_fetch_and_or (&si, 11); // CHECK: atomicrmw or + ui = __sync_fetch_and_or (&ui, 11); // CHECK: atomicrmw or + sll = __sync_fetch_and_or (&sll, 11); // CHECK: atomicrmw or + ull = __sync_fetch_and_or (&ull, 11); // CHECK: atomicrmw or + + sc = __sync_fetch_and_xor (&sc, 11); // CHECK: atomicrmw xor + uc = __sync_fetch_and_xor (&uc, 11); // CHECK: atomicrmw xor + ss = __sync_fetch_and_xor (&ss, 11); // CHECK: atomicrmw xor + us = __sync_fetch_and_xor (&us, 11); // CHECK: atomicrmw xor + si = __sync_fetch_and_xor (&si, 11); // CHECK: atomicrmw xor + ui = __sync_fetch_and_xor (&ui, 11); // CHECK: atomicrmw xor + sll = __sync_fetch_and_xor (&sll, 11); // CHECK: atomicrmw xor + ull = __sync_fetch_and_xor (&ull, 11); // CHECK: atomicrmw xor + + sc = __sync_fetch_and_and (&sc, 11); // CHECK: atomicrmw and + uc = __sync_fetch_and_and (&uc, 11); // CHECK: atomicrmw and + ss = __sync_fetch_and_and (&ss, 11); // CHECK: atomicrmw and + us = __sync_fetch_and_and (&us, 11); // CHECK: atomicrmw and + si = __sync_fetch_and_and (&si, 11); // CHECK: atomicrmw and + ui = __sync_fetch_and_and (&ui, 11); // CHECK: atomicrmw and + sll = __sync_fetch_and_and (&sll, 11); // CHECK: atomicrmw and + ull = __sync_fetch_and_and (&ull, 11); // CHECK: atomicrmw and + +} + +void test_op_and_fetch (void) +{ + sc = __sync_add_and_fetch (&sc, uc); // CHECK: atomicrmw add + uc = __sync_add_and_fetch (&uc, uc); // CHECK: atomicrmw add + ss = __sync_add_and_fetch (&ss, uc); // CHECK: atomicrmw add + us = __sync_add_and_fetch (&us, uc); // CHECK: atomicrmw add + si = __sync_add_and_fetch (&si, uc); // CHECK: atomicrmw add + ui = __sync_add_and_fetch (&ui, uc); // CHECK: atomicrmw add + sll = __sync_add_and_fetch (&sll, uc); // CHECK: atomicrmw add + ull = __sync_add_and_fetch (&ull, uc); // CHECK: atomicrmw add + + sc = __sync_sub_and_fetch (&sc, uc); // CHECK: atomicrmw sub + uc = __sync_sub_and_fetch (&uc, uc); // CHECK: atomicrmw sub + ss = __sync_sub_and_fetch (&ss, uc); // CHECK: atomicrmw sub + us = __sync_sub_and_fetch (&us, uc); // CHECK: atomicrmw sub + si = __sync_sub_and_fetch (&si, uc); // CHECK: atomicrmw sub + ui = __sync_sub_and_fetch (&ui, uc); // CHECK: atomicrmw sub + sll = __sync_sub_and_fetch (&sll, uc); // CHECK: atomicrmw sub + ull = __sync_sub_and_fetch (&ull, uc); // CHECK: atomicrmw sub + + sc = __sync_or_and_fetch (&sc, uc); // CHECK: atomicrmw or + uc = __sync_or_and_fetch (&uc, uc); // CHECK: atomicrmw or + ss = __sync_or_and_fetch (&ss, uc); // CHECK: atomicrmw or + us = __sync_or_and_fetch (&us, uc); // CHECK: atomicrmw or + si = __sync_or_and_fetch (&si, uc); // CHECK: atomicrmw or + ui = __sync_or_and_fetch (&ui, uc); // CHECK: atomicrmw or + sll = __sync_or_and_fetch (&sll, uc); // CHECK: atomicrmw or + ull = __sync_or_and_fetch (&ull, uc); // CHECK: atomicrmw or + + sc = __sync_xor_and_fetch (&sc, uc); // CHECK: atomicrmw xor + uc = __sync_xor_and_fetch (&uc, uc); // CHECK: atomicrmw xor + ss = __sync_xor_and_fetch (&ss, uc); // CHECK: atomicrmw xor + us = __sync_xor_and_fetch (&us, uc); // CHECK: atomicrmw xor + si = __sync_xor_and_fetch (&si, uc); // CHECK: atomicrmw xor + ui = __sync_xor_and_fetch (&ui, uc); // CHECK: atomicrmw xor + sll = __sync_xor_and_fetch (&sll, uc); // CHECK: atomicrmw xor + ull = __sync_xor_and_fetch (&ull, uc); // CHECK: atomicrmw xor + + sc = __sync_and_and_fetch (&sc, uc); // CHECK: atomicrmw and + uc = __sync_and_and_fetch (&uc, uc); // CHECK: atomicrmw and + ss = __sync_and_and_fetch (&ss, uc); // CHECK: atomicrmw and + us = __sync_and_and_fetch (&us, uc); // CHECK: atomicrmw and + si = __sync_and_and_fetch (&si, uc); // CHECK: atomicrmw and + ui = __sync_and_and_fetch (&ui, uc); // CHECK: atomicrmw and + sll = __sync_and_and_fetch (&sll, uc); // CHECK: atomicrmw and + ull = __sync_and_and_fetch (&ull, uc); // CHECK: atomicrmw and + +} + +void test_compare_and_swap (void) +{ + sc = __sync_val_compare_and_swap (&sc, uc, sc); // CHECK: cmpxchg i8 + uc = __sync_val_compare_and_swap (&uc, uc, sc); // CHECK: cmpxchg i8 + ss = __sync_val_compare_and_swap (&ss, uc, sc); // CHECK: cmpxchg i16 + us = __sync_val_compare_and_swap (&us, uc, sc); // CHECK: cmpxchg i16 + si = __sync_val_compare_and_swap (&si, uc, sc); // CHECK: cmpxchg i32 + ui = __sync_val_compare_and_swap (&ui, uc, sc); // CHECK: cmpxchg i32 + sll = __sync_val_compare_and_swap (&sll, uc, sc); // CHECK: cmpxchg i64 + ull = __sync_val_compare_and_swap (&ull, uc, sc); // CHECK: cmpxchg i64 + + ui = __sync_bool_compare_and_swap (&sc, uc, sc); // CHECK: cmpxchg + ui = __sync_bool_compare_and_swap (&uc, uc, sc); // CHECK: cmpxchg + ui = __sync_bool_compare_and_swap (&ss, uc, sc); // CHECK: cmpxchg + ui = __sync_bool_compare_and_swap (&us, uc, sc); // CHECK: cmpxchg + ui = __sync_bool_compare_and_swap (&si, uc, sc); // CHECK: cmpxchg + ui = __sync_bool_compare_and_swap (&ui, uc, sc); // CHECK: cmpxchg + ui = __sync_bool_compare_and_swap (&sll, uc, sc); // CHECK: cmpxchg + ui = __sync_bool_compare_and_swap (&ull, uc, sc); // CHECK: cmpxchg +} + +void test_lock (void) +{ + sc = __sync_lock_test_and_set (&sc, 1); // CHECK: atomicrmw xchg i8 + uc = __sync_lock_test_and_set (&uc, 1); // CHECK: atomicrmw xchg i8 + ss = __sync_lock_test_and_set (&ss, 1); // CHECK: atomicrmw xchg i16 + us = __sync_lock_test_and_set (&us, 1); // CHECK: atomicrmw xchg i16 + si = __sync_lock_test_and_set (&si, 1); // CHECK: atomicrmw xchg i32 + ui = __sync_lock_test_and_set (&ui, 1); // CHECK: atomicrmw xchg i32 + sll = __sync_lock_test_and_set (&sll, 1); // CHECK: atomicrmw xchg i64 + ull = __sync_lock_test_and_set (&ull, 1); // CHECK: atomicrmw xchg i64 + + __sync_synchronize (); // CHECK: fence seq_cst + + __sync_lock_release (&sc); // CHECK: store atomic {{.*}} release, align 1 + __sync_lock_release (&uc); // CHECK: store atomic {{.*}} release, align 1 + __sync_lock_release (&ss); // CHECK: store atomic {{.*}} release, align 2 + __sync_lock_release (&us); /// CHECK: store atomic {{.*}} release, align 2 + __sync_lock_release (&si); // CHECK: store atomic {{.*}} release, align 4 + __sync_lock_release (&ui); // CHECK: store atomic {{.*}} release, align 4 + __sync_lock_release (&sll); // CHECK: store atomic {{.*}} release, align 8 + __sync_lock_release (&ull); // CHECK: store atomic {{.*}} release, align 8 +} diff --git a/test/CodeGen/BasicInstrs.c b/test/CodeGen/BasicInstrs.c new file mode 100644 index 000000000000..2b8a6f67981a --- /dev/null +++ b/test/CodeGen/BasicInstrs.c @@ -0,0 +1,25 @@ +// This file can be used to see what a native C compiler is generating for a +// variety of interesting operations. +// +// RUN: %clang_cc1 -emit-llvm %s -o - + +unsigned int udiv(unsigned int X, unsigned int Y) { + return X/Y; +} +int sdiv(int X, int Y) { + return X/Y; +} +unsigned int urem(unsigned int X, unsigned int Y) { + return X%Y; +} +int srem(int X, int Y) { + return X%Y; +} + +_Bool setlt(int X, int Y) { + return X < Y; +} + +_Bool setgt(int X, int Y) { + return X > Y; +} diff --git a/test/CodeGen/always-inline.c b/test/CodeGen/always-inline.c new file mode 100644 index 000000000000..dc74be5e8c21 --- /dev/null +++ b/test/CodeGen/always-inline.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | grep call | not grep foo + +void bar() { +} + +inline void __attribute__((__always_inline__)) foo() { + bar(); +} + +void i_want_bar() { + foo(); +} diff --git a/test/CodeGen/annotate.c b/test/CodeGen/annotate.c deleted file mode 100644 index 9ed187d1d170..000000000000 --- a/test/CodeGen/annotate.c +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s - -__attribute((annotate("foo"))) char foo; -void a(char *a) { - __attribute__((annotate("bar"))) static char bar; -} - -// CHECK: private unnamed_addr global -// CHECK: private unnamed_addr global -// CHECK: @llvm.global.annotations = appending global [2 x { i8*, i8*, i8*, i32 }] diff --git a/test/CodeGen/annotations-builtin.c b/test/CodeGen/annotations-builtin.c new file mode 100644 index 000000000000..42421a0a5200 --- /dev/null +++ b/test/CodeGen/annotations-builtin.c @@ -0,0 +1,52 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s +// END. + +static long long llfoo; +static int intfoo; +static short shortfoo; +static char charfoo; + +// CHECK: private unnamed_addr constant [13 x i8] {{.*}}annotation_a{{.*}} section "llvm.metadata" +// CHECK-NOT: {{.*}}annotation_a{{.*}} + +static int foo(int a) { + return a + 1; +} + +int main(int argc, char **argv) { + char barray[16]; + char *b = (char *) __builtin_annotation((int)barray, "annotation_a"); +// CHECK: ptrtoint i8* {{.*}} to i32 +// CHECK-NEXT: call i32 @llvm.annotation.i32 +// CHECK: inttoptr {{.*}} to i8* + + int call = __builtin_annotation(foo(argc), "annotation_a"); +// CHECK: call {{.*}} @foo +// CHECK: call i32 @llvm.annotation.i32 + + long long lla = __builtin_annotation(llfoo, "annotation_a"); +// CHECK: trunc i64 {{.*}} to i32 +// CHECK-NEXT: call i32 @llvm.annotation.i32 +// CHECK-NEXT: zext i32 {{.*}} to i64 + + int inta = __builtin_annotation(intfoo, "annotation_a"); +// CHECK: load i32* @intfoo +// CHECK-NEXT: call i32 @llvm.annotation.i32 +// CHECK-NEXT: store + + short shorta = __builtin_annotation(shortfoo, "annotation_a"); +// CHECK: sext i16 {{.*}} to i32 +// CHECK-NEXT: call i32 @llvm.annotation.i32 +// CHECK-NEXT: trunc i32 {{.*}} to i16 + + char chara = __builtin_annotation(charfoo, "annotation_a"); +// CHECK: sext i8 {{.*}} to i32 +// CHECK-NEXT: call i32 @llvm.annotation.i32 +// CHECK-NEXT: trunc i32 {{.*}} to i8 +// + char **arg = (char**) __builtin_annotation((int) argv, "annotation_a"); +// CHECK: ptrtoint i8** {{.*}} to +// CHECK: call i32 @llvm.annotation.i32 +// CHECK: inttoptr {{.*}} to i8** + return 0; +} diff --git a/test/CodeGen/annotations-field.c b/test/CodeGen/annotations-field.c new file mode 100644 index 000000000000..6b443675850c --- /dev/null +++ b/test/CodeGen/annotations-field.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s +// END. + +// CHECK: private unnamed_addr constant [8 x i8] c"v_ann_{{.}}\00", section "llvm.metadata" +// CHECK: private unnamed_addr constant [8 x i8] c"v_ann_{{.}}\00", section "llvm.metadata" + +struct foo { + int v __attribute__((annotate("v_ann_0"))) __attribute__((annotate("v_ann_1"))); +}; + +static struct foo gf; + +int main(int argc, char **argv) { + struct foo f; + f.v = argc; +// CHECK: getelementptr inbounds %struct.foo* %f, i32 0, i32 0 +// CHECK-NEXT: bitcast i32* {{.*}} to i8* +// CHECK-NEXT: call i8* @llvm.ptr.annotation.p0i8({{.*}}str{{.*}}str{{.*}}i32 8) +// CHECK-NEXT: bitcast i8* {{.*}} to i32* +// CHECK-NEXT: bitcast i32* {{.*}} to i8* +// CHECK-NEXT: call i8* @llvm.ptr.annotation.p0i8({{.*}}str{{.*}}str{{.*}}i32 8) +// CHECK-NEXT: bitcast i8* {{.*}} to i32* + gf.v = argc; +// CHECK: bitcast i32* getelementptr inbounds (%struct.foo* @gf, i32 0, i32 0) to i8* +// CHECK-NEXT: call i8* @llvm.ptr.annotation.p0i8({{.*}}str{{.*}}str{{.*}}i32 8) + return 0; +} diff --git a/test/CodeGen/annotations-global.c b/test/CodeGen/annotations-global.c new file mode 100644 index 000000000000..2782525ed915 --- /dev/null +++ b/test/CodeGen/annotations-global.c @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 %s -emit-llvm -o %t1 +// RUN: FileCheck --check-prefix=FOO %s < %t1 +// RUN: FileCheck --check-prefix=A %s < %t1 +// RUN: FileCheck --check-prefix=BAR %s < %t1 +// RUN: FileCheck --check-prefix=FOOS %s < %t1 +// END. + +static __attribute((annotate("sfoo_0"))) __attribute((annotate("sfoo_1"))) char sfoo; +__attribute((annotate("foo_0"))) __attribute((annotate("foo_1"))) char foo; + +void __attribute((annotate("ann_a_0"))) __attribute((annotate("ann_a_1"))) __attribute((annotate("ann_a_2"))) __attribute((annotate("ann_a_3"))) a(char *a); +void __attribute((annotate("ann_a_0"))) __attribute((annotate("ann_a_1"))) a(char *a) { + __attribute__((annotate("bar_0"))) __attribute__((annotate("bar_1"))) static char bar; + sfoo = 0; +} + +// FOOS: target triple +// FOOS: private unnamed_addr constant [7 x i8] c"sfoo_{{.}}\00", section "llvm.metadata" +// FOOS: private unnamed_addr constant [7 x i8] c"sfoo_{{.}}\00", section "llvm.metadata" +// FOOS-NOT: sfoo_ +// FOOS: @llvm.global.annotations = appending global [10 x { i8*, i8*, i8*, i32 }] {{.*}}i8* @sfoo{{.*}}i8* @sfoo{{.*}}, section "llvm.metadata" + +// FOO: target triple +// FOO: private unnamed_addr constant [6 x i8] c"foo_{{.}}\00", section "llvm.metadata" +// FOO: private unnamed_addr constant [6 x i8] c"foo_{{.}}\00", section "llvm.metadata" +// FOO-NOT: foo_ +// FOO: @llvm.global.annotations = appending global [10 x { i8*, i8*, i8*, i32 }] {{.*}}i8* @foo{{.*}}i8* @foo{{.*}}, section "llvm.metadata" + +// A: target triple +// A: private unnamed_addr constant [8 x i8] c"ann_a_{{.}}\00", section "llvm.metadata" +// A: private unnamed_addr constant [8 x i8] c"ann_a_{{.}}\00", section "llvm.metadata" +// A: private unnamed_addr constant [8 x i8] c"ann_a_{{.}}\00", section "llvm.metadata" +// A: private unnamed_addr constant [8 x i8] c"ann_a_{{.}}\00", section "llvm.metadata" +// A-NOT: ann_a_ +// A: @llvm.global.annotations = appending global [10 x { i8*, i8*, i8*, i32 }] {{.*}}i8* bitcast (void (i8*)* @a to i8*){{.*}}i8* bitcast (void (i8*)* @a to i8*){{.*}}i8* bitcast (void (i8*)* @a to i8*){{.*}}i8* bitcast (void (i8*)* @a to i8*){{.*}}, section "llvm.metadata" + +// BAR: target triple +// BAR: private unnamed_addr constant [6 x i8] c"bar_{{.}}\00", section "llvm.metadata" +// BAR: private unnamed_addr constant [6 x i8] c"bar_{{.}}\00", section "llvm.metadata" +// BAR-NOT: bar_ +// BAR: @llvm.global.annotations = appending global [10 x { i8*, i8*, i8*, i32 }] {{.*}}i8* @a.bar{{.*}}i8* @a.bar{{.*}}, section "llvm.metadata" diff --git a/test/CodeGen/annotations-loc.c b/test/CodeGen/annotations-loc.c new file mode 100644 index 000000000000..4644f0e1d2ca --- /dev/null +++ b/test/CodeGen/annotations-loc.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s +// END. +# 1 "t.c" +# 1 "<built-in>" +# 1 "<command-line>" +# 1 "t.c" +int __attribute((annotate("foo"))) foo(void) { return 0; } + +// CHECK: private unnamed_addr constant [4 x i8] c"t.c\00" +// CHECK: @llvm.global.annotations = {{.*}}, i32 1 } diff --git a/test/CodeGen/annotations-var.c b/test/CodeGen/annotations-var.c new file mode 100644 index 000000000000..b8ada9fc0f3e --- /dev/null +++ b/test/CodeGen/annotations-var.c @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o %t1 %s +// RUN: FileCheck --check-prefix=LOCAL %s < %t1 +// RUN: FileCheck --check-prefix=UNDEF %s < %t1 +// RUN: FileCheck --check-prefix=PARAM %s < %t1 +// END. + +// LOCAL: private unnamed_addr constant [15 x i8] c"localvar_ann_{{.}}\00", section "llvm.metadata" +// LOCAL: private unnamed_addr constant [15 x i8] c"localvar_ann_{{.}}\00", section "llvm.metadata" + +// UNDEF: private unnamed_addr constant [15 x i8] c"undefvar_ann_0\00", section "llvm.metadata" + +// PARAM: private unnamed_addr constant [12 x i8] c"param_ann_{{.}}\00", section "llvm.metadata" +// PARAM: private unnamed_addr constant [12 x i8] c"param_ann_{{.}}\00", section "llvm.metadata" +// PARAM: private unnamed_addr constant [12 x i8] c"param_ann_{{.}}\00", section "llvm.metadata" +// PARAM: private unnamed_addr constant [12 x i8] c"param_ann_{{.}}\00", section "llvm.metadata" + +int foo(int v __attribute__((annotate("param_ann_2"))) __attribute__((annotate("param_ann_3")))); +int foo(int v __attribute__((annotate("param_ann_0"))) __attribute__((annotate("param_ann_1")))) { + return v + 1; +// PARAM: define {{.*}}@foo +// PARAM: [[V:%.*]] = alloca i32 +// PARAM: bitcast i32* [[V]] to i8* +// PARAM-NEXT: call void @llvm.var.annotation( +// PARAM-NEXT: bitcast i32* [[V]] to i8* +// PARAM-NEXT: call void @llvm.var.annotation( +// PARAM-NEXT: bitcast i32* [[V]] to i8* +// PARAM-NEXT: call void @llvm.var.annotation( +// PARAM-NEXT: bitcast i32* [[V]] to i8* +// PARAM-NEXT: call void @llvm.var.annotation( +} + +void local(void) { + int localvar __attribute__((annotate("localvar_ann_0"))) __attribute__((annotate("localvar_ann_1"))) = 3; +// LOCAL: define void @local() +// LOCAL: [[LOCALVAR:%.*]] = alloca i32, +// LOCAL-NEXT: [[T0:%.*]] = bitcast i32* [[LOCALVAR]] to i8* +// LOCAL-NEXT: call void @llvm.var.annotation(i8* [[T0]], i8* getelementptr inbounds ([15 x i8]* @{{.*}}), i8* getelementptr inbounds ({{.*}}), i32 33) +// LOCAL-NEXT: [[T0:%.*]] = bitcast i32* [[LOCALVAR]] to i8* +// LOCAL-NEXT: call void @llvm.var.annotation(i8* [[T0]], i8* getelementptr inbounds ([15 x i8]* @{{.*}}), i8* getelementptr inbounds ({{.*}}), i32 33) +} + +void undef(void) { + int undefvar __attribute__((annotate("undefvar_ann_0"))); +// UNDEF: define void @undef() +// UNDEF: [[UNDEFVAR:%.*]] = alloca i32, +// UNDEF-NEXT: [[T0:%.*]] = bitcast i32* [[UNDEFVAR]] to i8* +// UNDEF-NEXT: call void @llvm.var.annotation(i8* [[T0]], i8* getelementptr inbounds ([15 x i8]* @{{.*}}), i8* getelementptr inbounds ({{.*}}), i32 43) +} diff --git a/test/CodeGen/arm-aapcs-vfp.c b/test/CodeGen/arm-aapcs-vfp.c new file mode 100644 index 000000000000..20b8a742dd41 --- /dev/null +++ b/test/CodeGen/arm-aapcs-vfp.c @@ -0,0 +1,82 @@ +// RUN: %clang_cc1 -triple thumbv7-apple-darwin9 \ +// RUN: -target-abi aapcs \ +// RUN: -target-cpu cortex-a8 \ +// RUN: -mfloat-abi hard \ +// RUN: -ffreestanding \ +// RUN: -emit-llvm -w -o - %s | FileCheck %s + +#include <arm_neon.h> + +struct homogeneous_struct { + float f[2]; + float f3; + float f4; +}; +// CHECK: define arm_aapcs_vfpcc void @test_struct(float %{{.*}}, float %{{.*}}, float %{{.*}}, float %{{.*}}) +extern void struct_callee(struct homogeneous_struct); +void test_struct(struct homogeneous_struct arg) { + struct_callee(arg); +} + +struct nested_array { + double d[4]; +}; +// CHECK: define arm_aapcs_vfpcc void @test_array(double %{{.*}}, double %{{.*}}, double %{{.*}}, double %{{.*}}) +extern void array_callee(struct nested_array); +void test_array(struct nested_array arg) { + array_callee(arg); +} + +extern void complex_callee(__complex__ double); +// CHECK: define arm_aapcs_vfpcc void @test_complex(double %{{.*}}, double %{{.*}}) +void test_complex(__complex__ double cd) { + complex_callee(cd); +} + +// Structs with more than 4 elements of the base type are not treated +// as homogeneous aggregates. Test that. + +struct big_struct { + float f1; + float f[2]; + float f3; + float f4; +}; +// CHECK: define arm_aapcs_vfpcc void @test_big([5 x i32] %{{.*}}) +extern void big_callee(struct big_struct); +void test_big(struct big_struct arg) { + big_callee(arg); +} + +// Make sure that aggregates with multiple base types are not treated as +// homogeneous aggregates. + +struct heterogeneous_struct { + float f1; + int i2; +}; +// CHECK: define arm_aapcs_vfpcc void @test_hetero([2 x i32] %{{.*}}) +extern void hetero_callee(struct heterogeneous_struct); +void test_hetero(struct heterogeneous_struct arg) { + hetero_callee(arg); +} + +// Neon multi-vector types are homogeneous aggregates. +// CHECK: define arm_aapcs_vfpcc <16 x i8> @f0(<16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}}) +int8x16_t f0(int8x16x4_t v4) { + return vaddq_s8(v4.val[0], v4.val[3]); +} + +// ...and it doesn't matter whether the vectors are exactly the same, as long +// as they have the same size. + +struct neon_struct { + int8x8x2_t v12; + int32x2_t v3; + int16x4_t v4; +}; +// CHECK: define arm_aapcs_vfpcc void @test_neon(<8 x i8> %{{.*}}, <8 x i8> %{{.*}}, <2 x i32> %{{.*}}, <4 x i16> %{{.*}}) +extern void neon_callee(struct neon_struct); +void test_neon(struct neon_struct arg) { + neon_callee(arg); +} diff --git a/test/CodeGen/arm-apcs-zerolength-bitfield.c b/test/CodeGen/arm-apcs-zerolength-bitfield.c new file mode 100644 index 000000000000..3f9452539408 --- /dev/null +++ b/test/CodeGen/arm-apcs-zerolength-bitfield.c @@ -0,0 +1,240 @@ +// RUN: %clang_cc1 -target-abi apcs-gnu -triple armv7-apple-darwin10 %s -verify +// +// Note: gcc forces the alignment to 4 bytes, regardless of the type of the +// zero length bitfield. +// rdar://9859156 + +#include <stddef.h> + +struct t1 +{ + int foo : 1; + char : 0; + char bar; +}; +static int arr1_offset[(offsetof(struct t1, bar) == 4) ? 0 : -1]; +static int arr1_sizeof[(sizeof(struct t1) == 8) ? 0 : -1]; + +struct t2 +{ + int foo : 1; + short : 0; + char bar; +}; +static int arr2_offset[(offsetof(struct t2, bar) == 4) ? 0 : -1]; +static int arr2_sizeof[(sizeof(struct t2) == 8) ? 0 : -1]; + +struct t3 +{ + int foo : 1; + int : 0; + char bar; +}; +static int arr3_offset[(offsetof(struct t3, bar) == 4) ? 0 : -1]; +static int arr3_sizeof[(sizeof(struct t3) == 8) ? 0 : -1]; + +struct t4 +{ + int foo : 1; + long : 0; + char bar; +}; +static int arr4_offset[(offsetof(struct t4, bar) == 4) ? 0 : -1]; +static int arr4_sizeof[(sizeof(struct t4) == 8) ? 0 : -1]; + +struct t5 +{ + int foo : 1; + long long : 0; + char bar; +}; +static int arr5_offset[(offsetof(struct t5, bar) == 4) ? 0 : -1]; +static int arr5_sizeof[(sizeof(struct t5) == 8) ? 0 : -1]; + +struct t6 +{ + int foo : 1; + char : 0; + char bar : 1; + char bar2; +}; +static int arr6_offset[(offsetof(struct t6, bar2) == 5) ? 0 : -1]; +static int arr6_sizeof[(sizeof(struct t6) == 8) ? 0 : -1]; + +struct t7 +{ + int foo : 1; + short : 0; + char bar1 : 1; + char bar2; +}; +static int arr7_offset[(offsetof(struct t7, bar2) == 5) ? 0 : -1]; +static int arr7_sizeof[(sizeof(struct t7) == 8) ? 0 : -1]; + +struct t8 +{ + int foo : 1; + int : 0; + char bar1 : 1; + char bar2; +}; +static int arr8_offset[(offsetof(struct t8, bar2) == 5) ? 0 : -1]; +static int arr8_sizeof[(sizeof(struct t8) == 8) ? 0 : -1]; + +struct t9 +{ + int foo : 1; + long : 0; + char bar1 : 1; + char bar2; +}; +static int arr9_offset[(offsetof(struct t9, bar2) == 5) ? 0 : -1]; +static int arr9_sizeof[(sizeof(struct t9) == 8) ? 0 : -1]; + +struct t10 +{ + int foo : 1; + long long : 0; + char bar1 : 1; + char bar2; +}; +static int arr10_offset[(offsetof(struct t10, bar2) == 5) ? 0 : -1]; +static int arr10_sizeof[(sizeof(struct t10) == 8) ? 0 : -1]; + +struct t11 +{ + int foo : 1; + long long : 0; + char : 0; + char bar1 : 1; + char bar2; +}; +static int arr11_offset[(offsetof(struct t11, bar2) == 5) ? 0 : -1]; +static int arr11_sizeof[(sizeof(struct t11) == 8) ? 0 : -1]; + +struct t12 +{ + int foo : 1; + char : 0; + long long : 0; + char : 0; + char bar; +}; +static int arr12_offset[(offsetof(struct t12, bar) == 4) ? 0 : -1]; +static int arr12_sizeof[(sizeof(struct t12) == 8) ? 0 : -1]; + +struct t13 +{ + char foo; + long : 0; + char bar; +}; +static int arr13_offset[(offsetof(struct t13, bar) == 4) ? 0 : -1]; +static int arr13_sizeof[(sizeof(struct t13) == 8) ? 0 : -1]; + +struct t14 +{ + char foo1; + int : 0; + char foo2 : 1; + short foo3 : 16; + char : 0; + short foo4 : 16; + char bar1; + int : 0; + char bar2; +}; +static int arr14_bar1_offset[(offsetof(struct t14, bar1) == 10) ? 0 : -1]; +static int arr14_bar2_offset[(offsetof(struct t14, bar2) == 12) ? 0 : -1]; +static int arr14_sizeof[(sizeof(struct t14) == 16) ? 0 : -1]; + +struct t15 +{ + char foo; + char : 0; + int : 0; + char bar; + long : 0; + char : 0; +}; +static int arr15_offset[(offsetof(struct t15, bar) == 4) ? 0 : -1]; +static int arr15_sizeof[(sizeof(struct t15) == 8) ? 0 : -1]; + +struct t16 +{ + long : 0; + char bar; +}; +static int arr16_offset[(offsetof(struct t16, bar) == 0) ? 0 : -1]; +static int arr16_sizeof[(sizeof(struct t16) == 4) ? 0 : -1]; + +struct t17 +{ + char foo; + long : 0; + long : 0; + char : 0; + char bar; +}; +static int arr17_offset[(offsetof(struct t17, bar) == 4) ? 0 : -1]; +static int arr17_sizeof[(sizeof(struct t17) == 8) ? 0 : -1]; + +struct t18 +{ + long : 0; + long : 0; + char : 0; +}; +static int arr18_sizeof[(sizeof(struct t18) == 0) ? 0 : -1]; + +struct t19 +{ + char foo1; + long foo2 : 1; + char : 0; + long foo3 : 32; + char bar; +}; +static int arr19_offset[(offsetof(struct t19, bar) == 8) ? 0 : -1]; +static int arr19_sizeof[(sizeof(struct t19) == 12) ? 0 : -1]; + +struct t20 +{ + short : 0; + int foo : 1; + long : 0; + char bar; +}; +static int arr20_offset[(offsetof(struct t20, bar) == 4) ? 0 : -1]; +static int arr20_sizeof[(sizeof(struct t20) == 8) ? 0 : -1]; + +struct t21 +{ + short : 0; + int foo1 : 1; + char : 0; + int foo2 : 16; + long : 0; + char bar1; + int bar2; + long bar3; + char foo3 : 8; + char : 0; + long : 0; + int foo4 : 32; + short foo5: 1; + long bar4; + short foo6: 16; + short foo7: 16; + short foo8: 16; +}; +static int arr21_bar1_offset[(offsetof(struct t21, bar1) == 8) ? 0 : -1]; +static int arr21_bar2_offset[(offsetof(struct t21, bar2) == 12) ? 0 : -1]; +static int arr21_bar3_offset[(offsetof(struct t21, bar3) == 16) ? 0 : -1]; +static int arr21_bar4_offset[(offsetof(struct t21, bar4) == 32) ? 0 : -1]; +static int arr21_sizeof[(sizeof(struct t21) == 44) ? 0 : -1]; + +int main() { + return 0; +} + diff --git a/test/CodeGen/arm-arguments.c b/test/CodeGen/arm-arguments.c index 081bc89dcda7..3ae3b8ecd21f 100644 --- a/test/CodeGen/arm-arguments.c +++ b/test/CodeGen/arm-arguments.c @@ -28,13 +28,13 @@ struct s4 { struct s4_0 { int f0; } f0; }; struct s4 f4(void) {} // APCS-GNU: define void @f5( -// APCS-GNU: struct.s5* sret +// APCS-GNU: struct.s5* noalias sret // AAPCS: define arm_aapcscc i32 @f5() struct s5 { struct { } f0; int f1; }; struct s5 f5(void) {} // APCS-GNU: define void @f6( -// APCS-GNU: struct.s6* sret +// APCS-GNU: struct.s6* noalias sret // AAPCS: define arm_aapcscc i32 @f6() struct s6 { int f0[1]; }; struct s6 f6(void) {} @@ -45,7 +45,7 @@ struct s7 { struct { int : 0; } f0; }; struct s7 f7(void) {} // APCS-GNU: define void @f8( -// APCS-GNU: struct.s8* sret +// APCS-GNU: struct.s8* noalias sret // AAPCS: define arm_aapcscc void @f8() struct s8 { struct { int : 0; } f0[1]; }; struct s8 f8(void) {} @@ -61,7 +61,7 @@ struct s10 { int f0; int : 0; int : 0; }; struct s10 f10(void) {} // APCS-GNU: define void @f11( -// APCS-GNU: struct.s11* sret +// APCS-GNU: struct.s11* noalias sret // AAPCS: define arm_aapcscc i32 @f11() struct s11 { int : 0; int f0; }; struct s11 f11(void) {} @@ -72,7 +72,7 @@ union u12 { char f0; short f1; int f2; }; union u12 f12(void) {} // APCS-GNU: define void @f13( -// APCS-GNU: struct.s13* sret +// APCS-GNU: struct.s13* noalias sret // FIXME: This should return a float. // AAPCS-FIXME: darm_aapcscc efine float @f13() @@ -80,7 +80,7 @@ struct s13 { float f0; }; struct s13 f13(void) {} // APCS-GNU: define void @f14( -// APCS-GNU: union.u14* sret +// APCS-GNU: union.u14* noalias sret // AAPCS: define arm_aapcscc i32 @f14() union u14 { float f0; }; union u14 f14(void) {} @@ -104,13 +104,13 @@ struct s18 { short f0; char f1 : 4; }; struct s18 f18(void) {} // APCS-GNU: define void @f19( -// APCS-GNU: struct.s19* sret +// APCS-GNU: struct.s19* noalias sret // AAPCS: define arm_aapcscc i32 @f19() struct s19 { int f0; struct s8 f1; }; struct s19 f19(void) {} // APCS-GNU: define void @f20( -// APCS-GNU: struct.s20* sret +// APCS-GNU: struct.s20* noalias sret // AAPCS: define arm_aapcscc i32 @f20() struct s20 { struct s8 f1; int f0; }; struct s20 f20(void) {} @@ -128,10 +128,10 @@ struct s21 f21(void) {} // APCS-GNU: define i128 @f27() // AAPCS: define arm_aapcscc i16 @f22() // AAPCS: define arm_aapcscc i32 @f23() -// AAPCS: define arm_aapcscc void @f24({{.*}} sret -// AAPCS: define arm_aapcscc void @f25({{.*}} sret -// AAPCS: define arm_aapcscc void @f26({{.*}} sret -// AAPCS: define arm_aapcscc void @f27({{.*}} sret +// AAPCS: define arm_aapcscc void @f24({{.*}} noalias sret +// AAPCS: define arm_aapcscc void @f25({{.*}} noalias sret +// AAPCS: define arm_aapcscc void @f26({{.*}} noalias sret +// AAPCS: define arm_aapcscc void @f27({{.*}} noalias sret _Complex char f22(void) {} _Complex short f23(void) {} _Complex int f24(void) {} @@ -149,7 +149,7 @@ struct s28 f28() {} struct s29 { _Complex short f0; }; struct s29 f29() {} -// APCS-GNU: define void @f30({{.*}} sret -// AAPCS: define arm_aapcscc void @f30({{.*}} sret +// APCS-GNU: define void @f30({{.*}} noalias sret +// AAPCS: define arm_aapcscc void @f30({{.*}} noalias sret struct s30 { _Complex int f0; }; struct s30 f30() {} diff --git a/test/CodeGen/arm-inline-asm.c b/test/CodeGen/arm-inline-asm.c new file mode 100644 index 000000000000..0152b050fd7f --- /dev/null +++ b/test/CodeGen/arm-inline-asm.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -w -o - %s | FileCheck %s + +void t1 (void *f, int g) { + // CHECK: call void asm "str $1, $0", "=*Q,r" + asm("str %1, %0" : "=Q"(f) : "r"(g)); +} diff --git a/test/CodeGen/arm-vaarg-align.c b/test/CodeGen/arm-vaarg-align.c new file mode 100644 index 000000000000..1187c022914f --- /dev/null +++ b/test/CodeGen/arm-vaarg-align.c @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -triple arm -target-abi aapcs %s -emit-llvm -o - | FileCheck -check-prefix=AAPCS %s +// RUN: %clang_cc1 -triple arm -target-abi apcs-gnu %s -emit-llvm -o - | FileCheck -check-prefix=APCS-GNU %s +/* + * Check that va_arg accesses stack according to ABI alignment + * long long and double require 8-byte alignment under AAPCS + * however, they only require 4-byte alignment under APCS + */ +long long t1(int i, ...) { + // AAPCS: t1 + // APCS-GNU: t1 + __builtin_va_list ap; + __builtin_va_start(ap, i); + // AAPCS: add i32 %{{.*}} 7 + // AAPCS: and i32 %{{.*}} -8 + // APCS-GNU-NOT: add i32 %{{.*}} 7 + // APCS-GNU-NOT: and i32 %{{.*}} -8 + long long ll = __builtin_va_arg(ap, long long); + __builtin_va_end(ap); + return ll; +} +double t2(int i, ...) { + // AAPCS: t2 + // APCS-GNU: t2 + __builtin_va_list ap; + __builtin_va_start(ap, i); + // AAPCS: add i32 %{{.*}} 7 + // AAPCS: and i32 %{{.*}} -8 + // APCS-GNU-NOT: add i32 %{{.*}} 7 + // APCS-GNU-NOT: and i32 %{{.*}} -8 + double ll = __builtin_va_arg(ap, double); + __builtin_va_end(ap); + return ll; +} diff --git a/test/CodeGen/arm-vector-arguments.c b/test/CodeGen/arm-vector-arguments.c index c5ac0a7ad1b7..6bfb2f48a7f1 100644 --- a/test/CodeGen/arm-vector-arguments.c +++ b/test/CodeGen/arm-vector-arguments.c @@ -8,7 +8,7 @@ #include <arm_neon.h> -// CHECK: define void @f0(%struct.int8x16x2_t* sret %agg.result, <16 x i8> %{{.*}}, <16 x i8> %{{.*}}) +// CHECK: define void @f0(%struct.int8x16x2_t* noalias sret %agg.result, <16 x i8> %{{.*}}, <16 x i8> %{{.*}}) int8x16x2_t f0(int8x16_t a0, int8x16_t a1) { return vzipq_s8(a0, a1); } @@ -24,7 +24,7 @@ typedef float T_float32x16 __attribute__ ((__vector_size__ (64))); T_float32x2 f1_0(T_float32x2 a0) { return a0; } // CHECK: define <4 x float> @f1_1(<4 x float> %{{.*}}) T_float32x4 f1_1(T_float32x4 a0) { return a0; } -// CHECK: define void @f1_2(<8 x float>* sret %{{.*}}, <8 x float> %{{.*}}) +// CHECK: define void @f1_2(<8 x float>* noalias sret %{{.*}}, <8 x float> %{{.*}}) T_float32x8 f1_2(T_float32x8 a0) { return a0; } -// CHECK: define void @f1_3(<16 x float>* sret %{{.*}}, <16 x float> %{{.*}}) +// CHECK: define void @f1_3(<16 x float>* noalias sret %{{.*}}, <16 x float> %{{.*}}) T_float32x16 f1_3(T_float32x16 a0) { return a0; } diff --git a/test/CodeGen/arrayderef.c b/test/CodeGen/arrayderef.c new file mode 100644 index 000000000000..effc0a6de4a8 --- /dev/null +++ b/test/CodeGen/arrayderef.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -emit-llvm -O1 -o - | FileCheck %s +// The load here was getting lost because this code was close +// enough to the traditional (wrong) implementation of offsetof +// to confuse the gcc FE. 8629268. + +struct foo { + int x; + int *y; +}; + +struct foo Foo[1]; + +int * bar(unsigned int ix) { +// CHECK: load + return &Foo->y[ix]; +} diff --git a/test/CodeGen/asm-reg-var-local.c b/test/CodeGen/asm-reg-var-local.c new file mode 100644 index 000000000000..9060e120ffc9 --- /dev/null +++ b/test/CodeGen/asm-reg-var-local.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 %s -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s +// Exercise various use cases for local asm "register variables". + +int foo() { +// CHECK: [[A:%[a-zA-Z0-9]+]] = alloca i32 + + register int a asm("rsi")=5; +// CHECK: store i32 5, i32* [[A]] + + asm volatile("; %0 This asm defines rsi" : "=r"(a)); +// CHECK: [[Z:%[a-zA-Z0-9]+]] = call i32 asm sideeffect "; $0 This asm defines rsi", "={rsi},~{dirflag},~{fpsr},~{flags}"() +// CHECK: store i32 [[Z]], i32* [[A]] + + a = 42; +// CHECK: store i32 42, i32* [[A]] + + asm volatile("; %0 This asm uses rsi" : : "r"(a)); +// CHECK: [[TMP:%[a-zA-Z0-9]+]] = load i32* [[A]] +// CHECK: call void asm sideeffect "; $0 This asm uses rsi", "{rsi},~{dirflag},~{fpsr},~{flags}"(i32 [[TMP]]) + + return a; +// CHECK: [[TMP1:%[a-zA-Z0-9]+]] = load i32* [[A]] +// CHECK: ret i32 [[TMP1]] +} diff --git a/test/CodeGen/asm.c b/test/CodeGen/asm.c index 7199f09e1a3c..019eb9ca3e67 100644 --- a/test/CodeGen/asm.c +++ b/test/CodeGen/asm.c @@ -1,4 +1,13 @@ // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s + +// PR10415 +__asm__ ("foo1"); +__asm__ ("foo2"); +__asm__ ("foo3"); +// CHECK: module asm "foo1" +// CHECK-NEXT: module asm "foo2" +// CHECK-NEXT: module asm "foo3" + void t1(int len) { __asm__ volatile("" : "=&r"(len), "+&r"(len)); } @@ -191,6 +200,15 @@ unsigned char t23(unsigned char a, unsigned char b) { return res; } +void *t24(char c) { + void *addr; + // CHECK: @t24 + // CHECK: zext i8 {{.*}} to i32 + // CHECK-NEXT: call i8* asm "foobar" + __asm__ ("foobar" : "=a" (addr) : "0" (c)); + return addr; +} + // PR10299 - fpsr, fpcr void test(void) diff --git a/test/CodeGen/assign.c b/test/CodeGen/assign.c index 05141bb0bb60..fc008963c317 100644 --- a/test/CodeGen/assign.c +++ b/test/CodeGen/assign.c @@ -21,9 +21,9 @@ void f0() { // CHECK: define void @f1() // CHECK: [[x_1:%.*]] = alloca i32, align 4 // CHECK-NEXT: [[y_1:%.*]] = alloca i32, align 4 -// CHECK-NEXT: volatile store i32 1, i32* [[x_1]] -// CHECK-NEXT: volatile store i32 1, i32* [[x_1]] -// CHECK-NEXT: volatile store i32 1, i32* [[y_1]] +// CHECK-NEXT: store volatile i32 1, i32* [[x_1]] +// CHECK-NEXT: store volatile i32 1, i32* [[x_1]] +// CHECK-NEXT: store volatile i32 1, i32* [[y_1]] // CHECK: } void f1() { volatile int x, y; diff --git a/test/CodeGen/atomic-ops.c b/test/CodeGen/atomic-ops.c new file mode 100644 index 000000000000..e2904cf10e81 --- /dev/null +++ b/test/CodeGen/atomic-ops.c @@ -0,0 +1,77 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s + +// Basic IRGen tests for __atomic_* + +// FIXME: Need to implement __atomic_is_lock_free + +typedef enum memory_order { + memory_order_relaxed, memory_order_consume, memory_order_acquire, + memory_order_release, memory_order_acq_rel, memory_order_seq_cst +} memory_order; + +int fi1(_Atomic(int) *i) { + // CHECK: @fi1 + // CHECK: load atomic i32* {{.*}} seq_cst + return __atomic_load(i, memory_order_seq_cst); +} + +void fi2(_Atomic(int) *i) { + // CHECK: @fi2 + // CHECK: store atomic i32 {{.*}} seq_cst + __atomic_store(i, 1, memory_order_seq_cst); +} + +void fi3(_Atomic(int) *i) { + // CHECK: @fi3 + // CHECK: atomicrmw and + __atomic_fetch_and(i, 1, memory_order_seq_cst); +} + +void fi4(_Atomic(int) *i) { + // CHECK: @fi4 + // CHECK: cmpxchg i32* + int cmp = 0; + __atomic_compare_exchange_strong(i, &cmp, 1, memory_order_acquire, memory_order_acquire); +} + +float ff1(_Atomic(float) *d) { + // CHECK: @ff1 + // CHECK: load atomic i32* {{.*}} monotonic + return __atomic_load(d, memory_order_relaxed); +} + +void ff2(_Atomic(float) *d) { + // CHECK: @ff2 + // CHECK: store atomic i32 {{.*}} release + __atomic_store(d, 1, memory_order_release); +} + +float ff3(_Atomic(float) *d) { + return __atomic_exchange(d, 2, memory_order_seq_cst); +} + +int* fp1(_Atomic(int*) *p) { + // CHECK: @fp1 + // CHECK: load atomic i32* {{.*}} seq_cst + return __atomic_load(p, memory_order_seq_cst); +} + +int* fp2(_Atomic(int*) *p) { + // CHECK: @fp2 + // CHECK: store i32 4 + // CHECK: atomicrmw add {{.*}} monotonic + return __atomic_fetch_add(p, 1, memory_order_relaxed); +} + +_Complex float fc(_Atomic(_Complex float) *c) { + // CHECK: @fc + // CHECK: atomicrmw xchg i64* + return __atomic_exchange(c, 2, memory_order_seq_cst); +} + +typedef struct X { int x; } X; +X fs(_Atomic(X) *c) { + // CHECK: @fs + // CHECK: atomicrmw xchg i32* + return __atomic_exchange(c, (X){2}, memory_order_seq_cst); +} diff --git a/test/CodeGen/atomic.c b/test/CodeGen/atomic.c index 8ce2d96043f2..c8f4fd09bbc5 100644 --- a/test/CodeGen/atomic.c +++ b/test/CodeGen/atomic.c @@ -10,118 +10,75 @@ int atomic(void) { int cmp = 0; old = __sync_fetch_and_add(&val, 1); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.load.add.i32.p0i32(i32* %val, i32 1) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw add i32* %val, i32 1 seq_cst old = __sync_fetch_and_sub(&valc, 2); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i8 @llvm.atomic.load.sub.i8.p0i8(i8* %valc, i8 2) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw sub i8* %valc, i8 2 seq_cst old = __sync_fetch_and_min(&val, 3); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.load.min.i32.p0i32(i32* %val, i32 3) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw min i32* %val, i32 3 seq_cst old = __sync_fetch_and_max(&val, 4); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.load.max.i32.p0i32(i32* %val, i32 4) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw max i32* %val, i32 4 seq_cst old = __sync_fetch_and_umin(&uval, 5u); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.load.umin.i32.p0i32(i32* %uval, i32 5) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw umin i32* %uval, i32 5 seq_cst old = __sync_fetch_and_umax(&uval, 6u); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.load.umax.i32.p0i32(i32* %uval, i32 6) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw umax i32* %uval, i32 6 seq_cst old = __sync_lock_test_and_set(&val, 7); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.swap.i32.p0i32(i32* %val, i32 7) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw xchg i32* %val, i32 7 seq_cst old = __sync_swap(&val, 8); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.swap.i32.p0i32(i32* %val, i32 8) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw xchg i32* %val, i32 8 seq_cst old = __sync_val_compare_and_swap(&val, 4, 1976); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.cmp.swap.i32.p0i32(i32* %val, i32 4, i32 1976) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: cmpxchg i32* %val, i32 4, i32 1976 seq_cst old = __sync_bool_compare_and_swap(&val, 4, 1976); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.cmp.swap.i32.p0i32(i32* %val, i32 4, i32 1976) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: cmpxchg i32* %val, i32 4, i32 1976 seq_cst old = __sync_fetch_and_and(&val, 0x9); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.load.and.i32.p0i32(i32* %val, i32 9) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw and i32* %val, i32 9 seq_cst old = __sync_fetch_and_or(&val, 0xa); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.load.or.i32.p0i32(i32* %val, i32 10) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw or i32* %val, i32 10 seq_cst old = __sync_fetch_and_xor(&val, 0xb); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.load.xor.i32.p0i32(i32* %val, i32 11) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw xor i32* %val, i32 11 seq_cst old = __sync_add_and_fetch(&val, 1); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.load.add.i32.p0i32(i32* %val, i32 1) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw add i32* %val, i32 1 seq_cst old = __sync_sub_and_fetch(&val, 2); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.load.sub.i32.p0i32(i32* %val, i32 2) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw sub i32* %val, i32 2 seq_cst old = __sync_and_and_fetch(&valc, 3); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i8 @llvm.atomic.load.and.i8.p0i8(i8* %valc, i8 3) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw and i8* %valc, i8 3 seq_cst old = __sync_or_and_fetch(&valc, 4); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i8 @llvm.atomic.load.or.i8.p0i8(i8* %valc, i8 4) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: atomicrmw or i8* %valc, i8 4 seq_cst old = __sync_xor_and_fetch(&valc, 5); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i8 @llvm.atomic.load.xor.i8.p0i8(i8* %valc, i8 5) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - + // CHECK: atomicrmw xor i8* %valc, i8 5 seq_cst __sync_val_compare_and_swap((void **)0, (void *)0, (void *)0); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.cmp.swap.i32.p0i32(i32* null, i32 0, i32 0) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: cmpxchg i32* null, i32 0, i32 0 seq_cst if ( __sync_val_compare_and_swap(&valb, 0, 1)) { - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i8 @llvm.atomic.cmp.swap.i8.p0i8(i8* %valb, i8 0, i8 1) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: cmpxchg i8* %valb, i8 0, i8 1 seq_cst old = 42; } __sync_bool_compare_and_swap((void **)0, (void *)0, (void *)0); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.cmp.swap.i32.p0i32(i32* null, i32 0, i32 0) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) + // CHECK: cmpxchg i32* null, i32 0, i32 0 seq_cst __sync_lock_release(&val); - // CHECK: volatile store i32 0, i32* + // CHECK: store atomic {{.*}} release, align 4 __sync_synchronize (); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 false) + // CHECK: fence seq_cst return old; } @@ -130,7 +87,7 @@ int atomic(void) { void release_return(int *lock) { // Ensure this is actually returning void all the way through. return __sync_lock_release(lock); - // CHECK: volatile store i32 0, i32* + // CHECK: store atomic {{.*}} release, align 4 } @@ -138,21 +95,11 @@ void release_return(int *lock) { // CHECK: @addrspace void addrspace(int __attribute__((address_space(256))) * P) { __sync_bool_compare_and_swap(P, 0, 1); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.cmp.swap.i32.p256i32(i32 addrspace(256)*{{.*}}, i32 0, i32 1) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - - + // CHECK: cmpxchg i32 addrspace(256)*{{.*}}, i32 0, i32 1 seq_cst + __sync_val_compare_and_swap(P, 0, 1); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.cmp.swap.i32.p256i32(i32 addrspace(256)*{{.*}}, i32 0, i32 1) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - - + // CHECK: cmpxchg i32 addrspace(256)*{{.*}}, i32 0, i32 1 seq_cst + __sync_xor_and_fetch(P, 123); - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - // CHECK: call i32 @llvm.atomic.load.xor.i32.p256i32(i32 addrspace(256)* {{.*}}, i32 123) - // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true) - + // CHECK: atomicrmw xor i32 addrspace(256)*{{.*}}, i32 123 seq_cst } - diff --git a/test/CodeGen/attr-naked.c b/test/CodeGen/attr-naked.c index bccacc9916f1..2387d288eca8 100644 --- a/test/CodeGen/attr-naked.c +++ b/test/CodeGen/attr-naked.c @@ -1,9 +1,16 @@ -// RUN: %clang_cc1 -g -emit-llvm -o %t %s -// RUN: grep 'naked' %t +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 %s -emit-llvm -o - | FileCheck %s void t1() __attribute__((naked)); +// Basic functionality check +// (Note that naked needs to imply noinline to work properly.) +// CHECK: define void @t1() nounwind noinline naked { void t1() { } +// Make sure this doesn't explode in the verifier. +// (It doesn't really make sense, but it isn't invalid.) +// CHECK: define void @t2() nounwind noinline naked { +__attribute((naked, always_inline)) void t2() { +} diff --git a/test/CodeGen/attribute_constructor.c b/test/CodeGen/attribute_constructor.c new file mode 100644 index 000000000000..c82c263dda19 --- /dev/null +++ b/test/CodeGen/attribute_constructor.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | grep llvm.global_ctors + +void foo() __attribute__((constructor)); +void foo() { + bar(); +} diff --git a/test/CodeGen/avx-shuffle-builtins.c b/test/CodeGen/avx-shuffle-builtins.c new file mode 100644 index 000000000000..c11780a5e392 --- /dev/null +++ b/test/CodeGen/avx-shuffle-builtins.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -O3 -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s + +// Don't include mm_malloc.h, it's system specific. +#define __MM_MALLOC_H + +#include <immintrin.h> + +// +// Test LLVM IR codegen of shuffle instructions +// + +__m256 x(__m256 a, __m256 b) { + // Check if the mask is correct + // CHECK: shufflevector{{.*}}<i32 3, i32 2, i32 8, i32 11, i32 7, i32 6, i32 12, i32 15> + return _mm256_shuffle_ps(a, b, 203); +} diff --git a/test/CodeGen/block-3.c b/test/CodeGen/block-3.c new file mode 100644 index 000000000000..95cb6a735c73 --- /dev/null +++ b/test/CodeGen/block-3.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -fblocks -triple x86_64-apple-darwin10 +// rdar://10001085 + +int main() { + ^{ + __attribute__((__blocks__(byref))) int index = ({ int __a; int __b; __a < __b ? __b : __a; }); + }; +} diff --git a/test/CodeGen/block-copy.c b/test/CodeGen/block-copy.c new file mode 100644 index 000000000000..fba76ad21a14 --- /dev/null +++ b/test/CodeGen/block-copy.c @@ -0,0 +1,20 @@ +/* RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + + This should compile into a memcpy from a global, not 128 stores. */ + + + +void foo(); + +float bar() { + float lookupTable[] = {-1,-1,-1,0, -1,-1,0,-1, -1,-1,0,1, -1,-1,1,0, + -1,0,-1,-1, -1,0,-1,1, -1,0,1,-1, -1,0,1,1, + -1,1,-1,0, -1,1,0,-1, -1,1,0,1, -1,1,1,0, + 0,-1,-1,-1, 0,-1,-1,1, 0,-1,1,-1, 0,-1,1,1, + 1,-1,-1,0, 1,-1,0,-1, 1,-1,0,1, 1,-1,1,0, + 1,0,-1,-1, 1,0,-1,1, 1,0,1,-1, 1,0,1,1, + 1,1,-1,0, 1,1,0,-1, 1,1,0,1, 1,1,1,0, + 0,1,-1,-1, 0,1,-1,1, 0,1,1,-1, 0,1,1,1}; + // CHECK: memcpy + foo(lookupTable); +} diff --git a/test/CodeGen/block-decl-merging.c b/test/CodeGen/block-decl-merging.c deleted file mode 100644 index 1e7a9f4e92cb..000000000000 --- a/test/CodeGen/block-decl-merging.c +++ /dev/null @@ -1,20 +0,0 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin10 -fblocks -emit-llvm -o - %s | \ -// RUN: FileCheck %s - -// CHECK: @_NSConcreteGlobalBlock = extern_weak global -extern void * _NSConcreteStackBlock[32] __attribute__((weak_import)); -// CHECK: @_NSConcreteStackBlock = extern_weak global -extern void * _NSConcreteGlobalBlock[32] __attribute__((weak_import)); -extern void _Block_object_dispose(const void *, const int) __attribute__((weak_import)); -// CHECK: declare extern_weak void @_Block_object_assign -extern void _Block_object_assign(void *, const void *, const int) __attribute__((weak_import)); -// CHECK: declare extern_weak void @_Block_object_dispose - -void *x = ^(){}; - -void f1(void (^a0)(void)); - -void f0() { - __block int x; - f1(^(void){ x = 1; }); -} diff --git a/test/CodeGen/blocks.c b/test/CodeGen/blocks.c index b7b6a2d505ef..bef44c369015 100644 --- a/test/CodeGen/blocks.c +++ b/test/CodeGen/blocks.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o %t -fblocks +// RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - -fblocks | FileCheck %s void (^f)(void) = ^{}; // rdar://6768379 @@ -12,7 +12,7 @@ struct s0 { int a[64]; }; -// RUN: grep 'internal void @__f2_block_invoke_0(.struct.s0\* sret .*, .*, .* byval .*)' %t +// CHECK: define internal void @__f2_block_invoke_0(%struct.s0* noalias sret {{%.*}}, i8* {{%.*}}, %struct.s0* byval align 4 {{.*}}) struct s0 f2(struct s0 a0) { return ^(struct s0 a1){ return a1; }(a0); } diff --git a/test/CodeGen/builtin-attributes.c b/test/CodeGen/builtin-attributes.c index 822b8eecf7d7..3781eba26694 100644 --- a/test/CodeGen/builtin-attributes.c +++ b/test/CodeGen/builtin-attributes.c @@ -15,3 +15,44 @@ void f1() { char* f2(char* a, char* b) { return __builtin_strstr(a, b); } + +// frexp is NOT readnone. It writes to its pointer argument. +// <rdar://problem/10070234> +// +// CHECK: f3 +// CHECK: call double @frexp(double % +// CHECK-NOT: readnone +// CHECK: call float @frexpf(float % +// CHECK-NOT: readnone +// CHECK: call double @frexpl(double % +// CHECK-NOT: readnone +// +// Same thing for modf and friends. +// +// CHECK: call double @modf(double % +// CHECK-NOT: readnone +// CHECK: call float @modff(float % +// CHECK-NOT: readnone +// CHECK: call double @modfl(double % +// CHECK-NOT: readnone +// +// CHECK: call double @remquo(double % +// CHECK-NOT: readnone +// CHECK: call float @remquof(float % +// CHECK-NOT: readnone +// CHECK: call double @remquol(double % +// CHECK-NOT: readnone +// CHECK: ret +int f3(double x) { + int e; + __builtin_frexp(x, &e); + __builtin_frexpf(x, &e); + __builtin_frexpl(x, &e); + __builtin_modf(x, &e); + __builtin_modff(x, &e); + __builtin_modfl(x, &e); + __builtin_remquo(x, x, &e); + __builtin_remquof(x, x, &e); + __builtin_remquol(x, x, &e); + return e; +} diff --git a/test/CodeGen/capture-complex-expr-in-block.c b/test/CodeGen/capture-complex-expr-in-block.c new file mode 100644 index 000000000000..9ce7570a4486 --- /dev/null +++ b/test/CodeGen/capture-complex-expr-in-block.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -fblocks -triple x86_64-apple-darwin10 | FileCheck %s +// rdar://10033986 + +typedef void (^BLOCK)(void); +int main () +{ + _Complex double c; + BLOCK b = ^() { + _Complex double z; + z = z + c; + }; + b(); +} + +// CHECK: define internal void @__main_block_invoke_0 +// CHECK: [[C1:%.*]] = alloca { double, double }, align 8 +// CHECK: [[RP:%.*]] = getelementptr inbounds { double, double }* [[C1]], i32 0, i32 0 +// CHECK-NEXT: [[R:%.*]] = load double* [[RP]] +// CHECK-NEXT: [[IP:%.*]] = getelementptr inbounds { double, double }* [[C1]], i32 0, i32 1 +// CHECK-NEXT: [[I:%.*]] = load double* [[IP]] diff --git a/test/CodeGen/char-literal.c b/test/CodeGen/char-literal.c index 322041c0049a..5963ede392af 100644 --- a/test/CodeGen/char-literal.c +++ b/test/CodeGen/char-literal.c @@ -1,35 +1,93 @@ -// RUN: %clang_cc1 -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s -// Runs in c++ mode so that wchar_t is available. +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=C %s +// RUN: %clang_cc1 -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=C %s +// RUN: %clang_cc1 -x c++ -std=c++11 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=CPP0X %s + +#include <stddef.h> int main() { - // CHECK: store i8 97 + // CHECK-C: store i8 97 + // CHECK-CPP0X: store i8 97 char a = 'a'; // Should pick second character. - // CHECK: store i8 98 + // CHECK-C: store i8 98 + // CHECK-CPP0X: store i8 98 char b = 'ab'; - // CHECK: store i32 97 + // CHECK-C: store i32 97 + // CHECK-CPP0X: store i32 97 wchar_t wa = L'a'; // Should pick second character. - // CHECK: store i32 98 + // CHECK-C: store i32 98 + // CHECK-CPP0X: store i32 98 wchar_t wb = L'ab'; +#if __cplusplus >= 201103L + // CHECK-CPP0X: store i16 97 + char16_t ua = u'a'; + + // Should pick second character. + // CHECK-CPP0X: store i16 98 + char16_t ub = u'ab'; + + // CHECK-CPP0X: store i32 97 + char32_t Ua = U'a'; + + // Should pick second character. + // CHECK-CPP0X: store i32 98 + char32_t Ub = U'ab'; +#endif + // Should pick last character and store its lowest byte. // This does not match gcc, which takes the last character, converts it to // utf8, and then picks the second-lowest byte of that (they probably store // the utf8 in uint16_ts internally and take the lower byte of that). - // CHECK: store i8 48 + // CHECK-C: store i8 48 + // CHECK-CPP0X: store i8 48 char c = '\u1120\u0220\U00102030'; - // CHECK: store i32 61451 + // CHECK-C: store i32 61451 + // CHECK-CPP0X: store i32 61451 wchar_t wc = L'\uF00B'; - // CHECK: store i32 1110027 +#if __cplusplus >= 201103L + // -4085 == 0xf00b + // CHECK-CPP0X: store i16 -4085 + char16_t uc = u'\uF00B'; + + // CHECK-CPP0X: store i32 61451 + char32_t Uc = U'\uF00B'; +#endif + + // CHECK-C: store i32 1110027 + // CHECK-CPP0X: store i32 1110027 wchar_t wd = L'\U0010F00B'; +#if __cplusplus >= 201103L + // Should take lower word of the 4byte UNC sequence. This does not match + // gcc. I don't understand what gcc does (it looks like it converts to utf16, + // then takes the second (!) utf16 word, swaps the lower two nibbles, and + // stores that?). + // CHECK-CPP0X: store i16 -4085 + char16_t ud = u'\U0010F00B'; // has utf16 encoding dbc8 dcb0 + + // CHECK-CPP0X: store i32 1110027 + char32_t Ud = U'\U0010F00B'; +#endif + // Should pick second character. - // CHECK: store i32 1110027 + // CHECK-C: store i32 1110027 + // CHECK-CPP0X: store i32 1110027 wchar_t we = L'\u1234\U0010F00B'; + +#if __cplusplus >= 201103L + // Should pick second character. + // CHECK-CPP0X: store i16 -4085 + char16_t ue = u'\u1234\U0010F00B'; + + // Should pick second character. + // CHECK-CPP0X: store i32 1110027 + char32_t Ue = U'\u1234\U0010F00B'; +#endif } diff --git a/test/CodeGen/complex-init-list.c b/test/CodeGen/complex-init-list.c new file mode 100644 index 000000000000..819d4f9432de --- /dev/null +++ b/test/CodeGen/complex-init-list.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 | FileCheck %s + +// This file tests the clang extension which allows initializing the components +// of a complex number individually using an initialization list. (There is a +// extensive description and test in test/Sema/complex-init-list.c.) + +_Complex float x = { 1.0f, 1.0f/0.0f }; +// CHECK: @x = global { float, float } { float 1.000000e+00, float 0x7FF0000000000000 }, align 4 + +_Complex float f(float x, float y) { _Complex float z = { x, y }; return z; } +// CHECK: define <2 x float> @f +// CHECK: alloca { float, float }
\ No newline at end of file diff --git a/test/CodeGen/debug-dead-local-var.c b/test/CodeGen/debug-dead-local-var.c new file mode 100644 index 000000000000..f9ca8f2f297d --- /dev/null +++ b/test/CodeGen/debug-dead-local-var.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -mllvm -asm-verbose -S -O2 -g %s -o - | FileCheck %s +// Radar 8122864 + +// Code is not generated for function foo, but preserve type information of +// local variable xyz. +static void foo() { +// CHECK: DW_TAG_structure_type + struct X { int a; int b; } xyz; +} + +int bar() { + foo(); + return 1; +} diff --git a/test/CodeGen/debug-info-iv.c b/test/CodeGen/debug-info-iv.c index 92654738cfc5..1d9bf32c2cda 100644 --- a/test/CodeGen/debug-info-iv.c +++ b/test/CodeGen/debug-info-iv.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-darwin-apple -Os -S -g -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -Os -S -g -o - %s | FileCheck %s int calculate(int); static void test_indvars(int *Array1, int Array2[100][200]) { @@ -14,22 +14,22 @@ static void test_indvars(int *Array1, int Array2[100][200]) { for (i = 13; i < 100; i++) for (j = 0; j < 100; j+=3) /* 2d array access */ Array2[i][j/3] = Array2[i][i]; -} +} int main() { int Array[100][200], i, j; double sum = 0.0; - + for (i=0; i < 100; i+=2) for (j=0; j < 200; j++) Array[i][j] = 0; test_indvars(Array[0], Array); -//CHECK: .loc 2 30 3 +//CHECK: .loc 2 30 8 for (i=0; i < 100; i+=2) for (j=0; j < 200; j++) sum += Array[i][j]; - + return calculate(sum); } diff --git a/test/CodeGen/debug-info-line.c b/test/CodeGen/debug-info-line.c index b255d90b34c8..9e6e9714aa47 100644 --- a/test/CodeGen/debug-info-line.c +++ b/test/CodeGen/debug-info-line.c @@ -1,8 +1,9 @@ -// RUN: %clang -emit-llvm -S -g %s -o %t -// RUN: grep DW_TAG_lexical_block %t | count 3 +// RUN: %clang -emit-llvm -S -g %s -o - | FileCheck %s // Radar 8396182 -// There are three lexical blocks in this test case. +// There is only one lexical block, but we need a DILexicalBlock and two +// DILexicalBlockFile to correctly represent file info. This means we have +// two lexical blocks shown as the latter is also tagged as a lexical block. int foo() { int i = 1; @@ -13,3 +14,10 @@ int foo() { # 5 "m.c" 2 return i + j; } + +// CHECK: DW_TAG_lexical_block +// CHECK: DW_TAG_lexical_block +// CHECK: !"m.h" +// CHECK: DW_TAG_lexical_block +// CHECK: !"m.c" +// CHECK-NOT: DW_TAG_lexical_block diff --git a/test/CodeGen/debug-info-line3.c b/test/CodeGen/debug-info-line3.c new file mode 100644 index 000000000000..645ffb9e7485 --- /dev/null +++ b/test/CodeGen/debug-info-line3.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -g -S -emit-llvm %s -o - | FileCheck %s + +void func(char c, char* d) +{ + *d = c + 1; + return; + + + + + + +} + +// CHECK: ret void, !dbg !19 +// CHECK: !19 = metadata !{i32 6, diff --git a/test/CodeGen/debug-info-member.c b/test/CodeGen/debug-info-member.c index 54066fa53060..43d26f858d2c 100644 --- a/test/CodeGen/debug-info-member.c +++ b/test/CodeGen/debug-info-member.c @@ -1,3 +1,3 @@ -// RUN: %clang_cc1 -emit-llvm -g < %s | grep DW_TAG_member | grep \!3 +// RUN: %clang_cc1 -emit-llvm -g < %s | grep DW_TAG_member struct A { int x; } a; diff --git a/test/CodeGen/decl.c b/test/CodeGen/decl.c index 21b75797f0c3..2065e3364bcd 100644 --- a/test/CodeGen/decl.c +++ b/test/CodeGen/decl.c @@ -1,11 +1,11 @@ // RUN: %clang_cc1 -w -emit-llvm < %s | FileCheck %s // CHECK: @test1.x = internal constant [12 x i32] [i32 1 -// CHECK: @test2.x = internal unnamed_addr constant [13 x i32] [i32 1, +// CHECK: @test2.x = private unnamed_addr constant [13 x i32] [i32 1, // CHECK: @test5w = global { i32, [4 x i8] } { i32 2, [4 x i8] undef } // CHECK: @test5y = global { double } { double 7.300000e+0{{[0]*}}1 } -// CHECK: @test6.x = internal unnamed_addr constant %struct.SelectDest { i8 1, i8 2, i32 3, i32 0 } +// CHECK: @test6.x = private unnamed_addr constant %struct.SelectDest { i8 1, i8 2, i32 3, i32 0 } // CHECK: @test7 = global [2 x %struct.test7s] [%struct.test7s { i32 1, i32 2 }, %struct.test7s { i32 4, i32 0 }] @@ -24,7 +24,7 @@ void test2() { // This should codegen as a "@test2.x" global + memcpy. int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23, 24 }; foo(x); - + // CHECK: @test2() // CHECK: %x = alloca [13 x i32] // CHECK: call void @llvm.memcpy @@ -36,7 +36,7 @@ void test3() { // This should codegen as a memset. int x[100] = { 0 }; foo(x); - + // CHECK: @test3() // CHECK: %x = alloca [100 x i32] // CHECK: call void @llvm.memset diff --git a/test/CodeGen/exact-div-expr.c b/test/CodeGen/exact-div-expr.c new file mode 100644 index 000000000000..a2c12a0b3f6e --- /dev/null +++ b/test/CodeGen/exact-div-expr.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -O1 | grep ashr +// RUN: %clang_cc1 -emit-llvm %s -o - -O1 | not grep sdiv + +long long test(int *A, int *B) { + return A-B; +} diff --git a/test/CodeGen/exceptions.c b/test/CodeGen/exceptions.c index 018b975395b9..20eb706a03b1 100644 --- a/test/CodeGen/exceptions.c +++ b/test/CodeGen/exceptions.c @@ -14,6 +14,8 @@ void test1() { // CHECK-ARM: invoke arm_aapcscc void @test1_helper( test1_helper(^(int v) { x = v; }); - // CHECK: call {{.*}} @llvm.eh.selector({{.*}}, i8* bitcast (i32 (...)* @__gcc_personality_v0 to i8*) - // CHECK-ARM: call {{.*}} @llvm.eh.selector({{.*}}, i8* bitcast (i32 (...)* @__gcc_personality_sj0 to i8*) + // CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gcc_personality_v0 to i8*) + // CHECK-NEXT: cleanup + // CHECK-ARM: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gcc_personality_sj0 to i8*) + // CHECK-ARM-NEXT: cleanup } diff --git a/test/CodeGen/extern-weak.c b/test/CodeGen/extern-weak.c new file mode 100644 index 000000000000..6a78a33af65a --- /dev/null +++ b/test/CodeGen/extern-weak.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -O3 -emit-llvm -o - %s | grep extern_weak +// RUN: %clang_cc1 -O3 -emit-llvm -o - %s | llc + +#if !defined(__linux__) && !defined(__FreeBSD__) && \ + !defined(__OpenBSD__) && !defined(__CYGWIN__) && !defined(__DragonFly__) +void foo() __attribute__((weak_import)); +#else +void foo() __attribute__((weak)); +#endif + +void bar() { foo(); } + diff --git a/test/CodeGen/fp16-ops.c b/test/CodeGen/fp16-ops.c new file mode 100644 index 000000000000..cbbfb884df50 --- /dev/null +++ b/test/CodeGen/fp16-ops.c @@ -0,0 +1,283 @@ +// RUN: %clang_cc1 -emit-llvm -o - -triple arm-none-linux-gnueabi %s | FileCheck %s +typedef unsigned cond_t; + +volatile cond_t test; +volatile __fp16 h0 = 0.0, h1 = 1.0, h2; +volatile float f0, f1, f2; + +void foo(void) { + // CHECK: define void @foo() + + // Check unary ops + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK fptoi float + test = (h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une float + test = (!h1); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = -h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = +h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1++; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + ++h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + --h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1--; + + // Check binary ops with various operands + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = h0 * h2; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call i16 @llvm.convert.to.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = h0 * (__fp16) -2.0; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = h0 * f2; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = f0 * h2; + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h0 / h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h0 / (__fp16) -2.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h0 / f2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (f0 / h2); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h2 + h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = ((__fp16)-2.0 + h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h2 + f0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (f2 + h0); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h2 - h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = ((__fp16)-2.0 - h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h2 - f0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (f2 - h0); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp olt + test = (h2 < h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp olt + test = (h2 < (__fp16)42.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp olt + test = (h2 < f0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp olt + test = (f2 < h0); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ogt + test = (h0 > h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ogt + test = ((__fp16)42.0 > h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ogt + test = (h0 > f2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ogt + test = (f0 > h2); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ole + test = (h2 <= h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ole + test = (h2 <= (__fp16)42.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ole + test = (h2 <= f0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ole + test = (f2 <= h0); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oge + test = (h0 >= h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oge + test = (h0 >= (__fp16)-2.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oge + test = (h0 >= f2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oge + test = (f0 >= h2); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oeq + test = (h1 == h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oeq + test = (h1 == (__fp16)1.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oeq + test = (h1 == f1); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oeq + test = (f1 == h1); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une + test = (h1 != h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une + test = (h1 != (__fp16)1.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une + test = (h1 != f1); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une + test = (f1 != h1); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h1 ? h2 : h0); + // Check assignments (inc. compound) + h0 = h1; + // CHECK: call i16 @llvm.convert.to.fp16 + h0 = (__fp16)-2.0; + // CHECK: call i16 @llvm.convert.to.fp16 + h0 = f0; + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h0 += h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd + // CHECK: call i16 @llvm.convert.to.fp16 + h0 += (__fp16)1.0; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd + // CHECK: call i16 @llvm.convert.to.fp16 + h0 += f2; + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub + // CHECK: call i16 @llvm.convert.to.fp16 + h0 -= h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub + // CHECK: call i16 @llvm.convert.to.fp16 + h0 -= (__fp16)1.0; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub + // CHECK: call i16 @llvm.convert.to.fp16 + h0 -= f2; + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul + // CHECK: call i16 @llvm.convert.to.fp16 + h0 *= h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul + // CHECK: call i16 @llvm.convert.to.fp16 + h0 *= (__fp16)1.0; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul + // CHECK: call i16 @llvm.convert.to.fp16 + h0 *= f2; + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv + // CHECK: call i16 @llvm.convert.to.fp16 + h0 /= h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv + // CHECK: call i16 @llvm.convert.to.fp16 + h0 /= (__fp16)1.0; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv + // CHECK: call i16 @llvm.convert.to.fp16 + h0 /= f2; +} diff --git a/test/CodeGen/func-aligned.c b/test/CodeGen/func-aligned.c new file mode 100644 index 000000000000..f8a4a29d9d2c --- /dev/null +++ b/test/CodeGen/func-aligned.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// rdar://7270273 +void foo() __attribute__((aligned (64))); +void foo() { +// CHECK: define void @foo() {{.*}} align 64 +} diff --git a/test/CodeGen/funccall.c b/test/CodeGen/funccall.c new file mode 100644 index 000000000000..9735e3470570 --- /dev/null +++ b/test/CodeGen/funccall.c @@ -0,0 +1,17 @@ + +static int q; + +void foo() { + int t = q; + q = t + 1; +} +int main() { + q = 0; + foo(); + q = q - 1; + + return q; +} + +// This is the source that corresponds to funccall.ll +// RUN: echo foo diff --git a/test/CodeGen/function-attributes.c b/test/CodeGen/function-attributes.c index 3a1030a61b90..6cbf40ba220f 100644 --- a/test/CodeGen/function-attributes.c +++ b/test/CodeGen/function-attributes.c @@ -89,3 +89,25 @@ void f15(void) { void __attribute__((force_align_arg_pointer)) f16(void) { } +// PR11038 +// CHECK: define void @f18() +// CHECK: returns_twice +// CHECK: { +// CHECK: call void @f17() +// CHECK: returns_twice +// CHECK: ret void +__attribute__ ((returns_twice)) void f17(void); +__attribute__ ((returns_twice)) void f18(void) { + f17(); +} + +// CHECK: define void @f19() +// CHECK: { +// CHECK: call i32 @setjmp(i32* null) +// CHECK: returns_twice +// CHECK: ret void +typedef int jmp_buf[((9 * 2) + 3 + 16)]; +int setjmp(jmp_buf); +void f19(void) { + setjmp(0); +} diff --git a/test/CodeGen/functions.c b/test/CodeGen/functions.c index e51f93e57411..28e4bd0c8296 100644 --- a/test/CodeGen/functions.c +++ b/test/CodeGen/functions.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -emit-llvm -o - -verify | FileCheck %s +// RUN: %clang_cc1 %s -triple i386-unknown-unknown -emit-llvm -o - -verify | FileCheck %s int g(); @@ -24,7 +24,7 @@ void f0() {} void f1(); void f2(void) { -// CHECK: call void @f1() +// CHECK: call void bitcast (void ()* @f1 to void (i32, i32, i32)*)(i32 1, i32 2, i32 3) f1(1, 2, 3); } // CHECK: define void @f1() diff --git a/test/CodeGen/hidden-visibility.c b/test/CodeGen/hidden-visibility.c new file mode 100644 index 000000000000..65e6616ef19f --- /dev/null +++ b/test/CodeGen/hidden-visibility.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// CHECK: hidden global +int X __attribute__ ((__visibility__ ("hidden"))) = 123; diff --git a/test/CodeGen/implicit-arg.c b/test/CodeGen/implicit-arg.c new file mode 100644 index 000000000000..52ab58ec9801 --- /dev/null +++ b/test/CodeGen/implicit-arg.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 %s -emit-llvm -O0 -o - +// RUN: %clang_cc1 %s -emit-llvm -O1 -o - +// rdar://6518089 + +static int bar(); +void foo() { + int a = bar(); +} +int bar(unsigned a) { +} diff --git a/test/CodeGen/inline-asm-mrv.c b/test/CodeGen/inline-asm-mrv.c new file mode 100644 index 000000000000..929dd90fde60 --- /dev/null +++ b/test/CodeGen/inline-asm-mrv.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -O | not grep alloca +// PR2094 + +int sad16_sse2(void *v, unsigned char *blk2, unsigned char *blk1, + int stride, int h) { + int ret; + asm volatile( "%0 %1 %2 %3" + : "+r" (h), "+r" (blk1), "+r" (blk2) + : "r" ((long)stride)); + asm volatile("set %0 %1" : "=r"(ret) : "r"(blk1)); + return ret; +} diff --git a/test/CodeGen/inline.c b/test/CodeGen/inline.c index 96f9c5c9d4bb..6bc583df8c96 100644 --- a/test/CodeGen/inline.c +++ b/test/CodeGen/inline.c @@ -12,9 +12,10 @@ // RUN: grep "define void @test3()" %t // RUN: grep "define available_externally i32 @test4" %t // RUN: grep "define available_externally i32 @test5" %t +// RUN: grep "define i32 @test6" %t // RUN: echo "\nC99 tests:" -// RUN: %clang %s -O1 -emit-llvm -S -o %t -std=c99 +// RUN: %clang %s -O1 -emit-llvm -S -o %t -std=gnu99 // RUN: grep "define i32 @ei()" %t // RUN: grep "define available_externally i32 @foo()" %t // RUN: grep "define i32 @bar()" %t @@ -27,6 +28,8 @@ // RUN: grep "define void @test3" %t // RUN: grep "define available_externally i32 @test4" %t // RUN: grep "define available_externally i32 @test5" %t +// RUN: grep "define i32 @test6" %t +// RUN: grep "define available_externally i.. @strlcpy" %t // RUN: echo "\nC++ tests:" // RUN: %clang -x c++ %s -O1 -emit-llvm -S -o %t -std=c++98 @@ -84,3 +87,18 @@ extern __inline int __attribute__ ((__gnu_inline__)) test5(void) } void test_test5() { test5(); } + +// PR10233 + +__inline int test6() { return 0; } +extern int test6(); + + +// No PR#, but this once crashed clang in C99 mode due to buggy extern inline +// redeclaration detection. +void test7() { } +void test7(); + +// PR11062; the fact that the function is named strlcpy matters here. +inline __typeof(sizeof(int)) strlcpy(char *dest, const char *src, __typeof(sizeof(int)) size) { return 3; } +void test8() { strlcpy(0,0,0); } diff --git a/test/CodeGen/kr-call.c b/test/CodeGen/kr-call.c new file mode 100644 index 000000000000..ea4e3d3d70f0 --- /dev/null +++ b/test/CodeGen/kr-call.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple s390x-unknown-linux -emit-llvm -o - %s | FileCheck %s + +// Test that we don't crash. The s390x-unknown-linux target happens +// to need to set a sext argument attribute on this call, and we need +// to make sure that rewriting it correctly keeps that attribute. +void test0_helper(); +void test0() { + // CHECK: call void bitcast (void ()* @test0_helper to void (i32)*)(i32 signext 1) + test0_helper(1); +} +void test0_helper() {} + diff --git a/test/CodeGen/libcalls-d.c b/test/CodeGen/libcalls-d.c new file mode 100644 index 000000000000..b375f2bb83a6 --- /dev/null +++ b/test/CodeGen/libcalls-d.c @@ -0,0 +1,16 @@ +// llvm-gcc -O1+ should run simplify libcalls, O0 shouldn't +// and -fno-builtins shouldn't. +// -fno-math-errno should emit an llvm intrinsic, -fmath-errno should not. +// RUN: %clang_cc1 %s -emit-llvm -fno-math-errno -O0 -o - | grep {call.*exp2\\.f64} +// RUN: %clang_cc1 %s -emit-llvm -fmath-errno -O0 -o - | grep {call.*exp2} +// RUN: %clang_cc1 %s -emit-llvm -O1 -o - | grep {call.*ldexp} +// RUN: %clang_cc1 %s -emit-llvm -O3 -fno-builtin -o - | grep {call.*exp2} + +// clang doesn't support this yet. +// XFAIL: * + +double exp2(double); + +double t4(unsigned char x) { + return exp2(x); +} diff --git a/test/CodeGen/libcalls-ld.c b/test/CodeGen/libcalls-ld.c new file mode 100644 index 000000000000..2758761b5ee1 --- /dev/null +++ b/test/CodeGen/libcalls-ld.c @@ -0,0 +1,19 @@ +// llvm-gcc -O1+ should run simplify libcalls, O0 shouldn't +// and -fno-builtins shouldn't. +// -fno-math-errno should emit an llvm intrinsic, -fmath-errno should not. +// RUN: %clang_cc1 %s -emit-llvm -fno-math-errno -O0 -o - | grep {call.*exp2\\..*f} +// RUN: %clang_cc1 %s -emit-llvm -fmath-errno -O0 -o - | grep {call.*exp2l} +// RUN: %clang_cc1 %s -emit-llvm -O1 -o - | grep {call.*ldexp} +// RUN: %clang_cc1 %s -emit-llvm -O3 -fno-builtin -o - | grep {call.*exp2l} + +// clang doesn't support this yet. +// XFAIL: * + +// If this fails for you because your target doesn't support long double, +// please xfail the test. + +long double exp2l(long double); + +long double t4(unsigned char x) { + return exp2l(x); +} diff --git a/test/CodeGen/libcalls.c b/test/CodeGen/libcalls.c index 5ff684fd5b66..458c591837ff 100644 --- a/test/CodeGen/libcalls.c +++ b/test/CodeGen/libcalls.c @@ -24,9 +24,9 @@ void test_sqrt(float a0, double a1, long double a2) { // CHECK-YES: declare float @sqrtf(float) // CHECK-YES: declare double @sqrt(double) // CHECK-YES: declare x86_fp80 @sqrtl(x86_fp80) -// CHECK-NO: declare float @sqrtf(float) readnone -// CHECK-NO: declare double @sqrt(double) readnone -// CHECK-NO: declare x86_fp80 @sqrtl(x86_fp80) readnone +// CHECK-NO: declare float @sqrtf(float) nounwind readnone +// CHECK-NO: declare double @sqrt(double) nounwind readnone +// CHECK-NO: declare x86_fp80 @sqrtl(x86_fp80) nounwind readnone // CHECK-YES: define void @test_pow // CHECK-NO: define void @test_pow diff --git a/test/CodeGen/microsoft-call-conv.c b/test/CodeGen/microsoft-call-conv.c index 95f5fa3f83b5..390c3be05e61 100644 --- a/test/CodeGen/microsoft-call-conv.c +++ b/test/CodeGen/microsoft-call-conv.c @@ -46,5 +46,5 @@ int main(void) { void __stdcall f7(foo) int foo; {} void f8(void) { f7(0); - // CHECK: call x86_stdcallcc void (...)* bitcast + // CHECK: call x86_stdcallcc void @f7(i32 0) } diff --git a/test/CodeGen/misaligned-param.c b/test/CodeGen/misaligned-param.c new file mode 100644 index 000000000000..53f1f290f5c2 --- /dev/null +++ b/test/CodeGen/misaligned-param.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 %s -triple i386-apple-darwin -emit-llvm -o - | FileCheck %s +// Misaligned parameter must be memcpy'd to correctly aligned temporary. + +struct s { int x; long double y; }; +long double foo(struct s x, int i, struct s y) { +// CHECK: foo +// CHECK: %x = alloca %struct.s, align 16 +// CHECK: %y = alloca %struct.s, align 16 +// CHECK: memcpy +// CHECK: memcpy +// CHECK: bar + return bar(&x, &y); +} diff --git a/test/CodeGen/mrtd.c b/test/CodeGen/mrtd.c index 2cc71bb0086f..d7729a525068 100644 --- a/test/CodeGen/mrtd.c +++ b/test/CodeGen/mrtd.c @@ -4,7 +4,7 @@ void baz(int arg); // CHECK: define x86_stdcallcc void @foo(i32 %arg) nounwind void foo(int arg) { -// CHECK: call x86_stdcallcc i32 (...)* @bar(i32 +// CHECK: call x86_stdcallcc i32 bitcast (i32 (...)* @bar to i32 (i32)*)( bar(arg); // CHECK: call x86_stdcallcc void @baz(i32 baz(arg); diff --git a/test/CodeGen/ms_struct-bitfield-1.c b/test/CodeGen/ms_struct-bitfield-1.c index 0b15a24f0337..25c0ba233261 100644 --- a/test/CodeGen/ms_struct-bitfield-1.c +++ b/test/CodeGen/ms_struct-bitfield-1.c @@ -4,26 +4,26 @@ #define ATTR __attribute__((__ms_struct__)) struct { - unsigned int bf_1 : 12; - unsigned int : 0; - unsigned int bf_2 : 12; + unsigned int bf_1 : 12; + unsigned int : 0; + unsigned int bf_2 : 12; } ATTR t1; static int a1[(sizeof(t1) == 8) -1]; struct { - char foo : 4; - short : 0; - char bar; + char foo : 4; + short : 0; + char bar; } ATTR t2; static int a2[(sizeof(t2) == 4) -1]; #pragma ms_struct on struct { - char foo : 4; - short : 0; - char bar; + char foo : 4; + short : 0; + char bar; } t3; #pragma ms_struct off static int a3[(sizeof(t3) == 4) -1]; @@ -45,47 +45,47 @@ static int a5[(sizeof(t5) == 4) -1]; struct { - char foo : 4; - short : 0; - long :0; - char bar; + char foo : 4; + short : 0; + long : 0; + char bar; } ATTR t6; static int a6[(sizeof(t6) == 4) -1]; struct { - char foo : 4; - long :0; - short : 0; - char bar; + char foo : 4; + long : 0; + short : 0; + char bar; } ATTR t7; static int a7[(sizeof(t7) == 16) -1]; struct { - char foo : 4; - short : 0; - long :0; - char bar:7; + char foo : 4; + short : 0; + long : 0; + char bar:7; } ATTR t8; static int a8[(sizeof(t8) == 4) -1]; struct { - char foo : 4; - long :0; - short : 0; - char bar: 8; + char foo : 4; + long : 0; + short : 0; + char bar: 8; } ATTR t9; static int a9[(sizeof(t9) == 16) -1]; struct { - char foo : 4; - char : 0; - short : 0; - int : 0; - long :0; - char bar; + char foo : 4; + char : 0; + short : 0; + int : 0; + long :0; + char bar; } ATTR t10; static int a10[(sizeof(t10) == 2) -1]; diff --git a/test/CodeGen/pascal-wchar-string.c b/test/CodeGen/pascal-wchar-string.c index 7a03463d2cf1..a6b619643e1f 100644 --- a/test/CodeGen/pascal-wchar-string.c +++ b/test/CodeGen/pascal-wchar-string.c @@ -35,7 +35,7 @@ int main(int argc, char* argv[]) // PR8856 - -fshort-wchar makes wchar_t be unsigned. // CHECK: @test2 -// CHECK: volatile store i32 1, i32* %isUnsigned +// CHECK: store volatile i32 1, i32* %isUnsigned void test2() { volatile int isUnsigned = (wchar_t)-1 > (wchar_t)0; } diff --git a/test/CodeGen/pr2394.c b/test/CodeGen/pr2394.c new file mode 100644 index 000000000000..e43281a3cd3e --- /dev/null +++ b/test/CodeGen/pr2394.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s +struct __attribute((packed)) x {int a : 24;}; +int a(struct x* g) { + // CHECK: load i16 + // CHECK: load i8 + return g->a; +} diff --git a/test/CodeGen/pr3518.c b/test/CodeGen/pr3518.c new file mode 100644 index 000000000000..f96a5aa65f19 --- /dev/null +++ b/test/CodeGen/pr3518.c @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 %s -emit-llvm -O0 -o - | FileCheck %s +// PR 3518 +// Some of the objects were coming out as unintialized (external) before 3518 +// was fixed. Internal names are different between llvm-gcc and clang so they +// are not tested. + +extern void abort (void); + +// CHECK: @.compoundliteral = internal global %struct.A { i32 1, i32 2 } +// CHECK: @.compoundliteral1 = internal global %struct.A { i32 3, i32 4 } +// CHECK: @.compoundliteral2 = internal global %struct.B { %struct.A* @.compoundliteral, %struct.A* @.compoundliteral1 } +// CHECK: @.compoundliteral3 = internal global %struct.A { i32 5, i32 6 } + +struct A { int i; int j; }; +struct B { struct A *a; struct A *b; }; +struct C { struct B *c; struct A *d; }; +struct C e = { &(struct B) { &(struct A) { 1, 2 }, &(struct A) { 3, 4 } }, &(struct A) { 5, 6 } }; + +int +main (void) +{ + if (e.c->a->i != 1 || e.c->a->j != 2) + abort (); + if (e.c->b->i != 3 || e.c->b->j != 4) + abort (); + if (e.d->i != 5 || e.d->j != 6) + abort (); + return 0; +} diff --git a/test/CodeGen/pr4349.c b/test/CodeGen/pr4349.c new file mode 100644 index 000000000000..94b4fbd5db46 --- /dev/null +++ b/test/CodeGen/pr4349.c @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 %s -emit-llvm -O0 -o - | FileCheck %s +// PR 4349 + +union reg +{ + unsigned char b[2][2]; + unsigned short w[2]; + unsigned int d; +}; +struct cpu +{ + union reg pc; +}; +extern struct cpu cpu; +struct svar +{ + void *ptr; +}; +// CHECK: @svars1 = global [1 x %struct.svar] [%struct.svar { i8* bitcast (%struct.cpu* @cpu to i8*) }] +struct svar svars1[] = +{ + { &((cpu.pc).w[0]) } +}; +// CHECK: @svars2 = global [1 x %struct.svar] [%struct.svar { i8* getelementptr (i8* bitcast (%struct.cpu* @cpu to i8*), i64 1) }] +struct svar svars2[] = +{ + { &((cpu.pc).b[0][1]) } +}; +// CHECK: @svars3 = global [1 x %struct.svar] [%struct.svar { i8* getelementptr (i8* bitcast (%struct.cpu* @cpu to i8*), i64 2) }] +struct svar svars3[] = +{ + { &((cpu.pc).w[1]) } +}; +// CHECK: @svars4 = global [1 x %struct.svar] [%struct.svar { i8* getelementptr (i8* bitcast (%struct.cpu* @cpu to i8*), i64 3) }] +struct svar svars4[] = +{ + { &((cpu.pc).b[1][1]) } +}; diff --git a/test/CodeGen/pr5406.c b/test/CodeGen/pr5406.c new file mode 100644 index 000000000000..da74d6b64fe5 --- /dev/null +++ b/test/CodeGen/pr5406.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -emit-llvm -triple arm-apple-darwin -o - | FileCheck %s +// PR 5406 + +typedef struct { char x[3]; } A0; +void foo (int i, ...); + + +// CHECK: call arm_aapcscc void (i32, ...)* @foo(i32 1, [1 x i32] {{.*}}) +int main (void) +{ + A0 a3; + a3.x[0] = 0; + a3.x[0] = 0; + a3.x[2] = 26; + foo (1, a3 ); + return 0; +} diff --git a/test/CodeGen/pragma-weak.c b/test/CodeGen/pragma-weak.c index 1de60e106a95..7ad2b77d8e7e 100644 --- a/test/CodeGen/pragma-weak.c +++ b/test/CodeGen/pragma-weak.c @@ -136,7 +136,7 @@ void __both3(void) {} void __a1(void) __attribute((noinline)); #pragma weak a1 = __a1 void __a1(void) {} -// CHECK: define void @__a1() +// CHECK: define void @__a1() {{.*}} noinline // attributes introduced BEFORE a combination of #pragma weak and alias() // hold... @@ -144,13 +144,20 @@ void __a3(void) __attribute((noinline)); #pragma weak a3 = __a3 void a3(void) __attribute((alias("__a3"))); void __a3(void) {} -// CHECK: define void @__a3() +// CHECK: define void @__a3() {{.*}} noinline #pragma weak xxx = __xxx __attribute((pure,noinline,const,fastcall)) void __xxx(void) { } -// CHECK: void @__xxx() +// CHECK: void @__xxx() {{.*}} noinline -/// TODO: stuff that still doesn't work +///////////// PR10878: Make sure we can call a weak alias +void SHA512Pad(void *context) {} +#pragma weak SHA384Pad = SHA512Pad +void PR10878() { SHA384Pad(0); } +// CHECK: call void @SHA384Pad(i8* null) + + +///////////// TODO: stuff that still doesn't work // due to the fact that disparate TopLevelDecls cannot affect each other // (due to clang's Parser and ASTConsumer behavior, and quite reasonable) diff --git a/test/CodeGen/redef-ext-inline.c b/test/CodeGen/redef-ext-inline.c new file mode 100644 index 000000000000..b8e2f365ff41 --- /dev/null +++ b/test/CodeGen/redef-ext-inline.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -std=gnu89 +// rdar://7208839 + +extern inline int f1 (void) {return 1;} +int f3 (void) {return f1();} +int f1 (void) {return 0;} diff --git a/test/CodeGen/sret.c b/test/CodeGen/sret.c new file mode 100644 index 000000000000..ed1f9a44ef14 --- /dev/null +++ b/test/CodeGen/sret.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 %s -emit-llvm -O0 -o - | grep sret | count 5 + +struct abc { + long a; + long b; + long c; +}; + +struct abc foo1(void); +struct abc foo2(); + +void bar() { + struct abc dummy1 = foo1(); + struct abc dummy2 = foo2(); +} diff --git a/test/CodeGen/sret2.c b/test/CodeGen/sret2.c new file mode 100644 index 000000000000..c96ce4d5c4e0 --- /dev/null +++ b/test/CodeGen/sret2.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -emit-llvm -O0 -o - | grep sret | count 2 + +struct abc { + long a; + long b; + long c; +}; + +struct abc foo2(){} diff --git a/test/CodeGen/sse-builtins.c b/test/CodeGen/sse-builtins.c new file mode 100644 index 000000000000..64ee4c970fe0 --- /dev/null +++ b/test/CodeGen/sse-builtins.c @@ -0,0 +1,104 @@ +// RUN: %clang_cc1 -ffreestanding -triple i386-apple-darwin9 -target-cpu pentium4 -target-feature +sse4.1 -g -emit-llvm %s -o - | FileCheck %s + +#include <emmintrin.h> + +__m128 test_loadl_pi(__m128 x, void* y) { + // CHECK: define {{.*}} @test_loadl_pi + // CHECK: load <2 x float>* {{.*}}, align 1{{$}} + // CHECK: shufflevector {{.*}} <4 x i32> <i32 0, i32 1 + // CHECK: shufflevector {{.*}} <4 x i32> <i32 4, i32 5, i32 2, i32 3> + return _mm_loadl_pi(x,y); +} + +__m128 test_loadh_pi(__m128 x, void* y) { + // CHECK: define {{.*}} @test_loadh_pi + // CHECK: load <2 x float>* {{.*}}, align 1{{$}} + // CHECK: shufflevector {{.*}} <4 x i32> <i32 0, i32 1 + // CHECK: shufflevector {{.*}} <4 x i32> <i32 0, i32 1, i32 4, i32 5> + return _mm_loadh_pi(x,y); +} + +__m128 test_load_ss(void* y) { + // CHECK: define {{.*}} @test_load_ss + // CHECK: load float* {{.*}}, align 1{{$}} + return _mm_load_ss(y); +} + +__m128 test_load1_ps(void* y) { + // CHECK: define {{.*}} @test_load1_ps + // CHECK: load float* {{.*}}, align 1{{$}} + return _mm_load1_ps(y); +} + +void test_store_ss(__m128 x, void* y) { + // CHECK: define void @test_store_ss + // CHECK: store {{.*}} float* {{.*}}, align 1, + _mm_store_ss(y, x); +} + +__m128d test_load1_pd(__m128 x, void* y) { + // CHECK: define {{.*}} @test_load1_pd + // CHECK: load double* {{.*}}, align 1{{$}} + return _mm_load1_pd(y); +} + +__m128d test_loadr_pd(__m128 x, void* y) { + // CHECK: define {{.*}} @test_loadr_pd + // CHECK: load <2 x double>* {{.*}}, align 16{{$}} + return _mm_loadr_pd(y); +} + +__m128d test_load_sd(void* y) { + // CHECK: define {{.*}} @test_load_sd + // CHECK: load double* {{.*}}, align 1{{$}} + return _mm_load_sd(y); +} + +__m128d test_loadh_pd(__m128d x, void* y) { + // CHECK: define {{.*}} @test_loadh_pd + // CHECK: load double* {{.*}}, align 1{{$}} + return _mm_loadh_pd(x, y); +} + +__m128d test_loadl_pd(__m128d x, void* y) { + // CHECK: define {{.*}} @test_loadl_pd + // CHECK: load double* {{.*}}, align 1{{$}} + return _mm_loadl_pd(x, y); +} + +void test_store_sd(__m128d x, void* y) { + // CHECK: define void @test_store_sd + // CHECK: store {{.*}} double* {{.*}}, align 1{{$}} + _mm_store_sd(y, x); +} + +void test_store1_pd(__m128d x, void* y) { + // CHECK: define void @test_store1_pd + // CHECK: store {{.*}} double* {{.*}}, align 1{{$}} + // CHECK: store {{.*}} double* {{.*}}, align 1{{$}} + _mm_store1_pd(y, x); +} + +void test_storer_pd(__m128d x, void* y) { + // CHECK: define void @test_storer_pd + // CHECK: store {{.*}} <2 x double>* {{.*}}, align 16{{$}} + _mm_storer_pd(y, x); +} + +void test_storeh_pd(__m128d x, void* y) { + // CHECK: define void @test_storeh_pd + // CHECK: store {{.*}} double* {{.*}}, align 1{{$}} + _mm_storeh_pd(y, x); +} + +void test_storel_pd(__m128d x, void* y) { + // CHECK: define void @test_storel_pd + // CHECK: store {{.*}} double* {{.*}}, align 1{{$}} + _mm_storel_pd(y, x); +} + +__m128i test_loadl_epi64(void* y) { + // CHECK: define {{.*}} @test_loadl_epi64 + // CHECK: load i64* {{.*}}, align 1{{$}} + return _mm_loadl_epi64(y); +} diff --git a/test/CodeGen/stdcall-fastcall.c b/test/CodeGen/stdcall-fastcall.c index 6f3b00328771..3de7b6727bc2 100644 --- a/test/CodeGen/stdcall-fastcall.c +++ b/test/CodeGen/stdcall-fastcall.c @@ -46,5 +46,5 @@ int main(void) { void __attribute((stdcall)) f7(foo) int foo; {} void f8(void) { f7(0); - // CHECK: call x86_stdcallcc void (...)* bitcast + // CHECK: call x86_stdcallcc void @f7(i32 0) } diff --git a/test/CodeGen/string-literal-short-wstring.c b/test/CodeGen/string-literal-short-wstring.c index ce2990492ad7..770c3d426871 100644 --- a/test/CodeGen/string-literal-short-wstring.c +++ b/test/CodeGen/string-literal-short-wstring.c @@ -3,7 +3,7 @@ int main() { // This should convert to utf8. - // CHECK: internal unnamed_addr constant [10 x i8] c"\E1\84\A0\C8\A0\F4\82\80\B0\00", align 1 + // CHECK: private unnamed_addr constant [10 x i8] c"\E1\84\A0\C8\A0\F4\82\80\B0\00", align 1 char b[10] = "\u1120\u0220\U00102030"; // CHECK: private unnamed_addr constant [6 x i8] c"A\00B\00\00\00" diff --git a/test/CodeGen/string-literal.c b/test/CodeGen/string-literal.c index cc6c0943d95a..fa8f28a766c4 100644 --- a/test/CodeGen/string-literal.c +++ b/test/CodeGen/string-literal.c @@ -1,16 +1,80 @@ -// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=C %s +// RUN: %clang_cc1 -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=C %s +// RUN: %clang_cc1 -x c++ -std=c++11 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=CPP0X %s + +#include <stddef.h> int main() { - // CHECK: internal unnamed_addr constant [10 x i8] c"abc\00\00\00\00\00\00\00", align 1 + // CHECK-C: private unnamed_addr constant [10 x i8] c"abc\00\00\00\00\00\00\00", align 1 + // CHECK-CPP0X: private unnamed_addr constant [10 x i8] c"abc\00\00\00\00\00\00\00", align 1 char a[10] = "abc"; // This should convert to utf8. - // CHECK: internal unnamed_addr constant [10 x i8] c"\E1\84\A0\C8\A0\F4\82\80\B0\00", align 1 + // CHECK-C: private unnamed_addr constant [10 x i8] c"\E1\84\A0\C8\A0\F4\82\80\B0\00", align 1 + // CHECK-CPP0X: private unnamed_addr constant [10 x i8] c"\E1\84\A0\C8\A0\F4\82\80\B0\00", align 1 char b[10] = "\u1120\u0220\U00102030"; - // CHECK: private unnamed_addr constant [12 x i8] c"A\00\00\00B\00\00\00\00\00\00\00", align 1 - void *foo = L"AB"; + // CHECK-C: private unnamed_addr constant [12 x i8] c"A\00\00\00B\00\00\00\00\00\00\00", align 4 + // CHECK-CPP0X: private unnamed_addr constant [12 x i8] c"A\00\00\00B\00\00\00\00\00\00\00", align 4 + const wchar_t *foo = L"AB"; + + // CHECK-C: private unnamed_addr constant [12 x i8] c"4\12\00\00\0B\F0\10\00\00\00\00\00", align 4 + // CHECK-CPP0X: private unnamed_addr constant [12 x i8] c"4\12\00\00\0B\F0\10\00\00\00\00\00", align 4 + const wchar_t *bar = L"\u1234\U0010F00B"; + + // CHECK-C: private unnamed_addr constant [12 x i8] c"4\12\00\00\0C\F0\10\00\00\00\00\00", align 4 + // CHECK-CPP0X: private unnamed_addr constant [12 x i8] c"4\12\00\00\0C\F0\10\00\00\00\00\00", align 4 + const wchar_t *baz = L"\u1234" "\U0010F00C"; + +#if __cplusplus >= 201103L + // CHECK-CPP0X: private unnamed_addr constant [12 x i8] c"C\00\00\00D\00\00\00\00\00\00\00", align 4 + const char32_t *c = U"CD"; + + // CHECK-CPP0X: private unnamed_addr constant [12 x i8] c"5\12\00\00\0C\F0\10\00\00\00\00\00", align 4 + const char32_t *d = U"\u1235\U0010F00C"; + + // CHECK-CPP0X: private unnamed_addr constant [12 x i8] c"5\12\00\00\0B\F0\10\00\00\00\00\00", align 4 + const char32_t *o = "\u1235" U"\U0010F00B"; + + // CHECK-CPP0X: private unnamed_addr constant [6 x i8] c"E\00F\00\00\00", align 2 + const char16_t *e = u"EF"; + + // This should convert to utf16. + // CHECK-CPP0X: private unnamed_addr constant [10 x i8] c" \11 \02\C8\DB0\DC\00\00", align 2 + const char16_t *f = u"\u1120\u0220\U00102030"; + + // This should convert to utf16. + // CHECK-CPP0X: private unnamed_addr constant [10 x i8] c" \11 \03\C8\DB0\DC\00\00", align 2 + const char16_t *p = u"\u1120\u0320" "\U00102030"; + + // CHECK-CPP0X: private unnamed_addr constant [4 x i8] c"def\00", align 1 + const char *g = u8"def"; + + // CHECK-CPP0X: private unnamed_addr constant [4 x i8] c"ghi\00", align 1 + const char *h = R"foo(ghi)foo"; + + // CHECK-CPP0X: private unnamed_addr constant [4 x i8] c"jkl\00", align 1 + const char *i = u8R"bar(jkl)bar"; + + // CHECK-CPP0X: private unnamed_addr constant [6 x i8] c"G\00H\00\00\00", align 2 + const char16_t *j = uR"foo(GH)foo"; + + // CHECK-CPP0X: private unnamed_addr constant [12 x i8] c"I\00\00\00J\00\00\00\00\00\00\00", align 4 + const char32_t *k = UR"bar(IJ)bar"; + + // CHECK-CPP0X: private unnamed_addr constant [12 x i8] c"K\00\00\00L\00\00\00\00\00\00\00", align 4 + const wchar_t *l = LR"bar(KL)bar"; + + // CHECK-CPP0X: private unnamed_addr constant [9 x i8] c"abc\5Cndef\00", align 1 + const char *m = R"(abc\ndef)"; + + // CHECK-CPP0X: private unnamed_addr constant [8 x i8] c"abc\0Adef\00", align 1 + const char *n = R"(abc +def)"; + + // CHECK-CPP0X: private unnamed_addr constant [11 x i8] c"abc\0Adefghi\00", align 1 + const char *q = R"(abc +def)" "ghi"; - // CHECK: private unnamed_addr constant [12 x i8] c"4\12\00\00\0B\F0\10\00\00\00\00\00", align 1 - void *bar = L"\u1234\U0010F00B"; +#endif } diff --git a/test/CodeGen/struct-init.c b/test/CodeGen/struct-init.c index 8a605c1b67c8..6247729c17b7 100644 --- a/test/CodeGen/struct-init.c +++ b/test/CodeGen/struct-init.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -S -triple armv7-apple-darwin %s -emit-llvm -o - | FileCheck %s typedef struct _zend_ini_entry zend_ini_entry; struct _zend_ini_entry { @@ -23,17 +23,15 @@ typedef __attribute__(( ext_vector_type(2) )) unsigned int uint2; typedef __attribute__(( __vector_size__(8) )) unsigned int __neon_uint32x2_t; // rdar://8183908 -typedef struct __simd64_uint32_t { - __neon_uint32x2_t val; -} uint32x2_t; +typedef unsigned int uint32_t; +typedef __attribute__((neon_vector_type(2))) uint32_t uint32x2_t; void foo() { const uint32x2_t signBit = { (uint2) 0x80000000 }; } -// CHECK: %struct.fp_struct_foo = type { void (i32)* } +// CHECK: %struct.fp_struct_foo = type { void ([1 x i32])* } struct fp_struct_bar { int a; }; struct fp_struct_foo { void (*FP)(struct fp_struct_bar); } G; - diff --git a/test/CodeGen/struct-matching-constraint.c b/test/CodeGen/struct-matching-constraint.c new file mode 100644 index 000000000000..40c444f2b40d --- /dev/null +++ b/test/CodeGen/struct-matching-constraint.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -S -emit-llvm -triple armv7a-apple-darwin %s -o /dev/null +typedef unsigned short uint16_t; +typedef __attribute__((neon_vector_type(8))) uint16_t uint16x8_t; + +void b(uint16x8_t sat, uint16x8_t luma) +{ + __asm__("vmov.16 %1, %0 \n\t" + "vtrn.16 %0, %1 \n\t" + :"=w"(luma), "=w"(sat) + :"0"(luma) + ); + +} diff --git a/test/CodeGen/struct-passing.c b/test/CodeGen/struct-passing.c index 8e5c0adcfc10..efb00efd53ab 100644 --- a/test/CodeGen/struct-passing.c +++ b/test/CodeGen/struct-passing.c @@ -16,8 +16,8 @@ void __attribute__((pure)) f5(T1 a); void *ps[] = { f0, f1, f2, f3, f4, f5 }; -// CHECK: declare i32 @f0() readnone -// CHECK: declare i32 @f1() readonly +// CHECK: declare i32 @f0() nounwind readnone +// CHECK: declare i32 @f1() nounwind readonly // CHECK: declare void @f2({{.*}} sret) // CHECK: declare void @f3({{.*}} sret) // CHECK: declare void @f4({{.*}} byval align 4) diff --git a/test/CodeGen/target-data.c b/test/CodeGen/target-data.c index 8139a4efc599..fc8f758afa59 100644 --- a/test/CodeGen/target-data.c +++ b/test/CodeGen/target-data.c @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -triple i686-unknown-unknown -emit-llvm -o %t %s -// RUN: grep 'target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"' %t +// RUN: grep 'target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"' %t // RUN: %clang_cc1 -triple i686-apple-darwin9 -emit-llvm -o %t %s -// RUN: grep 'target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"' %t +// RUN: grep 'target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128"' %t // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o %t %s -// RUN: grep 'target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"' %t +// RUN: grep 'target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"' %t diff --git a/test/CodeGen/unaligned-memcpy.c b/test/CodeGen/unaligned-memcpy.c new file mode 100644 index 000000000000..0373b5617e05 --- /dev/null +++ b/test/CodeGen/unaligned-memcpy.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - + +void bork() { + char Qux[33] = {0}; +} diff --git a/test/CodeGen/union-align.c b/test/CodeGen/union-align.c new file mode 100644 index 000000000000..89a9456e609d --- /dev/null +++ b/test/CodeGen/union-align.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | grep load | grep "4 x float" | not grep "align 4" +// RUN: %clang_cc1 -emit-llvm %s -o - | grep load | grep "4 x float" | grep "align 16" +// PR3432 +// rdar://6536377 + +typedef float __m128 __attribute__ ((__vector_size__ (16))); + +typedef union +{ + int i[4]; + float f[4]; + __m128 v; +} u_t; + +__m128 t(u_t *a) { + return a->v; +} diff --git a/test/CodeGen/vla-2.c b/test/CodeGen/vla-2.c new file mode 100644 index 000000000000..0a74907f7b2d --- /dev/null +++ b/test/CodeGen/vla-2.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -std=gnu99 %s -emit-llvm -o - | grep ".*alloca.*align 16" + +extern void bar(int[]); + +void foo(int a) +{ + int var[a] __attribute__((__aligned__(16))); + bar(var); + return; +} diff --git a/test/CodeGen/vla-3.c b/test/CodeGen/vla-3.c new file mode 100644 index 000000000000..4927b464231f --- /dev/null +++ b/test/CodeGen/vla-3.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -std=gnu99 %s -emit-llvm -o - | grep ".*alloca.*align 16" + +void adr(char *); + +void vlaalign(int size) +{ + char __attribute__((aligned(16))) tmp[size+32]; + char tmp2[size+16]; + + adr(tmp); +} diff --git a/test/CodeGen/volatile-1.c b/test/CodeGen/volatile-1.c index 7c7a822e880c..65511593d32a 100644 --- a/test/CodeGen/volatile-1.c +++ b/test/CodeGen/volatile-1.c @@ -24,182 +24,182 @@ int printf(const char *, ...); // CHECK: define void @test() void test() { - // CHECK: volatile load [[INT]]* @i + // CHECK: load volatile [[INT]]* @i i; - // CHECK-NEXT: volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) - // CHECK-NEXT: volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) // CHECK-NEXT: sitofp [[INT]] (float)(ci); - // CHECK-NEXT: volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) - // CHECK-NEXT: volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) (void)ci; // CHECK-NEXT: bitcast // CHECK-NEXT: memcpy (void)a; - // CHECK-NEXT: [[R:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) - // CHECK-NEXT: [[I:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) - // CHECK-NEXT: volatile store [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) - // CHECK-NEXT: volatile store [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: [[R:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: store volatile [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: store volatile [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) (void)(ci=ci); - // CHECK-NEXT: [[T:%.*]] = volatile load [[INT]]* @j - // CHECK-NEXT: volatile store [[INT]] [[T]], [[INT]]* @i + // CHECK-NEXT: [[T:%.*]] = load volatile [[INT]]* @j + // CHECK-NEXT: store volatile [[INT]] [[T]], [[INT]]* @i (void)(i=j); - // CHECK-NEXT: [[R1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) - // CHECK-NEXT: [[I1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) - // CHECK-NEXT: [[R2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) - // CHECK-NEXT: [[I2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: [[R1:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I1:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: [[R2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) // Not sure why they're ordered this way. // CHECK-NEXT: [[R:%.*]] = add [[INT]] [[R2]], [[R1]] // CHECK-NEXT: [[I:%.*]] = add [[INT]] [[I2]], [[I1]] - // CHECK-NEXT: volatile store [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) - // CHECK-NEXT: volatile store [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: store volatile [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: store volatile [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) ci+=ci; - // CHECK-NEXT: [[R1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) - // CHECK-NEXT: [[I1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) - // CHECK-NEXT: [[R2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) - // CHECK-NEXT: [[I2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: [[R1:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I1:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: [[R2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) // CHECK-NEXT: [[R:%.*]] = add [[INT]] [[R2]], [[R1]] // CHECK-NEXT: [[I:%.*]] = add [[INT]] [[I2]], [[I1]] - // CHECK-NEXT: volatile store [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) - // CHECK-NEXT: volatile store [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) - // CHECK-NEXT: [[R2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) - // CHECK-NEXT: [[I2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: store volatile [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: store volatile [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: [[R2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) + // CHECK-NEXT: [[I2:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) // These additions can be elided // CHECK-NEXT: add [[INT]] [[R]], [[R2]] // CHECK-NEXT: add [[INT]] [[I]], [[I2]] (ci += ci) + ci; // CHECK-NEXT: call void asm asm("nop"); - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile // CHECK-NEXT: add nsw [[INT]] - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile load + // CHECK-NEXT: store volatile + // CHECK-NEXT: load volatile // CHECK-NEXT: add nsw [[INT]] (i += j) + k; // CHECK-NEXT: call void asm asm("nop"); - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile // CHECK-NEXT: add nsw [[INT]] - // CHECK-NEXT: volatile store + // CHECK-NEXT: store volatile // CHECK-NEXT: add nsw [[INT]] (i += j) + 1; // CHECK-NEXT: call void asm asm("nop"); - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile // CHECK-NEXT: add [[INT]] // CHECK-NEXT: add [[INT]] ci+ci; - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile __real i; - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile +ci; // CHECK-NEXT: call void asm asm("nop"); - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile (void)(i=i); - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile // CHECK-NEXT: sitofp (float)(i=i); - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile (void)i; - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile i=i; - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: store volatile i=i=i; #ifndef __cplusplus - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile (void)__builtin_choose_expr(0, i=i, j=j); #endif - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile // CHECK-NEXT: icmp // CHECK-NEXT: br i1 - // CHECK: volatile load - // CHECK-NEXT: volatile store + // CHECK: load volatile + // CHECK-NEXT: store volatile // CHECK-NEXT: br label - // CHECK: volatile load - // CHECK-NEXT: volatile store + // CHECK: load volatile + // CHECK-NEXT: store volatile // CHECK-NEXT: br label k ? (i=i) : (j=j); // CHECK: phi - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile (void)(i,(i=i)); - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: load volatile i=i,i; - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile (i=j,k=j); - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: load volatile (i=j,k); - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile (i,j); - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile // CHECK-NEXT: trunc - // CHECK-NEXT: volatile store + // CHECK-NEXT: store volatile // CHECK-NEXT: sext - // CHECK-NEXT: volatile store + // CHECK-NEXT: store volatile i=c=k; - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile // CHECK-NEXT: add nsw [[INT]] - // CHECK-NEXT: volatile store + // CHECK-NEXT: store volatile i+=k; - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile ci; #ifndef __cplusplus - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile (int)ci; - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile // CHECK-NEXT: icmp ne // CHECK-NEXT: icmp ne // CHECK-NEXT: or i1 (_Bool)ci; #endif - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: store volatile ci=ci; - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: store volatile ci=ci=ci; - // CHECK-NEXT: [[T:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) - // CHECK-NEXT: volatile store [[INT]] [[T]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) - // CHECK-NEXT: volatile store [[INT]] [[T]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: [[T:%.*]] = load volatile [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: store volatile [[INT]] [[T]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) + // CHECK-NEXT: store volatile [[INT]] [[T]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) __imag ci = __imag ci = __imag ci; - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile __real (i = j); - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile __imag i; // ============================================================ @@ -224,71 +224,71 @@ void test() { // Not a use. gcc got this wrong in 4.2 and omitted the side effects // entirely, but it is fixed in 4.4.0. - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile __imag (i = j); #ifndef __cplusplus // A use of the real part - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: store volatile // CHECK-NEXT: sitofp (float)(ci=ci); // Not a use, bug? gcc treats this as not a use, that's probably a bug due to // tree folding ignoring volatile. - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: store volatile (int)(ci=ci); #endif // A use. - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile // CHECK-NEXT: sitofp (float)(i=i); // A use. gcc treats this as not a use, that's probably a bug due to tree // folding ignoring volatile. - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile (int)(i=i); // A use. - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile // CHECK-NEXT: sub -(i=j); // A use. gcc treats this a not a use, that's probably a bug due to tree // folding ignoring volatile. - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile +(i=k); // A use. gcc treats this a not a use, that's probably a bug due to tree // folding ignoring volatile. - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: store volatile __real (ci=ci); // A use. - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile // CHECK-NEXT: add i + 0; // A use. - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store - // CHECK-NEXT: volatile load + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile + // CHECK-NEXT: load volatile // CHECK-NEXT: add (i=j) + i; // A use. gcc treats this as not a use, that's probably a bug due to tree // folding ignoring volatile. - // CHECK-NEXT: volatile load - // CHECK-NEXT: volatile store + // CHECK-NEXT: load volatile + // CHECK-NEXT: store volatile // CHECK-NEXT: add (i=j) + 0; diff --git a/test/CodeGen/volatile-2.c b/test/CodeGen/volatile-2.c index 490b7d776b9f..3d342de69005 100644 --- a/test/CodeGen/volatile-2.c +++ b/test/CodeGen/volatile-2.c @@ -3,8 +3,8 @@ void test0() { // CHECK: define void @test0() // CHECK: [[F:%.*]] = alloca float - // CHECK-NEXT: [[REAL:%.*]] = volatile load float* getelementptr inbounds ({ float, float }* @test0_v, i32 0, i32 0) - // CHECK-NEXT: volatile load float* getelementptr inbounds ({{.*}} @test0_v, i32 0, i32 1) + // CHECK-NEXT: [[REAL:%.*]] = load volatile float* getelementptr inbounds ({ float, float }* @test0_v, i32 0, i32 0) + // CHECK-NEXT: load volatile float* getelementptr inbounds ({{.*}} @test0_v, i32 0, i32 1) // CHECK-NEXT: store float [[REAL]], float* [[F]], align 4 // CHECK-NEXT: ret void extern volatile _Complex float test0_v; @@ -13,10 +13,10 @@ void test0() { void test1() { // CHECK: define void @test1() - // CHECK: [[REAL:%.*]] = volatile load float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 0) - // CHECK-NEXT: [[IMAG:%.*]] = volatile load float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 1) - // CHECK-NEXT: volatile store float [[REAL]], float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 0) - // CHECK-NEXT: volatile store float [[IMAG]], float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 1) + // CHECK: [[REAL:%.*]] = load volatile float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 0) + // CHECK-NEXT: [[IMAG:%.*]] = load volatile float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 1) + // CHECK-NEXT: store volatile float [[REAL]], float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 0) + // CHECK-NEXT: store volatile float [[IMAG]], float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 1) // CHECK-NEXT: ret void extern volatile _Complex float test1_v; test1_v = test1_v; diff --git a/test/CodeGen/wchar-const.c b/test/CodeGen/wchar-const.c new file mode 100644 index 000000000000..b672b15360a2 --- /dev/null +++ b/test/CodeGen/wchar-const.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -triple i386-pc-win32 | FileCheck %s --check-prefix=WIN +// RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-apple-darwin | FileCheck %s --check-prefix=DAR +// This should pass for any endianness combination of host and target. + +// This bit is taken from Sema/wchar.c so we can avoid the wchar.h include. +typedef __WCHAR_TYPE__ wchar_t; +#if defined(_WIN32) || defined(_M_IX86) || defined(__CYGWIN__) \ + || defined(_M_X64) || defined(SHORT_WCHAR) + #define WCHAR_T_TYPE unsigned short +#elif defined(__sun) || defined(__AuroraUX__) + #define WCHAR_T_TYPE long +#else /* Solaris or AuroraUX. */ + #define WCHAR_T_TYPE int +#endif + + +// CHECK-DAR: private unnamed_addr constant [72 x i8] c" +// CHECK-WIN: private unnamed_addr constant [36 x i8] c" +extern void foo(const wchar_t* p); +int main (int argc, const char * argv[]) +{ + foo(L"This is some text"); + return 0; +} diff --git a/test/CodeGen/weak_constant.c b/test/CodeGen/weak_constant.c new file mode 100644 index 000000000000..726d2ef122e1 --- /dev/null +++ b/test/CodeGen/weak_constant.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -w -emit-llvm %s -O1 -o - | FileCheck %s +// Check for bug compatibility with gcc. + +const int x __attribute((weak)) = 123; + +int* f(void) { + return &x; +} + +int g(void) { + // CHECK: ret i32 123 + return *f(); +} diff --git a/test/CodeGen/x86_32-arguments-darwin.c b/test/CodeGen/x86_32-arguments-darwin.c index 731d4f613f26..7727c43f6e8d 100644 --- a/test/CodeGen/x86_32-arguments-darwin.c +++ b/test/CodeGen/x86_32-arguments-darwin.c @@ -71,7 +71,7 @@ struct s10 { // Small vectors and 1 x {i64,double} are returned in registers // CHECK: i32 @f11() -// CHECK: void @f12(<2 x i32>* sret %agg.result) +// CHECK: void @f12(<2 x i32>* noalias sret %agg.result) // CHECK: i64 @f13() // CHECK: i64 @f14() // CHECK: <2 x i64> @f15() @@ -93,11 +93,11 @@ T16 f16(void) { while (1) {} } // 128-bits). // CHECK: i32 @f17() -// CHECK: void @f18(%{{.*}}* sret %agg.result) -// CHECK: void @f19(%{{.*}}* sret %agg.result) -// CHECK: void @f20(%{{.*}}* sret %agg.result) -// CHECK: void @f21(%{{.*}}* sret %agg.result) -// CHECK: void @f22(%{{.*}}* sret %agg.result) +// CHECK: void @f18(%{{.*}}* noalias sret %agg.result) +// CHECK: void @f19(%{{.*}}* noalias sret %agg.result) +// CHECK: void @f20(%{{.*}}* noalias sret %agg.result) +// CHECK: void @f21(%{{.*}}* noalias sret %agg.result) +// CHECK: void @f22(%{{.*}}* noalias sret %agg.result) struct { T11 a; } f17(void) { while (1) {} } struct { T12 a; } f18(void) { while (1) {} } struct { T13 a; } f19(void) { while (1) {} } @@ -116,11 +116,11 @@ struct { struct {} a; struct { float a[1]; } b; } f25(void) { while (1) {} } // Small structures are handled recursively // CHECK: i32 @f26() -// CHECK: void @f27(%struct.s27* sret %agg.result) +// CHECK: void @f27(%struct.s27* noalias sret %agg.result) struct s26 { struct { char a, b; } a; struct { char a, b; } b; } f26(void) { while (1) {} } struct s27 { struct { char a, b, c; } a; struct { char a; } b; } f27(void) { while (1) {} } -// CHECK: void @f28(%struct.s28* sret %agg.result) +// CHECK: void @f28(%struct.s28* noalias sret %agg.result) struct s28 { int a; int b[]; } f28(void) { while (1) {} } // CHECK: define i16 @f29() @@ -150,7 +150,7 @@ struct s36 { struct { int : 0; } a[2][10]; char b; char c; } f36(void) { while ( // CHECK: define float @f37() struct s37 { float c[1][1]; } f37(void) { while (1) {} } -// CHECK: define void @f38(%struct.s38* sret %agg.result) +// CHECK: define void @f38(%struct.s38* noalias sret %agg.result) struct s38 { char a[3]; short b; } f38(void) { while (1) {} } // CHECK: define void @f39(%struct.s39* byval align 16 %x) diff --git a/test/CodeGen/x86_64-arguments.c b/test/CodeGen/x86_64-arguments.c index 221c7d38a73d..8571ac965552 100644 --- a/test/CodeGen/x86_64-arguments.c +++ b/test/CodeGen/x86_64-arguments.c @@ -42,7 +42,7 @@ void f7(e7 a0) { // Test merging/passing of upper eightbyte with X87 class. // -// CHECK: define void @f8_1(%union.u8* sret %agg.result) +// CHECK: define void @f8_1(%union.u8* noalias sret %agg.result) // CHECK: define void @f8_2(%union.u8* byval align 16 %a0) union u8 { long double a; @@ -58,7 +58,7 @@ struct s9 { int a; int b; int : 0; } f9(void) { while (1) {} } struct s10 { int a; int b; int : 0; }; void f10(struct s10 a0) {} -// CHECK: define void @f11(%union.anon* sret %agg.result) +// CHECK: define void @f11(%union.anon* noalias sret %agg.result) union { long double a; float b; } f11() { while (1) {} } // CHECK: define i32 @f12_0() @@ -69,7 +69,7 @@ void f12_1(struct s12 a0) {} // Check that sret parameter is accounted for when checking available integer // registers. -// CHECK: define void @f13(%struct.s13_0* sret %agg.result, i32 %a, i32 %b, i32 %c, i32 %d, {{.*}}* byval align 8 %e, i32 %f) +// CHECK: define void @f13(%struct.s13_0* noalias sret %agg.result, i32 %a, i32 %b, i32 %c, i32 %d, {{.*}}* byval align 8 %e, i32 %f) struct s13_0 { long long f0[3]; }; struct s13_1 { long long f0[2]; }; |