wcc/ww: widen of a module-global tagged ident copies the whole box

Widening a global tagged union into a wider tagged slot copied
nothing of the box; treat the global ident as a tagged source and
copy the full box from g(SB) through the nested arm. Both-wrong pair:
cstage spills frame garbage as the box (filed task #44, residual
non-deterministic so the rows assert divergence only). The non-nested
SUBSET-widen shape remains open as task #49 (site comment at the
fall-through). Review item #51.
This commit is contained in:
2026-06-12 09:21:16 +09:00
parent 32848194d7
commit e416885d96
5 changed files with 328 additions and 30 deletions

View File

@@ -21303,6 +21303,14 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
// cg_widen_tagged_store's nested arm (cmd/w6c/cgen.c).
let srctagged: bool = (rhstaggedident(c, src) != nil)
|| rhstaggedabicall(c, src);
// #51 (#263): a module-global tagged ident is also a tagged source
// (no local slot — handled by the global branch in the nested copy).
if (!srctagged) { if (src.kind == nkind.N_IDENT) {
if (localfindnode(c, src.str) == nil) {
let gtn51: *node = letvartnode(c, src.str);
if (gtn51 != nil) { if (istaggedtype(c, gtn51)) { srctagged = true; }; };
};
}; };
if (srctagged) {
let nested: i32 = flatvariantidxt(dt, src.type_: *tinfo, false);
if (nested >= 0) {
@@ -21337,18 +21345,42 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
};
if (src.kind == nkind.N_IDENT) {
let lc: *local = localfindnode(c, src.str);
let soff: i32 = lc.off;
let ck: i32 = 0;
for (ck < ssz) {
emitline("\tMOVQ\t");
emitoff((soff + ck): i64);
emitline("(BP), AX\n");
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8 + ck): i64);
emitline("(BP)\n");
ck += 8;
if (lc != nil) {
let soff: i32 = lc.off;
let ck: i32 = 0;
for (ck < ssz) {
emitline("\tMOVQ\t");
emitoff((soff + ck): i64);
emitline("(BP), AX\n");
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8 + ck): i64);
emitline("(BP)\n");
ck += 8;
};
} else {
// #51 (#263 ww-runtime-correct): a module-global tagged
// ident source — no BP slot. Land g(SB) in SI
// (aggargsrcaddr) and copy the inner box to slot+8.
// Pre-fix rhstaggedident returned nil for a global, so
// srctagged was false and the value fell to the scalar
// word0 arm — gi's TAG landed as the payload. cstage
// copies frame garbage (cstage half #44).
if (aggargsrcaddr(c, src, "SI")) {
let ck2: i32 = 0;
for (ck2 < ssz) {
emitline("\tMOVQ\t");
emitoff(ck2: i64);
emitline("(SI), AX\n");
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8 + ck2): i64);
emitline("(BP)\n");
ck2 += 8;
};
};
};
} else {
// non-nested SUBSET-widen of a GLOBAL tagged
// source still mis-copies (both stages) — task #49.
// #38b: an sret-classified call result is in
// memory (AX = dest pointer), not the cursor —
// the spill below would store the pointer as

View File

@@ -3883,6 +3883,14 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
// cg_widen_tagged_store's nested arm (cmd/w6c/cgen.c).
let srctagged: bool = (rhstaggedident(c, src) != nil)
|| rhstaggedabicall(c, src);
// #51 (#263): a module-global tagged ident is also a tagged source
// (no local slot — handled by the global branch in the nested copy).
if (!srctagged) { if (src.kind == nkind.N_IDENT) {
if (localfindnode(c, src.str) == nil) {
let gtn51: *node = letvartnode(c, src.str);
if (gtn51 != nil) { if (istaggedtype(c, gtn51)) { srctagged = true; }; };
};
}; };
if (srctagged) {
let nested: i32 = flatvariantidxt(dt, src.type_: *tinfo, false);
if (nested >= 0) {
@@ -3917,18 +3925,42 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
};
if (src.kind == nkind.N_IDENT) {
let lc: *local = localfindnode(c, src.str);
let soff: i32 = lc.off;
let ck: i32 = 0;
for (ck < ssz) {
emitline("\tMOVQ\t");
emitoff((soff + ck): i64);
emitline("(BP), AX\n");
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8 + ck): i64);
emitline("(BP)\n");
ck += 8;
if (lc != nil) {
let soff: i32 = lc.off;
let ck: i32 = 0;
for (ck < ssz) {
emitline("\tMOVQ\t");
emitoff((soff + ck): i64);
emitline("(BP), AX\n");
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8 + ck): i64);
emitline("(BP)\n");
ck += 8;
};
} else {
// #51 (#263 ww-runtime-correct): a module-global tagged
// ident source — no BP slot. Land g(SB) in SI
// (aggargsrcaddr) and copy the inner box to slot+8.
// Pre-fix rhstaggedident returned nil for a global, so
// srctagged was false and the value fell to the scalar
// word0 arm — gi's TAG landed as the payload. cstage
// copies frame garbage (cstage half #44).
if (aggargsrcaddr(c, src, "SI")) {
let ck2: i32 = 0;
for (ck2 < ssz) {
emitline("\tMOVQ\t");
emitoff(ck2: i64);
emitline("(SI), AX\n");
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8 + ck2): i64);
emitline("(BP)\n");
ck2 += 8;
};
};
};
} else {
// non-nested SUBSET-widen of a GLOBAL tagged
// source still mis-copies (both stages) — task #49.
// #38b: an sret-classified call result is in
// memory (AX = dest pointer), not the cursor —
// the spill below would store the pointer as

View File

@@ -21303,6 +21303,14 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
// cg_widen_tagged_store's nested arm (cmd/w6c/cgen.c).
let srctagged: bool = (rhstaggedident(c, src) != nil)
|| rhstaggedabicall(c, src);
// #51 (#263): a module-global tagged ident is also a tagged source
// (no local slot — handled by the global branch in the nested copy).
if (!srctagged) { if (src.kind == nkind.N_IDENT) {
if (localfindnode(c, src.str) == nil) {
let gtn51: *node = letvartnode(c, src.str);
if (gtn51 != nil) { if (istaggedtype(c, gtn51)) { srctagged = true; }; };
};
}; };
if (srctagged) {
let nested: i32 = flatvariantidxt(dt, src.type_: *tinfo, false);
if (nested >= 0) {
@@ -21337,18 +21345,42 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
};
if (src.kind == nkind.N_IDENT) {
let lc: *local = localfindnode(c, src.str);
let soff: i32 = lc.off;
let ck: i32 = 0;
for (ck < ssz) {
emitline("\tMOVQ\t");
emitoff((soff + ck): i64);
emitline("(BP), AX\n");
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8 + ck): i64);
emitline("(BP)\n");
ck += 8;
if (lc != nil) {
let soff: i32 = lc.off;
let ck: i32 = 0;
for (ck < ssz) {
emitline("\tMOVQ\t");
emitoff((soff + ck): i64);
emitline("(BP), AX\n");
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8 + ck): i64);
emitline("(BP)\n");
ck += 8;
};
} else {
// #51 (#263 ww-runtime-correct): a module-global tagged
// ident source — no BP slot. Land g(SB) in SI
// (aggargsrcaddr) and copy the inner box to slot+8.
// Pre-fix rhstaggedident returned nil for a global, so
// srctagged was false and the value fell to the scalar
// word0 arm — gi's TAG landed as the payload. cstage
// copies frame garbage (cstage half #44).
if (aggargsrcaddr(c, src, "SI")) {
let ck2: i32 = 0;
for (ck2 < ssz) {
emitline("\tMOVQ\t");
emitoff(ck2: i64);
emitline("(SI), AX\n");
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8 + ck2): i64);
emitline("(BP)\n");
ck2 += 8;
};
};
};
} else {
// non-nested SUBSET-widen of a GLOBAL tagged
// source still mis-copies (both stages) — task #49.
// #38b: an sret-classified call result is in
// memory (AX = dest pointer), not the cursor —
// the spill below would store the pointer as