Files
ww/test/lang/alias_amp_idx_test.ww
Hojun-Cho 83f5956df2 test: banner purge + WHY-only comment sweep (rule 8)
Every section banner dies (103 -> 0) across test/lang, the observer
suites, the C carriers, and the five comment-heavy corpus fixtures;
banner provenance (#N cites, carrier numbers, repair-cluster labels)
folded into headers or adjacent WHY comments. Narration deleted; row
provenance, ref cites, divergence pins, and layout contracts kept
(fwd-ref decl-order guards and bootstrap-gate corpus rationale
restored where the sweep over-cut). Comment-only proven: all 3742
wwbuild workdir .s byte-identical before/after; test-commit and
test-byteid (161 lang + 1399 data, 0 pinned-divergent) green.
2026-08-08 21:40:23 +09:00

99 lines
3.0 KiB
Plaintext

// `&a[i]` over an ALIAS-typed array base must classify
// arrayness off the CHASED type, not the syntactic tnode, migrated from
// test/wcc/944_alias_amp_idx_run.c (#5 alias arc). cgun's TK_AMP N_INDEX
// classify keyed arrayness off the syntactic tnode (N_TNAME), so `&a[i]` over an
// alias-typed base missed the N_TARRAY gate and materialized the base as MOVQ
// (element-0 VALUE) instead of LEAQ (storage address) → wild pointer, ww SEGV
// 139 on the deref (esz was already alias-correct, ONLY the base classify moved).
// cstage classifies off the chased type and is the runtime-correct reference;
// the fix re-keys both legs off tichase(base.type_) gated on TY_NAMED, so
// non-alias rows are byte-id-neutral by construction. The .s is byte-identical
// cs==ww, so these behavioral @tests are the net.
//
// All reads/writes go THROUGH THE TAKEN POINTER; values exceed 255 to break
// little-endian prefix-luck and the LAST element is checked. amp_ctrl is the
// plain-local control; amp_l1/amp_l2 are 1-/2-level alias locals; amp_order is
// the forward-ref shape (the original placed `type arr` after the use — here
// module-level resolution subsumes it); amp_narrow pins that the alias BASE was
// the only wrong half (the narrow esz was already right); amp_g1/amp_g2 are
// alias-typed globals; amp_gctrl holds the plain-global + global-str #11 legs.
//
// NOT pinned here (filed, a DIFFERENT site both stages): `&D[i]` over a
// DEF-array — covered by def_amp_idx_test (#94).
package alias_amp_idx_test;
type arr = [4]int;
type arr2 = arr;
type A = [4]u32;
let g1: arr = [1000: int, 2000: int, 3000: int, 4000: int];
let g2: arr2 = [1000: int, 2000: int, 3000: int, 4000: int];
let gc: [4]int = [1000: int, 2000: int, 3000: int, 4000: int];
let gs: str = "wxyz";
@test fn amp_ctrl() void = {
let a: [4]int = [1000: int, 2000: int, 3000: int, 4000: int];
let p: *int = &a[2];
assert(*p == 3000);
*p = 7777;
assert(a[2] == 7777);
let q: *int = &a[3];
assert(*q == 4000);
};
@test fn amp_l1() void = {
let a: arr = [1000: int, 2000: int, 3000: int, 4000: int];
let p: *int = &a[3];
assert(*p == 4000);
*p = 8888;
assert(a[3] == 8888);
};
@test fn amp_l2() void = {
let a: arr2 = [1000: int, 2000: int, 3000: int, 4000: int];
let p: *int = &a[3];
assert(*p == 4000);
*p = 9999;
assert(a[3] == 9999);
};
@test fn amp_order() void = {
let a: arr = [1000: int, 2000: int, 3000: int, 4000: int];
let p: *int = &a[3];
assert(*p == 4000);
*p = 8888;
assert(a[3] == 8888);
};
@test fn amp_narrow() void = {
let a: A = [1000: u32, 2000: u32, 3000: u32, 4000: u32];
let p: *u32 = &a[3];
assert(*p == 4000);
*p = 5555;
assert(a[3] == 5555);
};
@test fn amp_g1() void = {
let p: *int = &g1[3];
assert(*p == 4000);
*p = 8888;
assert(g1[3] == 8888);
};
@test fn amp_g2() void = {
let p: *int = &g2[3];
assert(*p == 4000);
*p = 9999;
assert(g2[3] == 9999);
};
@test fn amp_gctrl() void = {
let p: *int = &gc[3];
assert(*p == 4000);
*p = 7777;
assert(gc[3] == 7777);
let q: *u8 = &gs[3];
assert(*q == 'z');
};