commit 9747c24c5a4aa056f0f2c3d89498be8edb971c47 parent 99f006fdd2e11062b6c6631cac7f6bdec96464b1 Author: Ryan Sepassi <rsepassi@gmail.com> Date: Sat, 9 May 2026 21:46:59 -0700 test/parse: extend corpus to §6.2–§6.9 + builtins, clang-verified Adds 76 positive cases and 22 negative cases covering namespace/ linkage/storage (§6.2), conversions (§6.3), expression-grammar remainder (§6.5 25-32), the type system (§6.7.2 specifiers, §6.7.2.1 struct/union details, §6.7.3 qualifiers including _Atomic, §6.7.4 inline/_Noreturn, §6.7.5 _Alignas, §6.7.6 declarators incl. variadic and VLA, §6.7.8 typedefs), designated initializers (§6.7.9 ext), _Static_assert (§6.7.10), variadic and global-init external defs (§6.9 ext), and __builtin_va_*/__builtin_offsetof/__atomic_* (builtins). All 138 positive cases compile and exit with the expected value mod 256 under clang; all 23 negative cases are rejected by clang's frontend with the targeted diagnostic. Diffstat:
176 files changed, 781 insertions(+), 0 deletions(-)
diff --git a/test/parse/CORPUS.md b/test/parse/CORPUS.md @@ -70,6 +70,39 @@ to diagnose more): |---|---|---|---| | `cases_err/6_5_undeclared` | · | identifier resolution | `return q;` — no such identifier | +## §6.2 Concepts + +Most of §6.2 is exercised implicitly by other rows (block scope by +`6_8_12`, internal/external linkage by `6_7_03`/`6_7_04`, automatic +storage by every local). The cases here pin down behaviors with no +natural home elsewhere. + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_2_3_01_tag_ord_namespace` | · | `struct s { int v; }; int s = 42; struct s t = {0}; return s + t.v;` | 42 | +| `6_2_3_02_label_namespace` | · | `int s = 0; goto s; s = 99; s: return 42;` | 42 | +| `6_2_4_01_static_keeps_value` | · | helper `int next(){static int n=40; return ++n;}`; `next(); return next();` | 42 | +| `6_2_5_01_void_func_no_value` | · | helper `void f(int *p){*p=42;} int x; f(&x); return x;` | 42 | + +## §6.3 Conversions + +Implicit and explicit conversions. `6_5_23_cast` covers narrowing via +explicit cast; rows here fill in the rest of the conversion matrix. + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_3_1_1_01_char_promotion` | · | `char c = 'A'; return c - '@' + 41;` | 42 | +| `6_3_1_3_01_signed_to_unsigned` | · | `int n = -1; unsigned u = (unsigned)n; return (int)(u & 0xff);` | 255 | +| `6_3_1_3_02_unsigned_narrow` | · | `unsigned u = 0x100002aU; int n = (int)u; return n;` | 42 | +| `6_3_1_4_01_float_to_int` | · | `double d = 42.9; return (int)d;` | 42 | +| `6_3_1_4_02_int_to_float` | · | `int n = 42; double d = n; return (int)d;` | 42 | +| `6_3_1_8_01_usual_arith_mixed` | · | `int s = -1; unsigned u = 1; return (s + u) ? 0 : 42;` | 42 | +| `6_3_2_1_01_array_to_ptr` | · | `int a[3] = {0,0,42}; int *p = a; return p[2];` | 42 | +| `6_3_2_1_02_func_to_ptr` | · | helper `id`; `int (*fp)(int) = id; return fp(42);` | 42 | +| `6_3_2_2_01_void_cast_discard` | · | `(void)42; return 42;` | 42 | +| `6_3_2_3_01_null_ptr_cmp` | · | `int *p = 0; return p ? 99 : 42;` | 42 | +| `6_3_2_3_02_void_ptr_roundtrip` | · | `int x=42; void *v=&x; int *p=(int*)v; return *p;` | 42 | + ## §6.5 Expressions Drives the entire expression grammar. One row per production where the @@ -102,6 +135,14 @@ here for completeness once they're real cases. | `6_5_22_sizeof_expr` | · | `int a[7]; return (int)(sizeof(a)/sizeof(int));` | 7 | | `6_5_23_cast` | · | `return (int)(unsigned char)(-1);` | 255 | | `6_5_24_func_call` | · | helper `int id(int x){return x;}` + `return id(42);` | 42 | +| `6_5_25_unary_plus` | · | `return +42;` | 42 | +| `6_5_26_pre_dec` | · | `int x = 43; return --x;` | 42 | +| `6_5_27_post_dec` | · | `int x = 43; x--; return x;` | 42 | +| `6_5_28_arrow` | · | `struct S{int v;} s={42}; struct S *p=&s; return p->v;` | 42 | +| `6_5_29_compound_literal` | · | `int *p = (int[]){10, 32}; return p[0]+p[1];` | 42 | +| `6_5_30_generic_selection`| · | `int x=42; return _Generic((x), int: x, default: 0);` | 42 | +| `6_5_31_subscript_commute`| · | `int a[5]={0,0,42,0,0}; return 2[a];` | 42 | +| `6_5_32_string_subscript` | · | `return "*"[0];` | 42 | ## §6.6 Constant expressions @@ -125,6 +166,97 @@ here for completeness once they're real cases. | `6_7_08_enum_basic` | · | `enum E { A = 40, B }; return B + 1;` | 42 | | `6_7_09_alignof` | · | `return (int)_Alignof(double);` | 8 | +## §6.7.2 Type specifiers + +Each integer/floating type the runtime can return through `test_main`. +Conversion behavior between types lives in §6.3; rows here only check +that the type round-trips through a declaration and back to `int`. + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_2_01_short` | · | `short x = 42; return x;` | 42 | +| `6_7_2_02_long` | · | `long x = 42L; return (int)x;` | 42 | +| `6_7_2_03_long_long` | · | `long long x = 42LL; return (int)x;` | 42 | +| `6_7_2_04_unsigned` | · | `unsigned x = 42U; return (int)x;` | 42 | +| `6_7_2_05_signed_char` | · | `signed char c = 42; return c;` | 42 | +| `6_7_2_06_unsigned_char` | · | `unsigned char c = 200; return c;` | 200 | +| `6_7_2_07_unsigned_short` | · | `unsigned short s = 42; return s;` | 42 | +| `6_7_2_08_unsigned_long` | · | `unsigned long x = 42UL; return (int)x;` | 42 | +| `6_7_2_09_bool` | · | `_Bool b = 5; return b ? 42 : 0;` | 42 | +| `6_7_2_10_float` | · | `float f = 42.0f; return (int)f;` | 42 | +| `6_7_2_11_double` | · | `double d = 42.5; return (int)d;` | 42 | +| `6_7_2_12_long_double` | · | `long double d = 42.0L; return (int)d;` | 42 | +| `6_7_2_13_complex` | (deferred) | `_Complex` is optional in C11 | — | + +## §6.7.2.1 Structure and union details + +Edge cases beyond the basic struct/union rows — bitfields, anonymous +members, self-reference through pointers, and forward declarations. + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_2_1_01_bitfield` | · | `struct {unsigned a:5, b:3;} s={2,5}; return s.b*8 + s.a;` | 42 | +| `6_7_2_1_02_anon_struct` | · | `struct S{int x; struct{int y;};} s={0,42}; return s.y;` | 42 | +| `6_7_2_1_03_anon_union` | · | `struct S{int x; union{int a,b;};} s; s.x=0; s.a=42; return s.b;` | 42 | +| `6_7_2_1_04_self_ref` | · | `struct N{int v; struct N *next;}; struct N b={42,0}, a={0,&b}; return a.next->v;` | 42 | +| `6_7_2_1_05_forward_tag` | · | `struct S; struct S *p; struct S{int v;}; struct S s={42}; p=&s; return p->v;` | 42 | +| `6_7_2_1_06_flex_array` | (deferred) | flexible array members need allocator support | — | + +## §6.7.3 Type qualifiers + +`const` is covered by `6_7_05_const_qualifier`; rows here cover the +remaining qualifier forms and pointer-qualifier interactions. + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_3_01_volatile` | · | `volatile int x = 42; return x;` | 42 | +| `6_7_3_02_restrict_param` | · | helper `int rd(int *restrict p){return *p;}` + caller | 42 | +| `6_7_3_03_const_pointer` | · | `int x=42; int *const p=&x; return *p;` | 42 | +| `6_7_3_04_ptr_to_const` | · | `const int x=42; const int *p=&x; return *p;` | 42 | +| `6_7_3_05_atomic` | · | `_Atomic int x = 42; return x;` | 42 | + +## §6.7.4 Function specifiers + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_4_01_inline` | · | `static inline int id(int x){return x;}` + `return id(42);` | 42 | +| `6_7_4_02_noreturn` | · | full TU: `_Noreturn void die(void){for(;;);} int test_main(void){return 42;}` (declared, not called) | 42 | + +## §6.7.5 Alignment specifier + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_5_01_alignas_obj` | · | `_Alignas(16) static char buf[16]; return (((unsigned long)buf)&15) ? 0 : 42;` | 42 | +| `6_7_5_02_alignas_type` | · | `_Alignas(double) static char buf[8]; return (int)_Alignof(double) * 5 + 2;` | 42 | + +## §6.7.6 Declarators + +Pointer/array/function declarator combinations beyond the basic forms +already exercised in §6.5 and §6.7. + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_6_01_ptr_to_ptr` | · | `int x=42; int *p=&x; int **pp=&p; return **pp;` | 42 | +| `6_7_6_02_array_2d` | · | `int a[2][3]={{0,0,0},{0,0,42}}; return a[1][2];` | 42 | +| `6_7_6_03_array_of_ptr` | · | `int x=42; int *a[2]={0,&x}; return *a[1];` | 42 | +| `6_7_6_04_funcptr_decl` | · | `int id(int x){return x;} int (*fp)(int)=id; return fp(42);` | 42 | +| `6_7_6_05_funcptr_returning_ptr` | · | helper returns `int*`; `int *(*fp)(int*)=...; return *fp(&x);` | 42 | +| `6_7_6_06_array_static_n` | · | helper `int rd(int p[static 3]){return p[2];}`; `int a[3]={0,0,42}; return rd(a);` | 42 | +| `6_7_6_07_vla_local` | · | `int n=7; int a[n]; for(int i=0;i<n;i++) a[i]=i*7; return a[n-1];` | 42 | +| `6_7_6_08_variadic_decl` | · | helper `int sum(int n, ...)` summing two ints; `sum(2, 20, 22)` | 42 | + +## §6.7.8 Type definitions + +`6_7_01_typedef` covers the simplest case (`typedef int I`); rows here +cover compound typedef targets. + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_8_01_typedef_struct` | · | `typedef struct{int v;} S; S s={42}; return s.v;` | 42 | +| `6_7_8_02_typedef_funcptr` | · | `typedef int (*FP)(int); int id(int x){return x;} FP f=id; return f(42);` | 42 | +| `6_7_8_03_typedef_array` | · | `typedef int A[3]; A a={0,0,42}; return a[2];` | 42 | +| `6_7_8_04_typedef_qualified` | · | `typedef const int CI; CI x = 42; return x;` | 42 | + ## §6.7.9 Initialization | Case | Status | Body | Expected | @@ -135,6 +267,17 @@ here for completeness once they're real cases. | `6_7_9_04_designated` | · | `int a[5] = {[2] = 42}; return a[2];` | 42 | | `6_7_9_05_struct_init` | · | `struct S {int a,b;} s={40,2}; return s.a+s.b;` | 42 | | `6_7_9_06_string_init` | · | `char s[] = "hi"; return s[0]+s[1]+s[2];` | 'h'+'i' | +| `6_7_9_07_designated_struct` | · | `struct S{int a,b,c;} s={.b=42}; return s.b;` | 42 | +| `6_7_9_08_nested_designated` | · | `int a[2][3] = {[1][2] = 42}; return a[1][2];` | 42 | +| `6_7_9_09_struct_in_array` | · | `struct P{int x,y;} a[2] = {{0,0},{0,42}}; return a[1].y;` | 42 | +| `6_7_9_10_zero_init_static` | · | full TU: `static int g[3]; int test_main(void){return g[0]+g[1]+g[2]+42;}` | 42 | + +## §6.7.10 Static assertions + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_10_01_static_assert_pass` | · | `_Static_assert(sizeof(int) >= 2, "wide int"); return 42;` | 42 | +| `6_7_10_02_static_assert_const` | · | `_Static_assert(1+1 == 2, "math"); return 42;` | 42 | ## §6.8 Statements @@ -165,6 +308,11 @@ here for completeness once they're real cases. | `6_9_03_tentative_def` | · | file-scope `int g;` (tentative) + use | 0 | | `6_9_04_static_func` | · | `static int helper(...)` + caller | 42 | | `6_9_05_proto_then_def` | · | forward declaration before body | 42 | +| `6_9_06_variadic_func` | · | `sum(int n, ...)` over `va_arg`; `sum(2,20,22)` (paired with builtin_03) | 42 | +| `6_9_07_global_const` | · | full TU: `const int g = 42; int test_main(void){return g;}` | 42 | +| `6_9_08_global_struct_init` | · | full TU: `struct S{int v;} g={42}; int test_main(void){return g.v;}` | 42 | +| `6_9_09_static_data_array` | · | full TU: `static int g[3] = {0, 0, 42}; int test_main(void){return g[2];}` | 42 | +| `6_9_10_kr_function_def` | (deferred) | K&R-style definitions are C90 carryover; revisit if needed | — | ## Builtins @@ -177,6 +325,12 @@ ordinary calls. |---|---|---|---| | `builtin_01_alloca` | · | `int *p = __builtin_alloca(4); *p=42; return *p;` | 42 | | `builtin_02_expect` | · | `if (__builtin_expect(1, 1)) return 42; return 0;` | 42 | +| `builtin_03_va_list` | · | uses `__builtin_va_start`/`__builtin_va_arg`/`__builtin_va_end` summing two ints | 42 | +| `builtin_04_offsetof` | · | `struct S {int a, b;}; return (int)__builtin_offsetof(struct S, b) * 10 + 2;` | 42 | +| `builtin_05_va_copy` | · | walks varargs twice via `__builtin_va_copy`; both walks return same sum | 42 | +| `builtin_06_atomic_load` | · | `int x = 42; return __atomic_load_n(&x, __ATOMIC_RELAXED);` | 42 | +| `builtin_07_atomic_fetch_add` | · | `int x = 40; __atomic_fetch_add(&x, 2, __ATOMIC_RELAXED); return x;` | 42 | +| `builtin_08_syscall0` | (deferred) | `__cfree_syscall0` requires linking against the syscall stub; covered in `test/libc` | — | ## Negative cases (cases_err/) @@ -188,6 +342,23 @@ ordinary calls. | `6_7_redefinition` | · | linkage / scope | two `int x = …` at file scope | | `6_8_break_outside_loop` | · | break/continue scope | `break;` outside iteration | | `6_9_redefinition_function` | · | external definition | two definitions of `f` | +| `6_5_member_not_in_struct` | · | member access | `s.zzz` for unknown field | +| `6_5_call_non_function` | · | call expression | `int x; x();` | +| `6_5_arrow_on_non_pointer` | · | member access | `struct S s; s->v;` | +| `6_5_sizeof_incomplete` | · | sizeof | `struct S; return sizeof(struct S);` | +| `6_7_2_storage_class_combo` | · | declaration | `static extern int x;` | +| `6_7_2_two_struct_defs` | · | tag | two `struct S { ... };` definitions in same scope | +| `6_7_2_1_bitfield_too_wide` | · | bitfield | `unsigned a:33;` exceeds underlying type | +| `6_7_3_const_assign` | · | const violation | `const int x = 0; x = 1;` | +| `6_7_10_static_assert_fail` | · | static assertion | `_Static_assert(0, "fail");` | +| `6_8_case_outside_switch` | · | switch scope | `case 1:` outside any switch | +| `6_8_continue_outside_loop` | · | iteration scope | `continue;` outside iteration | +| `6_8_default_outside_switch` | · | switch scope | `default:` outside switch | +| `6_8_duplicate_case` | · | switch | two `case 1:` in same switch | +| `6_8_duplicate_default` | · | switch | two `default:` labels in same switch | +| `6_8_goto_undefined_label` | · | goto | `goto missing;` with no matching label | +| `6_8_duplicate_label` | · | label | two `L:` in the same function | +| `6_9_void_param_with_other` | · | function declarator | `int f(void, int);` | ## Multi-TU (deferred) diff --git a/test/parse/cases/6_2_3_01_tag_ord_namespace.c b/test/parse/cases/6_2_3_01_tag_ord_namespace.c @@ -0,0 +1,6 @@ +struct s { int v; }; +int s = 42; +struct s t = {0}; +int test_main(void) { + return s + t.v; +} diff --git a/test/parse/cases/6_2_3_01_tag_ord_namespace.expected b/test/parse/cases/6_2_3_01_tag_ord_namespace.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_2_3_02_label_namespace.c b/test/parse/cases/6_2_3_02_label_namespace.c @@ -0,0 +1,7 @@ +int test_main(void) { + int s = 0; + goto s; + s = 99; +s: + return 42; +} diff --git a/test/parse/cases/6_2_3_02_label_namespace.expected b/test/parse/cases/6_2_3_02_label_namespace.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_2_4_01_static_keeps_value.c b/test/parse/cases/6_2_4_01_static_keeps_value.c @@ -0,0 +1,8 @@ +int next(void) { + static int n = 40; + return ++n; +} +int test_main(void) { + next(); + return next(); +} diff --git a/test/parse/cases/6_2_4_01_static_keeps_value.expected b/test/parse/cases/6_2_4_01_static_keeps_value.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_2_5_01_void_func_no_value.c b/test/parse/cases/6_2_5_01_void_func_no_value.c @@ -0,0 +1,8 @@ +void f(int *p) { + *p = 42; +} +int test_main(void) { + int x = 0; + f(&x); + return x; +} diff --git a/test/parse/cases/6_2_5_01_void_func_no_value.expected b/test/parse/cases/6_2_5_01_void_func_no_value.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_1_1_01_char_promotion.c b/test/parse/cases/6_3_1_1_01_char_promotion.c @@ -0,0 +1,4 @@ +int test_main(void) { + char c = 'A'; + return c - '@' + 41; +} diff --git a/test/parse/cases/6_3_1_1_01_char_promotion.expected b/test/parse/cases/6_3_1_1_01_char_promotion.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_1_3_01_signed_to_unsigned.c b/test/parse/cases/6_3_1_3_01_signed_to_unsigned.c @@ -0,0 +1,5 @@ +int test_main(void) { + int n = -1; + unsigned u = (unsigned)n; + return (int)(u & 0xff); +} diff --git a/test/parse/cases/6_3_1_3_01_signed_to_unsigned.expected b/test/parse/cases/6_3_1_3_01_signed_to_unsigned.expected @@ -0,0 +1 @@ +255 diff --git a/test/parse/cases/6_3_1_3_02_unsigned_narrow.c b/test/parse/cases/6_3_1_3_02_unsigned_narrow.c @@ -0,0 +1,5 @@ +int test_main(void) { + unsigned u = 0x100002aU; + int n = (int)u; + return n; +} diff --git a/test/parse/cases/6_3_1_3_02_unsigned_narrow.expected b/test/parse/cases/6_3_1_3_02_unsigned_narrow.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_1_4_01_float_to_int.c b/test/parse/cases/6_3_1_4_01_float_to_int.c @@ -0,0 +1,4 @@ +int test_main(void) { + double d = 42.9; + return (int)d; +} diff --git a/test/parse/cases/6_3_1_4_01_float_to_int.expected b/test/parse/cases/6_3_1_4_01_float_to_int.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_1_4_02_int_to_float.c b/test/parse/cases/6_3_1_4_02_int_to_float.c @@ -0,0 +1,5 @@ +int test_main(void) { + int n = 42; + double d = n; + return (int)d; +} diff --git a/test/parse/cases/6_3_1_4_02_int_to_float.expected b/test/parse/cases/6_3_1_4_02_int_to_float.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_1_8_01_usual_arith_mixed.c b/test/parse/cases/6_3_1_8_01_usual_arith_mixed.c @@ -0,0 +1,5 @@ +int test_main(void) { + int s = -1; + unsigned u = 1; + return (s + u) ? 0 : 42; +} diff --git a/test/parse/cases/6_3_1_8_01_usual_arith_mixed.expected b/test/parse/cases/6_3_1_8_01_usual_arith_mixed.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_2_1_01_array_to_ptr.c b/test/parse/cases/6_3_2_1_01_array_to_ptr.c @@ -0,0 +1,5 @@ +int test_main(void) { + int a[3] = {0, 0, 42}; + int *p = a; + return p[2]; +} diff --git a/test/parse/cases/6_3_2_1_01_array_to_ptr.expected b/test/parse/cases/6_3_2_1_01_array_to_ptr.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_2_1_02_func_to_ptr.c b/test/parse/cases/6_3_2_1_02_func_to_ptr.c @@ -0,0 +1,7 @@ +int id(int x) { + return x; +} +int test_main(void) { + int (*fp)(int) = id; + return fp(42); +} diff --git a/test/parse/cases/6_3_2_1_02_func_to_ptr.expected b/test/parse/cases/6_3_2_1_02_func_to_ptr.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_2_2_01_void_cast_discard.c b/test/parse/cases/6_3_2_2_01_void_cast_discard.c @@ -0,0 +1,4 @@ +int test_main(void) { + (void)42; + return 42; +} diff --git a/test/parse/cases/6_3_2_2_01_void_cast_discard.expected b/test/parse/cases/6_3_2_2_01_void_cast_discard.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_2_3_01_null_ptr_cmp.c b/test/parse/cases/6_3_2_3_01_null_ptr_cmp.c @@ -0,0 +1,4 @@ +int test_main(void) { + int *p = 0; + return p ? 99 : 42; +} diff --git a/test/parse/cases/6_3_2_3_01_null_ptr_cmp.expected b/test/parse/cases/6_3_2_3_01_null_ptr_cmp.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_2_3_02_void_ptr_roundtrip.c b/test/parse/cases/6_3_2_3_02_void_ptr_roundtrip.c @@ -0,0 +1,6 @@ +int test_main(void) { + int x = 42; + void *v = &x; + int *p = (int *)v; + return *p; +} diff --git a/test/parse/cases/6_3_2_3_02_void_ptr_roundtrip.expected b/test/parse/cases/6_3_2_3_02_void_ptr_roundtrip.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_25_unary_plus.c b/test/parse/cases/6_5_25_unary_plus.c @@ -0,0 +1,3 @@ +int test_main(void) { + return +42; +} diff --git a/test/parse/cases/6_5_25_unary_plus.expected b/test/parse/cases/6_5_25_unary_plus.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_26_pre_dec.c b/test/parse/cases/6_5_26_pre_dec.c @@ -0,0 +1,4 @@ +int test_main(void) { + int x = 43; + return --x; +} diff --git a/test/parse/cases/6_5_26_pre_dec.expected b/test/parse/cases/6_5_26_pre_dec.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_27_post_dec.c b/test/parse/cases/6_5_27_post_dec.c @@ -0,0 +1,5 @@ +int test_main(void) { + int x = 43; + x--; + return x; +} diff --git a/test/parse/cases/6_5_27_post_dec.expected b/test/parse/cases/6_5_27_post_dec.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_28_arrow.c b/test/parse/cases/6_5_28_arrow.c @@ -0,0 +1,5 @@ +int test_main(void) { + struct S { int v; } s = {42}; + struct S *p = &s; + return p->v; +} diff --git a/test/parse/cases/6_5_28_arrow.expected b/test/parse/cases/6_5_28_arrow.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_29_compound_literal.c b/test/parse/cases/6_5_29_compound_literal.c @@ -0,0 +1,4 @@ +int test_main(void) { + int *p = (int[]){10, 32}; + return p[0] + p[1]; +} diff --git a/test/parse/cases/6_5_29_compound_literal.expected b/test/parse/cases/6_5_29_compound_literal.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_30_generic_selection.c b/test/parse/cases/6_5_30_generic_selection.c @@ -0,0 +1,4 @@ +int test_main(void) { + int x = 42; + return _Generic((x), int: x, default: 0); +} diff --git a/test/parse/cases/6_5_30_generic_selection.expected b/test/parse/cases/6_5_30_generic_selection.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_31_subscript_commute.c b/test/parse/cases/6_5_31_subscript_commute.c @@ -0,0 +1,4 @@ +int test_main(void) { + int a[5] = {0, 0, 42, 0, 0}; + return 2[a]; +} diff --git a/test/parse/cases/6_5_31_subscript_commute.expected b/test/parse/cases/6_5_31_subscript_commute.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_32_string_subscript.c b/test/parse/cases/6_5_32_string_subscript.c @@ -0,0 +1,3 @@ +int test_main(void) { + return "*"[0]; +} diff --git a/test/parse/cases/6_5_32_string_subscript.expected b/test/parse/cases/6_5_32_string_subscript.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_10_01_static_assert_pass.c b/test/parse/cases/6_7_10_01_static_assert_pass.c @@ -0,0 +1,5 @@ +_Static_assert(sizeof(int) >= 2, "wide int"); + +int test_main(void) { + return 42; +} diff --git a/test/parse/cases/6_7_10_01_static_assert_pass.expected b/test/parse/cases/6_7_10_01_static_assert_pass.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_10_02_static_assert_const.c b/test/parse/cases/6_7_10_02_static_assert_const.c @@ -0,0 +1,5 @@ +_Static_assert(1 + 1 == 2, "math"); + +int test_main(void) { + return 42; +} diff --git a/test/parse/cases/6_7_10_02_static_assert_const.expected b/test/parse/cases/6_7_10_02_static_assert_const.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_01_short.c b/test/parse/cases/6_7_2_01_short.c @@ -0,0 +1,4 @@ +int test_main(void) { + short x = 42; + return x; +} diff --git a/test/parse/cases/6_7_2_01_short.expected b/test/parse/cases/6_7_2_01_short.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_02_long.c b/test/parse/cases/6_7_2_02_long.c @@ -0,0 +1,4 @@ +int test_main(void) { + long x = 42L; + return (int)x; +} diff --git a/test/parse/cases/6_7_2_02_long.expected b/test/parse/cases/6_7_2_02_long.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_03_long_long.c b/test/parse/cases/6_7_2_03_long_long.c @@ -0,0 +1,4 @@ +int test_main(void) { + long long x = 42LL; + return (int)x; +} diff --git a/test/parse/cases/6_7_2_03_long_long.expected b/test/parse/cases/6_7_2_03_long_long.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_04_unsigned.c b/test/parse/cases/6_7_2_04_unsigned.c @@ -0,0 +1,4 @@ +int test_main(void) { + unsigned x = 42U; + return (int)x; +} diff --git a/test/parse/cases/6_7_2_04_unsigned.expected b/test/parse/cases/6_7_2_04_unsigned.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_05_signed_char.c b/test/parse/cases/6_7_2_05_signed_char.c @@ -0,0 +1,4 @@ +int test_main(void) { + signed char c = 42; + return c; +} diff --git a/test/parse/cases/6_7_2_05_signed_char.expected b/test/parse/cases/6_7_2_05_signed_char.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_06_unsigned_char.c b/test/parse/cases/6_7_2_06_unsigned_char.c @@ -0,0 +1,4 @@ +int test_main(void) { + unsigned char c = 200; + return c; +} diff --git a/test/parse/cases/6_7_2_06_unsigned_char.expected b/test/parse/cases/6_7_2_06_unsigned_char.expected @@ -0,0 +1 @@ +200 diff --git a/test/parse/cases/6_7_2_07_unsigned_short.c b/test/parse/cases/6_7_2_07_unsigned_short.c @@ -0,0 +1,4 @@ +int test_main(void) { + unsigned short s = 42; + return s; +} diff --git a/test/parse/cases/6_7_2_07_unsigned_short.expected b/test/parse/cases/6_7_2_07_unsigned_short.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_08_unsigned_long.c b/test/parse/cases/6_7_2_08_unsigned_long.c @@ -0,0 +1,4 @@ +int test_main(void) { + unsigned long x = 42UL; + return (int)x; +} diff --git a/test/parse/cases/6_7_2_08_unsigned_long.expected b/test/parse/cases/6_7_2_08_unsigned_long.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_09_bool.c b/test/parse/cases/6_7_2_09_bool.c @@ -0,0 +1,4 @@ +int test_main(void) { + _Bool b = 5; + return b ? 42 : 0; +} diff --git a/test/parse/cases/6_7_2_09_bool.expected b/test/parse/cases/6_7_2_09_bool.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_10_float.c b/test/parse/cases/6_7_2_10_float.c @@ -0,0 +1,4 @@ +int test_main(void) { + float f = 42.0f; + return (int)f; +} diff --git a/test/parse/cases/6_7_2_10_float.expected b/test/parse/cases/6_7_2_10_float.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_11_double.c b/test/parse/cases/6_7_2_11_double.c @@ -0,0 +1,4 @@ +int test_main(void) { + double d = 42.5; + return (int)d; +} diff --git a/test/parse/cases/6_7_2_11_double.expected b/test/parse/cases/6_7_2_11_double.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_12_long_double.c b/test/parse/cases/6_7_2_12_long_double.c @@ -0,0 +1,4 @@ +int test_main(void) { + long double d = 42.0L; + return (int)d; +} diff --git a/test/parse/cases/6_7_2_12_long_double.expected b/test/parse/cases/6_7_2_12_long_double.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_1_01_bitfield.c b/test/parse/cases/6_7_2_1_01_bitfield.c @@ -0,0 +1,4 @@ +int test_main(void) { + struct { unsigned a:5, b:3; } s = {2, 5}; + return s.b * 8 + s.a; +} diff --git a/test/parse/cases/6_7_2_1_01_bitfield.expected b/test/parse/cases/6_7_2_1_01_bitfield.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_1_02_anon_struct.c b/test/parse/cases/6_7_2_1_02_anon_struct.c @@ -0,0 +1,4 @@ +int test_main(void) { + struct S { int x; struct { int y; }; } s = {0, 42}; + return s.y; +} diff --git a/test/parse/cases/6_7_2_1_02_anon_struct.expected b/test/parse/cases/6_7_2_1_02_anon_struct.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_1_03_anon_union.c b/test/parse/cases/6_7_2_1_03_anon_union.c @@ -0,0 +1,6 @@ +int test_main(void) { + struct S { int x; union { int a, b; }; } s; + s.x = 0; + s.a = 42; + return s.b; +} diff --git a/test/parse/cases/6_7_2_1_03_anon_union.expected b/test/parse/cases/6_7_2_1_03_anon_union.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_1_04_self_ref.c b/test/parse/cases/6_7_2_1_04_self_ref.c @@ -0,0 +1,6 @@ +int test_main(void) { + struct N { int v; struct N *next; }; + struct N b = {42, 0}; + struct N a = {0, &b}; + return a.next->v; +} diff --git a/test/parse/cases/6_7_2_1_04_self_ref.expected b/test/parse/cases/6_7_2_1_04_self_ref.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_1_05_forward_tag.c b/test/parse/cases/6_7_2_1_05_forward_tag.c @@ -0,0 +1,8 @@ +int test_main(void) { + struct S; + struct S *p; + struct S { int v; }; + struct S s = {42}; + p = &s; + return p->v; +} diff --git a/test/parse/cases/6_7_2_1_05_forward_tag.expected b/test/parse/cases/6_7_2_1_05_forward_tag.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_3_01_volatile.c b/test/parse/cases/6_7_3_01_volatile.c @@ -0,0 +1,4 @@ +int test_main(void) { + volatile int x = 42; + return x; +} diff --git a/test/parse/cases/6_7_3_01_volatile.expected b/test/parse/cases/6_7_3_01_volatile.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_3_02_restrict_param.c b/test/parse/cases/6_7_3_02_restrict_param.c @@ -0,0 +1,8 @@ +int rd(int *restrict p) { + return *p; +} + +int test_main(void) { + int x = 42; + return rd(&x); +} diff --git a/test/parse/cases/6_7_3_02_restrict_param.expected b/test/parse/cases/6_7_3_02_restrict_param.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_3_03_const_pointer.c b/test/parse/cases/6_7_3_03_const_pointer.c @@ -0,0 +1,5 @@ +int test_main(void) { + int x = 42; + int *const p = &x; + return *p; +} diff --git a/test/parse/cases/6_7_3_03_const_pointer.expected b/test/parse/cases/6_7_3_03_const_pointer.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_3_04_ptr_to_const.c b/test/parse/cases/6_7_3_04_ptr_to_const.c @@ -0,0 +1,5 @@ +int test_main(void) { + const int x = 42; + const int *p = &x; + return *p; +} diff --git a/test/parse/cases/6_7_3_04_ptr_to_const.expected b/test/parse/cases/6_7_3_04_ptr_to_const.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_3_05_atomic.c b/test/parse/cases/6_7_3_05_atomic.c @@ -0,0 +1,4 @@ +int test_main(void) { + _Atomic int x = 42; + return x; +} diff --git a/test/parse/cases/6_7_3_05_atomic.expected b/test/parse/cases/6_7_3_05_atomic.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_4_01_inline.c b/test/parse/cases/6_7_4_01_inline.c @@ -0,0 +1,7 @@ +static inline int id(int x) { + return x; +} + +int test_main(void) { + return id(42); +} diff --git a/test/parse/cases/6_7_4_01_inline.expected b/test/parse/cases/6_7_4_01_inline.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_4_02_noreturn.c b/test/parse/cases/6_7_4_02_noreturn.c @@ -0,0 +1,7 @@ +_Noreturn void die(void) { + for (;;) ; +} + +int test_main(void) { + return 42; +} diff --git a/test/parse/cases/6_7_4_02_noreturn.expected b/test/parse/cases/6_7_4_02_noreturn.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_5_01_alignas_obj.c b/test/parse/cases/6_7_5_01_alignas_obj.c @@ -0,0 +1,5 @@ +_Alignas(16) static char buf[16]; + +int test_main(void) { + return (((unsigned long)buf) & 15) ? 0 : 42; +} diff --git a/test/parse/cases/6_7_5_01_alignas_obj.expected b/test/parse/cases/6_7_5_01_alignas_obj.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_5_02_alignas_type.c b/test/parse/cases/6_7_5_02_alignas_type.c @@ -0,0 +1,6 @@ +_Alignas(double) static char buf[8]; + +int test_main(void) { + (void)buf; + return (int)_Alignof(double) * 5 + 2; +} diff --git a/test/parse/cases/6_7_5_02_alignas_type.expected b/test/parse/cases/6_7_5_02_alignas_type.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_01_ptr_to_ptr.c b/test/parse/cases/6_7_6_01_ptr_to_ptr.c @@ -0,0 +1,6 @@ +int test_main(void) { + int x = 42; + int *p = &x; + int **pp = &p; + return **pp; +} diff --git a/test/parse/cases/6_7_6_01_ptr_to_ptr.expected b/test/parse/cases/6_7_6_01_ptr_to_ptr.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_02_array_2d.c b/test/parse/cases/6_7_6_02_array_2d.c @@ -0,0 +1,4 @@ +int test_main(void) { + int a[2][3] = {{0, 0, 0}, {0, 0, 42}}; + return a[1][2]; +} diff --git a/test/parse/cases/6_7_6_02_array_2d.expected b/test/parse/cases/6_7_6_02_array_2d.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_03_array_of_ptr.c b/test/parse/cases/6_7_6_03_array_of_ptr.c @@ -0,0 +1,5 @@ +int test_main(void) { + int x = 42; + int *a[2] = {0, &x}; + return *a[1]; +} diff --git a/test/parse/cases/6_7_6_03_array_of_ptr.expected b/test/parse/cases/6_7_6_03_array_of_ptr.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_04_funcptr_decl.c b/test/parse/cases/6_7_6_04_funcptr_decl.c @@ -0,0 +1,6 @@ +int id(int x) { return x; } + +int test_main(void) { + int (*fp)(int) = id; + return fp(42); +} diff --git a/test/parse/cases/6_7_6_04_funcptr_decl.expected b/test/parse/cases/6_7_6_04_funcptr_decl.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_05_funcptr_returning_ptr.c b/test/parse/cases/6_7_6_05_funcptr_returning_ptr.c @@ -0,0 +1,7 @@ +int *passthrough(int *q) { return q; } + +int test_main(void) { + int x = 42; + int *(*fp)(int *) = passthrough; + return *fp(&x); +} diff --git a/test/parse/cases/6_7_6_05_funcptr_returning_ptr.expected b/test/parse/cases/6_7_6_05_funcptr_returning_ptr.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_06_array_static_n.c b/test/parse/cases/6_7_6_06_array_static_n.c @@ -0,0 +1,6 @@ +int rd(int p[static 3]) { return p[2]; } + +int test_main(void) { + int a[3] = {0, 0, 42}; + return rd(a); +} diff --git a/test/parse/cases/6_7_6_06_array_static_n.expected b/test/parse/cases/6_7_6_06_array_static_n.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_07_vla_local.c b/test/parse/cases/6_7_6_07_vla_local.c @@ -0,0 +1,6 @@ +int test_main(void) { + int n = 7; + int a[n]; + for (int i = 0; i < n; i++) a[i] = i * 7; + return a[n - 1]; +} diff --git a/test/parse/cases/6_7_6_07_vla_local.expected b/test/parse/cases/6_7_6_07_vla_local.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_08_variadic_decl.c b/test/parse/cases/6_7_6_08_variadic_decl.c @@ -0,0 +1,12 @@ +int sum(int n, ...) { + __builtin_va_list ap; + __builtin_va_start(ap, n); + int s = 0; + for (int i = 0; i < n; i++) s += __builtin_va_arg(ap, int); + __builtin_va_end(ap); + return s; +} + +int test_main(void) { + return sum(2, 20, 22); +} diff --git a/test/parse/cases/6_7_6_08_variadic_decl.expected b/test/parse/cases/6_7_6_08_variadic_decl.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_8_01_typedef_struct.c b/test/parse/cases/6_7_8_01_typedef_struct.c @@ -0,0 +1,5 @@ +int test_main(void) { + typedef struct { int v; } S; + S s = {42}; + return s.v; +} diff --git a/test/parse/cases/6_7_8_01_typedef_struct.expected b/test/parse/cases/6_7_8_01_typedef_struct.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_8_02_typedef_funcptr.c b/test/parse/cases/6_7_8_02_typedef_funcptr.c @@ -0,0 +1,7 @@ +int id(int x) { return x; } +typedef int (*FP)(int); + +int test_main(void) { + FP f = id; + return f(42); +} diff --git a/test/parse/cases/6_7_8_02_typedef_funcptr.expected b/test/parse/cases/6_7_8_02_typedef_funcptr.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_8_03_typedef_array.c b/test/parse/cases/6_7_8_03_typedef_array.c @@ -0,0 +1,5 @@ +int test_main(void) { + typedef int A[3]; + A a = {0, 0, 42}; + return a[2]; +} diff --git a/test/parse/cases/6_7_8_03_typedef_array.expected b/test/parse/cases/6_7_8_03_typedef_array.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_8_04_typedef_qualified.c b/test/parse/cases/6_7_8_04_typedef_qualified.c @@ -0,0 +1,5 @@ +int test_main(void) { + typedef const int CI; + CI x = 42; + return x; +} diff --git a/test/parse/cases/6_7_8_04_typedef_qualified.expected b/test/parse/cases/6_7_8_04_typedef_qualified.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_9_07_designated_struct.c b/test/parse/cases/6_7_9_07_designated_struct.c @@ -0,0 +1,4 @@ +int test_main(void) { + struct S { int a, b, c; } s = {.b = 42}; + return s.b; +} diff --git a/test/parse/cases/6_7_9_07_designated_struct.expected b/test/parse/cases/6_7_9_07_designated_struct.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_9_08_nested_designated.c b/test/parse/cases/6_7_9_08_nested_designated.c @@ -0,0 +1,4 @@ +int test_main(void) { + int a[2][3] = {[1][2] = 42}; + return a[1][2]; +} diff --git a/test/parse/cases/6_7_9_08_nested_designated.expected b/test/parse/cases/6_7_9_08_nested_designated.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_9_09_struct_in_array.c b/test/parse/cases/6_7_9_09_struct_in_array.c @@ -0,0 +1,4 @@ +int test_main(void) { + struct P { int x, y; } a[2] = {{0, 0}, {0, 42}}; + return a[1].y; +} diff --git a/test/parse/cases/6_7_9_09_struct_in_array.expected b/test/parse/cases/6_7_9_09_struct_in_array.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_9_10_zero_init_static.c b/test/parse/cases/6_7_9_10_zero_init_static.c @@ -0,0 +1,5 @@ +static int g[3]; + +int test_main(void) { + return g[0] + g[1] + g[2] + 42; +} diff --git a/test/parse/cases/6_7_9_10_zero_init_static.expected b/test/parse/cases/6_7_9_10_zero_init_static.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_9_06_variadic_func.c b/test/parse/cases/6_9_06_variadic_func.c @@ -0,0 +1,12 @@ +int sum(int n, ...) { + __builtin_va_list ap; + __builtin_va_start(ap, n); + int s = 0; + for (int i = 0; i < n; i++) s += __builtin_va_arg(ap, int); + __builtin_va_end(ap); + return s; +} + +int test_main(void) { + return sum(2, 20, 22); +} diff --git a/test/parse/cases/6_9_06_variadic_func.expected b/test/parse/cases/6_9_06_variadic_func.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_9_07_global_const.c b/test/parse/cases/6_9_07_global_const.c @@ -0,0 +1,5 @@ +const int g = 42; + +int test_main(void) { + return g; +} diff --git a/test/parse/cases/6_9_07_global_const.expected b/test/parse/cases/6_9_07_global_const.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_9_08_global_struct_init.c b/test/parse/cases/6_9_08_global_struct_init.c @@ -0,0 +1,5 @@ +struct S { int v; } g = {42}; + +int test_main(void) { + return g.v; +} diff --git a/test/parse/cases/6_9_08_global_struct_init.expected b/test/parse/cases/6_9_08_global_struct_init.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_9_09_static_data_array.c b/test/parse/cases/6_9_09_static_data_array.c @@ -0,0 +1,5 @@ +static int g[3] = {0, 0, 42}; + +int test_main(void) { + return g[2]; +} diff --git a/test/parse/cases/6_9_09_static_data_array.expected b/test/parse/cases/6_9_09_static_data_array.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/builtin_03_va_list.c b/test/parse/cases/builtin_03_va_list.c @@ -0,0 +1,12 @@ +int sum3(int n, ...) { + __builtin_va_list ap; + __builtin_va_start(ap, n); + int s = 0; + for (int i = 0; i < n; i++) s += __builtin_va_arg(ap, int); + __builtin_va_end(ap); + return s; +} + +int test_main(void) { + return sum3(3, 10, 20, 12); +} diff --git a/test/parse/cases/builtin_03_va_list.expected b/test/parse/cases/builtin_03_va_list.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/builtin_04_offsetof.c b/test/parse/cases/builtin_04_offsetof.c @@ -0,0 +1,5 @@ +struct S { int a, b; }; + +int test_main(void) { + return (int)__builtin_offsetof(struct S, b) * 10 + 2; +} diff --git a/test/parse/cases/builtin_04_offsetof.expected b/test/parse/cases/builtin_04_offsetof.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/builtin_05_va_copy.c b/test/parse/cases/builtin_05_va_copy.c @@ -0,0 +1,15 @@ +int sum2x(int n, ...) { + __builtin_va_list ap, ap2; + __builtin_va_start(ap, n); + __builtin_va_copy(ap2, ap); + int s = 0; + for (int i = 0; i < n; i++) s += __builtin_va_arg(ap, int); + for (int i = 0; i < n; i++) s += __builtin_va_arg(ap2, int); + __builtin_va_end(ap); + __builtin_va_end(ap2); + return s; +} + +int test_main(void) { + return sum2x(2, 10, 11); +} diff --git a/test/parse/cases/builtin_05_va_copy.expected b/test/parse/cases/builtin_05_va_copy.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/builtin_06_atomic_load.c b/test/parse/cases/builtin_06_atomic_load.c @@ -0,0 +1,4 @@ +int test_main(void) { + int x = 42; + return __atomic_load_n(&x, __ATOMIC_RELAXED); +} diff --git a/test/parse/cases/builtin_06_atomic_load.expected b/test/parse/cases/builtin_06_atomic_load.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/builtin_07_atomic_fetch_add.c b/test/parse/cases/builtin_07_atomic_fetch_add.c @@ -0,0 +1,5 @@ +int test_main(void) { + int x = 40; + __atomic_fetch_add(&x, 2, __ATOMIC_RELAXED); + return x; +} diff --git a/test/parse/cases/builtin_07_atomic_fetch_add.expected b/test/parse/cases/builtin_07_atomic_fetch_add.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases_err/6_5_arrow_on_non_pointer.c b/test/parse/cases_err/6_5_arrow_on_non_pointer.c @@ -0,0 +1,5 @@ +int test_main(void) { + struct S { int v; } s; + s.v = 0; + return s->v; +} diff --git a/test/parse/cases_err/6_5_call_non_function.c b/test/parse/cases_err/6_5_call_non_function.c @@ -0,0 +1,4 @@ +int test_main(void) { + int x = 0; + return x(); +} diff --git a/test/parse/cases_err/6_5_lvalue_required.c b/test/parse/cases_err/6_5_lvalue_required.c @@ -0,0 +1,4 @@ +int test_main(void) { + 1 = 2; + return 0; +} diff --git a/test/parse/cases_err/6_5_member_not_in_struct.c b/test/parse/cases_err/6_5_member_not_in_struct.c @@ -0,0 +1,5 @@ +int test_main(void) { + struct S { int a; } s; + s.zzz = 0; + return 0; +} diff --git a/test/parse/cases_err/6_5_sizeof_incomplete.c b/test/parse/cases_err/6_5_sizeof_incomplete.c @@ -0,0 +1,5 @@ +struct S; + +int test_main(void) { + return (int)sizeof(struct S); +} diff --git a/test/parse/cases_err/6_5_type_mismatch.c b/test/parse/cases_err/6_5_type_mismatch.c @@ -0,0 +1,7 @@ +int test_main(void) { + int x; + int y = 0; + int *p = &y; + x = p; + return x; +} diff --git a/test/parse/cases_err/6_7_10_static_assert_fail.c b/test/parse/cases_err/6_7_10_static_assert_fail.c @@ -0,0 +1,5 @@ +_Static_assert(0, "fail"); + +int test_main(void) { + return 42; +} diff --git a/test/parse/cases_err/6_7_2_1_bitfield_too_wide.c b/test/parse/cases_err/6_7_2_1_bitfield_too_wide.c @@ -0,0 +1,7 @@ +struct B { unsigned a:33; }; + +int test_main(void) { + struct B b; + b.a = 0; + return 0; +} diff --git a/test/parse/cases_err/6_7_2_storage_class_combo.c b/test/parse/cases_err/6_7_2_storage_class_combo.c @@ -0,0 +1,5 @@ +static extern int x; + +int test_main(void) { + return x; +} diff --git a/test/parse/cases_err/6_7_2_two_struct_defs.c b/test/parse/cases_err/6_7_2_two_struct_defs.c @@ -0,0 +1,6 @@ +struct S { int a; }; +struct S { int b; }; + +int test_main(void) { + return 0; +} diff --git a/test/parse/cases_err/6_7_3_const_assign.c b/test/parse/cases_err/6_7_3_const_assign.c @@ -0,0 +1,5 @@ +int test_main(void) { + const int x = 0; + x = 1; + return x; +} diff --git a/test/parse/cases_err/6_7_redefinition.c b/test/parse/cases_err/6_7_redefinition.c @@ -0,0 +1,6 @@ +int x = 1; +int x = 2; + +int test_main(void) { + return x; +} diff --git a/test/parse/cases_err/6_8_break_outside_loop.c b/test/parse/cases_err/6_8_break_outside_loop.c @@ -0,0 +1,4 @@ +int test_main(void) { + break; + return 0; +} diff --git a/test/parse/cases_err/6_8_case_outside_switch.c b/test/parse/cases_err/6_8_case_outside_switch.c @@ -0,0 +1,4 @@ +int test_main(void) { + case 1: + return 42; +} diff --git a/test/parse/cases_err/6_8_continue_outside_loop.c b/test/parse/cases_err/6_8_continue_outside_loop.c @@ -0,0 +1,4 @@ +int test_main(void) { + continue; + return 0; +} diff --git a/test/parse/cases_err/6_8_default_outside_switch.c b/test/parse/cases_err/6_8_default_outside_switch.c @@ -0,0 +1,4 @@ +int test_main(void) { + default: + return 42; +} diff --git a/test/parse/cases_err/6_8_duplicate_case.c b/test/parse/cases_err/6_8_duplicate_case.c @@ -0,0 +1,8 @@ +int test_main(void) { + int x = 1; + switch (x) { + case 1: return 1; + case 1: return 2; + } + return 0; +} diff --git a/test/parse/cases_err/6_8_duplicate_default.c b/test/parse/cases_err/6_8_duplicate_default.c @@ -0,0 +1,8 @@ +int test_main(void) { + int x = 1; + switch (x) { + default: return 1; + default: return 2; + } + return 0; +} diff --git a/test/parse/cases_err/6_8_duplicate_label.c b/test/parse/cases_err/6_8_duplicate_label.c @@ -0,0 +1,4 @@ +int test_main(void) { + L: ; + L: return 0; +} diff --git a/test/parse/cases_err/6_8_goto_undefined_label.c b/test/parse/cases_err/6_8_goto_undefined_label.c @@ -0,0 +1,4 @@ +int test_main(void) { + goto missing; + return 0; +} diff --git a/test/parse/cases_err/6_9_redefinition_function.c b/test/parse/cases_err/6_9_redefinition_function.c @@ -0,0 +1,6 @@ +int f(void) { return 1; } +int f(void) { return 2; } + +int test_main(void) { + return f(); +} diff --git a/test/parse/cases_err/6_9_void_param_with_other.c b/test/parse/cases_err/6_9_void_param_with_other.c @@ -0,0 +1,5 @@ +int f(void, int); + +int test_main(void) { + return 0; +} diff --git a/test/parse/run_errors.sh b/test/parse/run_errors.sh @@ -8,6 +8,11 @@ # Optional sidecar: # <name>.errpat — substring of stderr that must be present. If # missing, only exit status is checked. +# +# Filtering: +# ./run_errors.sh [name_filter] +# name_filter substring match against case basename +# Equivalent env var: CFREE_TEST_FILTER. set -u @@ -15,6 +20,8 @@ ROOT="$(cd "$(dirname "$0")/../.." && pwd)" TEST_DIR="$ROOT/test/parse" BUILD_DIR="$ROOT/build/test" +FILTER="${1:-${CFREE_TEST_FILTER:-}}" + PARSE_RUNNER="$BUILD_DIR/parse-runner" if [ ! -x "$PARSE_RUNNER" ]; then @@ -34,6 +41,7 @@ failures= for src in *.c; do [ -e "$src" ] || continue name="${src%.c}" + case "$name" in *"$FILTER"*) ;; *) [ -n "$FILTER" ] && continue ;; esac pat_file="$name.errpat" err_log="$BUILD_DIR/parse/$name.err.log" mkdir -p "$BUILD_DIR/parse"