w6c+wwstage: aggregate arg from any non-ident source via the closed addr machinery (#271) — close aggregate-arg family

Passing an aggregate BY VALUE as a call argument worked ONLY for a ≤16B
struct from an IDENT source; every non-ident source — CALL mk(), N_DOT
o.f, N_INDEX a[i], DEREF *p — and every array / >24B-struct (even as an
ident) fell to the scalar default: one PUSHQ for a multi-word aggregate,
stack-imbalancing against the type-based multi-word drain. cs!=ww, both
garbage (f(mk()) cs4/ww236, f(o.f) cs8/ww108, f(a[i]) cs4/ww28, f(*p)
cs4/ww140; arrays + 32B sret struct same).

The arg-pass twin of the #265/#268 let-init copy. A new aggregate-arg
push arm materialises the source into the arg convention: the source
ADDRESS in SI (ident LEAQ / deref operand / dotchainaddr #253 /
&base[i] spine #252-270) then its ceil(sz/8) words pushed high→low; a
CALL receives first — ≤24B in AX/DX/CX pushed straight, >24B sret'd
into a per-fn @aggargscr then pushed from there. The pop-forward drain
gained a matching array / >16B-struct arm and the callee prologue an
is_bigagg receive (ceil(sz/8) GP eightbytes), so caller and callee
agree on the multi-word layout. The ≤16B-struct-IDENT fast path is
untouched (byte-id preserved).

The new-arm exclusion is TYPE-keyed (the stamped tinfo, mirroring
cstage node_isstructarg over args[i]->type), not the name-keyed
structparamsize — a name-keyed gate re-opened the #211/#13 cross-module
same-leaf collision (784 symmetric: an 8B `sa.s` struct whose
name-resolution collides with `sb.s = *vtable` would miss the struct
fast path and wrongly enter the new arm, diverging from cstage's
1-word push). A float-bearing ≤16B struct from a non-ident source
loud-stops in both stages (the #165 SSE eightbyte transport the GP
push/drain can't model; out of scope). A const array/struct `def`
global as an aggregate arg is aligned DOWN to the leaner wwstage
(both loud-stop) per rule-10.

#110: cgen is compiler-imported by w6c + wwdump — main.combined.ww
regen'd for both.

949 rows: arg_{struct16,arr16,struct32}_{call,dot,idx,deref,ident},
full member readback (struct 16B reg-class + 32B sret-class + array
[4]u32, each non-ident source + ident control); byteid=1 throughout
(master both-broken-and-divergent → converge on the correct full
push, #263). All 111 dotbaseaddr + 3/3 784 pass; test-unit 241 green;
sizelint + smoke OK; the full w6c compiler source (214705 asm lines)
self-compiles cs==ww byte-id.
This commit is contained in:
2026-06-02 13:42:59 +09:00
parent 3c37b98164
commit 42dd70dc0c
7 changed files with 1204 additions and 38 deletions

View File

@@ -1180,6 +1180,147 @@ static const struct row rows[] = {
" let x: [2]inner = [p, q];\n"
" return (x[0].a + x[0].b + x[1].a + x[1].b): i32;\n"
"};\n", 18, 1 },
/* #271 aggregate ARG from any NON-IDENT source — the arg-pass twin
* of the #265/#268 let-init copy. Passing an aggregate BY VALUE as a
* call argument worked ONLY for an IDENT source (≤16B struct); every
* non-ident source (CALL mk(), N_DOT o.f, N_INDEX a[i], DEREF *p) and
* every array / >16B-struct (even as an IDENT) fell to the scalar
* default — one PUSHQ for a multi-word aggregate — stack-imbalancing
* against the multi-word drain (cs!=ww, both garbage). The fix
* materialises the source into the arg convention: the source ADDRESS
* in SI (ident LEAQ / deref / dotchainaddr #253 / &base[i] #252-270)
* then ceil(sz/8) words pushed; a CALL receives first (≤24B in
* AX/DX/CX, >24B sret'd into @aggargscr). The callee prologue gained a
* matching array / >16B-struct receive. Each callee reads back ALL
* members (full sum) so a dropped word fails. Covered: struct 16B
* (reg-class) AND struct 32B (sret-class) AND array [4]u32, from each
* non-ident source + an ident control. byteid=1 throughout: both
* stages converge on the correct full-aggregate push (master both-
* broken-and-divergent → fix correct, #263 lesson). */
{ "arg_struct16_call",
"package main;\n"
"type t = struct { x: i64, y: i64 };\n"
"fn mk() t = { let a: t; a.x=3i64; a.y=7i64; return a; };\n"
"fn sum(b: t) i64 = { return b.x + b.y; };\n"
"export fn main() i32 = { return sum(mk()): i32; };\n", 10, 1 },
{ "arg_struct16_dot",
"package main;\n"
"type t = struct { x: i64, y: i64 };\n"
"type o = struct { f: t };\n"
"fn sum(b: t) i64 = { return b.x + b.y; };\n"
"export fn main() i32 = {\n"
" let q: o; q.f.x=3i64; q.f.y=7i64;\n"
" return sum(q.f): i32;\n"
"};\n", 10, 1 },
{ "arg_struct16_idx",
"package main;\n"
"type t = struct { x: i64, y: i64 };\n"
"fn sum(b: t) i64 = { return b.x + b.y; };\n"
"export fn main() i32 = {\n"
" let a: [2]t; a[1].x=3i64; a[1].y=7i64;\n"
" return sum(a[1]): i32;\n"
"};\n", 10, 1 },
{ "arg_struct16_deref",
"package main;\n"
"type t = struct { x: i64, y: i64 };\n"
"fn sum(b: t) i64 = { return b.x + b.y; };\n"
"export fn main() i32 = {\n"
" let v: t; v.x=3i64; v.y=7i64; let p: *t = &v;\n"
" return sum(*p): i32;\n"
"};\n", 10, 1 },
{ "arg_struct16_ident",
"package main;\n"
"type t = struct { x: i64, y: i64 };\n"
"fn sum(b: t) i64 = { return b.x + b.y; };\n"
"export fn main() i32 = {\n"
" let v: t; v.x=3i64; v.y=7i64;\n"
" return sum(v): i32;\n"
"};\n", 10, 1 },
{ "arg_arr16_call",
"package main;\n"
"fn mk() [4]u32 = { let a: [4]u32; a[0]=1u32;a[1]=2u32;a[2]=3u32;a[3]=4u32; return a; };\n"
"fn sum(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; };\n"
"export fn main() i32 = { return sum(mk()); };\n", 10, 1 },
{ "arg_arr16_dot",
"package main;\n"
"type o = struct { f: [4]u32 };\n"
"fn sum(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; };\n"
"export fn main() i32 = {\n"
" let q: o; q.f[0]=1u32; q.f[1]=2u32; q.f[2]=3u32; q.f[3]=4u32;\n"
" return sum(q.f);\n"
"};\n", 10, 1 },
{ "arg_arr16_idx",
"package main;\n"
"fn sum(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; };\n"
"export fn main() i32 = {\n"
" let a: [2][4]u32;\n"
" a[1][0]=1u32; a[1][1]=2u32; a[1][2]=3u32; a[1][3]=4u32;\n"
" return sum(a[1]);\n"
"};\n", 10, 1 },
{ "arg_arr16_deref",
"package main;\n"
"fn sum(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; };\n"
"export fn main() i32 = {\n"
" let v: [4]u32; v[0]=1u32; v[1]=2u32; v[2]=3u32; v[3]=4u32;\n"
" let p: *[4]u32 = &v;\n"
" return sum(*p);\n"
"};\n", 10, 1 },
{ "arg_arr16_ident",
"package main;\n"
"fn sum(b: [4]u32) i32 = { return (b[0]+b[1]+b[2]+b[3]): i32; };\n"
"export fn main() i32 = {\n"
" let v: [4]u32; v[0]=1u32; v[1]=2u32; v[2]=3u32; v[3]=4u32;\n"
" return sum(v);\n"
"};\n", 10, 1 },
{ "arg_struct32_call",
"package main;\n"
"type t = struct { h: [8]u32 };\n"
"fn mk() t = { let a: t; a.h[0]=1u32;a.h[1]=2u32;a.h[2]=3u32;a.h[3]=4u32;a.h[4]=5u32;a.h[5]=6u32;a.h[6]=7u32;a.h[7]=8u32; return a; };\n"
"fn sum(b: t) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; };\n"
"export fn main() i32 = { return sum(mk()); };\n", 36, 1 },
{ "arg_struct32_dot",
"package main;\n"
"type t = struct { h: [8]u32 };\n"
"type o = struct { f: t };\n"
"fn sum(b: t) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; };\n"
"export fn main() i32 = {\n"
" let q: o;\n"
" q.f.h[0]=1u32;q.f.h[1]=2u32;q.f.h[2]=3u32;q.f.h[3]=4u32;\n"
" q.f.h[4]=5u32;q.f.h[5]=6u32;q.f.h[6]=7u32;q.f.h[7]=8u32;\n"
" return sum(q.f);\n"
"};\n", 36, 1 },
{ "arg_struct32_idx",
"package main;\n"
"type t = struct { h: [8]u32 };\n"
"fn sum(b: t) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; };\n"
"export fn main() i32 = {\n"
" let a: [2]t;\n"
" let p: *t = &a[1];\n"
" p.h[0]=1u32;p.h[1]=2u32;p.h[2]=3u32;p.h[3]=4u32;\n"
" p.h[4]=5u32;p.h[5]=6u32;p.h[6]=7u32;p.h[7]=8u32;\n"
" return sum(a[1]);\n"
"};\n", 36, 1 },
{ "arg_struct32_deref",
"package main;\n"
"type t = struct { h: [8]u32 };\n"
"fn sum(b: t) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; };\n"
"export fn main() i32 = {\n"
" let v: t;\n"
" v.h[0]=1u32;v.h[1]=2u32;v.h[2]=3u32;v.h[3]=4u32;\n"
" v.h[4]=5u32;v.h[5]=6u32;v.h[6]=7u32;v.h[7]=8u32;\n"
" let p: *t = &v;\n"
" return sum(*p);\n"
"};\n", 36, 1 },
{ "arg_struct32_ident",
"package main;\n"
"type t = struct { h: [8]u32 };\n"
"fn sum(b: t) i32 = { return (b.h[0]+b.h[1]+b.h[2]+b.h[3]+b.h[4]+b.h[5]+b.h[6]+b.h[7]): i32; };\n"
"export fn main() i32 = {\n"
" let v: t;\n"
" v.h[0]=1u32;v.h[1]=2u32;v.h[2]=3u32;v.h[3]=4u32;\n"
" v.h[4]=5u32;v.h[5]=6u32;v.h[6]=7u32;v.h[7]=8u32;\n"
" return sum(v);\n"
"};\n", 36, 1 },
{ NULL, NULL, 0, 0 }
};