From b025734047dd8b630c34cea53b371361adb2a65a Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Tue, 26 Jul 2011 21:42:32 +0000 Subject: [PATCH] Migrate: CodeGen/2003-08-21-WideString.c CodeGen/2003-10-02-UnionLValueError.c CodeGen/2004-02-20-Builtins.c CodeGen/2008-01-04-WideBitfield.c CodeGen/2002-07-14-MiscTests3.c CodeGen/2005-04-09-ComplexOps.c CodeGen/2008-12-23-AsmIntPointerTie.c CodeGen/2005-07-20-SqrtNoErrno.c CodeGen/2005-01-02-VAArgError-ICE.c CodeGen/2004-06-17-UnorderedCompares.c CodeGen/2002-06-25-FWriteInterfaceFailure.c CodeGen/2002-02-18-64bitConstant.c CodeGen/2002-05-24-Alloca.c CodeGen/2006-01-13-Includes.c CodeGen/2007-09-27-ComplexIntCompare.c CodeGen/2004-02-13-IllegalVararg.c CodeGen/2007-09-12-PragmaPack.c CodeGen/2002-08-02-UnionTest.c from test/FrontendC with changes to remove header file includes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136153 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/2002-02-18-64bitConstant.c | 10 + test/CodeGen/2002-05-24-Alloca.c | 11 ++ .../2002-06-25-FWriteInterfaceFailure.c | 9 + test/CodeGen/2002-07-14-MiscTests3.c | 182 ++++++++++++++++++ test/CodeGen/2002-08-02-UnionTest.c | 19 ++ test/CodeGen/2003-08-21-WideString.c | 16 ++ test/CodeGen/2003-10-02-UnionLValueError.c | 11 ++ test/CodeGen/2004-02-13-IllegalVararg.c | 9 + test/CodeGen/2004-02-20-Builtins.c | 5 + test/CodeGen/2004-06-17-UnorderedCompares.c | 19 ++ test/CodeGen/2005-01-02-VAArgError-ICE.c | 9 + test/CodeGen/2005-04-09-ComplexOps.c | 8 + test/CodeGen/2005-07-20-SqrtNoErrno.c | 10 + test/CodeGen/2006-01-13-Includes.c | 10 + test/CodeGen/2007-09-12-PragmaPack.c | 32 +++ test/CodeGen/2007-09-27-ComplexIntCompare.c | 15 ++ test/CodeGen/2008-01-04-WideBitfield.c | 12 ++ test/CodeGen/2008-12-23-AsmIntPointerTie.c | 8 + 18 files changed, 395 insertions(+) create mode 100644 test/CodeGen/2002-02-18-64bitConstant.c create mode 100644 test/CodeGen/2002-05-24-Alloca.c create mode 100644 test/CodeGen/2002-06-25-FWriteInterfaceFailure.c create mode 100644 test/CodeGen/2002-07-14-MiscTests3.c create mode 100644 test/CodeGen/2002-08-02-UnionTest.c create mode 100644 test/CodeGen/2003-08-21-WideString.c create mode 100644 test/CodeGen/2003-10-02-UnionLValueError.c create mode 100644 test/CodeGen/2004-02-13-IllegalVararg.c create mode 100644 test/CodeGen/2004-02-20-Builtins.c create mode 100644 test/CodeGen/2004-06-17-UnorderedCompares.c create mode 100644 test/CodeGen/2005-01-02-VAArgError-ICE.c create mode 100644 test/CodeGen/2005-04-09-ComplexOps.c create mode 100644 test/CodeGen/2005-07-20-SqrtNoErrno.c create mode 100644 test/CodeGen/2006-01-13-Includes.c create mode 100644 test/CodeGen/2007-09-12-PragmaPack.c create mode 100644 test/CodeGen/2007-09-27-ComplexIntCompare.c create mode 100644 test/CodeGen/2008-01-04-WideBitfield.c create mode 100644 test/CodeGen/2008-12-23-AsmIntPointerTie.c diff --git a/test/CodeGen/2002-02-18-64bitConstant.c b/test/CodeGen/2002-02-18-64bitConstant.c new file mode 100644 index 0000000000..95da72dc30 --- /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-05-24-Alloca.c b/test/CodeGen/2002-05-24-Alloca.c new file mode 100644 index 0000000000..30ba8bb8e2 --- /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 0000000000..24c67d1520 --- /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-MiscTests3.c b/test/CodeGen/2002-07-14-MiscTests3.c new file mode 100644 index 0000000000..f7ded4e720 --- /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-08-02-UnionTest.c b/test/CodeGen/2002-08-02-UnionTest.c new file mode 100644 index 0000000000..2be149909b --- /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/2003-08-21-WideString.c b/test/CodeGen/2003-08-21-WideString.c new file mode 100644 index 0000000000..4071d17c79 --- /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-10-02-UnionLValueError.c b/test/CodeGen/2003-10-02-UnionLValueError.c new file mode 100644 index 0000000000..180eb1080b --- /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/2004-02-13-IllegalVararg.c b/test/CodeGen/2004-02-13-IllegalVararg.c new file mode 100644 index 0000000000..cbc9151ec6 --- /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-20-Builtins.c b/test/CodeGen/2004-02-20-Builtins.c new file mode 100644 index 0000000000..9be0523b4a --- /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-06-17-UnorderedCompares.c b/test/CodeGen/2004-06-17-UnorderedCompares.c new file mode 100644 index 0000000000..7d2ba96147 --- /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/2005-01-02-VAArgError-ICE.c b/test/CodeGen/2005-01-02-VAArgError-ICE.c new file mode 100644 index 0000000000..06377c23d2 --- /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-04-09-ComplexOps.c b/test/CodeGen/2005-04-09-ComplexOps.c new file mode 100644 index 0000000000..23716d362c --- /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-07-20-SqrtNoErrno.c b/test/CodeGen/2005-07-20-SqrtNoErrno.c new file mode 100644 index 0000000000..873236ad2e --- /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 %tmp) readnone + // Check that this is marked readonly when errno is ignored. + return sqrtf(X); +} diff --git a/test/CodeGen/2006-01-13-Includes.c b/test/CodeGen/2006-01-13-Includes.c new file mode 100644 index 0000000000..12e32c9631 --- /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/2007-09-12-PragmaPack.c b/test/CodeGen/2007-09-12-PragmaPack.c new file mode 100644 index 0000000000..71c7537e9d --- /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-27-ComplexIntCompare.c b/test/CodeGen/2007-09-27-ComplexIntCompare.c new file mode 100644 index 0000000000..d07aa0cf7c --- /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/2008-01-04-WideBitfield.c b/test/CodeGen/2008-01-04-WideBitfield.c new file mode 100644 index 0000000000..ab50940c38 --- /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 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-12-23-AsmIntPointerTie.c b/test/CodeGen/2008-12-23-AsmIntPointerTie.c new file mode 100644 index 0000000000..df646b7801 --- /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; +} -- 2.40.0