commit f4598076bcaf8b69666403a8667f338f25870bc6 parent 0dcabba636a542050faf4f2e60e3755b217dac35 Author: Ryan Sepassi <rsepassi@gmail.com> Date: Sun, 10 May 2026 13:57:55 -0700 test/parse: §6.2–§6.9 corpus expansion — 80 new rows + status sweep CHAPTER-6 coverage gap-fill across §6.2 (concepts), §6.3 (conversions), §6.5 (expressions 40–57), §6.6 (constant exprs), §6.7.1–§6.7.10 (declarations), §6.8 (statements 16–28), §6.9 (externals 11–13). 60 rows pass D/R/E/J on cfree (★); 20 are registered as · pending parser support — pointer compound-assign, sizeof-on-VLA-runtime, struct copy init, designated union/enum init, _Alignas(0), VLA params, and friends. Also tightens parser-status.md Phase 2/3 unlocks (drops stale 6_7_6_02 / 6_7_2_1_01 caveats now that bitfield + nested-init pass). Diffstat:
164 files changed, 494 insertions(+), 11 deletions(-)
diff --git a/doc/parser-status.md b/doc/parser-status.md @@ -92,8 +92,7 @@ The `cg_alloca` stub in `cg.c` was wired through to `CGTarget.alloca_` since the aarch64 backend already implements it. Unlocks (status as landed): `6_3_2_1_01–02` ★, `6_5_22` ★, `6_5_31–32` ★, -`6_7_6_03–07` ★, `6_7_6_02` · (regalloc pressure under nested brace init — -needs the spill path that's also blocking other future cases). `6_5_28–30` +`6_7_6_02–07` ★. `6_5_28–30` were misattributed in the original phase plan: `6_5_28_arrow` and `6_5_30_generic_selection` need struct/`_Generic` (Phase 3), `6_5_29_compound_literal` needs Phase 6's brace-init machinery. @@ -112,8 +111,7 @@ aggregates, bitfields, `_Generic`. - [x] Self-referential pointers (`struct N { struct N *next; };`) - [x] Anonymous struct/union members (C11 §6.7.2.1) - [x] Bitfield members (`unsigned a:5`) — declarations parsed and recorded - as `FIELD_BITFIELD`; access deferred until `cg_bitfield_load/store` - land (the cg-side stubs still panic in this slice). + as `FIELD_BITFIELD`; access lowers through `cg_bitfield_load/store`. - [x] `_Generic` selection (type-keyed) Phase 3 also added: @@ -141,9 +139,7 @@ non-default match cannot be replayed (single-pass, no rewind), so we panic in that pathological case — none of the corpus rows hit it. Unlocks (status as landed): `6_5_28` ★, `6_5_30` ★, `6_6_01` ★, `6_7_06–08` ★, -`6_7_2_1_02–05` ★. `6_2_3_01_tag_ord_namespace` stays · pending Phase 4 -(file-scope object decls). `6_7_2_1_01_bitfield` stays · pending the -cg-side bitfield path. +`6_7_2_1_01–05` ★. --- @@ -183,8 +179,8 @@ Phase 4 also added: decl-spec line; `extern` followed by a defining declaration of the same name reuses the `ObjSymId` so the linker sees one symbol. -Unlocks (status as landed): `6_2_4_01` ★, `6_7_02–04` ★, `6_9_03` ★, -`6_9_07–09` ★. +Unlocks (status as landed): `6_2_3_01` ★, `6_2_4_01` ★, `6_7_02–04` ★, +`6_9_03` ★, `6_9_07–09` ★. --- diff --git a/test/parse/CORPUS.md b/test/parse/CORPUS.md @@ -79,10 +79,20 @@ 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_1_01_param_shadow` | ★ | helper `int f(int x){{int x=42; return x;}}`; `return f(99);` — block decl shadows function parameter | 42 | +| `6_2_1_02_label_in_nested_block` | ★ | `goto done; { done: r=42; }` — label declared inside nested block has function scope | 42 | +| `6_2_2_01_extern_in_block_inherits_internal` | · | full TU: `static int g=42; int test_main(void){extern int g; return g;}` — `extern` redeclares to inherit internal linkage | 42 | +| `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_01b_member_namespace_two_structs` | ★ | `struct A{int x;}; struct B{int x;}; ... return a.x+b.x;` — same member name in distinct struct types | 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_4_02_auto_reinit_each_iteration` | ★ | `for(int i=0;i<6;i++){int x=i; s+=x;}` — local re-initialized each iteration; `0+1+...+5=15` | 15 | +| `6_2_4_03_static_local_zero_init` | ★ | helper `int f(){static int n; return ++n;}`; `f()+f()` — static local zero-initialized | 3 | | `6_2_5_01_void_func_no_value` | ★ | helper `void f(int *p){*p=42;} int x; f(&x); return x;` | 42 | +| `6_2_5_01b_unsigned_wrap` | ★ | `unsigned char u=255; u++; return u;` — modular wrap to 0 | 0 | +| `6_2_5_02_incomplete_array_completed` | ★ | full TU: `extern int a[]; int a[3]={0,0,42}; ...return a[2];` — incomplete array completed by later definition | 42 | +| `6_2_7_01_composite_array_size` | · | full TU: `extern int a[]; int a[3]={40,0,0}; extern int a[3]; ...sizeof(a)/sizeof(a[0])` — composite type from compatible decls | 42 | +| `6_2_8_01_char_weakest_align` | ★ | `return (int)_Alignof(char);` — char has alignment 1 | 1 | ## §6.3 Conversions @@ -102,6 +112,11 @@ explicit cast; rows here fill in the rest of the conversion matrix. | `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_3_1_2_01_bool_from_ptr` | ★ | `_Bool b=(int*)&x ? 1 : 0; return b ? 42 : 0;` — non-null pointer → `_Bool` 1 | 42 | +| `6_3_1_2_02_bool_from_float` | ★ | `_Bool b = 0.0; return b ? 99 : 42;` — zero float → `_Bool` 0 | 42 | +| `6_3_1_3_03_uchar_wrap` | ★ | `int n = -1; unsigned char c = (unsigned char)n; return c;` — modular reduction mod 256 | 255 | +| `6_3_1_8_02_signed_wins` | ★ | `long a=40; unsigned int b=2; return (int)(a+b);` — signed `long` rank > `unsigned int` → result is `long` | 42 | +| `6_3_2_3_03_null_void_cast` | ★ | `int *p = (void*)0; return p ? 99 : 42;` — `(void*)0` is null pointer constant | 42 | ## §6.5 Expressions @@ -148,6 +163,24 @@ here for completeness once they're real cases. | `6_5_37_fp_int_promote` | ★ | `int + double` — usual arithmetic conversion promotes the int side to `double` before BO_FADD | 42 | | `6_5_38_fp_float_widen` | ★ | `float + double` — float widens to double before BO_FADD | 42 | | `6_5_39_float_arith` | ★ | `float * float` stays at single precision (BO_FMUL with `type=0`) | 42 | +| `6_5_40_ptr_add` | ★ | `int *p=a; p=p+3; return *p;` — `ptr+int` with stride scaling (4-byte element) | 42 | +| `6_5_41_ptr_sub_ptr` | ★ | `int *p=a+4; int *q=a+1; return (int)(p-q);` — pointer subtraction yields ptrdiff | 3 | +| `6_5_42_ptr_arith_stride` | ★ | `double a[3]={...}; double *p=a+2; return (int)*p;` — stride = sizeof(double) = 8 | 42 | +| `6_5_43_signed_rshift` | ★ | `int x=-256; (x>>4)+58` — arithmetic right-shift on signed value | 42 | +| `6_5_44_relational_all` | ★ | `(3>1)+(1<3)+(2<=2)+(2>=2)+(1!=2)+(2==2)` — covers `>`, `<=`, `>=`, `!=` | 6 | +| `6_5_45_ptr_eq_null` | ★ | `(p==0)+(q!=0)+(p!=q)` — pointer equality with null and pointer-vs-pointer `!=` | 3 | +| `6_5_46_ptr_relcmp` | ★ | `(p<q)+(q>p)+(p<=p)` — relational comparison of pointers into same array | 3 | +| `6_5_47_ternary_arith_conv` | · | `int c=1; double r = c ? 1 : 2.5; return (int)(r+41.0);` — ternary arms get usual arithmetic conversion to double | 42 | +| `6_5_48_ternary_ptr_null` | ★ | `int *p = 1 ? &x : 0; return *p;` — one arm pointer, other null pointer constant | 42 | +| `6_5_49_compound_assign_sub` | ★ | `int x=44; x-=2; return x;` — `-=` operator | 42 | +| `6_5_50_compound_assign_shift` | ★ | `int x=336; x>>=3; return x;` — `>>=` operator (336>>3=42) | 42 | +| `6_5_51_compound_assign_bitwise` | ★ | `x=0xff; x&=0x7f; x^=0x55; x\|=0x00;` — `&=`, `^=`, `\|=` | 42 | +| `6_5_52_compound_assign_ptr` | · | `int *p=a; p+=4; return *p;` — `+=` with pointer LHS | 42 | +| `6_5_53_sizeof_vla_runtime` | · | `int n=7; int a[n]; return (int)sizeof(a);` — sizeof on VLA evaluated at runtime | 28 | +| `6_5_54_sizeof_deref_ptr` | · | `double *p=&x; return (int)sizeof(*p);` — sizeof on dereferenced pointer; operand not evaluated | 8 | +| `6_5_55_generic_default_branch` | · | `_Generic((double)x, int: 0, default: 42)` — falls through to `default` | 42 | +| `6_5_56_compound_literal_struct` | · | `struct S s = (struct S){.a=20,.b=22}; return s.a+s.b;` — struct compound literal with designated init | 42 | +| `6_5_57_unsigned_wrap_add` | ★ | `unsigned x=0xFFFFFFFFU; x+=1; return (int)(x & 0xff);` — unsigned addition wraps modulo 2^32 | 0 | ## §6.6 Constant expressions @@ -155,7 +188,10 @@ here for completeness once they're real cases. |---|---|---|---| | `6_6_01_enum_const` | ★ | `enum { K = 42 }; return K;` | 42 | | `6_6_02_const_expr_init` | ★ | `int x = 1+2*3; return x;` | 7 | -| `6_6_03_array_size_const` | · | `int a[3+4] = {0}; return (int)sizeof a / (int)sizeof a[0];` | 7 | +| `6_6_03_array_size_const` | ★ | `int a[3+4] = {0}; return (int)sizeof a / (int)sizeof a[0];` | 7 | +| `6_6_04_alignof_array_size` | · | `int a[_Alignof(long long)]; return (int)sizeof(a)/sizeof(a[0]);` — `_Alignof` in array-size constant | 8 | +| `6_6_05_addr_const_static_init` | · | full TU: `static int g=7; static int *p=&g; ...return *p*6;` — address constant in static initializer | 42 | +| `6_6_06_addr_const_arith_init` | · | full TU: `static int arr[4]={0,0,0,42}; static int *p=arr+3; ...return *p;` — address constant + ICE in static initializer | 42 | ## §6.7 Declarations @@ -171,6 +207,16 @@ 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.1 Storage-class specifiers + +`static`/`extern`/`typedef` are exercised by `6_7_01`–`6_7_04`; rows here +cover `register` and other specifier interactions. + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_1_01_register_sizeof` | ★ | `register int x=42; return (int)sizeof(x)>0?x:0;` — `sizeof` is legal on a register variable | 42 | +| `6_7_1_02_register_multi_decl` | ★ | `register int x=40, y=2; return x+y;` — multi-declarator with `register` | 42 | + ## §6.7.2 Type specifiers Each integer/floating type the runtime can return through `test_main`. @@ -183,6 +229,7 @@ that the type round-trips through a declaration and back to `int`. | `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_01b_unsigned_long_long` | ★ | `unsigned long long x = 42ULL; return (int)x;` — `unsigned long long` multiset | 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 | @@ -206,6 +253,21 @@ members, self-reference through pointers, and forward declarations. | `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_2_1_07_signed_bitfield` | ★ | `struct {signed int s:8;} b={-1}; return (b.s<0)?42:0;` — signed bitfield sign extension | 42 | +| `6_7_2_1_08_zero_width_bitfield` | · | `struct {unsigned a:4; unsigned:0; unsigned b:4;}` — zero-width bitfield forces next field into new storage unit | 42 | +| `6_7_2_1_09_bool_bitfield` | ★ | `struct {_Bool b:1;} s; s.b=1; return s.b?42:0;` — `_Bool` bitfield | 42 | + +## §6.7.2.2 Enumeration specifiers + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_2_2_01_enum_restart` | ★ | `enum C{X=20, Y, Z=20, W}; return Y+W;` — auto-increment restarts after explicit `=`; duplicate values allowed (Y=21, W=21) | 42 | + +## §6.7.2.3 Tags + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_2_3_01_tag_inner_scope` | ★ | outer `struct S{int v;}; { struct S{int v;}; struct S s={42}; ...}` — inner-scope tag shadows outer; distinct types | 42 | ## §6.7.3 Type qualifiers @@ -219,6 +281,8 @@ remaining qualifier forms and pointer-qualifier interactions. | `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_3_06_repeated_const` | ★ | `const const int x = 42; return x;` — repeated qualifier is idempotent | 42 | +| `6_7_3_07_const_array_typedef` | ★ | `typedef int A[3]; const A a={10,20,12}; return a[0]+a[1]+a[2];` — `const` outside typedef makes elements const | 42 | ## §6.7.4 Function specifiers @@ -226,6 +290,8 @@ remaining qualifier forms and pointer-qualifier interactions. |---|---|---|---| | `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_4_03_extern_inline` | ★ | `static inline int add1(int x){return x+1;} return add1(41);` — inline definition (note: clang `extern inline` requires non-static external def; case uses static inline form to avoid ODR hazard) | 42 | +| `6_7_4_04_repeated_inline` | ★ | `static inline inline int id(int x){return x;}` — repeated function specifier is idempotent | 42 | ## §6.7.5 Alignment specifier @@ -233,6 +299,8 @@ remaining qualifier forms and pointer-qualifier interactions. |---|---|---|---| | `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_5_03_alignas_zero` | · | `_Alignas(0) static int x = 42;` — `_Alignas(0)` has no effect; object gets natural alignment | 42 | +| `6_7_5_04_alignas_multi` | ★ | `_Alignas(16) _Alignas(8) static char buf[16];` — strictest `_Alignas` wins | 42 | ## §6.7.6 Declarators @@ -249,6 +317,17 @@ already exercised in §6.5 and §6.7. | `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_6_09_ptr_to_array` | ★ | `int b[3]={0,0,42}; int (*pa)[3]=&b; return (*pa)[2];` — pointer-to-array declarator | 42 | +| `6_7_6_10_array_of_funcptr` | · | `int (*ops[2])(int)={add1,sub1}; return ops[0](ops[1](42));` — block-scope array of function pointers | 42 | +| `6_7_6_11_func_returning_funcptr` | ★ | `typedef int (*FP)(int); FP getfp(void){return id;} return getfp()(42);` — function returning function pointer | 42 | +| `6_7_6_12_vla_param` | · | `int sum_vla(int n, int a[n]){...}` — VLA dimension from earlier param; param adjusted to pointer | 42 | +| `6_7_6_13_star_in_proto` | · | `int total(int n, int a[*]); int total(int n, int a[n]){...}` — `[*]` in non-definition prototype | 42 | + +## §6.7.7 Type names + +| Case | Status | Body | Expected | +|---|---|---|---| +| `6_7_7_01_abstract_ptr_array_cast` | ★ | `((int(*)[3])v)[0][2]` — abstract declarator `int(*)[3]` in cast | 42 | ## §6.7.8 Type definitions @@ -261,6 +340,8 @@ cover compound typedef targets. | `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_8_05_typedef_vla_size_fixed` | · | `int f(int n){typedef int B[n]; n+=10; B a; ...}` — VLA typedef captures size at definition | 36 | +| `6_7_8_06_typedef_multi_decl` | ★ | `typedef int TWICE, (*PFUNC)(int);` — multiple declarators in one typedef | 42 | ## §6.7.9 Initialization @@ -276,6 +357,13 @@ cover compound typedef targets. | `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_9_11_array_size_from_init` | ★ | `int x[] = {10, 12, 20}; return x[0]+x[1]+x[2];` — array of unknown size; size from init list | 42 | +| `6_7_9_12_designator_override` | ★ | `int a[3] = {[1]=99, [1]=42, [0]=0};` — later designator overrides earlier | 42 | +| `6_7_9_13_string_init_fixed_larger` | ★ | `char s[6] = "hi";` — char array larger than string literal; excess elements zero-filled (sum = 'h'+'i'+0+0+0+0) | 209 | +| `6_7_9_14_struct_copy_init` | · | `struct S src={20,22}; struct S dst=src; return dst.a+dst.b;` — struct init from compatible struct expression | 42 | +| `6_7_9_15_union_designated_nonfirst` | · | `union U{int a; int b;} u={.b=42}; return u.b;` — designated init of non-first union member | 42 | +| `6_7_9_16_enum_designator` | · | `enum {X=2}; int a[4]={[X]=42}; return a[X];` — enum constant as array designator | 42 | +| `6_7_9_17_inconsistent_bracket_init` | ★ | `struct T{int a[2];int b;} w[2]={{1},2};` — flat init consumed into subaggregate without inner braces | 3 | ## §6.7.10 Static assertions @@ -283,6 +371,7 @@ cover compound typedef targets. |---|---|---|---| | `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_7_10_03_static_assert_file_scope` | ★ | full TU: `_Static_assert(sizeof(long)>=4,"long");` at file scope | 42 | ## §6.8 Statements @@ -303,6 +392,18 @@ cover compound typedef targets. | `6_8_13_compound_decl_mix` | ★ | declarations interleaved with statements (C99) | 42 | | `6_8_14_return_void` | ★ | `void f(void){return;}; f(); return 42;` | 42 | | `6_8_15_null_statement` | ★ | `for (int i=0;i<42;i++) ; return i;` | 42 | +| `6_8_16_dangling_else` | ★ | `if (1) if (0) r=1; else r=42;` — else binds to inner `if` | 42 | +| `6_8_17_switch_char_ctrl` | ★ | switch on `char c=2`; matches `case 2` | 42 | +| `6_8_18_switch_no_match_no_default` | ★ | switch(99) with no matching case and no default; `r` unchanged | 7 | +| `6_8_19_switch_nested_dup_case` | ★ | nested switch with `case 1`/`case 2` in inner — inner `case 2` wins | 42 | +| `6_8_20_switch_hidden_scope` | ★ | `int x=99;` initializer jumped over by switch; `case 1: r=42` still reached | 42 | +| `6_8_21_for_infinite_break` | ★ | `for(;;){ i++; if(i==42) break; }` — infinite loop terminated by break | 42 | +| `6_8_23_continue_do_while` | ★ | `continue` in `do..while` restarts the loop; sum of odd i in [1,10] = 1+3+5+7+9 | 25 | +| `6_8_24_break_switch_in_loop` | ★ | `break` inside switch inside for-loop exits switch, not loop; loop reaches `case 3` | 3 | +| `6_8_25_continue_inside_switch` | ★ | `continue` inside switch's `case 0:` continues the enclosing for-loop; s=1+3=4 | 4 | +| `6_8_26_goto_into_nested_block` | ★ | `goto inner;` where label is inside a nested block | 42 | +| `6_8_27_label_on_null_stmt` | ★ | `end: ;` — label applied to a null statement | 42 | +| `6_8_28_return_narrow_convert` | ★ | `unsigned char narrow(int x){return x;}` — 298 & 0xff = 42; narrowing on return | 42 | ## §6.9 External definitions @@ -318,6 +419,9 @@ cover compound typedef targets. | `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 | — | +| `6_9_11_tentative_multi` | ★ | full TU: `int g; int g;` — two tentative defs merge; `return g+42` | 42 | +| `6_9_12_tentative_incomplete_array` | ★ | full TU: `int arr[]; int arr[3];` — tentative + completing decl; `return arr[0]+arr[1]+arr[2]+42` | 42 | +| `6_9_13_extern_func_def` | ★ | full TU: `extern int helper(int x){return x+1;}` — extern on a definition; `helper(41)` | 42 | ## Builtins diff --git a/test/parse/cases/6_2_1_01_param_shadow.c b/test/parse/cases/6_2_1_01_param_shadow.c @@ -0,0 +1,2 @@ +int f(int x){ { int x=42; return x; } } +int test_main(void){ return f(99); } diff --git a/test/parse/cases/6_2_1_01_param_shadow.expected b/test/parse/cases/6_2_1_01_param_shadow.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_2_1_02_label_in_nested_block.c b/test/parse/cases/6_2_1_02_label_in_nested_block.c @@ -0,0 +1 @@ +int test_main(void){ int r=0; goto done; { done: r=42; } return r; } diff --git a/test/parse/cases/6_2_1_02_label_in_nested_block.expected b/test/parse/cases/6_2_1_02_label_in_nested_block.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_2_2_01_extern_in_block_inherits_internal.c b/test/parse/cases/6_2_2_01_extern_in_block_inherits_internal.c @@ -0,0 +1,2 @@ +static int g=42; +int test_main(void){ extern int g; return g; } diff --git a/test/parse/cases/6_2_2_01_extern_in_block_inherits_internal.expected b/test/parse/cases/6_2_2_01_extern_in_block_inherits_internal.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_2_3_01b_member_namespace_two_structs.c b/test/parse/cases/6_2_3_01b_member_namespace_two_structs.c @@ -0,0 +1,2 @@ +struct A{int x;}; struct B{int x;}; +int test_main(void){ struct A a={10}; struct B b={32}; return a.x+b.x; } diff --git a/test/parse/cases/6_2_3_01b_member_namespace_two_structs.expected b/test/parse/cases/6_2_3_01b_member_namespace_two_structs.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_2_4_02_auto_reinit_each_iteration.c b/test/parse/cases/6_2_4_02_auto_reinit_each_iteration.c @@ -0,0 +1 @@ +int test_main(void){ int s=0; for(int i=0;i<6;i++){ int x=i; s+=x; } return s; } diff --git a/test/parse/cases/6_2_4_02_auto_reinit_each_iteration.expected b/test/parse/cases/6_2_4_02_auto_reinit_each_iteration.expected @@ -0,0 +1 @@ +15 diff --git a/test/parse/cases/6_2_4_03_static_local_zero_init.c b/test/parse/cases/6_2_4_03_static_local_zero_init.c @@ -0,0 +1,2 @@ +int f(void){ static int n; return ++n; } +int test_main(void){ return f()+f(); } diff --git a/test/parse/cases/6_2_4_03_static_local_zero_init.expected b/test/parse/cases/6_2_4_03_static_local_zero_init.expected @@ -0,0 +1 @@ +3 diff --git a/test/parse/cases/6_2_5_01b_unsigned_wrap.c b/test/parse/cases/6_2_5_01b_unsigned_wrap.c @@ -0,0 +1 @@ +int test_main(void){ unsigned char u=255; u++; return u; } diff --git a/test/parse/cases/6_2_5_01b_unsigned_wrap.expected b/test/parse/cases/6_2_5_01b_unsigned_wrap.expected @@ -0,0 +1 @@ +0 diff --git a/test/parse/cases/6_2_5_02_incomplete_array_completed.c b/test/parse/cases/6_2_5_02_incomplete_array_completed.c @@ -0,0 +1,3 @@ +extern int a[]; +int a[3]={0,0,42}; +int test_main(void){return a[2];} diff --git a/test/parse/cases/6_2_5_02_incomplete_array_completed.expected b/test/parse/cases/6_2_5_02_incomplete_array_completed.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_2_7_01_composite_array_size.c b/test/parse/cases/6_2_7_01_composite_array_size.c @@ -0,0 +1,4 @@ +extern int a[]; +int a[3]={40,0,0}; +extern int a[3]; +int test_main(void){return a[0]+(int)(sizeof(a)/sizeof(a[0]))-1;} diff --git a/test/parse/cases/6_2_7_01_composite_array_size.expected b/test/parse/cases/6_2_7_01_composite_array_size.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_2_8_01_char_weakest_align.c b/test/parse/cases/6_2_8_01_char_weakest_align.c @@ -0,0 +1 @@ +int test_main(void){ return (int)_Alignof(char); } diff --git a/test/parse/cases/6_2_8_01_char_weakest_align.expected b/test/parse/cases/6_2_8_01_char_weakest_align.expected @@ -0,0 +1 @@ +1 diff --git a/test/parse/cases/6_3_1_2_01_bool_from_ptr.c b/test/parse/cases/6_3_1_2_01_bool_from_ptr.c @@ -0,0 +1 @@ +int test_main(void){ int x=1; _Bool b=(int*)&x ? 1 : 0; return b ? 42 : 0; } diff --git a/test/parse/cases/6_3_1_2_01_bool_from_ptr.expected b/test/parse/cases/6_3_1_2_01_bool_from_ptr.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_1_2_02_bool_from_float.c b/test/parse/cases/6_3_1_2_02_bool_from_float.c @@ -0,0 +1 @@ +int test_main(void){ _Bool b = 0.0; return b ? 99 : 42; } diff --git a/test/parse/cases/6_3_1_2_02_bool_from_float.expected b/test/parse/cases/6_3_1_2_02_bool_from_float.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_1_3_03_uchar_wrap.c b/test/parse/cases/6_3_1_3_03_uchar_wrap.c @@ -0,0 +1 @@ +int test_main(void){ int n = -1; unsigned char c = (unsigned char)n; return c; } diff --git a/test/parse/cases/6_3_1_3_03_uchar_wrap.expected b/test/parse/cases/6_3_1_3_03_uchar_wrap.expected @@ -0,0 +1 @@ +255 diff --git a/test/parse/cases/6_3_1_8_02_signed_wins.c b/test/parse/cases/6_3_1_8_02_signed_wins.c @@ -0,0 +1 @@ +int test_main(void){ long a = 40; unsigned int b = 2; return (int)(a + b); } diff --git a/test/parse/cases/6_3_1_8_02_signed_wins.expected b/test/parse/cases/6_3_1_8_02_signed_wins.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_3_2_3_03_null_void_cast.c b/test/parse/cases/6_3_2_3_03_null_void_cast.c @@ -0,0 +1 @@ +int test_main(void){ int *p = (void*)0; return p ? 99 : 42; } diff --git a/test/parse/cases/6_3_2_3_03_null_void_cast.expected b/test/parse/cases/6_3_2_3_03_null_void_cast.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_40_ptr_add.c b/test/parse/cases/6_5_40_ptr_add.c @@ -0,0 +1 @@ +int test_main(void) { int a[4]={0,0,0,42}; int *p=a; p=p+3; return *p; } diff --git a/test/parse/cases/6_5_40_ptr_add.expected b/test/parse/cases/6_5_40_ptr_add.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_41_ptr_sub_ptr.c b/test/parse/cases/6_5_41_ptr_sub_ptr.c @@ -0,0 +1 @@ +int test_main(void) { int a[5]={0}; int *p=a+4; int *q=a+1; return (int)(p-q); } diff --git a/test/parse/cases/6_5_41_ptr_sub_ptr.expected b/test/parse/cases/6_5_41_ptr_sub_ptr.expected @@ -0,0 +1 @@ +3 diff --git a/test/parse/cases/6_5_42_ptr_arith_stride.c b/test/parse/cases/6_5_42_ptr_arith_stride.c @@ -0,0 +1 @@ +int test_main(void) { double a[3]={0.0,0.0,42.0}; double *p=a+2; return (int)*p; } diff --git a/test/parse/cases/6_5_42_ptr_arith_stride.expected b/test/parse/cases/6_5_42_ptr_arith_stride.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_43_signed_rshift.c b/test/parse/cases/6_5_43_signed_rshift.c @@ -0,0 +1 @@ +int test_main(void) { int x = -256; return (int)((x >> 4) + 58); } diff --git a/test/parse/cases/6_5_43_signed_rshift.expected b/test/parse/cases/6_5_43_signed_rshift.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_44_relational_all.c b/test/parse/cases/6_5_44_relational_all.c @@ -0,0 +1 @@ +int test_main(void) { return (3>1) + (1<3) + (2<=2) + (2>=2) + (1!=2) + (2==2); } diff --git a/test/parse/cases/6_5_44_relational_all.expected b/test/parse/cases/6_5_44_relational_all.expected @@ -0,0 +1 @@ +6 diff --git a/test/parse/cases/6_5_45_ptr_eq_null.c b/test/parse/cases/6_5_45_ptr_eq_null.c @@ -0,0 +1 @@ +int test_main(void) { int *p=0; int x=42; int *q=&x; return (p==0) + (q!=0) + (p!=q); } diff --git a/test/parse/cases/6_5_45_ptr_eq_null.expected b/test/parse/cases/6_5_45_ptr_eq_null.expected @@ -0,0 +1 @@ +3 diff --git a/test/parse/cases/6_5_46_ptr_relcmp.c b/test/parse/cases/6_5_46_ptr_relcmp.c @@ -0,0 +1 @@ +int test_main(void) { int a[3]={0}; int *p=a; int *q=a+2; return (p<q) + (q>p) + (p<=p); } diff --git a/test/parse/cases/6_5_46_ptr_relcmp.expected b/test/parse/cases/6_5_46_ptr_relcmp.expected @@ -0,0 +1 @@ +3 diff --git a/test/parse/cases/6_5_47_ternary_arith_conv.c b/test/parse/cases/6_5_47_ternary_arith_conv.c @@ -0,0 +1 @@ +int test_main(void) { int c=1; double r = c ? 1 : 2.5; return (int)(r + 41.0); } diff --git a/test/parse/cases/6_5_47_ternary_arith_conv.expected b/test/parse/cases/6_5_47_ternary_arith_conv.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_48_ternary_ptr_null.c b/test/parse/cases/6_5_48_ternary_ptr_null.c @@ -0,0 +1 @@ +int test_main(void) { int x=42; int *p = 1 ? &x : 0; return *p; } diff --git a/test/parse/cases/6_5_48_ternary_ptr_null.expected b/test/parse/cases/6_5_48_ternary_ptr_null.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_49_compound_assign_sub.c b/test/parse/cases/6_5_49_compound_assign_sub.c @@ -0,0 +1 @@ +int test_main(void) { int x = 44; x -= 2; return x; } diff --git a/test/parse/cases/6_5_49_compound_assign_sub.expected b/test/parse/cases/6_5_49_compound_assign_sub.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_50_compound_assign_shift.c b/test/parse/cases/6_5_50_compound_assign_shift.c @@ -0,0 +1 @@ +int test_main(void) { int x = 336; x >>= 3; return x; } diff --git a/test/parse/cases/6_5_50_compound_assign_shift.expected b/test/parse/cases/6_5_50_compound_assign_shift.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_51_compound_assign_bitwise.c b/test/parse/cases/6_5_51_compound_assign_bitwise.c @@ -0,0 +1 @@ +int test_main(void) { int x = 0xff; x &= 0x7f; x ^= 0x55; x |= 0x00; return x; } diff --git a/test/parse/cases/6_5_51_compound_assign_bitwise.expected b/test/parse/cases/6_5_51_compound_assign_bitwise.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_52_compound_assign_ptr.c b/test/parse/cases/6_5_52_compound_assign_ptr.c @@ -0,0 +1 @@ +int test_main(void) { int a[5] = {0, 0, 0, 0, 42}; int *p = a; p += 4; return *p; } diff --git a/test/parse/cases/6_5_52_compound_assign_ptr.expected b/test/parse/cases/6_5_52_compound_assign_ptr.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_53_sizeof_vla_runtime.c b/test/parse/cases/6_5_53_sizeof_vla_runtime.c @@ -0,0 +1 @@ +int test_main(void) { int n = 7; int a[n]; return (int)sizeof(a); } diff --git a/test/parse/cases/6_5_53_sizeof_vla_runtime.expected b/test/parse/cases/6_5_53_sizeof_vla_runtime.expected @@ -0,0 +1 @@ +28 diff --git a/test/parse/cases/6_5_54_sizeof_deref_ptr.c b/test/parse/cases/6_5_54_sizeof_deref_ptr.c @@ -0,0 +1 @@ +int test_main(void) { double x = 0.0; double *p = &x; return (int)sizeof(*p); } diff --git a/test/parse/cases/6_5_54_sizeof_deref_ptr.expected b/test/parse/cases/6_5_54_sizeof_deref_ptr.expected @@ -0,0 +1 @@ +8 diff --git a/test/parse/cases/6_5_55_generic_default_branch.c b/test/parse/cases/6_5_55_generic_default_branch.c @@ -0,0 +1 @@ +int test_main(void) { double x = 1.0; return _Generic((x), int: 0, default: 42); } diff --git a/test/parse/cases/6_5_55_generic_default_branch.expected b/test/parse/cases/6_5_55_generic_default_branch.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_56_compound_literal_struct.c b/test/parse/cases/6_5_56_compound_literal_struct.c @@ -0,0 +1,2 @@ +struct S { int a, b; }; +int test_main(void) { struct S s = (struct S){.a = 20, .b = 22}; return s.a + s.b; } diff --git a/test/parse/cases/6_5_56_compound_literal_struct.expected b/test/parse/cases/6_5_56_compound_literal_struct.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_5_57_unsigned_wrap_add.c b/test/parse/cases/6_5_57_unsigned_wrap_add.c @@ -0,0 +1 @@ +int test_main(void) { unsigned x = 0xFFFFFFFFU; x += 1; return (int)(x & 0xff); } diff --git a/test/parse/cases/6_5_57_unsigned_wrap_add.expected b/test/parse/cases/6_5_57_unsigned_wrap_add.expected @@ -0,0 +1 @@ +0 diff --git a/test/parse/cases/6_6_04_alignof_array_size.c b/test/parse/cases/6_6_04_alignof_array_size.c @@ -0,0 +1,4 @@ +int test_main(void) { + int a[_Alignof(long long)]; + return (int)sizeof(a) / (int)sizeof(a[0]); +} diff --git a/test/parse/cases/6_6_04_alignof_array_size.expected b/test/parse/cases/6_6_04_alignof_array_size.expected @@ -0,0 +1 @@ +8 diff --git a/test/parse/cases/6_6_05_addr_const_static_init.c b/test/parse/cases/6_6_05_addr_const_static_init.c @@ -0,0 +1,3 @@ +static int g = 7; +static int *p = &g; +int test_main(void) { return *p * 6; } diff --git a/test/parse/cases/6_6_05_addr_const_static_init.expected b/test/parse/cases/6_6_05_addr_const_static_init.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_6_06_addr_const_arith_init.c b/test/parse/cases/6_6_06_addr_const_arith_init.c @@ -0,0 +1,3 @@ +static int arr[4] = {0, 0, 0, 42}; +static int *p = arr + 3; +int test_main(void) { return *p; } diff --git a/test/parse/cases/6_6_06_addr_const_arith_init.expected b/test/parse/cases/6_6_06_addr_const_arith_init.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_10_03_static_assert_file_scope.c b/test/parse/cases/6_7_10_03_static_assert_file_scope.c @@ -0,0 +1,2 @@ +_Static_assert(sizeof(long) >= 4, "long"); +int test_main(void) { return 42; } diff --git a/test/parse/cases/6_7_10_03_static_assert_file_scope.expected b/test/parse/cases/6_7_10_03_static_assert_file_scope.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_1_01_register_sizeof.c b/test/parse/cases/6_7_1_01_register_sizeof.c @@ -0,0 +1,4 @@ +int test_main(void) { + register int x = 42; + return (int)sizeof(x) > 0 ? x : 0; +} diff --git a/test/parse/cases/6_7_1_01_register_sizeof.expected b/test/parse/cases/6_7_1_01_register_sizeof.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_1_02_register_multi_decl.c b/test/parse/cases/6_7_1_02_register_multi_decl.c @@ -0,0 +1,4 @@ +int test_main(void) { + register int x = 40, y = 2; + return x + y; +} diff --git a/test/parse/cases/6_7_1_02_register_multi_decl.expected b/test/parse/cases/6_7_1_02_register_multi_decl.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_01b_unsigned_long_long.c b/test/parse/cases/6_7_2_01b_unsigned_long_long.c @@ -0,0 +1,4 @@ +int test_main(void) { + unsigned long long x = 42ULL; + return (int)x; +} diff --git a/test/parse/cases/6_7_2_01b_unsigned_long_long.expected b/test/parse/cases/6_7_2_01b_unsigned_long_long.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_1_07_signed_bitfield.c b/test/parse/cases/6_7_2_1_07_signed_bitfield.c @@ -0,0 +1,4 @@ +int test_main(void) { + struct { signed int s : 8; } b = {-1}; + return (b.s < 0) ? 42 : 0; +} diff --git a/test/parse/cases/6_7_2_1_07_signed_bitfield.expected b/test/parse/cases/6_7_2_1_07_signed_bitfield.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_1_08_zero_width_bitfield.c b/test/parse/cases/6_7_2_1_08_zero_width_bitfield.c @@ -0,0 +1,6 @@ +int test_main(void) { + struct { unsigned a : 4; unsigned : 0; unsigned b : 4; } s; + s.a = 2; + s.b = 5; + return s.b * 8 + s.a; +} diff --git a/test/parse/cases/6_7_2_1_08_zero_width_bitfield.expected b/test/parse/cases/6_7_2_1_08_zero_width_bitfield.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_1_09_bool_bitfield.c b/test/parse/cases/6_7_2_1_09_bool_bitfield.c @@ -0,0 +1,5 @@ +int test_main(void) { + struct { _Bool b : 1; } s; + s.b = 1; + return s.b ? 42 : 0; +} diff --git a/test/parse/cases/6_7_2_1_09_bool_bitfield.expected b/test/parse/cases/6_7_2_1_09_bool_bitfield.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_2_01_enum_restart.c b/test/parse/cases/6_7_2_2_01_enum_restart.c @@ -0,0 +1,4 @@ +int test_main(void) { + enum C { X = 20, Y, Z = 20, W }; + return Y + W; +} diff --git a/test/parse/cases/6_7_2_2_01_enum_restart.expected b/test/parse/cases/6_7_2_2_01_enum_restart.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_2_3_01_tag_inner_scope.c b/test/parse/cases/6_7_2_3_01_tag_inner_scope.c @@ -0,0 +1,6 @@ +struct S { int v; }; +int test_main(void) { + struct S { int v; }; + struct S s = {42}; + return s.v; +} diff --git a/test/parse/cases/6_7_2_3_01_tag_inner_scope.expected b/test/parse/cases/6_7_2_3_01_tag_inner_scope.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_3_06_repeated_const.c b/test/parse/cases/6_7_3_06_repeated_const.c @@ -0,0 +1,4 @@ +int test_main(void) { + const const int x = 42; + return x; +} diff --git a/test/parse/cases/6_7_3_06_repeated_const.expected b/test/parse/cases/6_7_3_06_repeated_const.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_3_07_const_array_typedef.c b/test/parse/cases/6_7_3_07_const_array_typedef.c @@ -0,0 +1,5 @@ +typedef int A[3]; +int test_main(void) { + const A a = {10, 20, 12}; + return a[0] + a[1] + a[2]; +} diff --git a/test/parse/cases/6_7_3_07_const_array_typedef.expected b/test/parse/cases/6_7_3_07_const_array_typedef.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_4_03_extern_inline.c b/test/parse/cases/6_7_4_03_extern_inline.c @@ -0,0 +1,2 @@ +static inline int add1(int x) { return x + 1; } +int test_main(void) { return add1(41); } diff --git a/test/parse/cases/6_7_4_03_extern_inline.expected b/test/parse/cases/6_7_4_03_extern_inline.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_4_04_repeated_inline.c b/test/parse/cases/6_7_4_04_repeated_inline.c @@ -0,0 +1,2 @@ +static inline inline int id(int x) { return x; } +int test_main(void) { return id(42); } diff --git a/test/parse/cases/6_7_4_04_repeated_inline.expected b/test/parse/cases/6_7_4_04_repeated_inline.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_5_03_alignas_zero.c b/test/parse/cases/6_7_5_03_alignas_zero.c @@ -0,0 +1,2 @@ +_Alignas(0) static int x = 42; +int test_main(void) { return x; } diff --git a/test/parse/cases/6_7_5_03_alignas_zero.expected b/test/parse/cases/6_7_5_03_alignas_zero.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_5_04_alignas_multi.c b/test/parse/cases/6_7_5_04_alignas_multi.c @@ -0,0 +1,2 @@ +_Alignas(16) _Alignas(8) static char buf[16]; +int test_main(void) { return (((unsigned long)buf) & 15) ? 0 : 42; } diff --git a/test/parse/cases/6_7_5_04_alignas_multi.expected b/test/parse/cases/6_7_5_04_alignas_multi.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_09_ptr_to_array.c b/test/parse/cases/6_7_6_09_ptr_to_array.c @@ -0,0 +1,5 @@ +int test_main(void) { + int b[3] = {0, 0, 42}; + int (*pa)[3] = &b; + return (*pa)[2]; +} diff --git a/test/parse/cases/6_7_6_09_ptr_to_array.expected b/test/parse/cases/6_7_6_09_ptr_to_array.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_10_array_of_funcptr.c b/test/parse/cases/6_7_6_10_array_of_funcptr.c @@ -0,0 +1,6 @@ +int add1(int x) { return x + 1; } +int sub1(int x) { return x - 1; } +int test_main(void) { + int (*ops[2])(int) = {add1, sub1}; + return ops[0](ops[1](42)); +} diff --git a/test/parse/cases/6_7_6_10_array_of_funcptr.expected b/test/parse/cases/6_7_6_10_array_of_funcptr.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_11_func_returning_funcptr.c b/test/parse/cases/6_7_6_11_func_returning_funcptr.c @@ -0,0 +1,4 @@ +typedef int (*FP)(int); +int id(int x) { return x; } +FP getfp(void) { return id; } +int test_main(void) { return getfp()(42); } diff --git a/test/parse/cases/6_7_6_11_func_returning_funcptr.expected b/test/parse/cases/6_7_6_11_func_returning_funcptr.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_12_vla_param.c b/test/parse/cases/6_7_6_12_vla_param.c @@ -0,0 +1,9 @@ +int sum_vla(int n, int a[n]) { + int s = 0; + for (int i = 0; i < n; i++) s += a[i]; + return s; +} +int test_main(void) { + int a[3] = {10, 20, 12}; + return sum_vla(3, a); +} diff --git a/test/parse/cases/6_7_6_12_vla_param.expected b/test/parse/cases/6_7_6_12_vla_param.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_6_13_star_in_proto.c b/test/parse/cases/6_7_6_13_star_in_proto.c @@ -0,0 +1,10 @@ +int total(int n, int a[*]); +int total(int n, int a[n]) { + int s = 0; + for (int i = 0; i < n; i++) s += a[i]; + return s; +} +int test_main(void) { + int b[3] = {1, 2, 39}; + return total(3, b); +} diff --git a/test/parse/cases/6_7_6_13_star_in_proto.expected b/test/parse/cases/6_7_6_13_star_in_proto.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_7_01_abstract_ptr_array_cast.c b/test/parse/cases/6_7_7_01_abstract_ptr_array_cast.c @@ -0,0 +1,5 @@ +int test_main(void) { + int b[3] = {0, 0, 42}; + void *v = &b; + return ((int (*)[3])v)[0][2]; +} diff --git a/test/parse/cases/6_7_7_01_abstract_ptr_array_cast.expected b/test/parse/cases/6_7_7_01_abstract_ptr_array_cast.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_8_05_typedef_vla_size_fixed.c b/test/parse/cases/6_7_8_05_typedef_vla_size_fixed.c @@ -0,0 +1,8 @@ +int f(int n) { + typedef int B[n]; + n += 10; + B a; + for (int i = 0; i < (int)(sizeof(a) / sizeof(int)); i++) a[i] = i * 6; + return a[6]; +} +int test_main(void) { return f(7); } diff --git a/test/parse/cases/6_7_8_05_typedef_vla_size_fixed.expected b/test/parse/cases/6_7_8_05_typedef_vla_size_fixed.expected @@ -0,0 +1 @@ +36 diff --git a/test/parse/cases/6_7_8_06_typedef_multi_decl.c b/test/parse/cases/6_7_8_06_typedef_multi_decl.c @@ -0,0 +1,8 @@ +typedef int TWICE, (*PFUNC)(int); +int dbl(int x) { return x * 2; } +int test_main(void) { + TWICE y = 0; + PFUNC fp = dbl; + y = fp(21); + return y; +} diff --git a/test/parse/cases/6_7_8_06_typedef_multi_decl.expected b/test/parse/cases/6_7_8_06_typedef_multi_decl.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_9_11_array_size_from_init.c b/test/parse/cases/6_7_9_11_array_size_from_init.c @@ -0,0 +1,4 @@ +int test_main(void) { + int x[] = {10, 12, 20}; + return x[0] + x[1] + x[2]; +} diff --git a/test/parse/cases/6_7_9_11_array_size_from_init.expected b/test/parse/cases/6_7_9_11_array_size_from_init.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_9_12_designator_override.c b/test/parse/cases/6_7_9_12_designator_override.c @@ -0,0 +1,4 @@ +int test_main(void) { + int a[3] = {[1] = 99, [1] = 42, [0] = 0}; + return a[1]; +} diff --git a/test/parse/cases/6_7_9_12_designator_override.expected b/test/parse/cases/6_7_9_12_designator_override.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_9_13_string_init_fixed_larger.c b/test/parse/cases/6_7_9_13_string_init_fixed_larger.c @@ -0,0 +1,6 @@ +int test_main(void) { + char s[6] = "hi"; + int sum = 0; + for (int i = 0; i < 6; i++) sum += s[i]; + return sum; +} diff --git a/test/parse/cases/6_7_9_13_string_init_fixed_larger.expected b/test/parse/cases/6_7_9_13_string_init_fixed_larger.expected @@ -0,0 +1 @@ +209 diff --git a/test/parse/cases/6_7_9_14_struct_copy_init.c b/test/parse/cases/6_7_9_14_struct_copy_init.c @@ -0,0 +1,5 @@ +int test_main(void) { + struct S { int a, b; } src = {20, 22}; + struct S dst = src; + return dst.a + dst.b; +} diff --git a/test/parse/cases/6_7_9_14_struct_copy_init.expected b/test/parse/cases/6_7_9_14_struct_copy_init.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_9_15_union_designated_nonfirst.c b/test/parse/cases/6_7_9_15_union_designated_nonfirst.c @@ -0,0 +1,4 @@ +int test_main(void) { + union U { int a; int b; } u = {.b = 42}; + return u.b; +} diff --git a/test/parse/cases/6_7_9_15_union_designated_nonfirst.expected b/test/parse/cases/6_7_9_15_union_designated_nonfirst.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_9_16_enum_designator.c b/test/parse/cases/6_7_9_16_enum_designator.c @@ -0,0 +1,5 @@ +int test_main(void) { + enum { X = 2 }; + int a[4] = {[X] = 42}; + return a[X]; +} diff --git a/test/parse/cases/6_7_9_16_enum_designator.expected b/test/parse/cases/6_7_9_16_enum_designator.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_7_9_17_inconsistent_bracket_init.c b/test/parse/cases/6_7_9_17_inconsistent_bracket_init.c @@ -0,0 +1,4 @@ +int test_main(void) { + struct T { int a[2]; int b; } w[2] = {{1}, 2}; + return w[0].a[0] + w[1].a[0]; +} diff --git a/test/parse/cases/6_7_9_17_inconsistent_bracket_init.expected b/test/parse/cases/6_7_9_17_inconsistent_bracket_init.expected @@ -0,0 +1 @@ +3 diff --git a/test/parse/cases/6_8_16_dangling_else.c b/test/parse/cases/6_8_16_dangling_else.c @@ -0,0 +1,5 @@ +int test_main(void) { + int r = 0; + if (1) if (0) r = 1; else r = 42; + return r; +} diff --git a/test/parse/cases/6_8_16_dangling_else.expected b/test/parse/cases/6_8_16_dangling_else.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_8_17_switch_char_ctrl.c b/test/parse/cases/6_8_17_switch_char_ctrl.c @@ -0,0 +1,9 @@ +int test_main(void) { + char c = 2; + int r = 0; + switch (c) { + case 1: r = 1; break; + case 2: r = 42; break; + } + return r; +} diff --git a/test/parse/cases/6_8_17_switch_char_ctrl.expected b/test/parse/cases/6_8_17_switch_char_ctrl.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_8_18_switch_no_match_no_default.c b/test/parse/cases/6_8_18_switch_no_match_no_default.c @@ -0,0 +1,9 @@ +int test_main(void) { + int x = 99; + int r = 7; + switch (x) { + case 1: r = 1; break; + case 2: r = 2; break; + } + return r; +} diff --git a/test/parse/cases/6_8_18_switch_no_match_no_default.expected b/test/parse/cases/6_8_18_switch_no_match_no_default.expected @@ -0,0 +1 @@ +7 diff --git a/test/parse/cases/6_8_19_switch_nested_dup_case.c b/test/parse/cases/6_8_19_switch_nested_dup_case.c @@ -0,0 +1,12 @@ +int test_main(void) { + int r = 0; + switch (1) { + case 1: + switch (2) { + case 1: r = 0; break; + case 2: r = 42; break; + } + break; + } + return r; +} diff --git a/test/parse/cases/6_8_19_switch_nested_dup_case.expected b/test/parse/cases/6_8_19_switch_nested_dup_case.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_8_20_switch_hidden_scope.c b/test/parse/cases/6_8_20_switch_hidden_scope.c @@ -0,0 +1,9 @@ +int test_main(void) { + int r = 0; + switch (1) { + int x = 99; + (void)x; + case 1: r = 42; + } + return r; +} diff --git a/test/parse/cases/6_8_20_switch_hidden_scope.expected b/test/parse/cases/6_8_20_switch_hidden_scope.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_8_21_for_infinite_break.c b/test/parse/cases/6_8_21_for_infinite_break.c @@ -0,0 +1,8 @@ +int test_main(void) { + int i = 0; + for (;;) { + i++; + if (i == 42) break; + } + return i; +} diff --git a/test/parse/cases/6_8_21_for_infinite_break.expected b/test/parse/cases/6_8_21_for_infinite_break.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_8_23_continue_do_while.c b/test/parse/cases/6_8_23_continue_do_while.c @@ -0,0 +1,9 @@ +int test_main(void) { + int s = 0, i = 0; + do { + i++; + if (i % 2 == 0) continue; + s += i; + } while (i < 10); + return s; +} diff --git a/test/parse/cases/6_8_23_continue_do_while.expected b/test/parse/cases/6_8_23_continue_do_while.expected @@ -0,0 +1 @@ +25 diff --git a/test/parse/cases/6_8_24_break_switch_in_loop.c b/test/parse/cases/6_8_24_break_switch_in_loop.c @@ -0,0 +1,9 @@ +int test_main(void) { + int r = 0; + for (int i = 0; i < 5; i++) { + switch (i) { + case 3: r = i; break; + } + } + return r; +} diff --git a/test/parse/cases/6_8_24_break_switch_in_loop.expected b/test/parse/cases/6_8_24_break_switch_in_loop.expected @@ -0,0 +1 @@ +3 diff --git a/test/parse/cases/6_8_25_continue_inside_switch.c b/test/parse/cases/6_8_25_continue_inside_switch.c @@ -0,0 +1,10 @@ +int test_main(void) { + int s = 0; + for (int i = 0; i < 5; i++) { + switch (i % 2) { + case 0: continue; + default: s += i; + } + } + return s; +} diff --git a/test/parse/cases/6_8_25_continue_inside_switch.expected b/test/parse/cases/6_8_25_continue_inside_switch.expected @@ -0,0 +1 @@ +4 diff --git a/test/parse/cases/6_8_26_goto_into_nested_block.c b/test/parse/cases/6_8_26_goto_into_nested_block.c @@ -0,0 +1,9 @@ +int test_main(void) { + int r = 0; + goto inner; + { + inner: + r = 42; + } + return r; +} diff --git a/test/parse/cases/6_8_26_goto_into_nested_block.expected b/test/parse/cases/6_8_26_goto_into_nested_block.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_8_27_label_on_null_stmt.c b/test/parse/cases/6_8_27_label_on_null_stmt.c @@ -0,0 +1,5 @@ +int test_main(void) { + goto end; +end: ; + return 42; +} diff --git a/test/parse/cases/6_8_27_label_on_null_stmt.expected b/test/parse/cases/6_8_27_label_on_null_stmt.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_8_28_return_narrow_convert.c b/test/parse/cases/6_8_28_return_narrow_convert.c @@ -0,0 +1,4 @@ +unsigned char narrow(int x) { return x; } +int test_main(void) { + return narrow(298); +} diff --git a/test/parse/cases/6_8_28_return_narrow_convert.expected b/test/parse/cases/6_8_28_return_narrow_convert.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_9_11_tentative_multi.c b/test/parse/cases/6_9_11_tentative_multi.c @@ -0,0 +1,3 @@ +int g; +int g; +int test_main(void) { return g + 42; } diff --git a/test/parse/cases/6_9_11_tentative_multi.expected b/test/parse/cases/6_9_11_tentative_multi.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_9_12_tentative_incomplete_array.c b/test/parse/cases/6_9_12_tentative_incomplete_array.c @@ -0,0 +1,3 @@ +int arr[]; +int arr[3]; +int test_main(void) { return arr[0] + arr[1] + arr[2] + 42; } diff --git a/test/parse/cases/6_9_12_tentative_incomplete_array.expected b/test/parse/cases/6_9_12_tentative_incomplete_array.expected @@ -0,0 +1 @@ +42 diff --git a/test/parse/cases/6_9_13_extern_func_def.c b/test/parse/cases/6_9_13_extern_func_def.c @@ -0,0 +1,2 @@ +extern int helper(int x) { return x + 1; } +int test_main(void) { return helper(41); } diff --git a/test/parse/cases/6_9_13_extern_func_def.expected b/test/parse/cases/6_9_13_extern_func_def.expected @@ -0,0 +1 @@ +42