wcc/ww: return of a module-global struct ident copies the global's bytes

Returning a global struct by name emitted nothing into the return
scratch (ww) — copy from the g(SB) base. Both-wrong pair: cstage
zeroes the retscr instead (filed task #42); rows pin ww-runtime-correct
with the documented cstage residual. Review item #41.
This commit is contained in:
2026-06-12 09:13:26 +09:00
parent b3a355744f
commit 4b8c8fd9ed
5 changed files with 200 additions and 0 deletions

View File

@@ -36329,6 +36329,14 @@ fn cgreturn(c: *cgen, n: *node) void = {
let addrsrc: bool = false;
if (rhs.kind == nkind.N_IDENT) {
okrhs = true;
// #41 (#263 ww-runtime-correct): a module-global struct
// source has no BP slot — route it through the addrsrc
// memcpy (LEAQ g(SB),SI via aggargsrcaddr). Pre-fix the
// rl==nil N_IDENT arm below emitted nothing → zeroed
// @retscr. cstage copies frame garbage (cstage half #42).
if (localfindnode(c, rhs.str) == nil) {
addrsrc = true;
};
};
if (rhs.kind == nkind.N_STRUCTLIT) {
okrhs = true;

View File

@@ -1421,6 +1421,14 @@ fn cgreturn(c: *cgen, n: *node) void = {
let addrsrc: bool = false;
if (rhs.kind == nkind.N_IDENT) {
okrhs = true;
// #41 (#263 ww-runtime-correct): a module-global struct
// source has no BP slot — route it through the addrsrc
// memcpy (LEAQ g(SB),SI via aggargsrcaddr). Pre-fix the
// rl==nil N_IDENT arm below emitted nothing → zeroed
// @retscr. cstage copies frame garbage (cstage half #42).
if (localfindnode(c, rhs.str) == nil) {
addrsrc = true;
};
};
if (rhs.kind == nkind.N_STRUCTLIT) {
okrhs = true;

View File

@@ -36329,6 +36329,14 @@ fn cgreturn(c: *cgen, n: *node) void = {
let addrsrc: bool = false;
if (rhs.kind == nkind.N_IDENT) {
okrhs = true;
// #41 (#263 ww-runtime-correct): a module-global struct
// source has no BP slot — route it through the addrsrc
// memcpy (LEAQ g(SB),SI via aggargsrcaddr). Pre-fix the
// rl==nil N_IDENT arm below emitted nothing → zeroed
// @retscr. cstage copies frame garbage (cstage half #42).
if (localfindnode(c, rhs.str) == nil) {
addrsrc = true;
};
};
if (rhs.kind == nkind.N_STRUCTLIT) {
okrhs = true;