wcc/ww: struct-local stack slot is the checker's natural size, not slot-padded

wwstage's slotsize() shared its TY_STRUCT arm with TUPLE/ARRAY and
returned ti.slotsize — the SUM of the slot-padded field widths. For a
struct LOCAL that over-reserves the frame slot whenever a field is a
sub-8 nested composite: a nested inner{x:u8,y:u8} (size 2, slotsize 8)
pads its in-struct footprint, and the local inherits that pad. cstage
has no slotsize SSoT — it reserves the local at f->type->size, the
checker's NATURAL r.size (cmd/w6c/cgen.c). So on outer{a:u8,
p:inner{x:u8,y:u8}, z:i64} wwstage emitted frame $32 / struct-base
-24(BP) while cstage emitted $16 / -16(BP): a uniform -8 BP shift on
every field access. Both stages exit 0 (each self-consistent), so it is
runtime-invisible — but it is a cs!=ww .s divergence (rule 10) and a
latent byte-id gate-landmine the day such a struct enters the corpus.
Same dual-SSoT leak as #44 (field-OFFSET) / #55, one notion over:
struct-local-slot-SIZE.

Fix: split the TY_STRUCT arm out and return round8(ti.size). The TUPLE
arm (8B/elem slot, user ruling #60) and the ARRAY arm (element stride,
#48 [N]Alias 24B) keep ti.slotsize — those are deliberate, ruled
divergences and are untouched. The struct-local slot consumers
(cgendecl.ww letslotsize via cglet, cgenstmt.ww) all flow through this
arm; si.totsize (registerstruct → structabisize / global-emit) is a
separate consumer and is not this path.

CLASS-N corpus-neutral: every corpus struct local is 8-aligned, so
round8(ti.size) == slotsize for all of them and the w6c_ww/wwdump_ww
emission does not move (994 byte-id on 18 corpus inputs + 995 5-tool
self-rebuild both green post-fix). 989_structlocal_frame is the
FRAME-ABSOLUTE proof (w6c vs w6c_ww .s byte-diff; nested3 + tail_u32 +
flat control) — the .s twin of the runtime 989_nestfield_run, which
deliberately does not gate the frame and points here for it.
This commit is contained in:
2026-06-13 13:57:21 +09:00
parent 037d59cf4e
commit 074e0e585e
5 changed files with 242 additions and 6 deletions

View File

@@ -257,6 +257,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
$(BIN)/test_tupfieldsize_run \
$(BIN)/test_tagtupfieldsize_run \
$(BIN)/test_nestfield_run \
$(BIN)/test_structlocal_frame \
$(BIN)/test_arrlit_tail_zero_run \
$(BIN)/test_defdim_slice_run \
$(BIN)/test_trystr_run \
@@ -776,6 +777,18 @@ $(BIN)/test_nestfield_run: test/wcc/989_nestfield_run.c \
$(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
# 989_structlocal_frame (#75): a sub-8 nested-composite struct LOCAL must
# reserve its frame slot at the struct's NATURAL size (round8(ti.size)),
# not the slot-padded ti.slotsize. wwstage's slotsize() TY_STRUCT arm
# over-reserved, so outer{a:u8,p:inner{x:u8,y:u8},z:i64} emitted frame $32
# / -24(BP) vs cstage's $16 / -16(BP) — runtime-invisible (both exit 0)
# but a cs!=ww .s divergence (rule 10) and a latent byte-id landmine. The
# FRAME-ABSOLUTE twin of the RUNTIME 989_nestfield_run: emits .s via w6c
# and w6c_ww and byte-diffs (no link, no run).
$(BIN)/test_structlocal_frame: test/wcc/989_structlocal_frame.c \
$(BIN)/w6c $(BIN)/w6c_ww | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
# 989_arrlit_tail_zero_run (#13): an under-length array literal zero-fills the
# unspecified tail, not the last value. Builds+runs on BOTH driver twins
# (rule-10), pinning the absolute value (pre-fix ww tail = last value).