wcc/cgen: #84 uninit [N]T array zero-fill (both-stage)

Drop the `!TY_ARRAY` exclusion in the bare-let no-rhs zero-fill (cgen.c
N_LET else + cgenstmt.ww cglet, both gated `sz>8 && !TY_ARRAY`) so an
uninit `[N]T` array local zero-fills like every other composite (Go-zero
per user ruling). The zero-fill extent is the array's chased ABI size
(lu->size / chased tinfo.size, rule-13 — never a hardcoded count*esz),
NOT the slot-padded letslotsize, so a non-8-multiple array ([20]u8 = 20)
zeroes its exact bytes instead of over-zeroing to the 24B slot. The
unrolled MOVQ/MOVL/MOVB run mirrors the existing composite path; the
largest real local array ([256]u8) is 32 MOVQs (pathbuf[4096] is a
module GLOBAL, BSS-filled — never on this stack path, so no large-fill
case exists).

Closes a gate-blind #263-class bug: `let a: [3]int;` (no init) read
whatever the stack held — a clean frame masked it (fresh stack = 0), a
dirtied frame exposed it (d_array=165 garbage). BOTH stages emitted no
fill, both-wrong-IDENTICAL, so the cs==ww byte-id net could not see it.
The load-bearing net is therefore a RUNTIME dirtied-stack zero-read
(944_array_zeroinit_run: array-elem / narrow [4]u32 / non-8-mult [20]u8
/ 2D + an initialized control), not asm presence.

Deliberate byte-id EVENT: every uninit-array source site gains zero-fill
insns, so the 990-997 .s MOVE vs the prior tree; cs==ww HOLDS (both add
the identical insns). The 990-997 byte-id + 995 self-rebuild staying
GREEN is the fixpoint proof — it proves every uninit compiler-array is
write-before-read, so the zero-fill is purely additive and the
ww1->ww2->ww3 self-rebuild fixpoint holds by construction. w6c/wwdump
main.combined.ww regenerated (cgenstmt.ww embeds there).

#84 is ARRAY-ONLY; the no-default reject-set (uninit tagged / plain-*T)
is split to #113, parked behind a ruling — selfhost relies on the
current (void|T) zero-fill (the "not-set-yet" idiom).
This commit is contained in:
2026-06-06 14:10:17 +09:00
parent 5d596206c6
commit 00d9580c9f
6 changed files with 312 additions and 97 deletions

View File

@@ -35525,33 +35525,14 @@ fn cglet(c: *cgen, n: *node) void = {
// `XORQ AX,AX` + a run of `MOVQ AX, ...` over the slot
// so reads after the bare let see {0...} rather than
// stack garbage.
// `[N]T` arrays of size != 8 keep the per-index-write
// contract — they're left uninit.
let isarr: bool = false;
if (n.lhs != nil) {
if (n.lhs.kind == nkind.N_TARRAY) { isarr = true; };
};
// #79 rider (#60 family): alias-NAMED bare let — the array
// classify must see through the N_TNAME leaf or an alias-
// to-array takes the composite zero-fill cstage doesn't
// emit (cstage keys on the chased lu->kind: arrays keep the
// per-index-write contract). An 8B alias-array stays
// isarr=false so it falls to the zsz==8 MOVQ $0 arm,
// matching cstage's 8B single-store shape.
if (!isarr && n.lhs != nil) {
if (n.lhs.kind == nkind.N_TNAME) {
let ati79: *tinfo = n.lhs.type_: *tinfo;
if (ati79 != nil) { if (ati79.kind == tykind.TY_NAMED) {
let au79: *tinfo = tichase(ati79);
if (au79 != nil) {
if (au79.kind == tykind.TY_ARRAY
&& au79.size: i32 != 8) {
isarr = true;
};
};
};};
};
};
// #84 (user ruling, Go-zero): `[N]T` arrays zero-fill like
// every other composite. They were excluded here, so a
// dirtied-stack `let a: [3]int;` read garbage — BOTH stages,
// both-wrong-IDENTICAL, gate-blind (#263). Dropping the
// exclusion (cstage dropped `!TY_ARRAY` symmetrically) routes
// arrays into the zsz>8 / zsz==8 arms below; an 8B array is
// already caught by typeis8byteprimitive (TY_ARRAY size==8) →
// single MOVQ $0, matching cstage's sz==8 store.
// Zero-fill extent. cstage sizes the run on `lu->size`
// (the natural ABI size from the type table, cgen.c:8397);
// wwstage's `sz` from letslotsize is slot-padded (round-to-8),
@@ -35567,20 +35548,30 @@ fn cglet(c: *cgen, n: *node) void = {
// UNTOUCHED — moving the fix there would shift field offsets.
let zsz: i32 = sz;
if (n.lhs != nil) {
if (n.lhs.kind == nkind.N_TNAME) {
// #84: an array's zero-fill extent is its chased ABI
// size (cstage `lu->size`), NOT the slot-padded sz from
// letslotsize — a non-8-multiple array (e.g. [20]u8 = 20)
// would over-zero MOVQ-rounded to 24 and diverge from
// cstage's exact 20-byte run. Handles direct N_TARRAY and
// alias-to-array (N_TNAME chasing through TY_NAMED) alike.
let zti: *tinfo = n.lhs.type_: *tinfo;
zti = tichase(zti);
if (zti != nil && zti.kind == tykind.TY_ARRAY) {
zsz = zti.size: i32;
} else { if (n.lhs.kind == nkind.N_TNAME) {
let szi: *structinfo = structlookupchain(c, n.lhs);
if (szi != nil) {
let ti: *tinfo = n.lhs.type_: *tinfo;
ti = tichase(ti);
if (ti != nil) { zsz = ti.size: i32; };
};
};
}; };
};
if (typeis8byteprimitive(c, n.lhs)) {
emitline("\tMOVQ\t$0, ");
emitoff(off: i64);
emitline("(BP)\n");
} else { if (!isarr) { if (zsz > 8) {
} else { if (zsz > 8) {
emitline("\tXORQ\tAX, AX\n");
let zi: i32 = 0;
for (zi + 8 <= zsz) {
@@ -35614,7 +35605,7 @@ fn cglet(c: *cgen, n: *node) void = {
emitline("\tMOVQ\t$0, ");
emitoff(off: i64);
emitline("(BP)\n");
}; }; }; };
}; }; };
};
c.lastwasreturn = 0;
return;