w6c+wwstage: zero high pad words on scalar/float widen into a >16B tagged union (#227)

cg_widen_tagged_store (cmd/w6c/cgen.c) and the wwstage twin cgwidentaggedstorebp (selfhost/cmd/wcc/cgenutil.ww) wrote only the tag (slot+0) and value (slot+8) in their scalar and float arms, leaving the high pad words (slot+16..sz) as stack garbage on the BP/let/assign/return-scratch path, which never pre-zeroes. A passthrough return or u8-reinterpret of a narrow scalar/float widened into a >16B union (fmt's field = (...formattable | *mods) is 32B via the str variant) then read that garbage. Both stages were wrong identically, so the byte-id gates stayed green while the runtime truncated; fmt's spread-union scalar widen is the first real consumer. Both arms now tail-zero slot+16..sz (gated size>16), mirroring the tagged-subset/struct tail-zeros and keeping the stages byte-identical (rule 10). Adds runtime test 793; regenerates w6c/wwdump combined.ww. fmt byte-id graduation still awaits the other residual, #226 (io.read nominal-remap).
This commit is contained in:
2026-05-31 22:20:53 +09:00
parent 3d44f742a0
commit 1995d8e43a
6 changed files with 334 additions and 9 deletions

View File

@@ -18015,6 +18015,21 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
emitline("\tX0, ");
emitoff((slot_off + 8): i64);
emitline("(BP)\n");
// #227: zero pad words (+16..slot_sz) so a >16B union slot
// carries the full dst payload width, not just the 1-word float
// value (the BP path never pre-zeroes; a passthrough return or
// *u8 reinterpret otherwise reads stack garbage at slot+16/+24).
// Symmetric with cstage cg_widen_tagged_store float arm.
if (slot_sz > 16) {
emitline("\tXORQ\tAX, AX\n");
let zp: i32 = 16;
for (zp < slot_sz) {
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + zp): i64);
emitline("(BP)\n");
zp += 8;
};
};
// #66 Phase-N step 3: the float arm has no pattern node to ride
// the typeeq flatvariantidx path, so pick the variant by float
// kind (f32 vs f64) over tinfo.params — a shape classification
@@ -18046,11 +18061,24 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
emitline("(BP)\n");
return;
};
// Scalar payload.
// Scalar payload. #227: zero pad words (+16..slot_sz) — see float
// arm above. The BP path never pre-zeroes, so a passthrough return /
// *u8 reinterpret of the narrow-tagged value otherwise reads stack
// garbage in slot+16/+24. Symmetric with cstage scalar arm.
cgexpr(c, src);
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8): i64);
emitline("(BP)\n");
if (slot_sz > 16) {
emitline("\tXORQ\tAX, AX\n");
let zp: i32 = 16;
for (zp < slot_sz) {
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + zp): i64);
emitline("(BP)\n");
zp += 8;
};
};
let tag: i32 = taggedvariantindext(c, dt, src);
if (tag < 0) { tag = 0; };
emitline("\tMOVQ\t$");