blob: c0259debd83b7958018466c8818e50b38addd2f0 [file] [log] [blame]
Daniel Dunbar83f705a2008-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");
Jennifer Yub8fee672019-06-03 15:57:25 +000074 int cond;
75 asm goto("" ::::label_true);
76label_true:
Daniel Dunbar83f705a2008-10-04 23:47:28 +000077 return;
78}
79
80// Expressions.
81
82#include <stdarg.h>
83
84typedef struct ipair {
85 int first, second;
86} ipair;
87
88void f4(int a0, int a1, int a2, va_list ap) {
89 int t0 = a0 ? a1 : a2;
90 float t1 = (float) a0;
91 ipair t2 = {1, 2};
Douglas Gregor278f52e2009-05-30 00:08:05 +000092 ipair t2a = { .second = 2 };
Daniel Dunbar83f705a2008-10-04 23:47:28 +000093 int t3 = sizeof(ipair);
94 ipair t4;
95 t4 = (ipair) {1, 2};
96 extern int g(int);
97 int t5 = g(a0);
98 int t6 = t4.first;
99 int t7[10];
100 int t8 = t7[a0];
101 t8++;
102 const char *t9 = __FUNCTION__;
103 char t10 = 'x';
104 int t11 = __builtin_offsetof(ipair, first);
105 int t12 = __builtin_types_compatible_p(ipair, int);
Daniel Dunbar363a5c02008-10-05 06:36:33 +0000106 int t12_0 = __builtin_classify_type(t0);
107 int t12_1 = __builtin_classify_type(t1);
108 int t12_2 = __builtin_classify_type(t2);
Daniel Dunbar00079612009-02-10 03:03:30 +0000109 // FIXME: Add _Complex and aggregate cases.
Daniel Dunbar83f705a2008-10-04 23:47:28 +0000110 int t13 = va_arg(ap, int);
Daniel Dunbar363a5c02008-10-05 06:36:33 +0000111 va_list t13_0;
112 va_copy(t13_0, ap);
113 int t14 = __extension__(t13);
114 int t15 = +t13;
115 unsigned t16 = t14 ^ t15;
116 int t17 = t14 % t15;
117 int t17_0 = t16 % t16;
118 float t18;
119 int t19 = t18 ? 0 : 1;
120 char *t20; ++t20; --t20;
121 float t21; ++t21; --t21;
122 double t22; ++t22; --t22;
123 long double t23; ++t23; --t23;
124 int t24 = !t19;
125 int t25 = __real t24;
126 int t26 = __imag t24;
127 const char *t27 = t9;
128 t27 += (unsigned char) 0xFF;
129 t27 += (signed char) 0xFF;
130
131 struct { char f0[10]; } *t28;
132 int t29 = t28 - t28;
Daniel Dunbar29fa8352008-10-21 21:32:38 +0000133 char *t30 = &t28->f0[1];
Daniel Dunbarbf1fe8c2009-03-24 02:38:23 +0000134
135 struct s1 { int f0; };
136 struct s1 t31_a, t31_b;
137 int t31_cond;
138 int t31 = (t31_cond ? t31_a : t31_b).f0;
139
140 _Complex float t32_a, t32_b;
141 int t32_cond;
142 int t32 = __real (t32_cond ? t32_a : t32_b);
Douglas Gregor2d042f12009-05-30 05:39:39 +0000143
144 struct { int x, y; } t33, *t34, t35[12], t36(int, float);
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +0000145 float t37, *t38, t39[9], t40(double);
Daniel Dunbar363a5c02008-10-05 06:36:33 +0000146}
147
148// Extended vectors
149
Daniel Dunbarbf1fe8c2009-03-24 02:38:23 +0000150typedef __attribute__((ext_vector_type(2))) float float2;
Daniel Dunbar363a5c02008-10-05 06:36:33 +0000151typedef __attribute__((ext_vector_type(4))) float float4;
152
153void f5() {
154 float4 t0 = (float4) { 0, 1, 2, 3 };
155 float4 t1 = t0;
Nate Begeman7e5185b2009-01-18 02:01:21 +0000156 t0.lo.even = t1.hi.x;
Daniel Dunbarbf1fe8c2009-03-24 02:38:23 +0000157
158 // irgen doesn't support this yet.
159#if 0
160 int t2_cond;
161 float2 t2 = (t2_cond ? t0 : t1).lo;
162#endif
Daniel Dunbar83f705a2008-10-04 23:47:28 +0000163}
Daniel Dunbar6ccea712008-10-17 23:04:32 +0000164
165void f6() {
Daniel Dunbar29fa8352008-10-21 21:32:38 +0000166 const char *s0 = __func__;
167 const char *s1 = __FUNCTION__;
168 const char *s2 = __PRETTY_FUNCTION__;
Daniel Dunbar6ccea712008-10-17 23:04:32 +0000169}
Daniel Dunbar6e3b7df2009-02-04 07:22:24 +0000170
171// Arg mismatch with passed type.
172void f7(x)
173 float x;
174{
175}
176
177void f8(x)
178 short x;
179{
180}
Zhongxing Xu01a5beb2009-04-05 02:04:38 +0000181
182// Function which inputs an array
183void f9(int x[]) { }
Daniel Dunbard443c0a2010-01-04 18:47:06 +0000184
185// Object literals.
186void f10() {
187 struct f10_s0 {
188 char iv0[10];
189 } x;
190
191 x = (struct f10_s0) { .iv0 = "name" };
192}
Daniel Dunbar37614d82010-09-29 16:09:28 +0000193
194// Nested structures.
195struct s11 {
196 struct s11_2 {
197 int f0;
198 } f0;
199 int f1;
200};
Serge Pavloveb57aa62014-06-20 17:08:28 +0000201
202// Unnamed structures.
203struct s12 {
204 struct {
205 unsigned char aa;
206 unsigned char bb;
207 };
208};
209
210void f11() {
211 struct s12 var = { .aa = 33 };
212}