w6c+w6c_ww: *[N]T indexing strides by element, not whole array (#61 A+B)

Indexing through a pointer-to-array auto-derefs, so esz and the element
classification must come from the pointee array's ELEMENT (cstage
idx_eff semantics, cgen.c:1163). Two halves of one root class:

A (wwstage-only, cs!=ww, cstage runtime-correct): elemsizeofc's #270-2
nested-array block treated an N_TPTR pointee-array like a [N][M]T outer
index and returned the whole-array size — every p[i] read/write/
compound scaled by N*size(T), and the same wrong element belief reached
the store-width chooser (var-idx write emitted an N*8B aggregate copy
sourced at the 8B rhs slot: caller-frame smash, the siphash round()
corruption). Fixed via two wwstage choke-points mirroring idx_eff:
idxeffti (tinfo: NAMED peel + TY_PTR->TY_ARRAY drill; feeds elemsizeofc
and elemissignedc/elemisfloatc/elemisf32c) and idxelemtn (node: element
tnode with the same drill; feeds every cgindex/cgassign/nodeisstr/
match-scrutinee elemtn resolution).

B (BOTH stages identically wrong, byte-id-BLIND): the TK_AMP &base[i]
arm read bu->sub->size without the ptr peel (&p[3]-&a[0] = 96, not 24).
cstage now routes esz through idx_eff.

A and B are FUSED by the pre-existing routing topology, not by choice
(rule 11): wwstage's TK_AMP arm already reads its esz via elemsizeofc
(selfhost/cmd/wcc/cgenexpr.ww:4095, the #11 addr-of twin of the #10
cgindex fix), so fixing A's choke-point flips wwstage's half of B in
the same stroke. A standalone A leaves &p[i] transiently cs!=ww;
B-first is the mirror transient; carving the TK_AMP caller out of the
fixed choke-point to preserve the wrong stride for one commit would be
a deliberate known-wrong intermediate (rule-7, vetoed by rob). One
choke-point, two enrolled routes — un-fusable without a red
intermediate.

