wcc/cgen: #52 error-first tagged-union success tag — successtag helper not hardcoded 0 (wwstage)
An error-first tagged union -- error variant at tag 0, success at tag 1+, e.g. (myerr | u16) -- was silently miscompiled by wwstage: the try/propagate codegen hardcoded success = tag 0, so the actual success value (tag 1) failed the CMPQ $0 and fell to the error path -> exit(1) instead of the value (44). cstage was correct (computes the success tag via cg_tagged_success_tag = first non-error variant). wwstage-only: a successtag/successvariant helper (mirroring cstage) replaces the hardcoded tag-0 / first-param assumption at all four try sites -- cgtryprop (?), cgtryunw (!), and the two latent shift sites cgtrytupleshift + cgtrytaggedshift (which bite an error-first union with an aggregate success payload). Success-first unions (the Hare idiom + what the selfhost uses) keep successtag=0 -> CMPQ $0 unchanged -> byte-id-neutral on 990-997. cstage untouched (w6c md5 unchanged). byte-id 990-997 8/8. test/wcc/825 table-driven (errfirst must/prop + tuple-success + success-first control). A separate nested-tagged-union construction divergence is filed (#10/#125).
This commit is contained in:
7
Makefile
7
Makefile
@@ -253,6 +253,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
|
||||
$(BIN)/test_struct_global_byval_arg \
|
||||
$(BIN)/test_inferred_global_let \
|
||||
$(BIN)/test_inferred_float_global \
|
||||
$(BIN)/test_errfirst_union_try \
|
||||
$(BIN)/test_slice_str_global_zero \
|
||||
$(BIN)/test_slice_literal_global \
|
||||
$(BIN)/test_global_arr_elem_field \
|
||||
@@ -679,6 +680,12 @@ $(BIN)/test_inferred_float_global: test/wcc/824_inferred_float_global.c $(BIN)/w
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)/test_errfirst_union_try: test/wcc/825_errfirst_union_try.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_def_arr_infer_len: test/wcc/814_def_arr_infer_len.c $(BIN)/ww \
|
||||
$(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
||||
|
||||
Reference in New Issue
Block a user