| 1 |
//-*- C -*- |
| 2 |
|
| 3 |
/* This is a |
| 4 |
multiline comment */ |
| 5 |
|
| 6 |
// Intended to exercise all syntactic parts of the C language. |
| 7 |
|
| 8 |
int g0; |
| 9 |
int g1, g2; |
| 10 |
|
| 11 |
struct s0; |
| 12 |
|
| 13 |
struct s0 { |
| 14 |
int x; |
| 15 |
}; |
| 16 |
|
| 17 |
int g3 = 10; |
| 18 |
|
| 19 |
__asm(""); |
| 20 |
|
| 21 |
typedef int td0; |
| 22 |
|
| 23 |
td0 g4; |
| 24 |
|
| 25 |
enum e0 { |
| 26 |
ec0 |
| 27 |
}; |
| 28 |
|
| 29 |
static void f0(int x) { |
| 30 |
} |
| 31 |
|
| 32 |
inline void f0_0(int x) { |
| 33 |
; |
| 34 |
} |
| 35 |
|
| 36 |
extern void f0_1(int x) { |
| 37 |
} |
| 38 |
|
| 39 |
void f1(int, ...); |
| 40 |
|
| 41 |
// Statements. |
| 42 |
void 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; |
| 58 |
theif: |
| 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 |
int cond; |
| 75 |
asm goto("" ::::label_true); |
| 76 |
label_true: |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
// Expressions. |
| 81 |
|
| 82 |
#include <stdarg.h> |
| 83 |
|
| 84 |
typedef struct ipair { |
| 85 |
int first, second; |
| 86 |
} ipair; |
| 87 |
|
| 88 |
void 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}; |
| 92 |
ipair t2a = { .second = 2 }; |
| 93 |
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); |
| 106 |
int t12_0 = __builtin_classify_type(t0); |
| 107 |
int t12_1 = __builtin_classify_type(t1); |
| 108 |
int t12_2 = __builtin_classify_type(t2); |
| 109 |
// FIXME: Add _Complex and aggregate cases. |
| 110 |
int t13 = va_arg(ap, int); |
| 111 |
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; |
| 133 |
char *t30 = &t28->f0[1]; |
| 134 |
|
| 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); |
| 143 |
|
| 144 |
struct { int x, y; } t33, *t34, t35[12], t36(int, float); |
| 145 |
float t37, *t38, t39[9], t40(double); |
| 146 |
} |
| 147 |
|
| 148 |
// Extended vectors |
| 149 |
|
| 150 |
typedef __attribute__((ext_vector_type(2))) float float2; |
| 151 |
typedef __attribute__((ext_vector_type(4))) float float4; |
| 152 |
|
| 153 |
void f5() { |
| 154 |
float4 t0 = (float4) { 0, 1, 2, 3 }; |
| 155 |
float4 t1 = t0; |
| 156 |
t0.lo.even = t1.hi.x; |
| 157 |
|
| 158 |
// irgen doesn't support this yet. |
| 159 |
#if 0 |
| 160 |
int t2_cond; |
| 161 |
float2 t2 = (t2_cond ? t0 : t1).lo; |
| 162 |
#endif |
| 163 |
} |
| 164 |
|
| 165 |
void f6() { |
| 166 |
const char *s0 = __func__; |
| 167 |
const char *s1 = __FUNCTION__; |
| 168 |
const char *s2 = __PRETTY_FUNCTION__; |
| 169 |
} |
| 170 |
|
| 171 |
// Arg mismatch with passed type. |
| 172 |
void f7(x) |
| 173 |
float x; |
| 174 |
{ |
| 175 |
} |
| 176 |
|
| 177 |
void f8(x) |
| 178 |
short x; |
| 179 |
{ |
| 180 |
} |
| 181 |
|
| 182 |
// Function which inputs an array |
| 183 |
void f9(int x[]) { } |
| 184 |
|
| 185 |
// Object literals. |
| 186 |
void f10() { |
| 187 |
struct f10_s0 { |
| 188 |
char iv0[10]; |
| 189 |
} x; |
| 190 |
|
| 191 |
x = (struct f10_s0) { .iv0 = "name" }; |
| 192 |
} |
| 193 |
|
| 194 |
// Nested structures. |
| 195 |
struct s11 { |
| 196 |
struct s11_2 { |
| 197 |
int f0; |
| 198 |
} f0; |
| 199 |
int f1; |
| 200 |
}; |
| 201 |
|
| 202 |
// Unnamed structures. |
| 203 |
struct s12 { |
| 204 |
struct { |
| 205 |
unsigned char aa; |
| 206 |
unsigned char bb; |
| 207 |
}; |
| 208 |
}; |
| 209 |
|
| 210 |
void f11() { |
| 211 |
struct s12 var = { .aa = 33 }; |
| 212 |
} |