cgen: address module-global str/slice pseudo-field stores via the symbol

A module-global base has no frame slot; treating its local-lookup miss
as offset zero wrote .ptr/.len/.cap at the caller return address. LEAQ
the symbol like the struct-field global arms do. Both stages.
This commit is contained in:
2026-08-07 23:00:08 +09:00
parent 7dc3150b65
commit 5ddada94e5
3 changed files with 67 additions and 3 deletions

View File

@@ -0,0 +1,19 @@
// A module-global slice header is not a BP-relative local. Writing its
// pseudo-fields through offset zero overwrites the caller's saved control
// state instead of the global header.
package global_slice_pseudofield_store_test;
let values: []i64 = [10, 20, 30, 40];
let replacement: [2]i64 = [70, 80];
@test fn global_header_store() void = {
values.ptr = &replacement[0];
values.len = 1;
values.cap = 2;
values.len += 1;
assert(values.len == 2);
assert(values.cap == 2);
assert(values[0] == 70);
assert(values[1] == 80);
};