w6c+wwstage: read array field of a global struct (#249 BUG B)
Reading an array-typed field of a module-global struct value (`G.arr[i]`) silently miscompiled: the N_INDEX fallback's cg_dotbase_addr (cstage) / dotbaseaddr (wwstage) helper — the #135 sibling that computes &(s.field) for a `[N]T` field — had no module-global-struct base arm. cstage emitted `LEAQ (BP)` (localfind returns 0 for a global, so it read the stack frame → 0); wwstage's localfindnode returned nil and the fallback keyed on the FIELD name, so it returned false and the caller's cgexpr(N_DOT) loaded the field VALUE as a pointer → SEGFAULT. The .data was already correct (emit_struct_lit_bytes #129 A.3); only the READ base address was wrong. Both stages now emit `LEAQ name(SB) (+ ADDQ field_off)` for a global value-struct base, mirroring the scalar global-field read (cgen.c:7532); const globals resolve via def_isstructdef. Symmetric both stages (rule 10), byte-identical .s. Unblocks base64's `const std_encoding.encmap[i]` reads (#22). Test 949_structlit_arrfield_run: global `let`/`def` struct array-field read, cstage run + cs==ww byte-id.
This commit is contained in:
6
Makefile
6
Makefile
@@ -402,6 +402,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
|
||||
$(BIN)/test_deref_narrow_run \
|
||||
$(BIN)/test_idx_compound_run \
|
||||
$(BIN)/test_dotbase_arr_run \
|
||||
$(BIN)/test_structlit_arrfield_run \
|
||||
$(BIN)/test_continue_run \
|
||||
$(BIN)/test_callret_unsigned_arith_run \
|
||||
$(BIN)/test_sar_shr_run \
|
||||
@@ -1592,6 +1593,11 @@ $(BIN)/test_dotbase_arr_run: test/wcc/949_dotbase_arr_run.c $(BIN)/ww \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)/test_structlit_arrfield_run: test/wcc/949_structlit_arrfield_run.c \
|
||||
$(BIN)/ww $(BIN)/w6c $(BIN)/w6c_ww $(BIN)/w6a $(BIN)/w6l \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)/test_continue_run: test/wcc/911_continue_run.c $(BIN)/ww \
|
||||
$(BIN)/w6c $(BIN)/w6c_ww $(BIN)/w6a $(BIN)/w6l \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
|
||||
Reference in New Issue
Block a user