Home | History | Annotate | Download | only in CodeGen
      1 // RUN: %clang_cc1 -w -emit-llvm %s  -o /dev/null
      2 
      3 void *malloc(unsigned);
      4 int puts(const char *s);
      5 
      6 struct FunStructTest {
      7   int Test1;
      8   char *Pointer;
      9   int Array[12];
     10 };
     11 
     12 struct SubStruct {
     13   short X, Y;
     14 };
     15 
     16 struct Quad {
     17   int w;
     18   struct SubStruct SS;
     19   struct SubStruct *SSP;
     20   char c;
     21   int y;
     22 };
     23 
     24 struct Quad GlobalQuad = { 4, {1, 2}, 0, 3, 156 };
     25 
     26 typedef int (*FuncPtr)(int);
     27 
     28 unsigned PtrFunc(int (*Func)(int), int X) {
     29   return Func(X);
     30 }
     31 
     32 char PtrFunc2(FuncPtr FuncTab[30], int Num) {
     33   return FuncTab[Num]('b');
     34 }
     35 
     36 extern char SmallArgs2(char w, char x, long long Zrrk, char y, char z);
     37 extern int SomeFunc(void);
     38 char SmallArgs(char w, char x, char y, char z) {
     39   SomeFunc();
     40   return SmallArgs2(w-1, x+1, y, z, w);
     41 }
     42 
     43 static int F0(struct Quad Q, int i) {              /* Pass Q by value */
     44   struct Quad R;
     45   if (i) R.SS = Q.SS;
     46   Q.SSP = &R.SS;
     47   Q.w = Q.y = Q.c = 1;
     48   return Q.SS.Y + i + R.y - Q.c;
     49 }
     50 
     51 int F1(struct Quad *Q, int i) {             /* Pass Q by address */
     52   struct Quad R;
     53 #if 0
     54   if (i) R.SS = Q->SS;
     55 #else
     56   if (i) R = *Q;
     57 #endif
     58   Q->w = Q->y = Q->c = 1;
     59   return Q->SS.Y+i+R.y-Q->c;
     60 }
     61 
     62 
     63 int BadFunc(float Val) {
     64   int Result;
     65   if (Val > 12.345) Result = 4;
     66   return Result;     /* Test use of undefined value */
     67 }
     68 
     69 int RealFunc(void) {
     70   return SomeUndefinedFunction(1, 4, 5);
     71 }
     72 
     73 extern int EF1(int *, char *, int *);
     74 
     75 int Func(int Param, long long Param2) {
     76   int Result = Param;
     77 
     78   {{{{
     79       char c; int X;
     80       EF1(&Result, &c, &X);
     81     }}}
     82 
     83     {   // c & X are duplicate names!
     84       char c; int X;
     85       EF1(&Result, &c, &X);
     86     }
     87 
     88   }
     89   return Result;
     90 }
     91 
     92 
     93 short FunFunc(long long x, char z) {
     94   return x+z;
     95 }
     96 
     97 unsigned castTest(int X) { return X; }
     98 
     99 double TestAdd(double X, float Y) {
    100   return X+Y+.5;
    101 }
    102 
    103 int func(int i, int j) {
    104   while (i != 20)
    105     i += 2;
    106 
    107   j += func(2, i);
    108   return (i * 3 + j*2)*j;
    109 }
    110 
    111 int SumArray(int Array[], int Num) {
    112   int i, Result = 0;
    113   for (i = 0; i < Num; ++i)
    114     Result += Array[i];
    115 
    116   return Result;
    117 }
    118 
    119 int ArrayParam(int Values[100]) {
    120   return EF1((int*)Values[50], (char*)1, &Values[50]);
    121 }
    122 
    123 int ArrayToSum(void) {
    124   int A[100], i;
    125   for (i = 0; i < 100; ++i)
    126     A[i] = i*4;
    127 
    128   return A[A[0]]; //SumArray(A, 100);
    129 }
    130 
    131 
    132 int ExternFunc(long long, unsigned*, short, unsigned char);
    133 
    134 int main(int argc, char *argv[]) {
    135   unsigned i;
    136   puts("Hello world!\n");
    137 
    138   ExternFunc(-1, 0, (short)argc, 2);
    139   //func(argc, argc);
    140 
    141   for (i = 0; i < 10; i++)
    142     puts(argv[3]);
    143   return 0;
    144 }
    145 
    146 double MathFunc(double X, double Y, double Z,
    147                 double AA, double BB, double CC, double DD,
    148                 double EE, double FF, double GG, double HH,
    149                 double aAA, double aBB, double aCC, double aDD,
    150                 double aEE, double aFF) {
    151   return X + Y + Z + AA + BB + CC + DD + EE + FF + GG + HH
    152        + aAA + aBB + aCC + aDD + aEE + aFF;
    153 }
    154 
    155 
    156 
    157 void strcpy(char *s1, char *s2) {
    158   while (*s1++ = *s2++);
    159 }
    160 
    161 void strcat(char *s1, char *s2) {
    162   while (*s1++);
    163   s1--;
    164   while (*s1++ = *s2++);
    165 }
    166 
    167 int strcmp(char *s1, char *s2) {
    168   while (*s1++ == *s2++);
    169   if (*s1 == 0) {
    170     if (*s2 == 0) {
    171       return 0;
    172     } else {
    173       return -1;
    174     }
    175   } else {
    176     if (*s2 == 0) {
    177       return 1;
    178     } else {
    179       return (*(--s1) - *(--s2));
    180     }
    181   }
    182 }
    183