// dotbase_hijack_test — indexing an `[N]T` field of a module-GLOBAL struct // (`gs.fld[i]`) must address gs's field, not be hijacked by an unrelated // module-global that shares the FIELD's name, migrated from // test/wcc/989_dotbasehijack_run.c (F8-c4, report-item #20). wwstage's // dotbaseaddr #128b probe did `letvartnode(base.str)` (base.str = the DOT's // FIELD name) whenever the inner ident wasn't a local; for `gs.fld` with gs a // module-global struct, the inner is global so the probe fired and, finding the // unrelated global `fld: [2]i64`, emitted `LEAQ fld(SB)` — the WRONG symbol // (returning 9 not 7). cstage gates the probe on a NULL/ty_err inner type (a // module qualifier has no struct type), so a typed-struct inner resolves the // field off the struct. The fix gates the wwstage probe the same way; the .s is // byte-identical. The colliding global is read directly (global_fld_intact) so // the name clash is genuine; no_collide is the typed-inner control the // probe-skip must keep correct. package dotbase_hijack_test; type s = struct { pad: i64, fld: [2]i64 }; type s2 = struct { pad: i64, arr: [2]i64 }; let gs: s = s { pad = 0, fld = [7, 8] }; let gs2: s2 = s2 { pad = 0, arr = [5, 6] }; let fld: [2]i64 = [9, 10]; @test fn collide_0() void = { // pre-fix wwstage read fld[0] (== 9) off the colliding global. assert(gs.fld[0]: i32 == 7); }; @test fn collide_1() void = { // pre-fix wwstage read fld[1] (== 10) off the colliding global. assert(gs.fld[1]: i32 == 8); }; @test fn no_collide() void = { // typed-struct inner with NO name collision — the probe-skip must not // break the ordinary global-struct array-field index. assert(gs2.arr[0]: i32 == 5); }; @test fn global_fld_intact() void = { // the colliding global is a genuine distinct symbol, not gs.fld. assert(fld[0]: i32 == 9); assert(fld[1]: i32 == 10); };