Commit e848e6cd
e848e6cdfeb1Merged
Ryan Seys <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): cast bigint locals to silence volatile-discard warnings
Locals in setjmp-bearing functions (anywhere with @needs_setjmp == 1,
including any function containing begin/rescue) are emitted
volatile sp_Bigint *. The bigint runtime functions take plain
sp_Bigint *. Without an explicit (sp_Bigint *) cast at the emit
site, gcc / clang warn "discards qualifiers" and the test runner's
-Werror promotes that to a hard build fail.
An earlier surgical fix covered the four sites that the zero-division test exercised. This sweep finishes the job for the remaining dispatch paths that any bigint-inside-rescue test would re-trigger:
- compile_call_expr
bigintrecv_type arm: to_s, to_i - compile_puts_single bigint arm: puts of bigint local
- compile_puts bigint arm: puts/print of bigint local
New regression test: test/bigint_volatile_combo.rb exercises every bigint dispatch path inside begin/rescue (binary ops, comparisons, to_s, to_i, compound assigns, puts). Any future change that drops a cast will re-trip -Werror in this test.
Tests: 372 pass, 0 fail, 0 error. Bootstrap: gen2.c == gen3.c.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- e848e6cdfeb1
- Parent
- 1d5291554707
spinel_codegen.rbmodifiedView file
# Bigint methods if recv_type == "bigint" # Cast away volatile from bigint locals (see compile_bigint_arg). rc_b = "(sp_Bigint *)" + rc if mname == "to_s" return "sp_bigint_to_s(" + rc + ")" return "sp_bigint_to_s(" + rc_b + ")" end if mname == "to_i" return "sp_bigint_to_int(" + rc + ")" return "sp_bigint_to_int(" + rc_b + ")" end end next end if at == "bigint" emit(" { const char *_bs = sp_bigint_to_s(" + val + "); fputs(_bs, stdout); putchar('" + bsl_n + "'); }") # Cast away volatile from bigint locals (see compile_bigint_arg). emit(" { const char *_bs = sp_bigint_to_s((sp_Bigint *)" + val + "); fputs(_bs, stdout); putchar('" + bsl_n + "'); }") k = k + 1 next end at = infer_type(aid) val = compile_expr(aid) if at == "bigint" emit(" fputs(sp_bigint_to_s(" + val + "), stdout);") # Cast away volatile from bigint locals (see compile_bigint_arg). emit(" fputs(sp_bigint_to_s((sp_Bigint *)" + val + "), stdout);") k = k + 1 next endtest/bigint_volatile_combo.rbaddedView file
Loading diff…
test/bigint_volatile_combo.rb.expectedaddedView file
Loading diff…