wcc: N_DOT-base address arithmetic for [N]T-field index (#135)
Strategy (a) use-site fix: new helper cg_dotbase_addr (cstage) / dotbaseaddr (wwstage) detects `base.kind == N_DOT` whose field type is TY_ARRAY and emits the field's address inline — LEAQ inner_off+ field_off(BP) for a value-struct inner, MOVQ inner_off(BP),reg + ADDQ field_off,reg for a *struct inner. The TY_ARRAY-only gate (after TY_NAMED peel) keeps the helper INERT on TY_PTR/TY_SLICE/TY_STR/ TY_TAGGED field kinds where the existing cgexpr(base) path is correct (loads pointer/header value, then adds scaled index). Wired at 6 sites: cstage cgassign N_INDEX-lhs plain ASSIGN + #133 compound arm + cgindex N_INDEX read fallback; wwstage twin × 3. Closes the silent-segfault on `(*struct).array_field[i]` reads and writes — pre-fix cgexpr on the N_DOT base auto-derefed and loaded the field's first 8 bytes as if they were a pointer, faulting on packed [N]u8 arrays (small u64 → unmapped page). Bootstrap-NEUTRAL: zero working callers in either direction pre-fix (symmetric READ + WRITE segfault evidence). All corpus + 990-997 byte-id + combined_ww_fresh stay green post-fix. 949_dotbase_arr_run: 3 rows direct runtime + cs==ww byte-id (READ u8, plain WRITE u8, compound WRITE u8). Wider element widths and value-struct base / pointer-field-control rows deferred — blocked by orthogonal pre-existing wwstage divergences (i32-return ABI MOVSXD vs MOVL, uninit-struct-let zero-init asymmetry) documented in the test body. The TY_ARRAY-gate no-over-fire is implicitly verified by 994/995 (corpus exercises thousands of struct.pointerfield[i] shapes; any over-fire would shift bytes). Chained N_DOT (`outer.inner.array[i]` depth ≥2) deferred to #137 — confirmed not in ref/hare/strconv/decimal.ha or sibling strconv/. Not a fold-3 blocker; helper bails (returns false) on chained shape, caller falls back to existing cgexpr path.
This commit is contained in:
6
Makefile
6
Makefile
@@ -331,6 +331,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
|
||||
$(BIN)/test_floatarr_run \
|
||||
$(BIN)/test_deref_narrow_run \
|
||||
$(BIN)/test_idx_compound_run \
|
||||
$(BIN)/test_dotbase_arr_run \
|
||||
$(BIN)/test_f64cgen_run \
|
||||
$(BIN)/test_f64crossmod_run \
|
||||
$(BIN)/test_tuprecv_run \
|
||||
@@ -1100,6 +1101,11 @@ $(BIN)/test_idx_compound_run: test/wcc/948_idx_compound_run.c $(BIN)/ww \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)/test_dotbase_arr_run: test/wcc/949_dotbase_arr_run.c $(BIN)/ww \
|
||||
$(BIN)/w6c $(BIN)/w6c_ww $(BIN)/w6a $(BIN)/w6l \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)/test_f64cgen_run: test/wcc/951_f64cgen_run.c $(BIN)/ww $(BIN)/w6c \
|
||||
$(BIN)/w6a $(BIN)/w6l $(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
Reference in New Issue
Block a user