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:
@@ -13443,6 +13443,11 @@ fn exprtype(c: *checker, e: *node, hint: *node) *node = {
|
||||
return tn;
|
||||
};
|
||||
};
|
||||
// Retained divergence: *[N]T does NOT decay here —
|
||||
// `p[lo:hi]` types as [][N]T (C-pointer-slicing), unlike
|
||||
// the index route (idxeffti) and unlike Hare. Loud on the
|
||||
// usual []T annotation; for-range likewise. Team task #18
|
||||
// (#61-residual A).
|
||||
if (bu.kind == nkind.N_TPTR && bu.lhs != nil) {
|
||||
let sl: *node = newnode(nkind.N_TSLICE, "", 0, 0);
|
||||
sl.lhs = bu.lhs;
|
||||
@@ -16942,11 +16947,9 @@ fn nodeisstr(c: *cgen, n: *node) bool = {
|
||||
if (lc != nil) { bt = lc.tnode; }
|
||||
else { bt = letvartnode(c, base.str); };
|
||||
if (bt != nil) {
|
||||
let elem: *node = nil;
|
||||
let bk: nkind = bt.kind;
|
||||
if (bk == nkind.N_TARRAY) { elem = bt.lhs; };
|
||||
if (bk == nkind.N_TSLICE) { elem = bt.lhs; };
|
||||
if (bk == nkind.N_TPTR) { elem = bt.lhs; };
|
||||
// idxelemtn: `*[N]T` drills to the pointee
|
||||
// array's element (#61).
|
||||
let elem: *node = idxelemtn(bt);
|
||||
if (elem != nil) {
|
||||
return isstrtype(c, elem);
|
||||
};
|
||||
@@ -16988,11 +16991,8 @@ fn nodeisstr(c: *cgen, n: *node) bool = {
|
||||
if (streq(fi.fname, fld)) {
|
||||
let ft: *node = fi.tnode;
|
||||
if (ft != nil) {
|
||||
let elem: *node = nil;
|
||||
let fk: nkind = ft.kind;
|
||||
if (fk == nkind.N_TPTR) { elem = ft.lhs; };
|
||||
if (fk == nkind.N_TSLICE) { elem = ft.lhs; };
|
||||
if (fk == nkind.N_TARRAY) { elem = ft.lhs; };
|
||||
// idxelemtn: `*[N]T` drill (#61).
|
||||
let elem: *node = idxelemtn(ft);
|
||||
if (elem != nil) {
|
||||
return isstrtype(c, elem);
|
||||
};
|
||||
@@ -17040,8 +17040,6 @@ fn typeis8byteprimitive(c: *cgen, t: *node) bool = {
|
||||
// the stamped tinfo so alias/enum recursion lives in lib/ww/typ.ww.
|
||||
fn elemissignedc(c: *cgen, t: *node) bool = {
|
||||
if (t == nil) { return false; };
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
if (ti == nil) { return false; };
|
||||
// #65 Phase-N step-2 cleanup: peel TY_NAMED before the .sub read.
|
||||
// #64 now flows per-decl NAMED wrappers, so a NAMED-of-(`*T`/`[]T`/
|
||||
// `[N]T`) reaching here would read NAMED.sub (nil) instead of the
|
||||
@@ -17049,7 +17047,10 @@ fn elemissignedc(c: *cgen, t: *node) bool = {
|
||||
// before the eff->sub read (:3518-3520). Byte-id-neutral: every
|
||||
// aliased indexable in-tree has a u8 element (typeissigned=false
|
||||
// either way). Transitive peel matches the #63 idiom.
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
// idxeffti additionally drills `*[N]T` to the pointee array (#61)
|
||||
// so a signed-narrow element behind a pointer-to-array still
|
||||
// sign-extends on load.
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti == nil) { return false; };
|
||||
return typeissigned(ti.sub);
|
||||
};
|
||||
@@ -17064,9 +17065,8 @@ fn elemissignedc(c: *cgen, t: *node) bool = {
|
||||
// (the unstamped-base trap that broke the exprfloatkind collapse, #121).
|
||||
fn elemisfloatc(c: *cgen, t: *node) bool = {
|
||||
if (t == nil) { return false; };
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
if (ti == nil) { return false; };
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
// idxeffti = TY_NAMED peel + the `*[N]T` drill (#61).
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti == nil) { return false; };
|
||||
return typeisfloat(ti.sub);
|
||||
};
|
||||
@@ -17075,9 +17075,8 @@ fn elemisfloatc(c: *cgen, t: *node) bool = {
|
||||
// so cgindex picks MOVSS over MOVSD at the #119 element load.
|
||||
fn elemisf32c(c: *cgen, t: *node) bool = {
|
||||
if (t == nil) { return false; };
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
if (ti == nil) { return false; };
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
// idxeffti = TY_NAMED peel + the `*[N]T` drill (#61).
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti == nil) { return false; };
|
||||
return typeisf32(ti.sub);
|
||||
};
|
||||
@@ -17211,6 +17210,46 @@ export fn localloadop(c: *cgen, tnode: *node) str = {
|
||||
return loadopsz(sigd, sz);
|
||||
};
|
||||
|
||||
// idxeffti — element-effective tinfo for indexing. `*[N]T` auto-derefs
|
||||
// at an index base, so its esz/element classification must come from
|
||||
// the pointee ARRAY (stride T), not from the pointer (whose .sub is
|
||||
// the whole [N]T — the #61 stride bug, N*size(T) off target per index
|
||||
// step). One peel choke-point: every tinfo-keyed index-element answer
|
||||
// (elemsizeofc / elemissignedc / elemisfloatc / elemisf32c) routes
|
||||
// through here. Mirrors cstage idx_eff (cmd/w6c/cgen.c:1163).
|
||||
fn idxeffti(t0: *tinfo) *tinfo = {
|
||||
let t: *tinfo = t0;
|
||||
for (t != nil && t.kind == tykind.TY_NAMED) { t = t.under; };
|
||||
if (t != nil && t.kind == tykind.TY_PTR) {
|
||||
let p: *tinfo = t.sub;
|
||||
for (p != nil && p.kind == tykind.TY_NAMED) { p = p.under; };
|
||||
if (p != nil && p.kind == tykind.TY_ARRAY) { return p; };
|
||||
};
|
||||
return t;
|
||||
};
|
||||
|
||||
// idxelemtn — element type-NODE for an indexable base tnode, the
|
||||
// node-keyed companion of idxeffti for the cgen arms that classify
|
||||
// the element structurally (istaggedtype / isstrtype / isslicetype /
|
||||
// isfloattype / tnodestoreop). Same `*[N]T` drill: the pointee array's
|
||||
// OWN element, never the array (#61 — an undrilled elemtn made the
|
||||
// store-width chooser believe the element IS `[N]T` and emit an
|
||||
// N*8-byte aggregate copy from an 8B source: caller-frame smash).
|
||||
// nil for non-indexable kinds (str N_TNAME: callers want nil so
|
||||
// tnodestoreop falls to the u8 byte store).
|
||||
fn idxelemtn(tn: *node) *node = {
|
||||
if (tn == nil) { return nil; };
|
||||
let k: nkind = tn.kind;
|
||||
if (k != nkind.N_TARRAY && k != nkind.N_TSLICE
|
||||
&& k != nkind.N_TPTR) { return nil; };
|
||||
let elem: *node = tn.lhs;
|
||||
if (k == nkind.N_TPTR && elem != nil
|
||||
&& elem.kind == nkind.N_TARRAY) {
|
||||
return elem.lhs;
|
||||
};
|
||||
return elem;
|
||||
};
|
||||
|
||||
// elemsizeof — given the type node of an indexable (`*T`, `[]T`,
|
||||
// `[N]T`, `str`), return the byte size of one element (1 for u8/i8/
|
||||
// bool/str-byte, 8 otherwise — same shape as C cgen's esz fallback).
|
||||
@@ -17280,9 +17319,15 @@ fn elemsizeofc(c: *cgen, t: *node) i32 = {
|
||||
// sub-array stride $12. Mirror cstage esz = idx_eff(bt)->sub->size
|
||||
// (cmd/w6c/cgen.c:4923): the element-array tinfo's natural size
|
||||
// (sub.size*elen, type.c:121) IS the outer stride.
|
||||
// N_TPTR is excluded (#61): a pointee-array is NOT a nested
|
||||
// element — `p[i]` on `*[N]T` auto-derefs and strides the array's
|
||||
// OWN element (idx_eff peels TY_PTR→TY_ARRAY before the .sub
|
||||
// read). Routing it through this whole-sub-array rule scaled
|
||||
// every index by N*size(T) — the siphash round() corruption. The
|
||||
// `*[N][M]T` outer stride still resolves below via idxeffti
|
||||
// (pointee array's .sub = [M]T, its natural size).
|
||||
let nk: nkind = t.kind;
|
||||
let nest: *node = nil;
|
||||
if (nk == nkind.N_TPTR) { nest = t.lhs; };
|
||||
if (nk == nkind.N_TSLICE) { nest = t.lhs; };
|
||||
if (nk == nkind.N_TARRAY) { nest = t.lhs; };
|
||||
if (nest != nil && nest.kind == nkind.N_TARRAY) {
|
||||
@@ -17303,20 +17348,16 @@ fn elemsizeofc(c: *cgen, t: *node) i32 = {
|
||||
// and the local-array-init STORE (frame-smash). Peel TY_NAMED on the
|
||||
// indexable and on its element, matching the #270-2 nested-array block
|
||||
// above. Structural slotsize fallback stays for the t.type_==nil case.
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
// idxeffti folds that peel together with the `*[N]T` TY_PTR→
|
||||
// TY_ARRAY drill (#61) so .sub is the array's element, never the
|
||||
// whole pointee array.
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti != nil) {
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
if (ti != nil) {
|
||||
let esub: *tinfo = ti.sub;
|
||||
for (esub != nil && esub.kind == tykind.TY_NAMED) { esub = esub.under; };
|
||||
if (esub != nil) { return esub.size: i32; };
|
||||
};
|
||||
let esub: *tinfo = ti.sub;
|
||||
for (esub != nil && esub.kind == tykind.TY_NAMED) { esub = esub.under; };
|
||||
if (esub != nil) { return esub.size: i32; };
|
||||
};
|
||||
let k: nkind = t.kind;
|
||||
let elem: *node = nil;
|
||||
if (k == nkind.N_TPTR) { elem = t.lhs; };
|
||||
if (k == nkind.N_TSLICE) { elem = t.lhs; };
|
||||
if (k == nkind.N_TARRAY) { elem = t.lhs; };
|
||||
let elem: *node = idxelemtn(t);
|
||||
if (elem == nil) { return direct; };
|
||||
if (elem.kind == nkind.N_TNAME) {
|
||||
let ps: i32 = primsize(elem.str);
|
||||
@@ -18209,11 +18250,8 @@ fn matchscrutt(c: *cgen, scrut: *node) *node = {
|
||||
if (bl != nil) { btn = bl.tnode; }
|
||||
else { btn = letvartnode(c, ibase.str); };
|
||||
if (btn == nil) { return nil; };
|
||||
let bk: nkind = btn.kind;
|
||||
let etn: *node = nil;
|
||||
if (bk == nkind.N_TARRAY) { etn = btn.lhs; };
|
||||
if (bk == nkind.N_TSLICE) { etn = btn.lhs; };
|
||||
if (bk == nkind.N_TPTR) { etn = btn.lhs; };
|
||||
// idxelemtn: `*[N]T` drills to the pointee array's element (#61).
|
||||
let etn: *node = idxelemtn(btn);
|
||||
if (etn == nil) { return nil; };
|
||||
return resolvetagged(c, etn);
|
||||
};
|
||||
@@ -21805,6 +21843,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
|
||||
@@ -21928,22 +21969,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)) {
|
||||
@@ -27162,13 +27195,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
|
||||
@@ -27190,14 +27222,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; };
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -27609,13 +27640,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
|
||||
@@ -27637,14 +27667,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; };
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -27795,12 +27824,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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1026,11 +1026,9 @@ fn nodeisstr(c: *cgen, n: *node) bool = {
|
||||
if (lc != nil) { bt = lc.tnode; }
|
||||
else { bt = letvartnode(c, base.str); };
|
||||
if (bt != nil) {
|
||||
let elem: *node = nil;
|
||||
let bk: nkind = bt.kind;
|
||||
if (bk == nkind.N_TARRAY) { elem = bt.lhs; };
|
||||
if (bk == nkind.N_TSLICE) { elem = bt.lhs; };
|
||||
if (bk == nkind.N_TPTR) { elem = bt.lhs; };
|
||||
// idxelemtn: `*[N]T` drills to the pointee
|
||||
// array's element (#61).
|
||||
let elem: *node = idxelemtn(bt);
|
||||
if (elem != nil) {
|
||||
return isstrtype(c, elem);
|
||||
};
|
||||
@@ -1072,11 +1070,8 @@ fn nodeisstr(c: *cgen, n: *node) bool = {
|
||||
if (streq(fi.fname, fld)) {
|
||||
let ft: *node = fi.tnode;
|
||||
if (ft != nil) {
|
||||
let elem: *node = nil;
|
||||
let fk: nkind = ft.kind;
|
||||
if (fk == nkind.N_TPTR) { elem = ft.lhs; };
|
||||
if (fk == nkind.N_TSLICE) { elem = ft.lhs; };
|
||||
if (fk == nkind.N_TARRAY) { elem = ft.lhs; };
|
||||
// idxelemtn: `*[N]T` drill (#61).
|
||||
let elem: *node = idxelemtn(ft);
|
||||
if (elem != nil) {
|
||||
return isstrtype(c, elem);
|
||||
};
|
||||
@@ -1124,8 +1119,6 @@ fn typeis8byteprimitive(c: *cgen, t: *node) bool = {
|
||||
// the stamped tinfo so alias/enum recursion lives in lib/ww/typ.ww.
|
||||
fn elemissignedc(c: *cgen, t: *node) bool = {
|
||||
if (t == nil) { return false; };
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
if (ti == nil) { return false; };
|
||||
// #65 Phase-N step-2 cleanup: peel TY_NAMED before the .sub read.
|
||||
// #64 now flows per-decl NAMED wrappers, so a NAMED-of-(`*T`/`[]T`/
|
||||
// `[N]T`) reaching here would read NAMED.sub (nil) instead of the
|
||||
@@ -1133,7 +1126,10 @@ fn elemissignedc(c: *cgen, t: *node) bool = {
|
||||
// before the eff->sub read (:3518-3520). Byte-id-neutral: every
|
||||
// aliased indexable in-tree has a u8 element (typeissigned=false
|
||||
// either way). Transitive peel matches the #63 idiom.
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
// idxeffti additionally drills `*[N]T` to the pointee array (#61)
|
||||
// so a signed-narrow element behind a pointer-to-array still
|
||||
// sign-extends on load.
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti == nil) { return false; };
|
||||
return typeissigned(ti.sub);
|
||||
};
|
||||
@@ -1148,9 +1144,8 @@ fn elemissignedc(c: *cgen, t: *node) bool = {
|
||||
// (the unstamped-base trap that broke the exprfloatkind collapse, #121).
|
||||
fn elemisfloatc(c: *cgen, t: *node) bool = {
|
||||
if (t == nil) { return false; };
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
if (ti == nil) { return false; };
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
// idxeffti = TY_NAMED peel + the `*[N]T` drill (#61).
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti == nil) { return false; };
|
||||
return typeisfloat(ti.sub);
|
||||
};
|
||||
@@ -1159,9 +1154,8 @@ fn elemisfloatc(c: *cgen, t: *node) bool = {
|
||||
// so cgindex picks MOVSS over MOVSD at the #119 element load.
|
||||
fn elemisf32c(c: *cgen, t: *node) bool = {
|
||||
if (t == nil) { return false; };
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
if (ti == nil) { return false; };
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
// idxeffti = TY_NAMED peel + the `*[N]T` drill (#61).
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti == nil) { return false; };
|
||||
return typeisf32(ti.sub);
|
||||
};
|
||||
@@ -1295,6 +1289,46 @@ export fn localloadop(c: *cgen, tnode: *node) str = {
|
||||
return loadopsz(sigd, sz);
|
||||
};
|
||||
|
||||
// idxeffti — element-effective tinfo for indexing. `*[N]T` auto-derefs
|
||||
// at an index base, so its esz/element classification must come from
|
||||
// the pointee ARRAY (stride T), not from the pointer (whose .sub is
|
||||
// the whole [N]T — the #61 stride bug, N*size(T) off target per index
|
||||
// step). One peel choke-point: every tinfo-keyed index-element answer
|
||||
// (elemsizeofc / elemissignedc / elemisfloatc / elemisf32c) routes
|
||||
// through here. Mirrors cstage idx_eff (cmd/w6c/cgen.c:1163).
|
||||
fn idxeffti(t0: *tinfo) *tinfo = {
|
||||
let t: *tinfo = t0;
|
||||
for (t != nil && t.kind == tykind.TY_NAMED) { t = t.under; };
|
||||
if (t != nil && t.kind == tykind.TY_PTR) {
|
||||
let p: *tinfo = t.sub;
|
||||
for (p != nil && p.kind == tykind.TY_NAMED) { p = p.under; };
|
||||
if (p != nil && p.kind == tykind.TY_ARRAY) { return p; };
|
||||
};
|
||||
return t;
|
||||
};
|
||||
|
||||
// idxelemtn — element type-NODE for an indexable base tnode, the
|
||||
// node-keyed companion of idxeffti for the cgen arms that classify
|
||||
// the element structurally (istaggedtype / isstrtype / isslicetype /
|
||||
// isfloattype / tnodestoreop). Same `*[N]T` drill: the pointee array's
|
||||
// OWN element, never the array (#61 — an undrilled elemtn made the
|
||||
// store-width chooser believe the element IS `[N]T` and emit an
|
||||
// N*8-byte aggregate copy from an 8B source: caller-frame smash).
|
||||
// nil for non-indexable kinds (str N_TNAME: callers want nil so
|
||||
// tnodestoreop falls to the u8 byte store).
|
||||
fn idxelemtn(tn: *node) *node = {
|
||||
if (tn == nil) { return nil; };
|
||||
let k: nkind = tn.kind;
|
||||
if (k != nkind.N_TARRAY && k != nkind.N_TSLICE
|
||||
&& k != nkind.N_TPTR) { return nil; };
|
||||
let elem: *node = tn.lhs;
|
||||
if (k == nkind.N_TPTR && elem != nil
|
||||
&& elem.kind == nkind.N_TARRAY) {
|
||||
return elem.lhs;
|
||||
};
|
||||
return elem;
|
||||
};
|
||||
|
||||
// elemsizeof — given the type node of an indexable (`*T`, `[]T`,
|
||||
// `[N]T`, `str`), return the byte size of one element (1 for u8/i8/
|
||||
// bool/str-byte, 8 otherwise — same shape as C cgen's esz fallback).
|
||||
@@ -1364,9 +1398,15 @@ fn elemsizeofc(c: *cgen, t: *node) i32 = {
|
||||
// sub-array stride $12. Mirror cstage esz = idx_eff(bt)->sub->size
|
||||
// (cmd/w6c/cgen.c:4923): the element-array tinfo's natural size
|
||||
// (sub.size*elen, type.c:121) IS the outer stride.
|
||||
// N_TPTR is excluded (#61): a pointee-array is NOT a nested
|
||||
// element — `p[i]` on `*[N]T` auto-derefs and strides the array's
|
||||
// OWN element (idx_eff peels TY_PTR→TY_ARRAY before the .sub
|
||||
// read). Routing it through this whole-sub-array rule scaled
|
||||
// every index by N*size(T) — the siphash round() corruption. The
|
||||
// `*[N][M]T` outer stride still resolves below via idxeffti
|
||||
// (pointee array's .sub = [M]T, its natural size).
|
||||
let nk: nkind = t.kind;
|
||||
let nest: *node = nil;
|
||||
if (nk == nkind.N_TPTR) { nest = t.lhs; };
|
||||
if (nk == nkind.N_TSLICE) { nest = t.lhs; };
|
||||
if (nk == nkind.N_TARRAY) { nest = t.lhs; };
|
||||
if (nest != nil && nest.kind == nkind.N_TARRAY) {
|
||||
@@ -1387,20 +1427,16 @@ fn elemsizeofc(c: *cgen, t: *node) i32 = {
|
||||
// and the local-array-init STORE (frame-smash). Peel TY_NAMED on the
|
||||
// indexable and on its element, matching the #270-2 nested-array block
|
||||
// above. Structural slotsize fallback stays for the t.type_==nil case.
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
// idxeffti folds that peel together with the `*[N]T` TY_PTR→
|
||||
// TY_ARRAY drill (#61) so .sub is the array's element, never the
|
||||
// whole pointee array.
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti != nil) {
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
if (ti != nil) {
|
||||
let esub: *tinfo = ti.sub;
|
||||
for (esub != nil && esub.kind == tykind.TY_NAMED) { esub = esub.under; };
|
||||
if (esub != nil) { return esub.size: i32; };
|
||||
};
|
||||
let esub: *tinfo = ti.sub;
|
||||
for (esub != nil && esub.kind == tykind.TY_NAMED) { esub = esub.under; };
|
||||
if (esub != nil) { return esub.size: i32; };
|
||||
};
|
||||
let k: nkind = t.kind;
|
||||
let elem: *node = nil;
|
||||
if (k == nkind.N_TPTR) { elem = t.lhs; };
|
||||
if (k == nkind.N_TSLICE) { elem = t.lhs; };
|
||||
if (k == nkind.N_TARRAY) { elem = t.lhs; };
|
||||
let elem: *node = idxelemtn(t);
|
||||
if (elem == nil) { return direct; };
|
||||
if (elem.kind == nkind.N_TNAME) {
|
||||
let ps: i32 = primsize(elem.str);
|
||||
@@ -2293,11 +2329,8 @@ fn matchscrutt(c: *cgen, scrut: *node) *node = {
|
||||
if (bl != nil) { btn = bl.tnode; }
|
||||
else { btn = letvartnode(c, ibase.str); };
|
||||
if (btn == nil) { return nil; };
|
||||
let bk: nkind = btn.kind;
|
||||
let etn: *node = nil;
|
||||
if (bk == nkind.N_TARRAY) { etn = btn.lhs; };
|
||||
if (bk == nkind.N_TSLICE) { etn = btn.lhs; };
|
||||
if (bk == nkind.N_TPTR) { etn = btn.lhs; };
|
||||
// idxelemtn: `*[N]T` drills to the pointee array's element (#61).
|
||||
let etn: *node = idxelemtn(btn);
|
||||
if (etn == nil) { return nil; };
|
||||
return resolvetagged(c, etn);
|
||||
};
|
||||
|
||||
@@ -3116,6 +3116,11 @@ fn exprtype(c: *checker, e: *node, hint: *node) *node = {
|
||||
return tn;
|
||||
};
|
||||
};
|
||||
// Retained divergence: *[N]T does NOT decay here —
|
||||
// `p[lo:hi]` types as [][N]T (C-pointer-slicing), unlike
|
||||
// the index route (idxeffti) and unlike Hare. Loud on the
|
||||
// usual []T annotation; for-range likewise. Team task #18
|
||||
// (#61-residual A).
|
||||
if (bu.kind == nkind.N_TPTR && bu.lhs != nil) {
|
||||
let sl: *node = newnode(nkind.N_TSLICE, "", 0, 0);
|
||||
sl.lhs = bu.lhs;
|
||||
|
||||
@@ -13443,6 +13443,11 @@ fn exprtype(c: *checker, e: *node, hint: *node) *node = {
|
||||
return tn;
|
||||
};
|
||||
};
|
||||
// Retained divergence: *[N]T does NOT decay here —
|
||||
// `p[lo:hi]` types as [][N]T (C-pointer-slicing), unlike
|
||||
// the index route (idxeffti) and unlike Hare. Loud on the
|
||||
// usual []T annotation; for-range likewise. Team task #18
|
||||
// (#61-residual A).
|
||||
if (bu.kind == nkind.N_TPTR && bu.lhs != nil) {
|
||||
let sl: *node = newnode(nkind.N_TSLICE, "", 0, 0);
|
||||
sl.lhs = bu.lhs;
|
||||
@@ -16942,11 +16947,9 @@ fn nodeisstr(c: *cgen, n: *node) bool = {
|
||||
if (lc != nil) { bt = lc.tnode; }
|
||||
else { bt = letvartnode(c, base.str); };
|
||||
if (bt != nil) {
|
||||
let elem: *node = nil;
|
||||
let bk: nkind = bt.kind;
|
||||
if (bk == nkind.N_TARRAY) { elem = bt.lhs; };
|
||||
if (bk == nkind.N_TSLICE) { elem = bt.lhs; };
|
||||
if (bk == nkind.N_TPTR) { elem = bt.lhs; };
|
||||
// idxelemtn: `*[N]T` drills to the pointee
|
||||
// array's element (#61).
|
||||
let elem: *node = idxelemtn(bt);
|
||||
if (elem != nil) {
|
||||
return isstrtype(c, elem);
|
||||
};
|
||||
@@ -16988,11 +16991,8 @@ fn nodeisstr(c: *cgen, n: *node) bool = {
|
||||
if (streq(fi.fname, fld)) {
|
||||
let ft: *node = fi.tnode;
|
||||
if (ft != nil) {
|
||||
let elem: *node = nil;
|
||||
let fk: nkind = ft.kind;
|
||||
if (fk == nkind.N_TPTR) { elem = ft.lhs; };
|
||||
if (fk == nkind.N_TSLICE) { elem = ft.lhs; };
|
||||
if (fk == nkind.N_TARRAY) { elem = ft.lhs; };
|
||||
// idxelemtn: `*[N]T` drill (#61).
|
||||
let elem: *node = idxelemtn(ft);
|
||||
if (elem != nil) {
|
||||
return isstrtype(c, elem);
|
||||
};
|
||||
@@ -17040,8 +17040,6 @@ fn typeis8byteprimitive(c: *cgen, t: *node) bool = {
|
||||
// the stamped tinfo so alias/enum recursion lives in lib/ww/typ.ww.
|
||||
fn elemissignedc(c: *cgen, t: *node) bool = {
|
||||
if (t == nil) { return false; };
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
if (ti == nil) { return false; };
|
||||
// #65 Phase-N step-2 cleanup: peel TY_NAMED before the .sub read.
|
||||
// #64 now flows per-decl NAMED wrappers, so a NAMED-of-(`*T`/`[]T`/
|
||||
// `[N]T`) reaching here would read NAMED.sub (nil) instead of the
|
||||
@@ -17049,7 +17047,10 @@ fn elemissignedc(c: *cgen, t: *node) bool = {
|
||||
// before the eff->sub read (:3518-3520). Byte-id-neutral: every
|
||||
// aliased indexable in-tree has a u8 element (typeissigned=false
|
||||
// either way). Transitive peel matches the #63 idiom.
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
// idxeffti additionally drills `*[N]T` to the pointee array (#61)
|
||||
// so a signed-narrow element behind a pointer-to-array still
|
||||
// sign-extends on load.
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti == nil) { return false; };
|
||||
return typeissigned(ti.sub);
|
||||
};
|
||||
@@ -17064,9 +17065,8 @@ fn elemissignedc(c: *cgen, t: *node) bool = {
|
||||
// (the unstamped-base trap that broke the exprfloatkind collapse, #121).
|
||||
fn elemisfloatc(c: *cgen, t: *node) bool = {
|
||||
if (t == nil) { return false; };
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
if (ti == nil) { return false; };
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
// idxeffti = TY_NAMED peel + the `*[N]T` drill (#61).
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti == nil) { return false; };
|
||||
return typeisfloat(ti.sub);
|
||||
};
|
||||
@@ -17075,9 +17075,8 @@ fn elemisfloatc(c: *cgen, t: *node) bool = {
|
||||
// so cgindex picks MOVSS over MOVSD at the #119 element load.
|
||||
fn elemisf32c(c: *cgen, t: *node) bool = {
|
||||
if (t == nil) { return false; };
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
if (ti == nil) { return false; };
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
// idxeffti = TY_NAMED peel + the `*[N]T` drill (#61).
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti == nil) { return false; };
|
||||
return typeisf32(ti.sub);
|
||||
};
|
||||
@@ -17211,6 +17210,46 @@ export fn localloadop(c: *cgen, tnode: *node) str = {
|
||||
return loadopsz(sigd, sz);
|
||||
};
|
||||
|
||||
// idxeffti — element-effective tinfo for indexing. `*[N]T` auto-derefs
|
||||
// at an index base, so its esz/element classification must come from
|
||||
// the pointee ARRAY (stride T), not from the pointer (whose .sub is
|
||||
// the whole [N]T — the #61 stride bug, N*size(T) off target per index
|
||||
// step). One peel choke-point: every tinfo-keyed index-element answer
|
||||
// (elemsizeofc / elemissignedc / elemisfloatc / elemisf32c) routes
|
||||
// through here. Mirrors cstage idx_eff (cmd/w6c/cgen.c:1163).
|
||||
fn idxeffti(t0: *tinfo) *tinfo = {
|
||||
let t: *tinfo = t0;
|
||||
for (t != nil && t.kind == tykind.TY_NAMED) { t = t.under; };
|
||||
if (t != nil && t.kind == tykind.TY_PTR) {
|
||||
let p: *tinfo = t.sub;
|
||||
for (p != nil && p.kind == tykind.TY_NAMED) { p = p.under; };
|
||||
if (p != nil && p.kind == tykind.TY_ARRAY) { return p; };
|
||||
};
|
||||
return t;
|
||||
};
|
||||
|
||||
// idxelemtn — element type-NODE for an indexable base tnode, the
|
||||
// node-keyed companion of idxeffti for the cgen arms that classify
|
||||
// the element structurally (istaggedtype / isstrtype / isslicetype /
|
||||
// isfloattype / tnodestoreop). Same `*[N]T` drill: the pointee array's
|
||||
// OWN element, never the array (#61 — an undrilled elemtn made the
|
||||
// store-width chooser believe the element IS `[N]T` and emit an
|
||||
// N*8-byte aggregate copy from an 8B source: caller-frame smash).
|
||||
// nil for non-indexable kinds (str N_TNAME: callers want nil so
|
||||
// tnodestoreop falls to the u8 byte store).
|
||||
fn idxelemtn(tn: *node) *node = {
|
||||
if (tn == nil) { return nil; };
|
||||
let k: nkind = tn.kind;
|
||||
if (k != nkind.N_TARRAY && k != nkind.N_TSLICE
|
||||
&& k != nkind.N_TPTR) { return nil; };
|
||||
let elem: *node = tn.lhs;
|
||||
if (k == nkind.N_TPTR && elem != nil
|
||||
&& elem.kind == nkind.N_TARRAY) {
|
||||
return elem.lhs;
|
||||
};
|
||||
return elem;
|
||||
};
|
||||
|
||||
// elemsizeof — given the type node of an indexable (`*T`, `[]T`,
|
||||
// `[N]T`, `str`), return the byte size of one element (1 for u8/i8/
|
||||
// bool/str-byte, 8 otherwise — same shape as C cgen's esz fallback).
|
||||
@@ -17280,9 +17319,15 @@ fn elemsizeofc(c: *cgen, t: *node) i32 = {
|
||||
// sub-array stride $12. Mirror cstage esz = idx_eff(bt)->sub->size
|
||||
// (cmd/w6c/cgen.c:4923): the element-array tinfo's natural size
|
||||
// (sub.size*elen, type.c:121) IS the outer stride.
|
||||
// N_TPTR is excluded (#61): a pointee-array is NOT a nested
|
||||
// element — `p[i]` on `*[N]T` auto-derefs and strides the array's
|
||||
// OWN element (idx_eff peels TY_PTR→TY_ARRAY before the .sub
|
||||
// read). Routing it through this whole-sub-array rule scaled
|
||||
// every index by N*size(T) — the siphash round() corruption. The
|
||||
// `*[N][M]T` outer stride still resolves below via idxeffti
|
||||
// (pointee array's .sub = [M]T, its natural size).
|
||||
let nk: nkind = t.kind;
|
||||
let nest: *node = nil;
|
||||
if (nk == nkind.N_TPTR) { nest = t.lhs; };
|
||||
if (nk == nkind.N_TSLICE) { nest = t.lhs; };
|
||||
if (nk == nkind.N_TARRAY) { nest = t.lhs; };
|
||||
if (nest != nil && nest.kind == nkind.N_TARRAY) {
|
||||
@@ -17303,20 +17348,16 @@ fn elemsizeofc(c: *cgen, t: *node) i32 = {
|
||||
// and the local-array-init STORE (frame-smash). Peel TY_NAMED on the
|
||||
// indexable and on its element, matching the #270-2 nested-array block
|
||||
// above. Structural slotsize fallback stays for the t.type_==nil case.
|
||||
let ti: *tinfo = t.type_: *tinfo;
|
||||
// idxeffti folds that peel together with the `*[N]T` TY_PTR→
|
||||
// TY_ARRAY drill (#61) so .sub is the array's element, never the
|
||||
// whole pointee array.
|
||||
let ti: *tinfo = idxeffti(t.type_: *tinfo);
|
||||
if (ti != nil) {
|
||||
for (ti != nil && ti.kind == tykind.TY_NAMED) { ti = ti.under; };
|
||||
if (ti != nil) {
|
||||
let esub: *tinfo = ti.sub;
|
||||
for (esub != nil && esub.kind == tykind.TY_NAMED) { esub = esub.under; };
|
||||
if (esub != nil) { return esub.size: i32; };
|
||||
};
|
||||
let esub: *tinfo = ti.sub;
|
||||
for (esub != nil && esub.kind == tykind.TY_NAMED) { esub = esub.under; };
|
||||
if (esub != nil) { return esub.size: i32; };
|
||||
};
|
||||
let k: nkind = t.kind;
|
||||
let elem: *node = nil;
|
||||
if (k == nkind.N_TPTR) { elem = t.lhs; };
|
||||
if (k == nkind.N_TSLICE) { elem = t.lhs; };
|
||||
if (k == nkind.N_TARRAY) { elem = t.lhs; };
|
||||
let elem: *node = idxelemtn(t);
|
||||
if (elem == nil) { return direct; };
|
||||
if (elem.kind == nkind.N_TNAME) {
|
||||
let ps: i32 = primsize(elem.str);
|
||||
@@ -18209,11 +18250,8 @@ fn matchscrutt(c: *cgen, scrut: *node) *node = {
|
||||
if (bl != nil) { btn = bl.tnode; }
|
||||
else { btn = letvartnode(c, ibase.str); };
|
||||
if (btn == nil) { return nil; };
|
||||
let bk: nkind = btn.kind;
|
||||
let etn: *node = nil;
|
||||
if (bk == nkind.N_TARRAY) { etn = btn.lhs; };
|
||||
if (bk == nkind.N_TSLICE) { etn = btn.lhs; };
|
||||
if (bk == nkind.N_TPTR) { etn = btn.lhs; };
|
||||
// idxelemtn: `*[N]T` drills to the pointee array's element (#61).
|
||||
let etn: *node = idxelemtn(btn);
|
||||
if (etn == nil) { return nil; };
|
||||
return resolvetagged(c, etn);
|
||||
};
|
||||
@@ -21805,6 +21843,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
|
||||
@@ -21928,22 +21969,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)) {
|
||||
@@ -27162,13 +27195,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
|
||||
@@ -27190,14 +27222,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; };
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -27609,13 +27640,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
|
||||
@@ -27637,14 +27667,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; };
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -27795,12 +27824,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;
|
||||
|
||||
Reference in New Issue
Block a user