Forbid arrays of function-type and structures with function-typed fields.
[llvm/avr.git] / test / FrontendC / 2002-07-14-MiscTests3.c
blob7ef7e232d99eddbec16bfdf2e4cf9ab1a7462af0
1 // RUN: %llvmgcc -w -S %s -o - | llvm-as -o /dev/null
5 void *malloc(unsigned);
7 //#include <stdio.h>
8 int puts(const char *s);
10 struct FunStructTest {
11 int Test1;
12 char *Pointer;
13 int Array[12];
16 struct SubStruct {
17 short X, Y;
20 struct Quad {
21 int w;
22 struct SubStruct SS;
23 struct SubStruct *SSP;
24 char c;
25 int y;
28 struct Quad GlobalQuad = { 4, {1, 2}, 0, 3, 156 };
30 typedef int (*FuncPtr)(int);
32 unsigned PtrFunc(int (*Func)(int), int X) {
33 return Func(X);
36 char PtrFunc2(FuncPtr FuncTab[30], int Num) {
37 return FuncTab[Num]('b');
40 extern char SmallArgs2(char w, char x, long long Zrrk, char y, char z);
41 extern int SomeFunc(void);
42 char SmallArgs(char w, char x, char y, char z) {
43 SomeFunc();
44 return SmallArgs2(w-1, x+1, y, z, w);
47 static int F0(struct Quad Q, int i) { /* Pass Q by value */
48 struct Quad R;
49 if (i) R.SS = Q.SS;
50 Q.SSP = &R.SS;
51 Q.w = Q.y = Q.c = 1;
52 return Q.SS.Y + i + R.y - Q.c;
55 int F1(struct Quad *Q, int i) { /* Pass Q by address */
56 struct Quad R;
57 #if 0
58 if (i) R.SS = Q->SS;
59 #else
60 if (i) R = *Q;
61 #endif
62 Q->w = Q->y = Q->c = 1;
63 return Q->SS.Y+i+R.y-Q->c;
67 int BadFunc(float Val) {
68 int Result;
69 if (Val > 12.345) Result = 4;
70 return Result; /* Test use of undefined value */
73 int RealFunc(void) {
74 return SomeUndefinedFunction(1, 4, 5);
77 extern int EF1(int *, char *, int *);
79 int Func(int Param, long long Param2) {
80 int Result = Param;
82 {{{{
83 char c; int X;
84 EF1(&Result, &c, &X);
85 }}}
87 { // c & X are duplicate names!
88 char c; int X;
89 EF1(&Result, &c, &X);
93 return Result;
97 short FunFunc(long long x, char z) {
98 return x+z;
101 unsigned castTest(int X) { return X; }
103 double TestAdd(double X, float Y) {
104 return X+Y+.5;
107 int func(int i, int j) {
108 while (i != 20)
109 i += 2;
111 j += func(2, i);
112 return (i * 3 + j*2)*j;
115 int SumArray(int Array[], int Num) {
116 int i, Result = 0;
117 for (i = 0; i < Num; ++i)
118 Result += Array[i];
120 return Result;
123 int ArrayParam(int Values[100]) {
124 return EF1((int*)Values[50], (char*)1, &Values[50]);
127 int ArrayToSum(void) {
128 int A[100], i;
129 for (i = 0; i < 100; ++i)
130 A[i] = i*4;
132 return A[A[0]]; //SumArray(A, 100);
136 int ExternFunc(long long, unsigned*, short, unsigned char);
138 int main(int argc, char *argv[]) {
139 unsigned i;
140 puts("Hello world!\n");
142 ExternFunc(-1, 0, (short)argc, 2);
143 //func(argc, argc);
145 for (i = 0; i < 10; i++)
146 puts(argv[3]);
147 return 0;
150 double MathFunc(double X, double Y, double Z,
151 double AA, double BB, double CC, double DD,
152 double EE, double FF, double GG, double HH,
153 double aAA, double aBB, double aCC, double aDD,
154 double aEE, double aFF) {
155 return X + Y + Z + AA + BB + CC + DD + EE + FF + GG + HH
156 + aAA + aBB + aCC + aDD + aEE + aFF;
161 void strcpy(char *s1, char *s2) {
162 while (*s1++ = *s2++);
165 void strcat(char *s1, char *s2) {
166 while (*s1++);
167 s1--;
168 while (*s1++ = *s2++);
171 int strcmp(char *s1, char *s2) {
172 while (*s1++ == *s2++);
173 if (*s1 == 0) {
174 if (*s2 == 0) {
175 return 0;
176 } else {
177 return -1;
179 } else {
180 if (*s2 == 0) {
181 return 1;
182 } else {
183 return (*(--s1) - *(--s2));