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 bigint recv_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

@@ -12286,11 +12286,13 @@
1228612286
1228712287 # Bigint methods
1228812288 if recv_type == "bigint"
12289+ # Cast away volatile from bigint locals (see compile_bigint_arg).
12290+ rc_b = "(sp_Bigint *)" + rc
1228912291 if mname == "to_s"
12290- return "sp_bigint_to_s(" + rc + ")"
12292+ return "sp_bigint_to_s(" + rc_b + ")"
1229112293 end
1229212294 if mname == "to_i"
12293- return "sp_bigint_to_int(" + rc + ")"
12295+ return "sp_bigint_to_int(" + rc_b + ")"
1229412296 end
1229512297 end
1229612298
@@ -26710,7 +26712,8 @@
2671026712 next
2671126713 end
2671226714 if at == "bigint"
26713- emit(" { const char *_bs = sp_bigint_to_s(" + val + "); fputs(_bs, stdout); putchar('" + bsl_n + "'); }")
26715+ # Cast away volatile from bigint locals (see compile_bigint_arg).
26716+ emit(" { const char *_bs = sp_bigint_to_s((sp_Bigint *)" + val + "); fputs(_bs, stdout); putchar('" + bsl_n + "'); }")
2671426717 k = k + 1
2671526718 next
2671626719 end
@@ -26828,7 +26831,8 @@
2682826831 at = infer_type(aid)
2682926832 val = compile_expr(aid)
2683026833 if at == "bigint"
26831- emit(" fputs(sp_bigint_to_s(" + val + "), stdout);")
26834+ # Cast away volatile from bigint locals (see compile_bigint_arg).
26835+ emit(" fputs(sp_bigint_to_s((sp_Bigint *)" + val + "), stdout);")
2683226836 k = k + 1
2683326837 next
2683426838 end