Commit a0152639
a015263931daMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): reset in_gc_scope at void initialize wrapper entry
The synthesized sp_<C>_initialize super-chain wrapper (emitted
alongside sp_<C>_new for every heap class) inherits
@in_gc_scope from whatever the prior emit left it at —
typically the heap-path constructor's tail value of 1. When the
void wrapper's body has both:
- a String pointer local (forcing declare_method_locals'
has_gc_localsbranch to want to emitSP_GC_SAVE()), and - an early bare
return(which compile_return_stmt lowers toSP_GC_RESTORE()because@in_gc_scope == 1is inherited),
declare_method_locals' guard @needs_gc == 1 && @in_gc_scope == 0
is false on the inherited 1 and skips the SP_GC_SAVE emit. The
emitted body then references _gc_saved (declared by SAVE) from
RESTORE — gcc errors with _gc_saved undeclared.
Fix: reset @in_gc_scope = 0 at the start of the void wrapper
body so declare_method_locals decides cleanly, and restore the
saved value when leaving.
Surfaced via Roundhouse's
ActiveSupport::HashWithIndifferentAccess#initialize shape:
poly-typed other = nil param + return if other.nil? early
exit + a String pointer local that needs GC rooting.
matz/spinel#314 follow-up.
Refs #314
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- a015263931da
- Parent
- 5fef0b63ea90
spinel_codegen.rbmodifiedView file
@current_method_has_self = 1 @current_method_return = "void" @current_class_idx = ci # Issue #314 follow-up: if the body contains an early `return`, # compile_return_stmt emits `SP_GC_RESTORE()` (which references # `_gc_saved`). The matching `SP_GC_SAVE()` at the top of the # function must therefore exist. emit_constructor restored # `@in_gc_scope` to its pre-constructor value just above; if # that was 1 from a stale prior emit, declare_method_locals' # `@in_gc_scope == 0` guard skips the SAVE emit and `_gc_saved` # ends up undeclared. Reset to 0 here so declare_method_locals # can decide cleanly. saved_in_gc_scope2 = @in_gc_scope @in_gc_scope = 0 all_params = @cls_meth_params[ci].split("|") all_ptypes = @cls_meth_ptypes[ci].split("|") pnames = "".split(",") @current_class_idx = -1 @current_method_return = saved_method_return @current_method_has_self = saved_has_self2 @in_gc_scope = saved_in_gc_scope2 end emit_raw("}") emit_raw("")test/initialize_void_wrapper_gc_save.rbaddedView file
Loading diff…
test/initialize_void_wrapper_gc_save.rb.expectedaddedView file
Loading diff…