wwstage: size struct tuple-field slot via fieldsize (#237)
The wwstage checker `fieldslotsize` (check.ww) summed each struct field's
SLOT width to stamp the enclosing struct's tinfo.slotsize, but had no
TY_TUPLE arm — a tuple-typed field fell through to the 8B default. So
`struct { f: ([]u8,[]u8) }` stamped slotsize=8 while size=48 (the natural
element sum, correct). A `let s: S` slot is allocated off ti.slotsize
(cgenutil.ww slotsize), so wwstage reserved an 8-byte frame slot for a
48-byte struct: a SILENT stack-corrupting miscompile.
cstage has no size/slotsize split — it sizes the field at f->type->size=48
throughout — so the stages diverged on the emitted frame ($16 wwstage vs
$64 cstage), invisible to a cstage-only check and caught only by cs==ww
byte-id (rule 10).
Add the TY_TUPLE arm (return the tuple's own slotsize, the per-element slot
sum already stamped at the N_TTUPLE arm with slices at 24 each). This
aligns the checker's field-slotsize with cgenutil.ww fieldsize, which
already returns the tuple's natural size (48). The stale comment claiming
"TY_TUPLE inside a struct currently defaults to 8 in cgenutil" is removed —
fieldsize stopped defaulting to 8 at the 2026-05-23 review.
Test 930 pins cs==ww .s byte-id for a struct with a tuple field (with and
without a leading scalar field, foff 0 and !=0); pure frame-size gate, no
runtime — the divergence is fully visible in the emitted assembly. No
selfhost source has a tuple-typed struct field, so the w6c/wwdump combined
amalgams regen with no asm change (byte-id-neutral bootstrap).
This commit is contained in:
7
Makefile
7
Makefile
@@ -364,6 +364,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
|
||||
$(BIN)/test_len_strglobal_run \
|
||||
$(BIN)/test_tuple_sret_callee \
|
||||
$(BIN)/test_tuple_sret_receive_run \
|
||||
$(BIN)/test_struct_tuple_field_slot \
|
||||
$(BIN)/test_widen_pad_zero_run \
|
||||
$(BIN)/test_named_ptr_alias_variant_widen \
|
||||
$(BIN)/test_single_field_struct_zeroinit \
|
||||
@@ -879,6 +880,12 @@ $(BIN)/test_tuple_sret_receive_run: test/wcc/799_tuple_sret_receive_run.c \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
# #237: a tuple-typed struct field must contribute its real slot width to
|
||||
# the enclosing struct's slotsize — pure cs==ww .s byte-id (frame size).
|
||||
$(BIN)/test_struct_tuple_field_slot: test/wcc/930_struct_tuple_field_slot.c \
|
||||
$(BIN)/w6c $(BIN)/w6c_ww | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
# #15: widening a bare *vtable into a NAMED-alias variant (`stream` =
|
||||
# *vtable) of `(file | stream)` must compute the right tag, not default
|
||||
# to tag 0. Both-stage byte-id + runtime, plus a degenerate-ambiguity
|
||||
|
||||
Reference in New Issue
Block a user