Close-by-construction proof-grep (both stages): every remaining raw
sub->size index-stride read is TY_ARRAY-gated, a slice-only builtin
(delete/insert), a checker-stamped element tinfo (indexresult already
decays *[N]T, check.ww:2277-2284), or a non-index context (tuple
slots, let-init elements). Two true residuals filed with site+symptom
instead of silently absorbed: N_SLICE through *[N]T does not decay
(LOUD type error, Hare divergence; team task #18) and non-ident
cast-expression index bases keep wwstage's 8B-default esz (pre-existing
#74-style cluster; team task #19). cstage's N_INDEX read-side
str/slice header gates also move from u->sub to esub (identical for
every non-ptr-to-array base; honest for *[N]str — pre-fix BOTH stages
were runtime-wrong there, differently).

949_ptrarr_index_run pins the class at runtime + byte-id: {1,2,4,8}B
elems, const+var idx, param/local/cast bases, read/write/compound,
neighbor guards, &p[i] pointer-difference, siphash-round mix shape.
989_lib_byteid: siphash_test graduates #59.7 DIVERGE -> ID (ratchet
tripped loud pre-update; no other #59.x pin flipped in the same run).
(*p)[i] (sub-bug C) follows separately.
This commit is contained in:
2026-06-04 22:03:33 +09:00
parent 95fea97868
commit eea3e197c2
10 changed files with 739 additions and 252 deletions

View File

@@ -1471,6 +1471,9 @@ fn cgindex(c: *cgen, n: *node) void = {
// path when the base is a bare ident (mem.ww shape).
let base: *node = n.lhs;
let idx: *node = n.rhs;
// Direct non-ident index bases that match none of the typed arms
// below (e.g. a cast-expression base) keep this 8B default —
// cs!=ww for narrow elements. Team task #19 (#61-residual B).
let esz: i32 = 8;
let signed_elem: bool = false;
// #119: float element loads route to MOVSS/MOVSD into X0, not the
@@ -1594,22 +1597,14 @@ fn cgindex(c: *cgen, n: *node) void = {
if (base.kind == nkind.N_IDENT) {
let bl: *local = baselocal;
let etn: *node = nil;
// idxelemtn drills `*[N]T` to the pointee array's own
// element (#61) — an undrilled etn classified the whole
// array, missing tagged/str/slice elements behind a
// pointer-to-array base.
if (bl != nil) {
let btn: *node = bl.tnode;
if (btn != nil) {
let bk: nkind = btn.kind;
if (bk == nkind.N_TARRAY) { etn = btn.lhs; };
if (bk == nkind.N_TSLICE) { etn = btn.lhs; };
if (bk == nkind.N_TPTR) { etn = btn.lhs; };
};
etn = idxelemtn(bl.tnode);
} else {
let tn: *node = letvartnode(c, base.str);
if (tn != nil) {
let bk: nkind = tn.kind;
if (bk == nkind.N_TARRAY) { etn = tn.lhs; };
if (bk == nkind.N_TSLICE) { etn = tn.lhs; };
if (bk == nkind.N_TPTR) { etn = tn.lhs; };
};
etn = idxelemtn(letvartnode(c, base.str));
};
if (istaggedtype(c, etn)) {
if (!isnullabletype(etn)) {
@@ -6828,13 +6823,12 @@ fn cgassign(c: *cgen, n: *node) void = {
baselocal = localfindnode(c, bn);
if (baselocal != nil) {
esz = elemsizeofc(c, baselocal.tnode);
let btn: *node = baselocal.tnode;
if (btn != nil) {
let bk: nkind = btn.kind;
if (bk == nkind.N_TARRAY) { elemtn = btn.lhs; };
if (bk == nkind.N_TSLICE) { elemtn = btn.lhs; };
if (bk == nkind.N_TPTR) { elemtn = btn.lhs; };
};
// idxelemtn drills `*[N]T` to the pointee
// array's element (#61): an undrilled elemtn
// made the width chooser believe the element
// IS the whole array (N*8B aggregate copy
// from an 8B source — frame smash).
elemtn = idxelemtn(baselocal.tnode);
} else {
// #11: store/compound twin of the #10 cgindex
// read fix. A global str/slice element store hit
@@ -6856,14 +6850,13 @@ fn cgassign(c: *cgen, n: *node) void = {
if (tn != nil) {
globalname = bn;
esz = elemsizeofc(c, tn);
let bk: nkind = tn.kind;
if (bk == nkind.N_TARRAY) {
// idxelemtn: `*[N]T` drill, see the
// local branch above (#61).
elemtn = idxelemtn(tn);
if (tn.kind == nkind.N_TARRAY) {
isglobalarr = true;
elemtn = tn.lhs;
} else {
isglobalptr = true;
if (bk == nkind.N_TSLICE) { elemtn = tn.lhs; };
if (bk == nkind.N_TPTR) { elemtn = tn.lhs; };
};
};
};
@@ -7275,13 +7268,12 @@ fn cgassign(c: *cgen, n: *node) void = {
baselocal = localfindnode(c, bn);
if (baselocal != nil) {
esz = elemsizeofc(c, baselocal.tnode);
let btn: *node = baselocal.tnode;
if (btn != nil) {
let bk: nkind = btn.kind;
if (bk == nkind.N_TARRAY) { elemtn = btn.lhs; };
if (bk == nkind.N_TSLICE) { elemtn = btn.lhs; };
if (bk == nkind.N_TPTR) { elemtn = btn.lhs; };
};
// idxelemtn drills `*[N]T` to the pointee
// array's element (#61): an undrilled elemtn
// made the width chooser believe the element
// IS the whole array (N*8B aggregate copy
// from an 8B source — frame smash).
elemtn = idxelemtn(baselocal.tnode);
} else {
// #11: store/compound twin of the #10 cgindex
// read fix. A global str/slice element store hit
@@ -7303,14 +7295,13 @@ fn cgassign(c: *cgen, n: *node) void = {
if (tn != nil) {
globalname = bn;
esz = elemsizeofc(c, tn);
let bk: nkind = tn.kind;
if (bk == nkind.N_TARRAY) {
// idxelemtn: `*[N]T` drill, see the
// local branch above (#61).
elemtn = idxelemtn(tn);
if (tn.kind == nkind.N_TARRAY) {
isglobalarr = true;
elemtn = tn.lhs;
} else {
isglobalptr = true;
if (bk == nkind.N_TSLICE) { elemtn = tn.lhs; };
if (bk == nkind.N_TPTR) { elemtn = tn.lhs; };
};
};
};
@@ -7461,12 +7452,10 @@ fn cgassign(c: *cgen, n: *node) void = {
let lc: *local = localfindnode(c, idxbase.str);
if (lc != nil) { if (lc.tnode != nil) {
let tn: *node = lc.tnode;
let elemt: *node = nil;
let baseisarray: bool = false;
let tk: nkind = tn.kind;
if (tk == nkind.N_TSLICE) { elemt = tn.lhs; };
if (tk == nkind.N_TARRAY) { elemt = tn.lhs; baseisarray = true; };
if (tk == nkind.N_TPTR) { elemt = tn.lhs; };
// idxelemtn: `*[N]T` drills to the pointee
// array's element (#61).
let elemt: *node = idxelemtn(tn);
let baseisarray: bool = tn.kind == nkind.N_TARRAY;
let sname: str;
sname.ptr = nil; sname.len = 0;
let viaptr: bool = false;