w6c+wwstage: [N]struct literal element store (#270-1c)
`let x: [2]inner = [inner{..}, inner{..}]` left the array unpopulated:
the N_ARRLIT per-element store handled scalar/str/float ONLY, so a
struct/array/tuple element hit the multi-word-store gap and stored just
the first 8 bytes (cs0/ww0). Both stages symmetric-broken; converge on
the populated result (#263).
Fix: an aggregate element of an array literal fills each element slot
from its source — cg_structlit_fill_bp for an N_STRUCTLIT element,
word-copy for an N_IDENT element (reusing COMMIT 2's per-element copy
shape). esz is the element's natural size (cstage esub->size). cgen.c
N_ARRLIT arm + cgenstmt.ww cglet. An aggregate `...` repeat and other
element shapes hard-stop loud (rule-7).
949 rows: arrlit_structlit, arrlit_structident (8B struct, byteid=1,
full readback). All 96 pass; test-unit 241 green; smoke OK.
This commit is contained in:
@@ -1158,6 +1158,28 @@ static const struct row rows[] = {
|
||||
" let c: inner = a[1][0];\n"
|
||||
" return (c.a + c.b + c.c): i32;\n"
|
||||
"};\n", 66, 0 },
|
||||
/* #270-1c: `[N]struct` array LITERAL element store. The N_ARRLIT
|
||||
* per-element store handled scalar/str/float ONLY; a struct/array
|
||||
* element hit the multi-word-store gap and stored just the first 8
|
||||
* bytes (unpopulated). Fix fills each element from its literal
|
||||
* (cg_structlit_fill_bp) or source ident (word-copy). 8B struct
|
||||
* (slot==natural) keeps byteid=1; full readback of all members. */
|
||||
{ "arrlit_structlit",
|
||||
"package main;\n"
|
||||
"type inner = struct { a: u32, b: u32 };\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let x: [2]inner = [inner{a=1u32,b=2u32}, inner{a=3u32,b=4u32}];\n"
|
||||
" return (x[0].a + x[0].b + x[1].a + x[1].b): i32;\n"
|
||||
"};\n", 10, 1 },
|
||||
{ "arrlit_structident",
|
||||
"package main;\n"
|
||||
"type inner = struct { a: u32, b: u32 };\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let p: inner; p.a = 7u32; p.b = 8u32;\n"
|
||||
" let q: inner; q.a = 1u32; q.b = 2u32;\n"
|
||||
" 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 },
|
||||
{ NULL, NULL, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user