selfhost+test: wwstage type-info loss through struct-field N_INDEX (#37)

The original #37 symptom (worker-34's `..findflag` mangle) cannot
reproduce on master — was a runtime miscompile misattributed to a
link-time issue. Investigation surfaced three real wwstage cgen
gaps in the N_INDEX-through-struct-field family, sister bugs to
#34 (N_INDEX N_IDENT-base) and #36 (primsize-default-to-8).

1. `indexbaseesz` slice-element stride defaulted to 8 for named-
   struct elements. `&opts.ptr[i]` for `opts: *[]option` computed
   MOVQ $8 instead of $24. Fix: route slice case through
   `elemsizeofc(c, innert)`; ptr-to-named-struct via structlookup.

2. `cgun TK_AMP N_INDEX` ignored N_DOT base. `&p.ptr[i]` left
   esz=8 because only N_IDENT base was handled. Mirror cgindex's
   existing N_DOT arm.

3. `nodeisstr` N_INDEX arm only walked N_IDENT bases. `cmd.argsptr[i]`
   for `argsptr: *str` returned false; pushargsrev dropped the
   .len half at call sites. Add N_DOT-base arm that walks the
   struct field's pointee.

Test 713 (struct_field_index): 3 rows × 2 stages = 6 fixtures, one
per fix shape. Runtime-only; bootstrap byte-id (995_self_rebuild)
covers cross-stage drift.

Residual: getopttest's errortable still fails through wwstage with
a slice-of-str-via-&arr[expr] miscompile. Filed as task #38.
This commit is contained in:
2026-05-16 12:52:36 +09:00
parent 2fb594748c
commit de3bd5cc3b
6 changed files with 452 additions and 6 deletions

View File

@@ -236,6 +236,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
$(BIN)/test_cgreturn_variant_zero \
$(BIN)/test_arrlit_str_full \
$(BIN)/test_redecl \
$(BIN)/test_struct_field_index \
$(BIN)/test_param_shadow_mod \
$(BIN)/test_localoff_scope \
$(BIN)/test_cast_enum_movl \
@@ -463,6 +464,12 @@ $(BIN)/test_redecl: test/wcc/712_redecl.c \
$(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
$(BIN)/test_struct_field_index: test/wcc/713_struct_field_index.c \
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
$(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
$(BIN)/test_use_promote_alias: test/wcc/699_use_promote_alias.c \
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
$(LIB)/libwwrt.a | $(BIN)