wcc/ww: no-init array global emits one DATAW slot, not two

The str-size arm of the global data emit was size-keyed and matched a
24-sized array, emitting a second DATAW for the same symbol. Gate on
the array kind (!isarr8). Review item #12.
This commit is contained in:
2026-06-13 00:14:35 +09:00
parent 0f0d2d2c1c
commit 94a55c565f
5 changed files with 196 additions and 3 deletions

View File

@@ -43467,7 +43467,14 @@ fn emitletdataw(c: *cgen, file: *node) void = {
emitline("\"\n");
};
};
if (sz == primtypesize("str"): i32 && !issg && !istup && !istagged && !letvarisslice(c, nm)) {
// #12: this arm is SIZE-keyed (sz == 24), not type-keyed,
// so a no-init array global whose bytes sum to str width
// (e.g. `let g: [3]u64;`) matched here AND the TY_ARRAY arm
// below → two identical `DATAW g` rows (cstage is type-
// keyed via let_isstr and emits one). Exclude arrays — the
// emitarraydata path owns them — mirroring the existing
// isarr8 guard on the sz==8 scalar arm.
if (sz == primtypesize("str"): i32 && !issg && !istup && !istagged && !isarr8 && !letvarisslice(c, nm)) {
let r: *node = d.rhs;
for (r != nil) {
if (r.kind != nkind.N_CAST) { break; };

View File

@@ -2936,7 +2936,14 @@ fn emitletdataw(c: *cgen, file: *node) void = {
emitline("\"\n");
};
};
if (sz == primtypesize("str"): i32 && !issg && !istup && !istagged && !letvarisslice(c, nm)) {
// #12: this arm is SIZE-keyed (sz == 24), not type-keyed,
// so a no-init array global whose bytes sum to str width
// (e.g. `let g: [3]u64;`) matched here AND the TY_ARRAY arm
// below → two identical `DATAW g` rows (cstage is type-
// keyed via let_isstr and emits one). Exclude arrays — the
// emitarraydata path owns them — mirroring the existing
// isarr8 guard on the sz==8 scalar arm.
if (sz == primtypesize("str"): i32 && !issg && !istup && !istagged && !isarr8 && !letvarisslice(c, nm)) {
let r: *node = d.rhs;
for (r != nil) {
if (r.kind != nkind.N_CAST) { break; };

View File

@@ -43467,7 +43467,14 @@ fn emitletdataw(c: *cgen, file: *node) void = {
emitline("\"\n");
};
};
if (sz == primtypesize("str"): i32 && !issg && !istup && !istagged && !letvarisslice(c, nm)) {
// #12: this arm is SIZE-keyed (sz == 24), not type-keyed,
// so a no-init array global whose bytes sum to str width
// (e.g. `let g: [3]u64;`) matched here AND the TY_ARRAY arm
// below → two identical `DATAW g` rows (cstage is type-
// keyed via let_isstr and emits one). Exclude arrays — the
// emitarraydata path owns them — mirroring the existing
// isarr8 guard on the sz==8 scalar arm.
if (sz == primtypesize("str"): i32 && !issg && !istup && !istagged && !isarr8 && !letvarisslice(c, nm)) {
let r: *node = d.rhs;
for (r != nil) {
if (r.kind != nkind.N_CAST) { break; };