diff --git a/Makefile b/Makefile index 4a28fd07..86b9e118 100644 --- a/Makefile +++ b/Makefile @@ -544,7 +544,6 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \ $(BIN)/test_checked_run \ $(BIN)/test_floatarr_run \ $(BIN)/test_inferred_scalar_global_run \ - $(BIN)/test_dotbase_addr_slice_run \ $(BIN)/test_globalslice_arg_run \ $(BIN)/test_structlit_arrfield_run \ $(BIN)/test_defdim_struct_run \ @@ -3024,11 +3023,6 @@ $(BIN)/test_inferred_scalar_global_run: test/wcc/947_inferred_scalar_global_run. $(LIB)/libwwrt.a | $(BIN) $(CC) $(CFLAGS) -o $@ $< -$(BIN)/test_dotbase_addr_slice_run: test/wcc/949_dotbase_addr_slice_run.c \ - $(BIN)/ww $(BIN)/w6c $(BIN)/w6c_ww $(BIN)/w6a $(BIN)/w6l \ - $(LIB)/libwwrt.a | $(BIN) - $(CC) $(CFLAGS) -o $@ $< - $(BIN)/test_globalslice_arg_run: test/wcc/953_globalslice_arg_run.c \ $(BIN)/ww $(BIN)/w6c $(BIN)/w6c_ww $(BIN)/w6a $(BIN)/w6l \ $(LIB)/libwwrt.a | $(BIN) @@ -3278,9 +3272,9 @@ test-lang: all # (`ww build --sep` over selfhost/data) plus //ww:error reject-routing (assert # both legs fail) — no reject cases exist in test/lang today. LANGBYTEID_DIR = $(OUT)/langbyteid -LANGBYTEID_FILES = $(wildcard test/lang/*_test.ww) +LANGBYTEID_FILES = $(filter-out %_runonly_test.ww,$(wildcard test/lang/*_test.ww)) LANGBYTEID_VERB = test -c -LANGBYTEID_EXPECTED_MIN = 54 +LANGBYTEID_EXPECTED_MIN = 55 $(if $(LANGBYTEID_FILES),,$(error test-lang-byteid: empty corpus)) test-lang-byteid: all @set -e; \ diff --git a/test/lang/dotbase_addr_slice_runonly_test.ww b/test/lang/dotbase_addr_slice_runonly_test.ww new file mode 100644 index 00000000..885a0500 --- /dev/null +++ b/test/lang/dotbase_addr_slice_runonly_test.ww @@ -0,0 +1,69 @@ +// dotbase_addr_slice_runonly_test — the VALUE-nested-struct cell of the +// array-field-base-address family (#253 chained-base / #270-3a aggregate +// index-base copy), migrated from test/wcc/949_dotbase_addr_slice_run.c. +// +// RUN-ONLY (#254): these rows exercise the SAME fixed cg_dotbase_addr / +// dotchainaddr helper as their sibling dotbase_addr_slice_test.ww rows and +// run CORRECTLY — the #253 segfault is gone for the value-container cell. +// But a value nested-struct instance trips TWO orthogonal pre-existing +// cs!=ww emission divergences, unrelated to the base-address fix: +// 1. bare-let zero-init policy — wwstage emits an extra `MOVQ $0,off(BP)` +// for a value nested-struct local that cstage does not; +// 2. global DATAW byte count — wwstage over-emits. +// Until #254 fixes both, the rule-10 T2 byte-id gate cannot apply to these +// rows. The `_runonly_test.ww` filename suffix is the EXPLICIT opt-out that +// excludes this file from LANGBYTEID_FILES (Makefile) — value-run only, no +// byteid. They stay as LIVE run-only value pins proving the segfault is gone +// for the value cell; never dropped. PRIMITIVE-only asserts (read back the +// value; a wrong base yields a wrong readback) — no fmt/strconv. + +package dotbase_addr_slice_runonly_test; + +type vinner = struct { m: [4]u8 }; +type outv = struct { i: vinner }; + +// #253 chained VALUE-container arm (o.i.m — inner is a value nested struct). +@test fn chain_val_rd() void = { + let o: outv; o.i.m[1] = 66u8; + assert(o.i.m[1]: i32 == 66i32); +}; + +@test fn chain_val_addr() void = { + let o: outv; o.i.m[2] = 55u8; + let q: *u8 = &o.i.m[2]; + assert((*q): i32 == 55i32); +}; + +@test fn chain_val_slice() void = { + let o: outv; o.i.m[1] = 66u8; + let s: []u8 = o.i.m[1:4]; + assert(len(s): i32 == 3i32); + assert(s[0]: i32 == 66i32); +}; + +type vmid = struct { b: vinner }; +type vtop = struct { a: vmid }; +@test fn chain_deep_val() void = { + let o: vtop; o.a.b.m[1] = 66u8; + assert(o.a.b.m[1]: i32 == 66i32); +}; + +// #270-3a value-struct aggregate index-base let-init copy. Same #254 +// carve-out as chain_val_* above (the .c marked these byteid=0 explicitly). +type lcinner = struct { a: u32, b: u32, c: u32 }; +type lcbox = struct { arr: [3]lcinner }; +@test fn letcopy_dot_struct() void = { + let x: lcbox; + let v: lcinner; v.a = 10u32; v.b = 20u32; v.c = 30u32; + x.arr[1] = v; + let c: lcinner = x.arr[1]; + assert((c.a + c.b + c.c): i32 == 60i32); +}; + +@test fn letcopy_nest_struct() void = { + let a: [2][2]lcinner; + let v: lcinner; v.a = 11u32; v.b = 22u32; v.c = 33u32; + a[1][0] = v; + let c: lcinner = a[1][0]; + assert((c.a + c.b + c.c): i32 == 66i32); +}; diff --git a/test/lang/dotbase_addr_slice_test.ww b/test/lang/dotbase_addr_slice_test.ww new file mode 100644 index 00000000..ef5db95e --- /dev/null +++ b/test/lang/dotbase_addr_slice_test.ww @@ -0,0 +1,914 @@ +// dotbase_addr_slice_test — the array-field-base-address family: addr-of + +// slice of a struct's `[N]T` FIELD (#252), the CHAINED-base close-out (#253), +// the signed-narrow N_DOT-base index load (#255), the call-arg consumption +// axis (#257), the tagged-element store/read/return cluster (#259/#261/#263), +// the aggregate addressable-rhs let-init / arg / return copy axes +// (#265/#268/#271), the array return-by-value ABI (#267), nested-array stride +// + array-of-struct element store + array-literal element store (#270), and +// the aggregate def-global copy (#268). Migrated from +// test/wcc/949_dotbase_addr_slice_run.c. +// +// The shared root: taking `&x.o[i]` / slicing `x.o[lo:hi]` / indexing a +// chained `o.p.m[i]` of an `[N]T`-typed FIELD must compute the field's +// ADDRESS (LEAQ), not auto-deref its first 8 bytes AS a pointer (MOVL) — +// garbage base -> segfault. cg_dotbase_addr/dotbaseaddr (+ the dotchain spine +// for chained inners) close the whole family; every op (index r/w, addr-of, +// slice, compound, store, call-arg, copy) routes through the one helper. +// cs==ww broken IDENTICALLY pre-fix (gate-blind, pure correctness), so the +// .s is byte-identical post-fix and the T2 byteid gate is the rule-10 net; +// these behavioral @tests are the runtime net. PRIMITIVE-only asserts (read +// back the value through the &-derived pointer / slice; a wrong base or a +// dropped header/word yields a wrong readback) — no fmt/strconv anywhere. +// +// The chained VALUE-container arm (`o.i.m`, value nested struct) and the +// value-nested-struct let-init copy rows are byteid=0 (#254: bare-let +// zero-init extra MOVQ $0 + global DATAW over-emit) and live in the sibling +// dotbase_addr_slice_runonly_test.ww, excluded from T2 by the _runonly_ +// suffix. + +package dotbase_addr_slice_test; + +// ---- shared element-array struct shapes (field `o`) -------------------- +type eu8 = struct { o: [4]u8 }; +type ei32 = struct { o: [4]i32 }; +type ei16 = struct { o: [4]i16 }; +type ei8 = struct { o: [4]i8 }; + +// ---- chained-base shapes (#253): inner field `m`, pointer-outer ---------- +type cinner = struct { m: [4]u8 }; // also the ctrl `e` shape +type couter = struct { p: *cinner }; +type cinneri = struct { m: [4]i32 }; +type couteri = struct { p: *cinneri }; + +// ============================ #252 bare-ident ============================ +@test fn addr_local_u8() void = { + let x: eu8; + x.o[1] = 66u8; + let p: *u8 = &x.o[1]; + assert((*p): i32 == 66i32); +}; + +fn rd_addr_ptr_u8(x: *eu8) u8 = { let p: *u8 = &x.o[2]; return *p; }; +@test fn addr_ptr_u8() void = { + let x: eu8; + x.o[2] = 77u8; + assert(rd_addr_ptr_u8(&x): i32 == 77i32); +}; + +@test fn addr_i32() void = { + let x: ei32; + x.o[2] = 88; + let p: *i32 = &x.o[2]; + assert(*p == 88i32); +}; + +@test fn slice_u8_expl() void = { + let x: eu8; + x.o[1] = 66u8; + let s: []u8 = x.o[1:4]; + assert(len(s): i32 == 3i32); + assert(s[0]: i32 == 66i32); +}; + +@test fn slice_u8_dflthi() void = { + let x: eu8; + x.o[1] = 66u8; + let s: []u8 = x.o[1:]; + assert(len(s): i32 == 3i32); + assert(s[0]: i32 == 66i32); +}; + +fn sl_slice_ptr_u8(x: *eu8) u8 = { let s: []u8 = x.o[1:4]; return s[0]; }; +@test fn slice_ptr_u8() void = { + let x: eu8; + x.o[1] = 66u8; + assert(sl_slice_ptr_u8(&x): i32 == 66i32); +}; + +@test fn slice_i32_expl() void = { + let x: ei32; + x.o[1] = 99; + x.o[2] = 88; + let s: []i32 = x.o[1:3]; + assert(len(s): i32 == 2i32); + assert(s[1] == 88i32); +}; + +@test fn slice_i32_dflt() void = { + let x: ei32; + x.o[3] = 55; + let s: []i32 = x.o[1:]; + assert(len(s): i32 == 3i32); + assert(s[2] == 55i32); +}; + +@test fn control_bare() void = { + let a: [4]u8; + a[2] = 44u8; + let p: *u8 = &a[1]; + *p = 33u8; + let s: []u8 = a[1:4]; + assert(s[0]: i32 == 33i32); // the &a[1] write landed + assert(s[1]: i32 == 44i32); +}; + +// ============================ #253 chained-base ========================== +@test fn chain_ptr_rd() void = { + let a: cinner; a.m[1] = 66u8; + let o: couter; o.p = &a; + assert(o.p.m[1]: i32 == 66i32); +}; + +@test fn chain_ptr_wr() void = { + let a: cinner; + let o: couter; o.p = &a; + o.p.m[2] = 77u8; + assert(a.m[2]: i32 == 77i32); +}; + +@test fn chain_ptr_addr() void = { + let a: cinner; a.m[2] = 55u8; + let o: couter; o.p = &a; + let q: *u8 = &o.p.m[2]; + assert((*q): i32 == 55i32); +}; + +@test fn chain_ptr_sl_e() void = { + let a: cinner; a.m[1] = 66u8; + let o: couter; o.p = &a; + let s: []u8 = o.p.m[1:4]; + assert(len(s): i32 == 3i32); + assert(s[0]: i32 == 66i32); +}; + +@test fn chain_ptr_sl_d() void = { + let a: cinner; a.m[1] = 66u8; + let o: couter; o.p = &a; + let s: []u8 = o.p.m[1:]; + assert(len(s): i32 == 3i32); + assert(s[0]: i32 == 66i32); +}; + +@test fn chain_ptr_comp() void = { + let a: cinner; a.m[1] = 60u8; + let o: couter; o.p = &a; + o.p.m[1] += 6u8; + assert(o.p.m[1]: i32 == 66i32); +}; + +type cmid = struct { b: *cinner }; +type ctop = struct { a: cmid }; +@test fn chain_deep_lf() void = { + let z: cinner; z.m[1] = 66u8; + let o: ctop; o.a.b = &z; + assert(o.a.b.m[1]: i32 == 66i32); +}; + +type camid = struct { q: *cinner }; +type cotop = struct { p: *camid }; +@test fn chain_triple() void = { + let z: cinner; z.m[1] = 66u8; + let aa: camid; aa.q = &z; + let o: cotop; o.p = &aa; + assert(o.p.q.m[1]: i32 == 66i32); +}; + +@test fn chain_tri_comp() void = { + let z: cinner; z.m[1] = 60u8; + let aa: camid; aa.q = &z; + let o: cotop; o.p = &aa; + o.p.q.m[1] += 6u8; + assert(o.p.q.m[1]: i32 == 66i32); +}; + +@test fn chain_i32_addr() void = { + let a: cinneri; a.m[2] = 88; + let o: couteri; o.p = &a; + let q: *i32 = &o.p.m[2]; + assert(*q == 88i32); +}; + +@test fn chain_i32_slice() void = { + let a: cinneri; a.m[1] = 99; a.m[2] = 88; + let o: couteri; o.p = &a; + let s: []i32 = o.p.m[1:3]; + assert(len(s): i32 == 2i32); + assert(s[1] == 88i32); +}; + +fn rd_ctrl_ptr_rd(p: *cinner) u8 = { return p.m[1]; }; +@test fn ctrl_ptr_rd() void = { + let x: cinner; x.m[1] = 66u8; + assert(rd_ctrl_ptr_rd(&x): i32 == 66i32); +}; + +@test fn ctrl_local_rd() void = { + let x: cinner; x.m[1] = 66u8; + assert(x.m[1]: i32 == 66i32); +}; + +// ============================ #255 signed-narrow ========================= +@test fn nload_i32() void = { + let x: ei32; + x.o[2] = -5; + let v: i32 = x.o[2]; + assert(v == -5i32); +}; + +@test fn nload_i16() void = { + let x: ei16; + x.o[2] = -5i16; + let v: i16 = x.o[2]; + assert(v: i32 == -5i32); +}; + +@test fn nload_i8() void = { + let x: ei8; + x.o[2] = -5i8; + let v: i8 = x.o[2]; + assert(v: i32 == -5i32); +}; + +// ============================ #257 call-arg ============================== +fn rd_callarg_u8(b: []u8) i32 = { return b[0]: i32; }; +@test fn callarg_u8() void = { + let x: eu8; + x.o[1] = 66u8; + assert(rd_callarg_u8(x.o[1:4]) == 66i32); +}; + +fn rd_callarg_i32(b: []i32) i32 = { return b[0]; }; +@test fn callarg_i32() void = { + let x: ei32; + x.o[1] = 88; + assert(rd_callarg_i32(x.o[1:3]) == 88i32); +}; + +fn rd_callarg_ptr_u8(b: []u8) i32 = { return b[0]: i32; }; +fn f_callarg_ptr_u8(p: *eu8) i32 = { return rd_callarg_ptr_u8(p.o[1:4]); }; +@test fn callarg_ptr_u8() void = { + let x: eu8; + x.o[1] = 66u8; + assert(f_callarg_ptr_u8(&x) == 66i32); +}; + +fn rd_callarg_chain(b: []u8) i32 = { return b[0]: i32; }; +@test fn callarg_chain() void = { + let a: cinner; a.m[1] = 66u8; + let o: couter; o.p = &a; + assert(rd_callarg_chain(o.p.m[1:4]) == 66i32); +}; + +fn rd_callarg_ctrl_local(b: []u8) i32 = { return b[0]: i32; }; +@test fn callarg_ctrl_local() void = { + let x: eu8; + x.o[1] = 66u8; + let sl: []u8 = x.o[1:4]; + assert(rd_callarg_ctrl_local(sl) == 66i32); +}; + +fn rd_callarg_ctrl_arr(b: []u8) i32 = { return b[0]: i32; }; +@test fn callarg_ctrl_arr() void = { + let a: [4]u8; + a[1] = 66u8; + assert(rd_callarg_ctrl_arr(a[1:4]) == 66i32); +}; + +type wsf = struct { v: []i32 }; +fn rd_callarg_slicefield(s: []i32) i32 = { return s[0]; }; +@test fn callarg_slicefield() void = { + let backing: [4]i32; + backing[1] = 88; + let q: wsf; + q.v = backing[0:4]; + assert(rd_callarg_slicefield(q.v[1:3]) == 88i32); +}; + +type wstr = struct { v: str }; +fn rd_callarg_strfield(s: str) i32 = { return len(s): i32; }; +@test fn callarg_strfield() void = { + let q: wstr; + q.v = "hello"; + assert(rd_callarg_strfield(q.v[1:4]) == 3i32); +}; + +// ===================== #259/#261/#263 tagged cluster ===================== +type etag = struct { o: [4](i32 | void) }; +type etagnull = struct { o: [4](*i32 | void) }; +type mtag2d = struct { g: [2][2](i32 | void) }; + +@test fn tagged_store_own() void = { + let x: etag; + x.o[1] = 66; + let v: (i32 | void) = x.o[1]; + let r: i32 = match (v) { + case let n: i32 => yield n; + case void => yield 0: i32; + }; + assert(r == 66i32); +}; + +fn wr_tagged_store_ptr(x: *etag) void = { x.o[2] = 77; }; +@test fn tagged_store_ptr() void = { + let x: etag; + wr_tagged_store_ptr(&x); + let v: (i32 | void) = x.o[2]; + let r: i32 = match (v) { + case let n: i32 => yield n; + case void => yield 0: i32; + }; + assert(r == 77i32); +}; + +@test fn tagged_store_own_rd() void = { + let x: etag; + x.o[1] = 66; + let v: (i32 | void) = x.o[1]; + let r: i32 = match (v) { + case let n: i32 => yield n; + case void => yield 0: i32; + }; + assert(r == 66i32); +}; + +fn wr_tagged_store_ptr_rd(x: *etag) void = { x.o[2] = 77; }; +@test fn tagged_store_ptr_rd() void = { + let x: etag; + wr_tagged_store_ptr_rd(&x); + let v: (i32 | void) = x.o[2]; + let r: i32 = match (v) { + case let n: i32 => yield n; + case void => yield 0: i32; + }; + assert(r == 77i32); +}; + +@test fn tagged_rd_void() void = { + let x: etag; + x.o[1] = void; + let v: (i32 | void) = x.o[1]; + let r: i32 = match (v) { + case let n: i32 => yield 99: i32; + case void => yield 1: i32; + }; + assert(r == 1i32); +}; + +fn take_tagged_callarg_i32(v: (i32 | void)) i32 = { + return match (v) { + case let n: i32 => yield n; + case void => yield 1: i32; + }; +}; +@test fn tagged_callarg_i32() void = { + let x: etag; + x.o[2] = 55; + assert(take_tagged_callarg_i32(x.o[2]) == 55i32); +}; + +fn take_tagged_callarg_void(v: (i32 | void)) i32 = { + return match (v) { + case let n: i32 => yield 99: i32; + case void => yield 1: i32; + }; +}; +@test fn tagged_callarg_void() void = { + let x: etag; + x.o[2] = void; + assert(take_tagged_callarg_void(x.o[2]) == 1i32); +}; + +fn ret_tagged_return_i32(x: *etag) (i32 | void) = { return x.o[1]; }; +@test fn tagged_return_i32() void = { + let x: etag; + x.o[1] = 88; + let v: (i32 | void) = ret_tagged_return_i32(&x); + let r: i32 = match (v) { + case let n: i32 => yield n; + case void => yield 1: i32; + }; + assert(r == 88i32); +}; + +fn ret_tagged_return_void(x: *etag) (i32 | void) = { return x.o[1]; }; +@test fn tagged_return_void() void = { + let x: etag; + x.o[1] = void; + let v: (i32 | void) = ret_tagged_return_void(&x); + let r: i32 = match (v) { + case let n: i32 => yield 99: i32; + case void => yield 1: i32; + }; + assert(r == 1i32); +}; + +@test fn tagged_chained_i32() void = { + let y: mtag2d; + y.g[1][1] = 44; + let v: (i32 | void) = y.g[1][1]; + let r: i32 = match (v) { + case let n: i32 => yield n; + case void => yield 1: i32; + }; + assert(r == 44i32); +}; + +@test fn tagged_chained_void() void = { + let y: mtag2d; + y.g[1][1] = void; + let v: (i32 | void) = y.g[1][1]; + let r: i32 = match (v) { + case let n: i32 => yield 99: i32; + case void => yield 1: i32; + }; + assert(r == 1i32); +}; + +@test fn tagged_ctrl_bare_rd() void = { + let a: [4](i32 | void); + a[1] = 33; + let v: (i32 | void) = a[1]; + let r: i32 = match (v) { + case let n: i32 => yield n; + case void => yield 1: i32; + }; + assert(r == 33i32); +}; + +@test fn tagged_null_ptr_rd() void = { + let k: i32 = 7; + let x: etagnull; + x.o[1] = &k; + let v: (*i32 | void) = x.o[1]; + let r: i32 = match (v) { + case let p: *i32 => yield 55: i32; + case void => yield 1: i32; + }; + assert(r == 55i32); +}; + +@test fn tagged_null_void_rd() void = { + let x: etagnull; + x.o[1] = void; + let v: (*i32 | void) = x.o[1]; + let r: i32 = match (v) { + case let p: *i32 => yield 99: i32; + case void => yield 1: i32; + }; + assert(r == 1i32); +}; + +fn g_tagged_ident_ret_i32() (i32 | void) = { let v: (i32 | void) = 7i32; return v; }; +@test fn tagged_ident_ret_i32() void = { + let r: i32 = match (g_tagged_ident_ret_i32()) { + case let n: i32 => yield n; + case void => yield 1: i32; + }; + assert(r == 7i32); +}; + +fn g_tagged_ident_ret_void() (i32 | void) = { let v: (i32 | void) = void; return v; }; +@test fn tagged_ident_ret_void() void = { + let r: i32 = match (g_tagged_ident_ret_void()) { + case let n: i32 => yield 99: i32; + case void => yield 1: i32; + }; + assert(r == 1i32); +}; + +fn inner_tagged_call_ret_ctrl() (i32 | void) = { let v: (i32 | void) = 42i32; return v; }; +fn outer_tagged_call_ret_ctrl() (i32 | void) = { return inner_tagged_call_ret_ctrl(); }; +@test fn tagged_call_ret_ctrl() void = { + let r: i32 = match (outer_tagged_call_ret_ctrl()) { + case let n: i32 => yield n; + case void => yield 1: i32; + }; + assert(r == 42i32); +}; + +type wtagfield = struct { f: (i32 | void) }; +fn dot_tagged_dot_ret_ctrl(x: *wtagfield) (i32 | void) = { return x.f; }; +@test fn tagged_dot_ret_ctrl() void = { + let x: wtagfield; + x.f = 63; + let r: i32 = match (dot_tagged_dot_ret_ctrl(&x)) { + case let n: i32 => yield n; + case void => yield 1: i32; + }; + assert(r == 63i32); +}; + +// ===================== #265 aggregate deref-rhs let-init ================= +type t16 = struct { h: [4]u32 }; +type t32 = struct { h: [8]u32 }; + +@test fn deref_struct16() void = { + let s: t16; + s.h[0]=10u32; s.h[1]=20u32; s.h[2]=30u32; s.h[3]=40u32; + let c: t16 = *(&s); + assert((c.h[0]+c.h[1]+c.h[2]+c.h[3]): i32 == 100i32); +}; + +@test fn deref_struct32() void = { + let s: t32; + s.h[0]=1u32; s.h[1]=2u32; s.h[2]=3u32; s.h[3]=4u32; + s.h[4]=5u32; s.h[5]=6u32; s.h[6]=7u32; s.h[7]=8u32; + let c: t32 = *(&s); + assert((c.h[0]+c.h[1]+c.h[2]+c.h[3] + +c.h[4]+c.h[5]+c.h[6]+c.h[7]): i32 == 36i32); +}; + +@test fn deref_ptr32() void = { + let s: t32; + s.h[0]=1u32; s.h[1]=2u32; s.h[2]=3u32; s.h[3]=4u32; + s.h[4]=5u32; s.h[5]=6u32; s.h[6]=7u32; s.h[7]=8u32; + let p: *t32 = &s; + let c: t32 = *p; + assert((c.h[0]+c.h[1]+c.h[2]+c.h[3] + +c.h[4]+c.h[5]+c.h[6]+c.h[7]): i32 == 36i32); +}; + +@test fn deref_array16() void = { + let s: [4]u32; + s[0]=5u32; s[1]=6u32; s[2]=7u32; s[3]=8u32; + let c: [4]u32 = *(&s); + assert((c[0]+c[1]+c[2]+c[3]): i32 == 26i32); +}; + +@test fn deref_tail12() void = { + let s: [3]u32; + s[0]=7u32; s[1]=8u32; s[2]=9u32; + let c: [3]u32 = *(&s); + assert((c[0]+c[1]+c[2]): i32 == 24i32); +}; + +@test fn deref_tail11() void = { + let s: [11]u8; + s[0]=1u8; s[1]=2u8; s[2]=3u8; s[3]=4u8; s[4]=5u8; + s[5]=6u8; s[6]=7u8; s[7]=8u8; s[8]=9u8; s[9]=10u8; + s[10]=11u8; + let c: [11]u8 = *(&s); + assert((c[0]+c[1]+c[2]+c[3]+c[4]+c[5] + +c[6]+c[7]+c[8]+c[9]+c[10]): i32 == 66i32); +}; + +// ===================== #268 addressable-rhs let-init copy ================ +@test fn ai_array16() void = { + let s: [4]u32; + s[0]=11u32; s[1]=22u32; s[2]=33u32; s[3]=44u32; + let c: [4]u32 = s; + assert((c[0]+c[1]+c[2]+c[3]): i32 == 110i32); +}; + +@test fn ai_array32() void = { + let s: [8]u32; + s[0]=1u32; s[1]=2u32; s[2]=3u32; s[3]=4u32; + s[4]=5u32; s[5]=6u32; s[6]=7u32; s[7]=8u32; + let c: [8]u32 = s; + assert((c[0]+c[1]+c[2]+c[3]+c[4]+c[5]+c[6]+c[7]): i32 == 36i32); +}; + +@test fn ai_tail12() void = { + let s: [3]u32; + s[0]=7u32; s[1]=8u32; s[2]=9u32; + let c: [3]u32 = s; + assert((c[0]+c[1]+c[2]): i32 == 24i32); +}; + +@test fn ai_tail11() void = { + let s: [11]u8; + s[0]=1u8; s[1]=2u8; s[2]=3u8; s[3]=4u8; s[4]=5u8; + s[5]=6u8; s[6]=7u8; s[7]=8u8; s[8]=9u8; s[9]=10u8; + s[10]=11u8; + let c: [11]u8 = s; + assert((c[0]+c[1]+c[2]+c[3]+c[4]+c[5] + +c[6]+c[7]+c[8]+c[9]+c[10]): i32 == 66i32); +}; + +type dinner16 = struct { m: [4]u32 }; +type douter16 = struct { i: dinner16 }; +@test fn dot_struct16() void = { + let o: douter16; + o.i.m[0]=10u32; o.i.m[1]=20u32; o.i.m[2]=30u32; o.i.m[3]=40u32; + let c: dinner16 = o.i; + assert((c.m[0]+c.m[1]+c.m[2]+c.m[3]): i32 == 100i32); +}; + +type douter32 = struct { o: [8]u32 }; +@test fn dot_arr32() void = { + let x: douter32; + x.o[0]=1u32; x.o[1]=2u32; x.o[2]=3u32; x.o[3]=4u32; + x.o[4]=5u32; x.o[5]=6u32; x.o[6]=7u32; x.o[7]=8u32; + let c: [8]u32 = x.o; + assert((c[0]+c[1]+c[2]+c[3]+c[4]+c[5]+c[6]+c[7]): i32 == 36i32); +}; + +type dinner11 = struct { m: [11]u8 }; +type douter11 = struct { i: dinner11 }; +@test fn dot_tail11() void = { + let o: douter11; + o.i.m[0]=1u8; o.i.m[1]=2u8; o.i.m[2]=3u8; o.i.m[3]=4u8; + o.i.m[4]=5u8; o.i.m[5]=6u8; o.i.m[6]=7u8; o.i.m[7]=8u8; + o.i.m[8]=9u8; o.i.m[9]=10u8; o.i.m[10]=11u8; + let c: dinner11 = o.i; + assert((c.m[0]+c.m[1]+c.m[2]+c.m[3]+c.m[4]+c.m[5] + +c.m[6]+c.m[7]+c.m[8]+c.m[9]+c.m[10]): i32 == 66i32); +}; + +@test fn idx_struct16() void = { + let a: [2]dinner16; + let p: *dinner16 = &a[1]; + p.m[0]=10u32; p.m[1]=20u32; p.m[2]=30u32; p.m[3]=40u32; + let c: dinner16 = a[1]; + assert((c.m[0]+c.m[1]+c.m[2]+c.m[3]): i32 == 100i32); +}; + +type dinner32 = struct { m: [8]u32 }; +@test fn idx_struct32() void = { + let a: [2]dinner32; + let p: *dinner32 = &a[1]; + p.m[0]=1u32; p.m[1]=2u32; p.m[2]=3u32; p.m[3]=4u32; + p.m[4]=5u32; p.m[5]=6u32; p.m[6]=7u32; p.m[7]=8u32; + let c: dinner32 = a[1]; + assert((c.m[0]+c.m[1]+c.m[2]+c.m[3] + +c.m[4]+c.m[5]+c.m[6]+c.m[7]): i32 == 36i32); +}; + +def Gad: [4]u32 = [11u32, 22u32, 33u32, 44u32]; +@test fn arraydef_global() void = { + let c: [4]u32 = Gad; + assert((c[0]+c[1]+c[2]+c[3]): i32 == 110i32); +}; + +type gT = struct { a: u32, b: u32, c: u32, d: u32 }; +def Gsd: gT = gT { a = 10u32, b = 20u32, c = 30u32, d = 40u32 }; +@test fn structdef_global() void = { + let c: gT = Gsd; + assert((c.a+c.b+c.c+c.d): i32 == 100i32); +}; + +// ===================== #267 array return-by-value ABI ==================== +fn mk_ret_arr_u32_8() [2]u32 = { let a: [2]u32; a[0]=3u32; a[1]=4u32; return a; }; +@test fn ret_arr_u32_8() void = { + let c = mk_ret_arr_u32_8(); + assert((c[0]+c[1]): i32 == 7i32); +}; + +fn mk_ret_arr_u32_16() [4]u32 = { let a: [4]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32; return a; }; +@test fn ret_arr_u32_16() void = { + let c = mk_ret_arr_u32_16(); + assert((c[0]+c[1]+c[2]+c[3]): i32 == 10i32); +}; + +fn mk_ret_arr_u32_24() [6]u32 = { let a: [6]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32;a[4]=5u32;a[5]=6u32; return a; }; +@test fn ret_arr_u32_24() void = { + let c = mk_ret_arr_u32_24(); + assert((c[0]+c[1]+c[2]+c[3]+c[4]+c[5]): i32 == 21i32); +}; + +fn mk_ret_arr_u32_32_sret() [8]u32 = { let a: [8]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32;a[4]=5u32;a[5]=6u32;a[6]=7u32;a[7]=8u32; return a; }; +@test fn ret_arr_u32_32_sret() void = { + let c = mk_ret_arr_u32_32_sret(); + assert((c[0]+c[1]+c[2]+c[3]+c[4]+c[5]+c[6]+c[7]): i32 == 36i32); +}; + +fn mk_ret_arr_u8_4() [4]u8 = { let a: [4]u8; a[0]=10u8;a[1]=20u8;a[2]=30u8;a[3]=40u8; return a; }; +@test fn ret_arr_u8_4() void = { + let c = mk_ret_arr_u8_4(); + assert((c[0]+c[1]+c[2]+c[3]): i32 == 100i32); +}; + +fn mk_ret_arr_u8_32_sret() [32]u8 = { let a: [32]u8; a[0]=50u8;a[15]=30u8;a[31]=40u8; return a; }; +@test fn ret_arr_u8_32_sret() void = { + let c = mk_ret_arr_u8_32_sret(); + assert((c[0]+c[15]+c[31]): i32 == 120i32); +}; + +fn mk_ret_arr_assign_16() [4]u32 = { let a: [4]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32; return a; }; +@test fn ret_arr_assign_16() void = { + let c: [4]u32; c = mk_ret_arr_assign_16(); + assert((c[0]+c[1]+c[2]+c[3]): i32 == 10i32); +}; + +fn mk_ret_arr_assign_32_sret() [8]u32 = { let a: [8]u32; a[0]=1u32;a[7]=8u32; return a; }; +@test fn ret_arr_assign_32_sret() void = { + let c: [8]u32; c = mk_ret_arr_assign_32_sret(); + assert((c[0]+c[7]): i32 == 9i32); +}; + +fn mk_ret_arr_fwd_16() [4]u32 = { let a: [4]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32; return a; }; +fn fwd_ret_arr_fwd_16() [4]u32 = { return mk_ret_arr_fwd_16(); }; +@test fn ret_arr_fwd_16() void = { + let c = fwd_ret_arr_fwd_16(); + assert((c[0]+c[1]+c[2]+c[3]): i32 == 10i32); +}; + +fn mk_ret_arr_fwd_32_sret() [8]u32 = { let a: [8]u32; a[0]=1u32;a[7]=8u32; return a; }; +fn fwd_ret_arr_fwd_32_sret() [8]u32 = { return mk_ret_arr_fwd_32_sret(); }; +@test fn ret_arr_fwd_32_sret() void = { + let c = fwd_ret_arr_fwd_32_sret(); + assert((c[0]+c[7]): i32 == 9i32); +}; + +type sret3 = struct { a: u32, b: u32, c: u32 }; +fn mk_ctrl_struct_ret() sret3 = { let s: sret3; s.a=1u32;s.b=2u32;s.c=3u32; return s; }; +@test fn ctrl_struct_ret() void = { + let v = mk_ctrl_struct_ret(); + assert((v.a+v.b+v.c): i32 == 6i32); +}; + +// ===================== #270-2 nested-array outer stride ================== +@test fn nest2d_u32() void = { + let a: [2][3]u32; + a[0][1] = 11u32; + a[1][1] = 22u32; + a[1][2] = 33u32; + assert((a[0][1] + a[1][1] + a[1][2]): i32 == 66i32); +}; + +@test fn nest2d_u8() void = { + let a: [2][3]u8; + a[0][2] = 10u8; + a[1][0] = 20u8; + a[1][2] = 30u8; + assert((a[0][2] + a[1][0] + a[1][2]): i32 == 60i32); +}; + +@test fn nest2d_i32() void = { + let a: [2][3]i32; + a[0][1] = 40; + a[1][1] = 88; + assert((a[1][1] - a[0][1]): i32 == 48i32); +}; + +// ===================== #270-1 element store axes ========================= +type efinner = struct { m: [4]u32 }; +@test fn elemfield_store() void = { + let a: [3]efinner; + a[0].m[1] = 5u32; + a[2].m[3] = 7u32; + a[2].m[0] = 9u32; + assert((a[0].m[1] + a[2].m[3] + a[2].m[0]): i32 == 21i32); +}; + +@test fn elem_struct_store() void = { + let arr: [3]gT; + let v: gT; v.a=10u32; v.b=20u32; v.c=30u32; v.d=40u32; + arr[2] = v; + assert((arr[2].a + arr[2].b + arr[2].c + arr[2].d): i32 == 100i32); +}; + +@test fn elem_arr_store() void = { + let arr: [2][4]u32; + let s: [4]u32; s[0]=1u32; s[1]=2u32; s[2]=3u32; s[3]=4u32; + arr[1] = s; + assert((arr[1][0]+arr[1][1]+arr[1][2]+arr[1][3]): i32 == 10i32); +}; + +// ===================== #270-3a aggregate index-base copy ================= +type boxprim = struct { arr: [2][4]u32 }; +@test fn letcopy_dot_prim() void = { + let s: [4]u32; s[0]=1u32; s[1]=2u32; s[2]=3u32; s[3]=4u32; + let x: boxprim; + x.arr[1] = s; + let c: [4]u32 = x.arr[1]; + assert((c[0]+c[1]+c[2]+c[3]): i32 == 10i32); +}; + +@test fn letcopy_nest_prim() void = { + let a: [2][2][4]u32; + let s: [4]u32; s[0]=2u32; s[1]=4u32; s[2]=6u32; s[3]=8u32; + a[1][0] = s; + let c: [4]u32 = a[1][0]; + assert((c[0]+c[1]+c[2]+c[3]): i32 == 20i32); +}; + +@test fn letcopy_subarr() void = { + let a: [2][3]u32; + a[1][0] = 5u32; a[1][1] = 6u32; a[1][2] = 7u32; + let c: [3]u32 = a[1]; + assert((c[0] + c[1] + c[2]): i32 == 18i32); +}; + +// ===================== #270-1c array-literal element store =============== +type inner2 = struct { a: u32, b: u32 }; +@test fn arrlit_structlit() void = { + let x: [2]inner2 = [inner2{a=1u32,b=2u32}, inner2{a=3u32,b=4u32}]; + assert((x[0].a + x[0].b + x[1].a + x[1].b): i32 == 10i32); +}; + +@test fn arrlit_structident() void = { + let p: inner2; p.a = 7u32; p.b = 8u32; + let q: inner2; q.a = 1u32; q.b = 2u32; + let x: [2]inner2 = [p, q]; + assert((x[0].a + x[0].b + x[1].a + x[1].b): i32 == 18i32); +}; + +// ===================== #271 aggregate ARG from any source ================ +type argt16 = struct { x: i64, y: i64 }; +type argo16 = struct { f: argt16 }; + +fn mk_arg_struct16_call() argt16 = { let a: argt16; a.x=3i64; a.y=7i64; return a; }; +fn sum_arg_struct16_call(b: argt16) i64 = { return b.x + b.y; }; +@test fn arg_struct16_call() void = { + assert(sum_arg_struct16_call(mk_arg_struct16_call()): i32 == 10i32); +}; + +fn sum_arg_struct16_dot(b: argt16) i64 = { return b.x + b.y; }; +@test fn arg_struct16_dot() void = { + let q: argo16; q.f.x=3i64; q.f.y=7i64; + assert(sum_arg_struct16_dot(q.f): i32 == 10i32); +}; + +fn sum_arg_struct16_idx(b: argt16) i64 = { return b.x + b.y; }; +@test fn arg_struct16_idx() void = { + let a: [2]argt16; a[1].x=3i64; a[1].y=7i64; + assert(sum_arg_struct16_idx(a[1]): i32 == 10i32); +}; + +fn sum_arg_struct16_deref(b: argt16) i64 = { return b.x + b.y; }; +@test fn arg_struct16_deref() void = { + let v: argt16; v.x=3i64; v.y=7i64; let p: *argt16 = &v; + assert(sum_arg_struct16_deref(*p): i32 == 10i32); +}; + +fn sum_arg_struct16_ident(b: argt16) i64 = { return b.x + b.y; }; +@test fn arg_struct16_ident() void = { + let v: argt16; v.x=3i64; v.y=7i64; + assert(sum_arg_struct16_ident(v): i32 == 10i32); +}; + +fn mk_arg_arr16_call() [4]u32 = { let a: [4]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32; return a; }; +fn sum_arg_arr16_call(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; }; +@test fn arg_arr16_call() void = { + assert(sum_arg_arr16_call(mk_arg_arr16_call()) == 10i32); +}; + +type argof = struct { f: [4]u32 }; +fn sum_arg_arr16_dot(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; }; +@test fn arg_arr16_dot() void = { + let q: argof; q.f[0]=1u32; q.f[1]=2u32; q.f[2]=3u32; q.f[3]=4u32; + assert(sum_arg_arr16_dot(q.f) == 10i32); +}; + +fn sum_arg_arr16_idx(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; }; +@test fn arg_arr16_idx() void = { + let a: [2][4]u32; + a[1][0]=1u32; a[1][1]=2u32; a[1][2]=3u32; a[1][3]=4u32; + assert(sum_arg_arr16_idx(a[1]) == 10i32); +}; + +fn sum_arg_arr16_deref(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; }; +@test fn arg_arr16_deref() void = { + let v: [4]u32; v[0]=1u32; v[1]=2u32; v[2]=3u32; v[3]=4u32; + let p: *[4]u32 = &v; + assert(sum_arg_arr16_deref(*p) == 10i32); +}; + +fn sum_arg_arr16_ident(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; }; +@test fn arg_arr16_ident() void = { + let v: [4]u32; v[0]=1u32; v[1]=2u32; v[2]=3u32; v[3]=4u32; + assert(sum_arg_arr16_ident(v) == 10i32); +}; + +type argo32 = struct { f: t32 }; + +fn mk_arg_struct32_call() t32 = { let a: t32; a.h[0]=1u32;a.h[1]=2u32;a.h[2]=3u32;a.h[3]=4u32;a.h[4]=5u32;a.h[5]=6u32;a.h[6]=7u32;a.h[7]=8u32; return a; }; +fn sum_arg_struct32_call(b: t32) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; }; +@test fn arg_struct32_call() void = { + assert(sum_arg_struct32_call(mk_arg_struct32_call()) == 36i32); +}; + +fn sum_arg_struct32_dot(b: t32) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; }; +@test fn arg_struct32_dot() void = { + let q: argo32; + q.f.h[0]=1u32;q.f.h[1]=2u32;q.f.h[2]=3u32;q.f.h[3]=4u32; + q.f.h[4]=5u32;q.f.h[5]=6u32;q.f.h[6]=7u32;q.f.h[7]=8u32; + assert(sum_arg_struct32_dot(q.f) == 36i32); +}; + +fn sum_arg_struct32_idx(b: t32) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; }; +@test fn arg_struct32_idx() void = { + let a: [2]t32; + let p: *t32 = &a[1]; + p.h[0]=1u32;p.h[1]=2u32;p.h[2]=3u32;p.h[3]=4u32; + p.h[4]=5u32;p.h[5]=6u32;p.h[6]=7u32;p.h[7]=8u32; + assert(sum_arg_struct32_idx(a[1]) == 36i32); +}; + +fn sum_arg_struct32_deref(b: t32) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; }; +@test fn arg_struct32_deref() void = { + let v: t32; + v.h[0]=1u32;v.h[1]=2u32;v.h[2]=3u32;v.h[3]=4u32; + v.h[4]=5u32;v.h[5]=6u32;v.h[6]=7u32;v.h[7]=8u32; + let p: *t32 = &v; + assert(sum_arg_struct32_deref(*p) == 36i32); +}; + +fn sum_arg_struct32_ident(b: t32) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; }; +@test fn arg_struct32_ident() void = { + let v: t32; + v.h[0]=1u32;v.h[1]=2u32;v.h[2]=3u32;v.h[3]=4u32; + v.h[4]=5u32;v.h[5]=6u32;v.h[6]=7u32;v.h[7]=8u32; + assert(sum_arg_struct32_ident(v) == 36i32); +}; diff --git a/test/wcc/949_dotbase_addr_slice_run.c b/test/wcc/949_dotbase_addr_slice_run.c deleted file mode 100644 index ae424893..00000000 --- a/test/wcc/949_dotbase_addr_slice_run.c +++ /dev/null @@ -1,1449 +0,0 @@ -/* - * 949_dotbase_addr_slice_run — runtime + byte-id net for the array- - * field-base-address family: #252 (the addr-of + slice SIBLING of #135), - * #253 (the CHAINED-base close-out), and #257 (the CALL-ARG consumption - * axis — an inline struct-array-field slice passed straight as a call - * argument). 949_dotbase_arr_run covers the single-level read/write - * index path. - * - * #252: taking `&x.o[i]` (address-of an element) or slicing - * `x.o[lo:hi]` / `x.o[lo:]` of a struct's `[N]T`-typed FIELD computed - * the field's VALUE as the base address instead of its ADDRESS: cgen - * emitted `MOVL off(BP),AX` (load the field's first 8 bytes as a - * pointer) where it must emit `LEAQ off(BP),AX` (the field's address) - * -> garbage pointer -> SEGFAULT. The index read/write path was fixed - * in #135; the addr-of N_INDEX "complex base" arm and the N_SLICE base - * arm still fell to the generic cgexpr(base) auto-deref. - * - * #253: the same family with a CHAINED base — the inner is itself an - * N_DOT (`o.p.m[i]` / `o.i.m[i]` / `o.a.b.m[i]`), not a bare ident. - * `cg_dotbase_addr` / `dotbaseaddr` rejected a non-ident inner, so the - * caller fell to cgexpr(base) which auto-derefs the array field's first - * 8 bytes AS a pointer -> garbage base -> SEGFAULT (base64 fillobuf - * `s.enc.encmap[...]` blocker). The fix recovers the container base via - * the dot-chain spine (`cg_dotchain_addr` / `dotchainaddr`): the pointer - * VALUE of inner when inner is a *struct, else the ADDRESS of inner, - * then adds the field offset. One helper extension per stage closes the - * whole family — every op (index r/w, addr-of, slice, compound) routes - * through the same helper. cs==ww BOTH stages broken identically - * pre-fix (gate-blind, pure correctness — not a byte-id divergence). - * - * Byte-id rows (cstage `ww build` + run for exit code; w6c vs w6c_ww - * `.s` cmp for rule-10 byte-id): - * #252 (bare-ident base): - * - addr_local_u8 &x.o[1] on a local value-struct, *p read → 66 - * - addr_ptr_u8 &x.o[2] via a *struct param, *p read → 77 - * - addr_i32 &x.o[2] on [4]i32 field, *p read (esz=4) → 88 - * - slice_u8_expl x.o[1:4] explicit hi, s[0] read → 66 - * - slice_u8_dflthi x.o[1:] default hi, s[0] read → 66 - * - slice_ptr_u8 x.o[1:4] via a *struct param, s[0] read → 66 - * - slice_i32_expl [4]i32 field x.o[1:3], s[1] read (esz=4) → 88 - * - slice_i32_dflt [4]i32 field x.o[1:], s[2] read (esz=4) → 55 - * - control_bare bare-local [4]u8 &a[1] write + a[1:4] read → 44 - * #253 (chained base — *struct-field-pointer / deeper / non-u8): - * - chain_ptr_rd o.p.m[1] read (p:*inner field) → 66 - * - chain_ptr_wr o.p.m[2] write, read back via a.m[2] → 77 - * - chain_ptr_addr &o.p.m[2] then *q read → 55 - * - chain_ptr_sl_e o.p.m[1:4] explicit hi, s[0] → 66 - * - chain_ptr_sl_d o.p.m[1:] default hi, s[0] → 66 - * - chain_ptr_comp o.p.m[1] += v compound → 66 - * - chain_deep_lf o.a.b.m[1] read (a value, b:*inner leaf) → 66 - * - chain_triple o.p.q.m[1] read (two ptr links: dotchain → 66 - * internal deref, pointer-only structs) - * - chain_tri_comp o.p.q.m[1] += v through the triple chain → 66 - * - chain_i32_addr &o.p.m[2] on [4]i32 (esz=4 stride) → 88 - * - chain_i32_slice o.p.m[1:3] on [4]i32, s[1] (esz=4) → 88 - * - ctrl_ptr_rd p.m[1] read via *e param (control) → 66 - * - ctrl_local_rd x.m[1] read, value-local field (control) → 66 - * - * Run-only rows (byteid=0): the chained VALUE-container arm (`o.i.m`, - * inner is a value nested struct). These exercise the same fixed helper - * and run correctly, but a value nested-struct instance trips two - * orthogonal pre-existing cs!=ww divergences unrelated to #253 — bare- - * let zero-init policy (wwstage emits an extra `MOVQ $0,off(BP)`) and - * global DATAW byte count (wwstage over-emits) — so the rule-10 byte-id - * gate can't apply here until those are fixed (#254). (A third, the - * signed-narrow index-fallback element-LOAD opcode, was #255 — now - * fixed; these u8 rows never hit it anyway.) Run correctness alone - * proves the #253 segfault is gone for this cell. - * - chain_val_rd o.i.m[1] read (i value nested) → 66 - * - chain_val_addr &o.i.m[2] then *q read → 55 - * - chain_val_slice o.i.m[1:4], s[0] → 66 - * - chain_deep_val o.a.b.m[1] read, full value chain → 66 - * - * The bare-local control asserts the N_IDENT base paths still emit - * correct code; the non-u8 rows assert the esz stride extension is - * wired (not silently esz=1). - */ -#include -#include -#include -#include -#include -#include - -static int -runwait(const char *cmd) -{ - int rc = system(cmd); - if (rc == -1) return -1; - if (WIFEXITED(rc)) return WEXITSTATUS(rc); - return -1; -} - -struct row { const char *label; const char *src; int want_exit; int byteid; }; - -static const struct row rows[] = { - { "addr_local_u8", - "package main;\n" - "type e = struct { o: [4]u8 };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 66u8;\n" - " let p: *u8 = &x.o[1];\n" - " return (*p): i32;\n" - "};\n", 66, 1 }, - { "addr_ptr_u8", - "package main;\n" - "type e = struct { o: [4]u8 };\n" - "fn rd(x: *e) u8 = { let p: *u8 = &x.o[2]; return *p; };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[2] = 77u8;\n" - " return rd(&x): i32;\n" - "};\n", 77, 1 }, - { "addr_i32", - "package main;\n" - "type e = struct { o: [4]i32 };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[2] = 88;\n" - " let p: *i32 = &x.o[2];\n" - " return *p;\n" - "};\n", 88, 1 }, - { "slice_u8_expl", - "package main;\n" - "type e = struct { o: [4]u8 };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 66u8;\n" - " let s: []u8 = x.o[1:4];\n" - " return s[0]: i32;\n" - "};\n", 66, 1 }, - { "slice_u8_dflthi", - "package main;\n" - "type e = struct { o: [4]u8 };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 66u8;\n" - " let s: []u8 = x.o[1:];\n" - " return s[0]: i32;\n" - "};\n", 66, 1 }, - { "slice_ptr_u8", - "package main;\n" - "type e = struct { o: [4]u8 };\n" - "fn sl(x: *e) u8 = { let s: []u8 = x.o[1:4]; return s[0]; };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 66u8;\n" - " return sl(&x): i32;\n" - "};\n", 66, 1 }, - { "slice_i32_expl", - "package main;\n" - "type e = struct { o: [4]i32 };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 99;\n" - " x.o[2] = 88;\n" - " let s: []i32 = x.o[1:3];\n" - " return s[1];\n" - "};\n", 88, 1 }, - { "slice_i32_dflt", - "package main;\n" - "type e = struct { o: [4]i32 };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[3] = 55;\n" - " let s: []i32 = x.o[1:];\n" - " return s[2];\n" - "};\n", 55, 1 }, - { "control_bare", - "package main;\n" - "export fn main() i32 = {\n" - " let a: [4]u8;\n" - " a[2] = 44u8;\n" - " let p: *u8 = &a[1];\n" - " *p = 33u8;\n" - " let s: []u8 = a[1:4];\n" - " return s[1]: i32;\n" - "};\n", 44, 1 }, - /* #253 chained-base rows. inner/outer types declared per-row so - * each source is self-contained. */ - { "chain_ptr_rd", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type outer = struct { p: *inner };\n" - "export fn main() i32 = {\n" - " let a: inner; a.m[1] = 66u8;\n" - " let o: outer; o.p = &a;\n" - " return o.p.m[1]: i32;\n" - "};\n", 66, 1 }, - { "chain_ptr_wr", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type outer = struct { p: *inner };\n" - "export fn main() i32 = {\n" - " let a: inner;\n" - " let o: outer; o.p = &a;\n" - " o.p.m[2] = 77u8;\n" - " return a.m[2]: i32;\n" - "};\n", 77, 1 }, - { "chain_ptr_addr", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type outer = struct { p: *inner };\n" - "export fn main() i32 = {\n" - " let a: inner; a.m[2] = 55u8;\n" - " let o: outer; o.p = &a;\n" - " let q: *u8 = &o.p.m[2];\n" - " return (*q): i32;\n" - "};\n", 55, 1 }, - { "chain_ptr_sl_e", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type outer = struct { p: *inner };\n" - "export fn main() i32 = {\n" - " let a: inner; a.m[1] = 66u8;\n" - " let o: outer; o.p = &a;\n" - " let s: []u8 = o.p.m[1:4];\n" - " return s[0]: i32;\n" - "};\n", 66, 1 }, - { "chain_ptr_sl_d", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type outer = struct { p: *inner };\n" - "export fn main() i32 = {\n" - " let a: inner; a.m[1] = 66u8;\n" - " let o: outer; o.p = &a;\n" - " let s: []u8 = o.p.m[1:];\n" - " return s[0]: i32;\n" - "};\n", 66, 1 }, - { "chain_ptr_comp", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type outer = struct { p: *inner };\n" - "export fn main() i32 = {\n" - " let a: inner; a.m[1] = 60u8;\n" - " let o: outer; o.p = &a;\n" - " o.p.m[1] += 6u8;\n" - " return o.p.m[1]: i32;\n" - "};\n", 66, 1 }, - { "chain_deep_lf", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type mid = struct { b: *inner };\n" - "type top = struct { a: mid };\n" - "export fn main() i32 = {\n" - " let z: inner; z.m[1] = 66u8;\n" - " let o: top; o.a.b = &z;\n" - " return o.a.b.m[1]: i32;\n" - "};\n", 66, 1 }, - { "chain_triple", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type amid = struct { q: *inner };\n" - "type otop = struct { p: *amid };\n" - "export fn main() i32 = {\n" - " let z: inner; z.m[1] = 66u8;\n" - " let aa: amid; aa.q = &z;\n" - " let o: otop; o.p = &aa;\n" - " return o.p.q.m[1]: i32;\n" - "};\n", 66, 1 }, - { "chain_tri_comp", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type amid = struct { q: *inner };\n" - "type otop = struct { p: *amid };\n" - "export fn main() i32 = {\n" - " let z: inner; z.m[1] = 60u8;\n" - " let aa: amid; aa.q = &z;\n" - " let o: otop; o.p = &aa;\n" - " o.p.q.m[1] += 6u8;\n" - " return o.p.q.m[1]: i32;\n" - "};\n", 66, 1 }, - { "chain_i32_addr", - "package main;\n" - "type inneri = struct { m: [4]i32 };\n" - "type outeri = struct { p: *inneri };\n" - "export fn main() i32 = {\n" - " let a: inneri; a.m[2] = 88;\n" - " let o: outeri; o.p = &a;\n" - " let q: *i32 = &o.p.m[2];\n" - " return *q;\n" - "};\n", 88, 1 }, - { "chain_i32_slice", - "package main;\n" - "type inneri = struct { m: [4]i32 };\n" - "type outeri = struct { p: *inneri };\n" - "export fn main() i32 = {\n" - " let a: inneri; a.m[1] = 99; a.m[2] = 88;\n" - " let o: outeri; o.p = &a;\n" - " let s: []i32 = o.p.m[1:3];\n" - " return s[1];\n" - "};\n", 88, 1 }, - { "ctrl_ptr_rd", - "package main;\n" - "type e = struct { m: [4]u8 };\n" - "fn rd(p: *e) u8 = { return p.m[1]; };\n" - "export fn main() i32 = {\n" - " let x: e; x.m[1] = 66u8;\n" - " return rd(&x): i32;\n" - "};\n", 66, 1 }, - { "ctrl_local_rd", - "package main;\n" - "type e = struct { m: [4]u8 };\n" - "export fn main() i32 = {\n" - " let x: e; x.m[1] = 66u8;\n" - " return x.m[1]: i32;\n" - "};\n", 66, 1 }, - /* #255 signed-narrow N_DOT-base index read. Reading x.o[k] of a - * [N]i32/i16/i8 struct field via the N_DOT-base index fallback must - * sign-extend the narrow element (loadopsz keys on (signed,sz) → - * MOVSXD/MOVSWQ/MOVSBQ); pre-fix wwstage left signedness unset and - * emitted MOVL/MOVZ* (zero-extend) where cstage emits MOVS* — a - * byte-id divergence bootstrap never indexes, so these rows ARE the - * net. Negative round-trip (-5 → exit 251 = 256-5). */ - { "nload_i32", - "package main;\n" - "type e = struct { o: [4]i32 };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[2] = -5;\n" - " let v: i32 = x.o[2];\n" - " return v;\n" - "};\n", 251, 1 }, - { "nload_i16", - "package main;\n" - "type e = struct { o: [4]i16 };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[2] = -5i16;\n" - " let v: i16 = x.o[2];\n" - " return v: i32;\n" - "};\n", 251, 1 }, - { "nload_i8", - "package main;\n" - "type e = struct { o: [4]i8 };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[2] = -5i8;\n" - " let v: i8 = x.o[2];\n" - " return v: i32;\n" - "};\n", 251, 1 }, - /* #253 chained VALUE-container arm (o.i.m). Run-only (byteid=0): - * a value nested-struct instance trips orthogonal pre-existing - * cs!=ww emission divergences (see header). The fixed helper runs - * these correctly — the segfault is gone. */ - { "chain_val_rd", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type outv = struct { i: inner };\n" - "export fn main() i32 = {\n" - " let o: outv; o.i.m[1] = 66u8;\n" - " return o.i.m[1]: i32;\n" - "};\n", 66, 0 }, - { "chain_val_addr", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type outv = struct { i: inner };\n" - "export fn main() i32 = {\n" - " let o: outv; o.i.m[2] = 55u8;\n" - " let q: *u8 = &o.i.m[2];\n" - " return (*q): i32;\n" - "};\n", 55, 0 }, - { "chain_val_slice", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type outv = struct { i: inner };\n" - "export fn main() i32 = {\n" - " let o: outv; o.i.m[1] = 66u8;\n" - " let s: []u8 = o.i.m[1:4];\n" - " return s[0]: i32;\n" - "};\n", 66, 0 }, - { "chain_deep_val", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type mid = struct { b: inner };\n" - "type top = struct { a: mid };\n" - "export fn main() i32 = {\n" - " let o: top; o.a.b.m[1] = 66u8;\n" - " return o.a.b.m[1]: i32;\n" - "};\n", 66, 0 }, - /* #257 call-arg consumption axis. An INLINE slice of a struct - * `[N]T`-field passed DIRECTLY as a call argument materialized the - * slice .ptr from the field VALUE, not its ADDRESS: the pushargs - * N_SLICE inline builder's non-ident else-arm did plain cgexpr(base) - * -> the N_DOT field auto-derefs (MOVL field,AX used as .ptr) -> - * callee derefs garbage -> SEGFAULT. The let-init / assign-rhs / - * return / hoist-to-local contexts already routed through the cgslice - * #252 choke-point; only this call-arg builder kept a private - * duplicate. Fix routes the else-arm through cg_dotbase_addr / - * dotbaseaddr (array-field-gated; chained inner via #253) + extends - * the N_IDENT-only esz gate to N_DOT bases (element width from the - * checker-stamped base->type). cs==ww both segfaulted identically - * pre-fix (gate-blind). */ - { "callarg_u8", - "package main;\n" - "type e = struct { o: [4]u8 };\n" - "fn rd(b: []u8) i32 = { return b[0]: i32; };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 66u8;\n" - " return rd(x.o[1:4]);\n" - "};\n", 66, 1 }, - { "callarg_i32", - "package main;\n" - "type e = struct { o: [4]i32 };\n" - "fn rd(b: []i32) i32 = { return b[0]; };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 88;\n" - " return rd(x.o[1:3]);\n" - "};\n", 88, 1 }, - { "callarg_ptr_u8", - "package main;\n" - "type e = struct { o: [4]u8 };\n" - "fn rd(b: []u8) i32 = { return b[0]: i32; };\n" - "fn f(p: *e) i32 = { return rd(p.o[1:4]); };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 66u8;\n" - " return f(&x);\n" - "};\n", 66, 1 }, - { "callarg_chain", - "package main;\n" - "type inner = struct { m: [4]u8 };\n" - "type outer = struct { p: *inner };\n" - "fn rd(b: []u8) i32 = { return b[0]: i32; };\n" - "export fn main() i32 = {\n" - " let a: inner; a.m[1] = 66u8;\n" - " let o: outer; o.p = &a;\n" - " return rd(o.p.m[1:4]);\n" - "};\n", 66, 1 }, - /* Controls: an N_IDENT slice arg (hoist-to-local) and a bare-local- - * array slice arg take the N_IDENT fast-paths, NOT the N_DOT else-arm - * — assert they still emit correct code. */ - { "callarg_ctrl_local", - "package main;\n" - "type e = struct { o: [4]u8 };\n" - "fn rd(b: []u8) i32 = { return b[0]: i32; };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 66u8;\n" - " let sl: []u8 = x.o[1:4];\n" - " return rd(sl);\n" - "};\n", 66, 1 }, - { "callarg_ctrl_arr", - "package main;\n" - "fn rd(b: []u8) i32 = { return b[0]: i32; };\n" - "export fn main() i32 = {\n" - " let a: [4]u8;\n" - " a[1] = 66u8;\n" - " return rd(a[1:4]);\n" - "};\n", 66, 1 }, - /* Helper-deviation guard rows (load-bearing): a slice of a NON-array - * field (`[]T` field, str field) passed as a call arg must FALL - * THROUGH the array-gated cg_dotbase_addr/dotbaseaddr to cgexpr, - * which loads the field's slice/str HEADER .ptr — NOT take the field - * ADDRESS (that would treat the header words as inline array data). - * The N_DOT esz extension also applies on the fall-through arm: the - * slice is re-sliced by the element width (esz=4 for []i32), so - * q.v[1:3][0] = backing[1]. If the gate over-fired (emitted &field), - * .ptr would point at the header itself -> wrong value / segfault. */ - { "callarg_slicefield", - "package main;\n" - "type w = struct { v: []i32 };\n" - "fn rd(s: []i32) i32 = { return s[0]; };\n" - "export fn main() i32 = {\n" - " let backing: [4]i32;\n" - " backing[1] = 88;\n" - " let q: w;\n" - " q.v = backing[0:4];\n" - " return rd(q.v[1:3]);\n" - "};\n", 88, 1 }, - { "callarg_strfield", - "package main;\n" - "type w = struct { v: str };\n" - "fn rd(s: str) i32 = { return len(s): i32; };\n" - "export fn main() i32 = {\n" - " let q: w;\n" - " q.v = \"hello\";\n" - " return rd(q.v[1:4]);\n" - "};\n", 3, 1 }, - /* #259 tagged-union array-field indexed STORE via N_DOT base. The - * tagged-element store arm computed &arr[i] from a non-ident base - * (`x.o`) with a plain cgexpr(base) — the N_DOT array field auto- - * derefs (loads the field's first 8 bytes AS a pointer) -> garbage - * dest -> SEGFAULT. Last unrouted cell of the array-field-base- - * address family (#135/#252/#253/#255/#257 proof-grep residual). Fix - * routes the store base through cg_dotbase_addr/dotbaseaddr (array- - * gated; viaptr + chained handled by the shared helper). cs==ww - * broken identically pre-fix (gate-blind correctness). - * - * STORE byte-id rows (byteid=1): store-only into a tagged array field - * (own value-struct + via *struct param), return a constant. These - * gate the #259 store base-address emission cs==ww — the store - * portion is byte-identical post-fix (LEAQ base, not auto-deref). */ - { "tagged_store_own", - "package main;\n" - "type e = struct { o: [4](i32 | void) };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 66;\n" - " return 0;\n" - "};\n", 0, 1 }, - { "tagged_store_ptr", - "package main;\n" - "type e = struct { o: [4](i32 | void) };\n" - "fn wr(x: *e) void = { x.o[2] = 77; };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " wr(&x);\n" - " return 0;\n" - "};\n", 0, 1 }, - /* #261 tagged-element READ materialization via an N_DOT / chained - * N_INDEX base. The #259 store fix UNMASKED a pre-existing latent - * cs!=ww in the read-back: wwstage's cgindex N_DOT/N_INDEX-base arm - * never set elem_tagged (the detection block was gated on an N_IDENT - * base), so a tagged element fell to the SCALAR loadopsz path — one - * word into AX + a zeroed tag — where cstage copies the full 16B slot - * (AX=tag, DX=payload). Two more sites keyed off the same N_IDENT-only - * gate: rhstaggedabicall (let/call-arg widen source) and the return- - * path forwardtagged. All three drop the tag/payload-high word -> the - * wrong variant. Fix mirrors cstage (classify TY_TAGGED for ANY base, - * read the checker-stamped element type_): cgindex slot-copy + - * rhstaggedabicall typeistagged(src.type_) + forwardtagged broadened - * to N_INDEX/N_DOT. read + call-arg + return + chained 2D all close by - * construction. byteid=1 throughout: post-fix the materialization is - * byte-identical. - * - * Tag-survival proof: each shape is tested with BOTH an i32 variant - * AND an explicit `= void` variant. The old one-word load that zeroed - * the tag would misread the void slot as the i32 variant (tag 0); the - * void rows return 1 only if the tag survived. */ - { "tagged_store_own_rd", - "package main;\n" - "type e = struct { o: [4](i32 | void) };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 66;\n" - " let v: (i32 | void) = x.o[1];\n" - " return match (v) {\n" - " case let n: i32 => yield n;\n" - " case void => yield 0: i32;\n" - " };\n" - "};\n", 66, 1 }, - { "tagged_store_ptr_rd", - "package main;\n" - "type e = struct { o: [4](i32 | void) };\n" - "fn wr(x: *e) void = { x.o[2] = 77; };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " wr(&x);\n" - " let v: (i32 | void) = x.o[2];\n" - " return match (v) {\n" - " case let n: i32 => yield n;\n" - " case void => yield 0: i32;\n" - " };\n" - "};\n", 77, 1 }, - { "tagged_rd_void", - "package main;\n" - "type e = struct { o: [4](i32 | void) };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = void;\n" - " let v: (i32 | void) = x.o[1];\n" - " return match (v) {\n" - " case let n: i32 => yield 99: i32;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 1, 1 }, - { "tagged_callarg_i32", - "package main;\n" - "type e = struct { o: [4](i32 | void) };\n" - "fn take(v: (i32 | void)) i32 = {\n" - " return match (v) {\n" - " case let n: i32 => yield n;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[2] = 55;\n" - " return take(x.o[2]);\n" - "};\n", 55, 1 }, - { "tagged_callarg_void", - "package main;\n" - "type e = struct { o: [4](i32 | void) };\n" - "fn take(v: (i32 | void)) i32 = {\n" - " return match (v) {\n" - " case let n: i32 => yield 99: i32;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[2] = void;\n" - " return take(x.o[2]);\n" - "};\n", 1, 1 }, - { "tagged_return_i32", - "package main;\n" - "type e = struct { o: [4](i32 | void) };\n" - "fn ret(x: *e) (i32 | void) = { return x.o[1]; };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = 88;\n" - " let v: (i32 | void) = ret(&x);\n" - " return match (v) {\n" - " case let n: i32 => yield n;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 88, 1 }, - { "tagged_return_void", - "package main;\n" - "type e = struct { o: [4](i32 | void) };\n" - "fn ret(x: *e) (i32 | void) = { return x.o[1]; };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = void;\n" - " let v: (i32 | void) = ret(&x);\n" - " return match (v) {\n" - " case let n: i32 => yield 99: i32;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 1, 1 }, - { "tagged_chained_i32", - "package main;\n" - "type m = struct { g: [2][2](i32 | void) };\n" - "export fn main() i32 = {\n" - " let y: m;\n" - " y.g[1][1] = 44;\n" - " let v: (i32 | void) = y.g[1][1];\n" - " return match (v) {\n" - " case let n: i32 => yield n;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 44, 1 }, - { "tagged_chained_void", - "package main;\n" - "type m = struct { g: [2][2](i32 | void) };\n" - "export fn main() i32 = {\n" - " let y: m;\n" - " y.g[1][1] = void;\n" - " let v: (i32 | void) = y.g[1][1];\n" - " return match (v) {\n" - " case let n: i32 => yield 99: i32;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 1, 1 }, - { "tagged_ctrl_bare_rd", - "package main;\n" - "export fn main() i32 = {\n" - " let a: [4](i32 | void);\n" - " a[1] = 33;\n" - " let v: (i32 | void) = a[1];\n" - " return match (v) {\n" - " case let n: i32 => yield n;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 33, 1 }, - /* #261 NULLABLE-fold deviation: a (*T | void) element is the 8B - * one-word fold, NOT the 16B tag+payload slot. The fix mirrors - * cstage exactly — classify TY_TAGGED for ANY base WITHOUT excluding - * the nullable fold (slot_sz=8 degrades the copy arm to a single - * MOVQ). These rows pin that the no-exclusion path is byte-id for the - * fold too. The pointer-present / void cases prove the discriminant - * (the pointer value itself) survives materialization. The variant - * payload is read by constant (no `*p` deref) only to dodge an - * ORTHOGONAL pre-existing wwstage checker bug (asserttyped: un on a - * deref of a match-bound pointer) — distinct from #261's cgen axis. */ - { "tagged_null_ptr_rd", - "package main;\n" - "type e = struct { o: [4](*i32 | void) };\n" - "export fn main() i32 = {\n" - " let k: i32 = 7;\n" - " let x: e;\n" - " x.o[1] = &k;\n" - " let v: (*i32 | void) = x.o[1];\n" - " return match (v) {\n" - " case let p: *i32 => yield 55: i32;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 55, 1 }, - { "tagged_null_void_rd", - "package main;\n" - "type e = struct { o: [4](*i32 | void) };\n" - "export fn main() i32 = {\n" - " let x: e;\n" - " x.o[1] = void;\n" - " let v: (*i32 | void) = x.o[1];\n" - " return match (v) {\n" - " case let p: *i32 => yield 99: i32;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 1, 1 }, - /* #263 IDENT-source tagged return. `return v` where v is a tagged - * LOCAL ident: cstage's passthrough predicate was TYPE-only (no kind - * filter), so it forwarded the source's AX/DX unchanged — but cgexpr - * of a tagged ident loads only word0 (the tag) into AX, never the - * payload into DX, so the payload was DROPPED (cstage exited 0 on the - * i32-7 repro; wwstage exited 7 — the runtime oracle that proved - * cstage is the bug). Fix gates passthrough to the register-resident - * source kinds (N_CALL/N_INDEX/N_DOT) and routes a tagged-ident return - * through the scratch-widen path, mirroring wwstage's forwardtagged - * kind filter. byteid=1: post-fix the materialization is byte-id with - * wwstage's return scratch-widen. The void row proves the tag survives - * (the dropped-payload bug would still surface the wrong variant; the - * void tag is read correctly either way, so its survival pins the tag - * column like the #261 i32-AND-void design). */ - { "tagged_ident_ret_i32", - "package main;\n" - "fn g() (i32 | void) = { let v: (i32 | void) = 7i32; return v; };\n" - "export fn main() i32 = {\n" - " return match (g()) {\n" - " case let n: i32 => yield n;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 7, 1 }, - { "tagged_ident_ret_void", - "package main;\n" - "fn g() (i32 | void) = { let v: (i32 | void) = void; return v; };\n" - "export fn main() i32 = {\n" - " return match (g()) {\n" - " case let n: i32 => yield 99: i32;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 1, 1 }, - /* #263 CONTROLS: the register-resident passthrough must STILL fire - * (don't over-gate). CALL-source (forwarding another tagged-returning - * fn) + DOT-source (a tagged struct field). INDEX-source is already - * covered by tagged_return_i32 above (`return x.o[1]`). */ - { "tagged_call_ret_ctrl", - "package main;\n" - "fn inner() (i32 | void) = { let v: (i32 | void) = 42i32; return v; };\n" - "fn outer() (i32 | void) = { return inner(); };\n" - "export fn main() i32 = {\n" - " return match (outer()) {\n" - " case let n: i32 => yield n;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 42, 1 }, - { "tagged_dot_ret_ctrl", - "package main;\n" - "type w = struct { f: (i32 | void) };\n" - "fn dot(x: *w) (i32 | void) = { return x.f; };\n" - "export fn main() i32 = {\n" - " let x: w;\n" - " x.f = 63;\n" - " return match (dot(&x)) {\n" - " case let n: i32 => yield n;\n" - " case void => yield 1: i32;\n" - " };\n" - "};\n", 63, 1 }, - /* #265 fold-1 aggregate deref-rhs let-init `let c: T = *p` (T a - * struct or array, >8B). Pre-fix NEITHER stage copied the whole - * aggregate: cstage DROPPED the copy entirely (c read garbage); - * wwstage copied only the FIRST 8 bytes (the scalar `MOVQ AX,off` - * tail). Fix: both stages memcpy the ABI-size aggregate slot→slot - * via SI — a MOVQ run plus a sized MOVL/MOVW/MOVB tail. Converged - * (rule-10, byteid=1). Each row writes DISTINCT values to ALL - * members and reads back EVERY member (sum), so a partial/zero copy - * fails — a c[0]-only readback would pass a truncated copy. Covers: - * struct{[4]u32} 16B + struct{[8]u32} 32B (sha256 `*h` shape, both - * `*(&s)` and `*p` pointer-ident) + a bare [4]u32 array + non-8-mult - * tails ([3]u32 12B → MOVL tail; [11]u8 11B → MOVW+MOVB tail). The - * by-value aggregate RETURN ABI is fold-2 (#267, deferred). */ - { "deref_struct16", - "package main;\n" - "type t = struct { h: [4]u32 };\n" - "export fn main() i32 = {\n" - " let s: t;\n" - " s.h[0]=10u32; s.h[1]=20u32; s.h[2]=30u32; s.h[3]=40u32;\n" - " let c: t = *(&s);\n" - " return (c.h[0]+c.h[1]+c.h[2]+c.h[3]): i32;\n" - "};\n", 100, 1 }, - { "deref_struct32", - "package main;\n" - "type t = struct { h: [8]u32 };\n" - "export fn main() i32 = {\n" - " let s: t;\n" - " s.h[0]=1u32; s.h[1]=2u32; s.h[2]=3u32; s.h[3]=4u32;\n" - " s.h[4]=5u32; s.h[5]=6u32; s.h[6]=7u32; s.h[7]=8u32;\n" - " let c: t = *(&s);\n" - " return (c.h[0]+c.h[1]+c.h[2]+c.h[3]\n" - " +c.h[4]+c.h[5]+c.h[6]+c.h[7]): i32;\n" - "};\n", 36, 1 }, - { "deref_ptr32", - "package main;\n" - "type t = struct { h: [8]u32 };\n" - "export fn main() i32 = {\n" - " let s: t;\n" - " s.h[0]=1u32; s.h[1]=2u32; s.h[2]=3u32; s.h[3]=4u32;\n" - " s.h[4]=5u32; s.h[5]=6u32; s.h[6]=7u32; s.h[7]=8u32;\n" - " let p: *t = &s;\n" - " let c: t = *p;\n" - " return (c.h[0]+c.h[1]+c.h[2]+c.h[3]\n" - " +c.h[4]+c.h[5]+c.h[6]+c.h[7]): i32;\n" - "};\n", 36, 1 }, - { "deref_array16", - "package main;\n" - "export fn main() i32 = {\n" - " let s: [4]u32;\n" - " s[0]=5u32; s[1]=6u32; s[2]=7u32; s[3]=8u32;\n" - " let c: [4]u32 = *(&s);\n" - " return (c[0]+c[1]+c[2]+c[3]): i32;\n" - "};\n", 26, 1 }, - { "deref_tail12", - "package main;\n" - "export fn main() i32 = {\n" - " let s: [3]u32;\n" - " s[0]=7u32; s[1]=8u32; s[2]=9u32;\n" - " let c: [3]u32 = *(&s);\n" - " return (c[0]+c[1]+c[2]): i32;\n" - "};\n", 24, 1 }, - { "deref_tail11", - "package main;\n" - "export fn main() i32 = {\n" - " let s: [11]u8;\n" - " s[0]=1u8; s[1]=2u8; s[2]=3u8; s[3]=4u8; s[4]=5u8;\n" - " s[5]=6u8; s[6]=7u8; s[7]=8u8; s[8]=9u8; s[9]=10u8;\n" - " s[10]=11u8;\n" - " let c: [11]u8 = *(&s);\n" - " return (c[0]+c[1]+c[2]+c[3]+c[4]+c[5]\n" - " +c[6]+c[7]+c[8]+c[9]+c[10]): i32;\n" - "};\n", 66, 1 }, - /* #265 fold-1b (#268) the remaining addressable-rhs aggregate let- - * init copy axes, all routed through the SAME memcpy loop as the - * deref rows above via a per-rhs source-address setup: an array - * IDENT `= s` (LEAQ slot), an N_DOT field `= o.i` (cg_dotchain_addr), - * an N_INDEX element `= a[i]` (the &base[i] spine). Pre-fix array- - * ident/N_DOT truncated to the first 8B and N_INDEX scalar-loaded the - * element address (segfault); both stages converged on the full copy - * (rule-10, byteid=1). Each row writes DISTINCT values to ALL members - * and sums EVERY member back, so a truncated/partial copy fails. With - * the deref rows + the #32 struct-ident arm this closes the whole - * addressable-rhs let-init-copy family: struct-ident / array-ident / - * deref / N_DOT / N_INDEX. The N_INDEX source array is populated - * through a `*inner` to `&a[i]` (the #135/#252 store path), NOT the - * array-of-struct-element direct store (`a[i].m[j]=v` / `a[i]=s`), - * which segfaults on a SEPARATE pre-existing bug reported alongside - * this fold; the populate stays off that path so the row isolates the - * copy. */ - { "ai_array16", - "package main;\n" - "export fn main() i32 = {\n" - " let s: [4]u32;\n" - " s[0]=11u32; s[1]=22u32; s[2]=33u32; s[3]=44u32;\n" - " let c: [4]u32 = s;\n" - " return (c[0]+c[1]+c[2]+c[3]): i32;\n" - "};\n", 110, 1 }, - { "ai_array32", - "package main;\n" - "export fn main() i32 = {\n" - " let s: [8]u32;\n" - " s[0]=1u32; s[1]=2u32; s[2]=3u32; s[3]=4u32;\n" - " s[4]=5u32; s[5]=6u32; s[6]=7u32; s[7]=8u32;\n" - " let c: [8]u32 = s;\n" - " return (c[0]+c[1]+c[2]+c[3]+c[4]+c[5]+c[6]+c[7]): i32;\n" - "};\n", 36, 1 }, - { "ai_tail12", - "package main;\n" - "export fn main() i32 = {\n" - " let s: [3]u32;\n" - " s[0]=7u32; s[1]=8u32; s[2]=9u32;\n" - " let c: [3]u32 = s;\n" - " return (c[0]+c[1]+c[2]): i32;\n" - "};\n", 24, 1 }, - { "ai_tail11", - "package main;\n" - "export fn main() i32 = {\n" - " let s: [11]u8;\n" - " s[0]=1u8; s[1]=2u8; s[2]=3u8; s[3]=4u8; s[4]=5u8;\n" - " s[5]=6u8; s[6]=7u8; s[7]=8u8; s[8]=9u8; s[9]=10u8;\n" - " s[10]=11u8;\n" - " let c: [11]u8 = s;\n" - " return (c[0]+c[1]+c[2]+c[3]+c[4]+c[5]\n" - " +c[6]+c[7]+c[8]+c[9]+c[10]): i32;\n" - "};\n", 66, 1 }, - { "dot_struct16", - "package main;\n" - "type inner = struct { m: [4]u32 };\n" - "type outer = struct { i: inner };\n" - "export fn main() i32 = {\n" - " let o: outer;\n" - " o.i.m[0]=10u32; o.i.m[1]=20u32; o.i.m[2]=30u32; o.i.m[3]=40u32;\n" - " let c: inner = o.i;\n" - " return (c.m[0]+c.m[1]+c.m[2]+c.m[3]): i32;\n" - "};\n", 100, 1 }, - { "dot_arr32", - "package main;\n" - "type outer = struct { o: [8]u32 };\n" - "export fn main() i32 = {\n" - " let x: outer;\n" - " x.o[0]=1u32; x.o[1]=2u32; x.o[2]=3u32; x.o[3]=4u32;\n" - " x.o[4]=5u32; x.o[5]=6u32; x.o[6]=7u32; x.o[7]=8u32;\n" - " let c: [8]u32 = x.o;\n" - " return (c[0]+c[1]+c[2]+c[3]+c[4]+c[5]+c[6]+c[7]): i32;\n" - "};\n", 36, 1 }, - { "dot_tail11", - "package main;\n" - "type inner = struct { m: [11]u8 };\n" - "type outer = struct { i: inner };\n" - "export fn main() i32 = {\n" - " let o: outer;\n" - " o.i.m[0]=1u8; o.i.m[1]=2u8; o.i.m[2]=3u8; o.i.m[3]=4u8;\n" - " o.i.m[4]=5u8; o.i.m[5]=6u8; o.i.m[6]=7u8; o.i.m[7]=8u8;\n" - " o.i.m[8]=9u8; o.i.m[9]=10u8; o.i.m[10]=11u8;\n" - " let c: inner = o.i;\n" - " return (c.m[0]+c.m[1]+c.m[2]+c.m[3]+c.m[4]+c.m[5]\n" - " +c.m[6]+c.m[7]+c.m[8]+c.m[9]+c.m[10]): i32;\n" - "};\n", 66, 1 }, - { "idx_struct16", - "package main;\n" - "type inner = struct { m: [4]u32 };\n" - "export fn main() i32 = {\n" - " let a: [2]inner;\n" - " let p: *inner = &a[1];\n" - " p.m[0]=10u32; p.m[1]=20u32; p.m[2]=30u32; p.m[3]=40u32;\n" - " let c: inner = a[1];\n" - " return (c.m[0]+c.m[1]+c.m[2]+c.m[3]): i32;\n" - "};\n", 100, 1 }, - { "idx_struct32", - "package main;\n" - "type inner = struct { m: [8]u32 };\n" - "export fn main() i32 = {\n" - " let a: [2]inner;\n" - " let p: *inner = &a[1];\n" - " p.m[0]=1u32; p.m[1]=2u32; p.m[2]=3u32; p.m[3]=4u32;\n" - " p.m[4]=5u32; p.m[5]=6u32; p.m[6]=7u32; p.m[7]=8u32;\n" - " let c: inner = a[1];\n" - " return (c.m[0]+c.m[1]+c.m[2]+c.m[3]\n" - " +c.m[4]+c.m[5]+c.m[6]+c.m[7]): i32;\n" - "};\n", 36, 1 }, - /* #268 reviewer: the addressable-rhs N_IDENT axis also covers a - * laid-out-aggregate GLOBAL (#129 A.2/A.3) — an array `def` and a - * struct `def`, both DATA-stored and LEAQ'd by symbol. The struct- - * def case was the one cs!=ww divergence the unified arm shipped: - * wwstage's deflookup (any def) copied it while cstage's def_is- - * arraydef alone truncated, so they diverged (a struct-LET global - * already copied on both, making the def gap an inconsistency). - * Aligned both to copy via the def_is{array,struct}def pairing held - * identical to defisaddressable. Full readback; byteid=1. */ - { "arraydef_global", - "package main;\n" - "def G: [4]u32 = [11u32, 22u32, 33u32, 44u32];\n" - "export fn main() i32 = {\n" - " let c: [4]u32 = G;\n" - " return (c[0]+c[1]+c[2]+c[3]): i32;\n" - "};\n", 110, 1 }, - { "structdef_global", - "package main;\n" - "type T = struct { a: u32, b: u32, c: u32, d: u32 };\n" - "def G: T = T { a = 10u32, b = 20u32, c = 30u32, d = 40u32 };\n" - "export fn main() i32 = {\n" - " let c: T = G;\n" - " return (c.a+c.b+c.c+c.d): i32;\n" - "};\n", 100, 1 }, - /* #267 fold-2: array return-by-value ABI. Arrays ride the existing - * struct-return path (≤24B in AX:DX:CX, >24B via sret) — these rows - * pin the runtime value AND cs==ww byte-id across reg-class (8/16/ - * 24B) and sret-class (32B), [N]u32 and [N]u8, at the let-init / - * assign / return-forward receive contexts. ctrl_struct_ret is the - * regression control: a struct return still byte-id (the struct path - * the arrays were wired into didn't change). FULL readback (sum every - * member) so a dropped eightbyte surfaces. */ - { "ret_arr_u32_8", - "package main;\n" - "fn mk() [2]u32 = { let a: [2]u32; a[0]=3u32; a[1]=4u32; return a; };\n" - "export fn main() i32 = { let c = mk(); return (c[0]+c[1]): i32; };\n", - 7, 1 }, - { "ret_arr_u32_16", - "package main;\n" - "fn mk() [4]u32 = { let a: [4]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32; return a; };\n" - "export fn main() i32 = { let c = mk(); return (c[0]+c[1]+c[2]+c[3]): i32; };\n", - 10, 1 }, - { "ret_arr_u32_24", - "package main;\n" - "fn mk() [6]u32 = { let a: [6]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32;a[4]=5u32;a[5]=6u32; return a; };\n" - "export fn main() i32 = { let c = mk(); return (c[0]+c[1]+c[2]+c[3]+c[4]+c[5]): i32; };\n", - 21, 1 }, - { "ret_arr_u32_32_sret", - "package main;\n" - "fn mk() [8]u32 = { let a: [8]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32;a[4]=5u32;a[5]=6u32;a[6]=7u32;a[7]=8u32; return a; };\n" - "export fn main() i32 = { let c = mk(); return (c[0]+c[1]+c[2]+c[3]+c[4]+c[5]+c[6]+c[7]): i32; };\n", - 36, 1 }, - { "ret_arr_u8_4", - "package main;\n" - "fn mk() [4]u8 = { let a: [4]u8; a[0]=10u8;a[1]=20u8;a[2]=30u8;a[3]=40u8; return a; };\n" - "export fn main() i32 = { let c = mk(); return (c[0]+c[1]+c[2]+c[3]): i32; };\n", - 100, 1 }, - { "ret_arr_u8_32_sret", - "package main;\n" - "fn mk() [32]u8 = { let a: [32]u8; a[0]=50u8;a[15]=30u8;a[31]=40u8; return a; };\n" - "export fn main() i32 = { let c = mk(); return (c[0]+c[15]+c[31]): i32; };\n", - 120, 1 }, - { "ret_arr_assign_16", - "package main;\n" - "fn mk() [4]u32 = { let a: [4]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32; return a; };\n" - "export fn main() i32 = { let c: [4]u32; c = mk(); return (c[0]+c[1]+c[2]+c[3]): i32; };\n", - 10, 1 }, - { "ret_arr_assign_32_sret", - "package main;\n" - "fn mk() [8]u32 = { let a: [8]u32; a[0]=1u32;a[7]=8u32; return a; };\n" - "export fn main() i32 = { let c: [8]u32; c = mk(); return (c[0]+c[7]): i32; };\n", - 9, 1 }, - { "ret_arr_fwd_16", - "package main;\n" - "fn mk() [4]u32 = { let a: [4]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32; return a; };\n" - "fn fwd() [4]u32 = { return mk(); };\n" - "export fn main() i32 = { let c = fwd(); return (c[0]+c[1]+c[2]+c[3]): i32; };\n", - 10, 1 }, - { "ret_arr_fwd_32_sret", - "package main;\n" - "fn mk() [8]u32 = { let a: [8]u32; a[0]=1u32;a[7]=8u32; return a; };\n" - "fn fwd() [8]u32 = { return mk(); };\n" - "export fn main() i32 = { let c = fwd(); return (c[0]+c[7]): i32; };\n", - 9, 1 }, - { "ctrl_struct_ret", - "package main;\n" - "type T = struct { a: u32, b: u32, c: u32 };\n" - "fn mk() T = { let s: T; s.a=1u32;s.b=2u32;s.c=3u32; return s; };\n" - "export fn main() i32 = { let v = mk(); return (v.a+v.b+v.c): i32; };\n", - 6, 1 }, - /* #270-2: nested-array OUTER-index stride. `a[i][j]` on a 2D - * `[N][M]T` indexes the outer dim by the WHOLE sub-array `[M]T` - * (stride = M*sizeof(T)), then the inner dim by sizeof(T). wwstage's - * elemsizeofc drilled the outer stride down to the scalar T (the - * documented elemsizeof FOOTGUN) → esz=$4 where cstage emits $12 - * (the sub-array size, type.c:121 sub->size*len). Runtime stayed - * self-consistent (write+read the same wrong stride) → masked until a - * CROSS-CELL test writes a[0][j] AND a[1][j] at distinct cells and - * reads both back. byteid=1: post-fix wwstage aligns up to cstage's - * $12. Distinct element widths assert the stride is the sub-array - * size, not a fixed literal. */ - { "nest2d_u32", - "package main;\n" - "export fn main() i32 = {\n" - " let a: [2][3]u32;\n" - " a[0][1] = 11u32;\n" - " a[1][1] = 22u32;\n" - " a[1][2] = 33u32;\n" - " return (a[0][1] + a[1][1] + a[1][2]): i32;\n" - "};\n", 66, 1 }, - { "nest2d_u8", - "package main;\n" - "export fn main() i32 = {\n" - " let a: [2][3]u8;\n" - " a[0][2] = 10u8;\n" - " a[1][0] = 20u8;\n" - " a[1][2] = 30u8;\n" - " return (a[0][2] + a[1][0] + a[1][2]): i32;\n" - "};\n", 60, 1 }, - { "nest2d_i32", - "package main;\n" - "export fn main() i32 = {\n" - " let a: [2][3]i32;\n" - " a[0][1] = 40;\n" - " a[1][1] = 88;\n" - " return (a[1][1] - a[0][1]): i32;\n" - "};\n", 48, 1 }, - /* #270-1a: `a[i].m[j] = v` — array-of-struct element field, then - * index INTO that field. The `arr[i].field` read/write arm computed - * &a[i] then DEREF'd it (loaded the struct's first 8 bytes as a - * value) for an `[N]T`-typed field → garbage base → SEGFAULT on the - * outer store. Fix: an array-typed field of an array element leaves - * the field ADDRESS (the #135 read-side, applied to the array-element - * base). Multiple cells written then read back; byteid=1. */ - { "elemfield_store", - "package main;\n" - "type inner = struct { m: [4]u32 };\n" - "export fn main() i32 = {\n" - " let a: [3]inner;\n" - " a[0].m[1] = 5u32;\n" - " a[2].m[3] = 7u32;\n" - " a[2].m[0] = 9u32;\n" - " return (a[0].m[1] + a[2].m[3] + a[2].m[0]): i32;\n" - "};\n", 21, 1 }, - /* #270-1b: `a[i] = aggregateval` — whole-element STORE. The scalar - * store path copied only the first 8 bytes (fldstoreop MOVQ). Fix: - * an aggregate (struct/array >8B) element store word-copies the - * element from the rhs source address (WRITE-twin of the #268 - * let-init loop). Struct element + array element, full readback; - * byteid=1. */ - /* 16B struct (slot == natural) keeps byteid=1: a struct whose - * natural size is NOT an 8-multiple trips the orthogonal - * elemsizeofc slot-vs-natural array-stride divergence (cstage strides - * by sub->size, wwstage by slotsize) — see letcopy_dot_struct. */ - { "elem_struct_store", - "package main;\n" - "type inner = struct { a: u32, b: u32, c: u32, d: u32 };\n" - "export fn main() i32 = {\n" - " let arr: [3]inner;\n" - " let v: inner; v.a=10u32; v.b=20u32; v.c=30u32; v.d=40u32;\n" - " arr[2] = v;\n" - " return (arr[2].a + arr[2].b + arr[2].c + arr[2].d): i32;\n" - "};\n", 100, 1 }, - { "elem_arr_store", - "package main;\n" - "export fn main() i32 = {\n" - " let arr: [2][4]u32;\n" - " let s: [4]u32; s[0]=1u32; s[1]=2u32; s[2]=3u32; s[3]=4u32;\n" - " arr[1] = s;\n" - " return (arr[1][0]+arr[1][1]+arr[1][2]+arr[1][3]): i32;\n" - "};\n", 10, 1 }, - /* #270-3a: aggregate let-init COPY whose index base is an N_DOT - * array-field (`x.arr[i]`) or a nested N_INDEX (`a[i][j]`) — the - * let-init N_INDEX source-addr arm was N_IDENT-base-gated (#268 - * residual), so both fell to the 8B truncation. Fix computes - * &base[idx] via cg_dotbase_addr (N_DOT) / the &abase[bidx] spine - * (nested). Primitive-element rows are byteid=1; the value-struct - * rows below run-correct but trip the orthogonal value-nested-struct - * frame divergence (#254), so byteid=0 (same carve-out as chain_val_* - * above). */ - { "letcopy_dot_prim", - "package main;\n" - "type box = struct { arr: [2][4]u32 };\n" - "export fn main() i32 = {\n" - " let s: [4]u32; s[0]=1u32; s[1]=2u32; s[2]=3u32; s[3]=4u32;\n" - " let x: box;\n" - " x.arr[1] = s;\n" - " let c: [4]u32 = x.arr[1];\n" - " return (c[0]+c[1]+c[2]+c[3]): i32;\n" - "};\n", 10, 1 }, - { "letcopy_nest_prim", - "package main;\n" - "export fn main() i32 = {\n" - " let a: [2][2][4]u32;\n" - " let s: [4]u32; s[0]=2u32; s[1]=4u32; s[2]=6u32; s[3]=8u32;\n" - " a[1][0] = s;\n" - " let c: [4]u32 = a[1][0];\n" - " return (c[0]+c[1]+c[2]+c[3]): i32;\n" - "};\n", 20, 1 }, - { "letcopy_subarr", - "package main;\n" - "export fn main() i32 = {\n" - " let a: [2][3]u32;\n" - " a[1][0] = 5u32; a[1][1] = 6u32; a[1][2] = 7u32;\n" - " let c: [3]u32 = a[1];\n" - " return (c[0] + c[1] + c[2]): i32;\n" - "};\n", 18, 1 }, - { "letcopy_dot_struct", - "package main;\n" - "type inner = struct { a: u32, b: u32, c: u32 };\n" - "type box = struct { arr: [3]inner };\n" - "export fn main() i32 = {\n" - " let x: box;\n" - " let v: inner; v.a = 10u32; v.b = 20u32; v.c = 30u32;\n" - " x.arr[1] = v;\n" - " let c: inner = x.arr[1];\n" - " return (c.a + c.b + c.c): i32;\n" - "};\n", 60, 0 }, - { "letcopy_nest_struct", - "package main;\n" - "type inner = struct { a: u32, b: u32, c: u32 };\n" - "export fn main() i32 = {\n" - " let a: [2][2]inner;\n" - " let v: inner; v.a = 11u32; v.b = 22u32; v.c = 33u32;\n" - " a[1][0] = v;\n" - " let c: inner = a[1][0];\n" - " return (c.a + c.b + c.c): i32;\n" - "};\n", 66, 0 }, - /* #270-1c: `[N]struct` array LITERAL element store. The N_ARRLIT - * per-element store handled scalar/str/float ONLY; a struct/array - * element hit the multi-word-store gap and stored just the first 8 - * bytes (unpopulated). Fix fills each element from its literal - * (cg_structlit_fill_bp) or source ident (word-copy). 8B struct - * (slot==natural) keeps byteid=1; full readback of all members. */ - { "arrlit_structlit", - "package main;\n" - "type inner = struct { a: u32, b: u32 };\n" - "export fn main() i32 = {\n" - " let x: [2]inner = [inner{a=1u32,b=2u32}, inner{a=3u32,b=4u32}];\n" - " return (x[0].a + x[0].b + x[1].a + x[1].b): i32;\n" - "};\n", 10, 1 }, - { "arrlit_structident", - "package main;\n" - "type inner = struct { a: u32, b: u32 };\n" - "export fn main() i32 = {\n" - " let p: inner; p.a = 7u32; p.b = 8u32;\n" - " let q: inner; q.a = 1u32; q.b = 2u32;\n" - " let x: [2]inner = [p, q];\n" - " return (x[0].a + x[0].b + x[1].a + x[1].b): i32;\n" - "};\n", 18, 1 }, - /* #271 aggregate ARG from any NON-IDENT source — the arg-pass twin - * of the #265/#268 let-init copy. Passing an aggregate BY VALUE as a - * call argument worked ONLY for an IDENT source (≤16B struct); every - * non-ident source (CALL mk(), N_DOT o.f, N_INDEX a[i], DEREF *p) and - * every array / >16B-struct (even as an IDENT) fell to the scalar - * default — one PUSHQ for a multi-word aggregate — stack-imbalancing - * against the multi-word drain (cs!=ww, both garbage). The fix - * materialises the source into the arg convention: the source ADDRESS - * in SI (ident LEAQ / deref / dotchainaddr #253 / &base[i] #252-270) - * then ceil(sz/8) words pushed; a CALL receives first (≤24B in - * AX/DX/CX, >24B sret'd into @aggargscr). The callee prologue gained a - * matching array / >16B-struct receive. Each callee reads back ALL - * members (full sum) so a dropped word fails. Covered: struct 16B - * (reg-class) AND struct 32B (sret-class) AND array [4]u32, from each - * non-ident source + an ident control. byteid=1 throughout: both - * stages converge on the correct full-aggregate push (master both- - * broken-and-divergent → fix correct, #263 lesson). */ - { "arg_struct16_call", - "package main;\n" - "type t = struct { x: i64, y: i64 };\n" - "fn mk() t = { let a: t; a.x=3i64; a.y=7i64; return a; };\n" - "fn sum(b: t) i64 = { return b.x + b.y; };\n" - "export fn main() i32 = { return sum(mk()): i32; };\n", 10, 1 }, - { "arg_struct16_dot", - "package main;\n" - "type t = struct { x: i64, y: i64 };\n" - "type o = struct { f: t };\n" - "fn sum(b: t) i64 = { return b.x + b.y; };\n" - "export fn main() i32 = {\n" - " let q: o; q.f.x=3i64; q.f.y=7i64;\n" - " return sum(q.f): i32;\n" - "};\n", 10, 1 }, - { "arg_struct16_idx", - "package main;\n" - "type t = struct { x: i64, y: i64 };\n" - "fn sum(b: t) i64 = { return b.x + b.y; };\n" - "export fn main() i32 = {\n" - " let a: [2]t; a[1].x=3i64; a[1].y=7i64;\n" - " return sum(a[1]): i32;\n" - "};\n", 10, 1 }, - { "arg_struct16_deref", - "package main;\n" - "type t = struct { x: i64, y: i64 };\n" - "fn sum(b: t) i64 = { return b.x + b.y; };\n" - "export fn main() i32 = {\n" - " let v: t; v.x=3i64; v.y=7i64; let p: *t = &v;\n" - " return sum(*p): i32;\n" - "};\n", 10, 1 }, - { "arg_struct16_ident", - "package main;\n" - "type t = struct { x: i64, y: i64 };\n" - "fn sum(b: t) i64 = { return b.x + b.y; };\n" - "export fn main() i32 = {\n" - " let v: t; v.x=3i64; v.y=7i64;\n" - " return sum(v): i32;\n" - "};\n", 10, 1 }, - { "arg_arr16_call", - "package main;\n" - "fn mk() [4]u32 = { let a: [4]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32; return a; };\n" - "fn sum(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; };\n" - "export fn main() i32 = { return sum(mk()); };\n", 10, 1 }, - { "arg_arr16_dot", - "package main;\n" - "type o = struct { f: [4]u32 };\n" - "fn sum(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; };\n" - "export fn main() i32 = {\n" - " let q: o; q.f[0]=1u32; q.f[1]=2u32; q.f[2]=3u32; q.f[3]=4u32;\n" - " return sum(q.f);\n" - "};\n", 10, 1 }, - { "arg_arr16_idx", - "package main;\n" - "fn sum(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; };\n" - "export fn main() i32 = {\n" - " let a: [2][4]u32;\n" - " a[1][0]=1u32; a[1][1]=2u32; a[1][2]=3u32; a[1][3]=4u32;\n" - " return sum(a[1]);\n" - "};\n", 10, 1 }, - { "arg_arr16_deref", - "package main;\n" - "fn sum(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; };\n" - "export fn main() i32 = {\n" - " let v: [4]u32; v[0]=1u32; v[1]=2u32; v[2]=3u32; v[3]=4u32;\n" - " let p: *[4]u32 = &v;\n" - " return sum(*p);\n" - "};\n", 10, 1 }, - { "arg_arr16_ident", - "package main;\n" - "fn sum(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; };\n" - "export fn main() i32 = {\n" - " let v: [4]u32; v[0]=1u32; v[1]=2u32; v[2]=3u32; v[3]=4u32;\n" - " return sum(v);\n" - "};\n", 10, 1 }, - { "arg_struct32_call", - "package main;\n" - "type t = struct { h: [8]u32 };\n" - "fn mk() t = { let a: t; a.h[0]=1u32;a.h[1]=2u32;a.h[2]=3u32;a.h[3]=4u32;a.h[4]=5u32;a.h[5]=6u32;a.h[6]=7u32;a.h[7]=8u32; return a; };\n" - "fn sum(b: t) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; };\n" - "export fn main() i32 = { return sum(mk()); };\n", 36, 1 }, - { "arg_struct32_dot", - "package main;\n" - "type t = struct { h: [8]u32 };\n" - "type o = struct { f: t };\n" - "fn sum(b: t) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; };\n" - "export fn main() i32 = {\n" - " let q: o;\n" - " q.f.h[0]=1u32;q.f.h[1]=2u32;q.f.h[2]=3u32;q.f.h[3]=4u32;\n" - " q.f.h[4]=5u32;q.f.h[5]=6u32;q.f.h[6]=7u32;q.f.h[7]=8u32;\n" - " return sum(q.f);\n" - "};\n", 36, 1 }, - { "arg_struct32_idx", - "package main;\n" - "type t = struct { h: [8]u32 };\n" - "fn sum(b: t) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; };\n" - "export fn main() i32 = {\n" - " let a: [2]t;\n" - " let p: *t = &a[1];\n" - " p.h[0]=1u32;p.h[1]=2u32;p.h[2]=3u32;p.h[3]=4u32;\n" - " p.h[4]=5u32;p.h[5]=6u32;p.h[6]=7u32;p.h[7]=8u32;\n" - " return sum(a[1]);\n" - "};\n", 36, 1 }, - { "arg_struct32_deref", - "package main;\n" - "type t = struct { h: [8]u32 };\n" - "fn sum(b: t) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; };\n" - "export fn main() i32 = {\n" - " let v: t;\n" - " v.h[0]=1u32;v.h[1]=2u32;v.h[2]=3u32;v.h[3]=4u32;\n" - " v.h[4]=5u32;v.h[5]=6u32;v.h[6]=7u32;v.h[7]=8u32;\n" - " let p: *t = &v;\n" - " return sum(*p);\n" - "};\n", 36, 1 }, - { "arg_struct32_ident", - "package main;\n" - "type t = struct { h: [8]u32 };\n" - "fn sum(b: t) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; };\n" - "export fn main() i32 = {\n" - " let v: t;\n" - " v.h[0]=1u32;v.h[1]=2u32;v.h[2]=3u32;v.h[3]=4u32;\n" - " v.h[4]=5u32;v.h[5]=6u32;v.h[6]=7u32;v.h[7]=8u32;\n" - " return sum(v);\n" - "};\n", 36, 1 }, - { NULL, NULL, 0, 0 } -}; - -static int -slurp_eq(const char *a, const char *b) -{ - FILE *fa = fopen(a, "rb"); - FILE *fb = fopen(b, "rb"); - if (!fa || !fb) { if (fa) fclose(fa); if (fb) fclose(fb); return -1; } - int rc = 0; - for (;;) { - int ca = fgetc(fa); - int cb = fgetc(fb); - if (ca != cb) { rc = -1; break; } - if (ca == EOF) break; - } - fclose(fa); fclose(fb); - return rc; -} - -int -main(void) -{ - const char *bin = getenv("BIN"); - if (!bin) bin = "out/bin"; - char absbin[1024]; - if (bin[0] != '/') { - char cwd[1024]; - if (getcwd(cwd, sizeof cwd) == NULL) return 1; - snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin); - bin = absbin; - } - - char w6c[1100], w6c_ww[1100]; - snprintf(w6c, sizeof w6c, "%s/w6c", bin); - snprintf(w6c_ww, sizeof w6c_ww, "%s/w6c_ww", bin); - if (access(w6c_ww, X_OK) != 0) { - fprintf(stderr, "dotbaseaddr: w6c_ww missing — cannot run the " - "cs==ww byte-id gate (the whole point of this test)\n"); - return 1; - } - - int n = 0, fail = 0; - for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwdbs_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwdbs_%d_d_%d", - getpid(), i); - mkdir(tmpdir, 0755); - - char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); - if (runwait(cmd) != 0) { - fprintf(stderr, "row[%s]: cstage build failed\n", - rows[i].label); - fail++; - unlink(src); rmdir(tmpdir); - continue; - } - - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - - int got = runwait(outbin); - if (got != rows[i].want_exit) { - fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", - rows[i].label, got, rows[i].want_exit); - fail++; - } - unlink(outbin); rmdir(tmpdir); - - if (!rows[i].byteid) { - /* Run-only row — byte-id blocked by an orthogonal - * pre-existing cs!=ww divergence (see header). */ - unlink(src); - continue; - } - - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwdbs_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwdbs_%d_%d_ww.s", - getpid(), i); - - snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", - w6c, cs_s, src); - if (runwait(cmd) != 0) { - fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; - } - snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", - w6c_ww, ws_s, src); - if (runwait(cmd) != 0) { - fprintf(stderr, "row[%s]: w6c_ww failed\n", - rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; - } - if (slurp_eq(cs_s, ws_s) != 0) { - fprintf(stderr, - "row[%s]: cstage/wwstage .s DIFFER (rule-10 " - "byte-id violation)\n", rows[i].label); - fail++; - } - unlink(src); unlink(cs_s); unlink(ws_s); - } - - if (fail) { - fprintf(stderr, "%d/%d dotbase-addr-slice tests failed\n", - fail, n); - return 1; - } - printf("dotbaseaddr: %d/%d ok (cstage run + cs==ww byte-id)\n", - n, n); - return 0; -}