blob: 656e8fe0c625e4285fe147e934305968617f10c4 [file] [log] [blame]
Daniel Dunbar417dd172008-10-04 23:47:28 +00001//-*- C -*-
2
3/* This is a
4 multiline comment */
5
6// Intended to exercise all syntactic parts of the C language.
7
8int g0;
9int g1, g2;
10
11struct s0;
12
13struct s0 {
14 int x;
15};
16
17int g3 = 10;
18
19__asm("");
20
21typedef int td0;
22
23td0 g4;
24
25enum e0 {
26 ec0
27};
28
29static void f0(int x) {
30}
31
32inline void f0_0(int x) {
33 ;
34}
35
36extern void f0_1(int x) {
37}
38
39void f1(int, ...);
40
41// Statements.
42void f2() {
43 for (;;) {
44 break;
45 continue;
46 }
47
48 while (0) {
49 }
50
51 do {
52 } while (0);
53
54 void *label = &&theif;
55 goto *label;
56
57 goto theif;
58theif:
59 if (0) {
60 ;
61 } else if (0) {
62 } else {
63 }
64
65 switch(0) {
66 case 0:
67 case 1 ... 2:
68 break;
69 default:
70 break;
71 }
72
73 asm ("nop");
74
75 return;
76}
77
78// Expressions.
79
80#include <stdarg.h>
81
82typedef struct ipair {
83 int first, second;
84} ipair;
85
86void f4(int a0, int a1, int a2, va_list ap) {
87 int t0 = a0 ? a1 : a2;
88 float t1 = (float) a0;
89 ipair t2 = {1, 2};
90 int t3 = sizeof(ipair);
91 ipair t4;
92 t4 = (ipair) {1, 2};
93 extern int g(int);
94 int t5 = g(a0);
95 int t6 = t4.first;
96 int t7[10];
97 int t8 = t7[a0];
98 t8++;
99 const char *t9 = __FUNCTION__;
100 char t10 = 'x';
101 int t11 = __builtin_offsetof(ipair, first);
102 int t12 = __builtin_types_compatible_p(ipair, int);
Daniel Dunbarea7a31f2008-10-05 06:36:33 +0000103 int t12_0 = __builtin_classify_type(t0);
104 int t12_1 = __builtin_classify_type(t1);
105 int t12_2 = __builtin_classify_type(t2);
Daniel Dunbar4e484b82009-02-10 03:03:30 +0000106 // FIXME: Add _Complex and aggregate cases.
Daniel Dunbar417dd172008-10-04 23:47:28 +0000107 int t13 = va_arg(ap, int);
Daniel Dunbarea7a31f2008-10-05 06:36:33 +0000108 va_list t13_0;
109 va_copy(t13_0, ap);
110 int t14 = __extension__(t13);
111 int t15 = +t13;
112 unsigned t16 = t14 ^ t15;
113 int t17 = t14 % t15;
114 int t17_0 = t16 % t16;
115 float t18;
116 int t19 = t18 ? 0 : 1;
117 char *t20; ++t20; --t20;
118 float t21; ++t21; --t21;
119 double t22; ++t22; --t22;
120 long double t23; ++t23; --t23;
121 int t24 = !t19;
122 int t25 = __real t24;
123 int t26 = __imag t24;
124 const char *t27 = t9;
125 t27 += (unsigned char) 0xFF;
126 t27 += (signed char) 0xFF;
127
128 struct { char f0[10]; } *t28;
129 int t29 = t28 - t28;
Daniel Dunbarbd589e02008-10-21 21:32:38 +0000130 char *t30 = &t28->f0[1];
Daniel Dunbar90345582009-03-24 02:38:23 +0000131
132 struct s1 { int f0; };
133 struct s1 t31_a, t31_b;
134 int t31_cond;
135 int t31 = (t31_cond ? t31_a : t31_b).f0;
136
137 _Complex float t32_a, t32_b;
138 int t32_cond;
139 int t32 = __real (t32_cond ? t32_a : t32_b);
Daniel Dunbarea7a31f2008-10-05 06:36:33 +0000140}
141
142// Extended vectors
143
Daniel Dunbar90345582009-03-24 02:38:23 +0000144typedef __attribute__((ext_vector_type(2))) float float2;
Daniel Dunbarea7a31f2008-10-05 06:36:33 +0000145typedef __attribute__((ext_vector_type(4))) float float4;
146
147void f5() {
148 float4 t0 = (float4) { 0, 1, 2, 3 };
149 float4 t1 = t0;
Nate Begeman190d6a22009-01-18 02:01:21 +0000150 t0.lo.even = t1.hi.x;
Daniel Dunbar90345582009-03-24 02:38:23 +0000151
152 // irgen doesn't support this yet.
153#if 0
154 int t2_cond;
155 float2 t2 = (t2_cond ? t0 : t1).lo;
156#endif
Daniel Dunbar417dd172008-10-04 23:47:28 +0000157}
Daniel Dunbar63c3a5f2008-10-17 23:04:32 +0000158
159void f6() {
Daniel Dunbarbd589e02008-10-21 21:32:38 +0000160 const char *s0 = __func__;
161 const char *s1 = __FUNCTION__;
162 const char *s2 = __PRETTY_FUNCTION__;
Daniel Dunbar63c3a5f2008-10-17 23:04:32 +0000163}
Daniel Dunbar8b29a382009-02-04 07:22:24 +0000164
165// Arg mismatch with passed type.
166void f7(x)
167 float x;
168{
169}
170
171void f8(x)
172 short x;
173{
174}