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