cgen: load the full header for a wwstage global-dot slice field

let x: []T = g.buf on a module-global struct dispatched only str
fields to the 3-word header load; a []T field fell to the scalar
tail (ptr word only), so len/cap read stale registers and the shape
was byteid-divergent against cstage's TY_STR||TY_SLICE arm (#263).
This commit is contained in:
2026-08-08 00:23:55 +09:00
parent 8a9be47f65
commit cc22abfc04
3 changed files with 35 additions and 5 deletions

View File

@@ -0,0 +1,25 @@
//ww:run
// A module-global struct's slice field read BY VALUE must load the
// full 24B {ptr,len,cap} header. The pre-fix wwstage global-dot arm
// dispatched only str fields to the header load; a []T field fell to
// the scalar tail (ptr word only) and len(x) read stale registers.
package main;
type box = struct {
buf: []i32,
name: str,
};
let g: box = box{};
export fn main() int = {
let arr: [4]i32 = [10, 20, 30, 40];
g.buf = arr[:];
g.name = "globals";
let x: []i32 = g.buf;
if (len(x) != 4) { return 1; };
if (x[2] != 30) { return 2; };
let s: str = g.name;
if (len(s) != 7) { return 3; };
return 0;
};