| Daniel Dunbar | 417dd17 | 2008-10-04 23:47:28 +0000 | [diff] [blame] | 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 |  | 
|  | 75 | return; | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | // Expressions. | 
|  | 79 |  | 
|  | 80 | #include <stdarg.h> | 
|  | 81 |  | 
|  | 82 | typedef struct ipair { | 
|  | 83 | int first, second; | 
|  | 84 | } ipair; | 
|  | 85 |  | 
|  | 86 | void 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}; | 
| Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame^] | 90 | ipair t2a = { .second = 2 }; | 
| Daniel Dunbar | 417dd17 | 2008-10-04 23:47:28 +0000 | [diff] [blame] | 91 | int t3 = sizeof(ipair); | 
|  | 92 | ipair t4; | 
|  | 93 | t4 = (ipair) {1, 2}; | 
|  | 94 | extern int g(int); | 
|  | 95 | int t5 = g(a0); | 
|  | 96 | int t6 = t4.first; | 
|  | 97 | int t7[10]; | 
|  | 98 | int t8 = t7[a0]; | 
|  | 99 | t8++; | 
|  | 100 | const char *t9 = __FUNCTION__; | 
|  | 101 | char t10 = 'x'; | 
|  | 102 | int t11 = __builtin_offsetof(ipair, first); | 
|  | 103 | int t12 = __builtin_types_compatible_p(ipair, int); | 
| Daniel Dunbar | ea7a31f | 2008-10-05 06:36:33 +0000 | [diff] [blame] | 104 | int t12_0 = __builtin_classify_type(t0); | 
|  | 105 | int t12_1 = __builtin_classify_type(t1); | 
|  | 106 | int t12_2 = __builtin_classify_type(t2); | 
| Daniel Dunbar | 4e484b8 | 2009-02-10 03:03:30 +0000 | [diff] [blame] | 107 | // FIXME: Add _Complex and aggregate cases. | 
| Daniel Dunbar | 417dd17 | 2008-10-04 23:47:28 +0000 | [diff] [blame] | 108 | int t13 = va_arg(ap, int); | 
| Daniel Dunbar | ea7a31f | 2008-10-05 06:36:33 +0000 | [diff] [blame] | 109 | va_list t13_0; | 
|  | 110 | va_copy(t13_0, ap); | 
|  | 111 | int t14 = __extension__(t13); | 
|  | 112 | int t15 = +t13; | 
|  | 113 | unsigned t16 = t14 ^ t15; | 
|  | 114 | int t17 = t14 % t15; | 
|  | 115 | int t17_0 = t16 % t16; | 
|  | 116 | float t18; | 
|  | 117 | int t19 = t18 ? 0 : 1; | 
|  | 118 | char *t20; ++t20; --t20; | 
|  | 119 | float t21; ++t21; --t21; | 
|  | 120 | double t22; ++t22; --t22; | 
|  | 121 | long double t23; ++t23; --t23; | 
|  | 122 | int t24 = !t19; | 
|  | 123 | int t25 = __real t24; | 
|  | 124 | int t26 = __imag t24; | 
|  | 125 | const char *t27 = t9; | 
|  | 126 | t27 += (unsigned char) 0xFF; | 
|  | 127 | t27 += (signed char) 0xFF; | 
|  | 128 |  | 
|  | 129 | struct { char f0[10]; } *t28; | 
|  | 130 | int t29 = t28 - t28; | 
| Daniel Dunbar | bd589e0 | 2008-10-21 21:32:38 +0000 | [diff] [blame] | 131 | char *t30 = &t28->f0[1]; | 
| Daniel Dunbar | 9034558 | 2009-03-24 02:38:23 +0000 | [diff] [blame] | 132 |  | 
|  | 133 | struct s1 { int f0; }; | 
|  | 134 | struct s1 t31_a, t31_b; | 
|  | 135 | int t31_cond; | 
|  | 136 | int t31 = (t31_cond ? t31_a : t31_b).f0; | 
|  | 137 |  | 
|  | 138 | _Complex float t32_a, t32_b; | 
|  | 139 | int t32_cond; | 
|  | 140 | int t32 = __real (t32_cond ? t32_a : t32_b); | 
| Daniel Dunbar | ea7a31f | 2008-10-05 06:36:33 +0000 | [diff] [blame] | 141 | } | 
|  | 142 |  | 
|  | 143 | // Extended vectors | 
|  | 144 |  | 
| Daniel Dunbar | 9034558 | 2009-03-24 02:38:23 +0000 | [diff] [blame] | 145 | typedef __attribute__((ext_vector_type(2))) float float2; | 
| Daniel Dunbar | ea7a31f | 2008-10-05 06:36:33 +0000 | [diff] [blame] | 146 | typedef __attribute__((ext_vector_type(4))) float float4; | 
|  | 147 |  | 
|  | 148 | void f5() { | 
|  | 149 | float4 t0 = (float4) { 0, 1, 2, 3 }; | 
|  | 150 | float4 t1 = t0; | 
| Nate Begeman | 190d6a2 | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 151 | t0.lo.even = t1.hi.x; | 
| Daniel Dunbar | 9034558 | 2009-03-24 02:38:23 +0000 | [diff] [blame] | 152 |  | 
|  | 153 | // irgen doesn't support this yet. | 
|  | 154 | #if 0 | 
|  | 155 | int t2_cond; | 
|  | 156 | float2 t2 = (t2_cond ? t0 : t1).lo; | 
|  | 157 | #endif | 
| Daniel Dunbar | 417dd17 | 2008-10-04 23:47:28 +0000 | [diff] [blame] | 158 | } | 
| Daniel Dunbar | 63c3a5f | 2008-10-17 23:04:32 +0000 | [diff] [blame] | 159 |  | 
|  | 160 | void f6() { | 
| Daniel Dunbar | bd589e0 | 2008-10-21 21:32:38 +0000 | [diff] [blame] | 161 | const char *s0 = __func__; | 
|  | 162 | const char *s1 = __FUNCTION__; | 
|  | 163 | const char *s2 = __PRETTY_FUNCTION__; | 
| Daniel Dunbar | 63c3a5f | 2008-10-17 23:04:32 +0000 | [diff] [blame] | 164 | } | 
| Daniel Dunbar | 8b29a38 | 2009-02-04 07:22:24 +0000 | [diff] [blame] | 165 |  | 
|  | 166 | // Arg mismatch with passed type. | 
|  | 167 | void f7(x) | 
|  | 168 | float x; | 
|  | 169 | { | 
|  | 170 | } | 
|  | 171 |  | 
|  | 172 | void f8(x) | 
|  | 173 | short x; | 
|  | 174 | { | 
|  | 175 | } | 
| Zhongxing Xu | ba16be9 | 2009-04-05 02:04:38 +0000 | [diff] [blame] | 176 |  | 
|  | 177 | // Function which inputs an array | 
|  | 178 | void f9(int x[]) { } |