Commit 14c43aee
14c43aee0945Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
codegen: at_exit hook calls pass a zero-init args buffer (CI fix)
main()'s at_exit loop was emitting `sp_proc_call(p, NULL)`. The proc fn unconditionally reads `args[0]` to bind the synthesized `lv__unused` even for zero-arity blocks, which makes the NULL case undefined behaviour — locally the optimizer elided the dead read, but CI gcc / clang / macos all segfaulted before the hook body ran (visible as empty stdout in at_exit_lifo / warn_kernel).
Allocate a small zero-init args[16] buffer inside a block scope at the call site so every arity up to 16 sees zeros, matching what the proc fn would have read had it been called from a normal yield.
Refs #990
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 14c43aee0945
- Parent
- 0ca54a313a97
spinel_codegen.rbmodifiedView file
} if @needs_at_exit == 1 emit_raw(" for (mrb_int _ax = sp_at_exit_count - 1; _ax >= 0; _ax--) sp_proc_call(sp_at_exit_hooks[_ax], NULL);") # Pass a zero-init args buffer instead of NULL — the proc fn's # synthesized `args[0]` read happens even for zero-arity blocks, # and reading from NULL is undefined (locally elided by the # optimizer; CI gcc/clang/macos all segfaulted on it). emit_raw(" { mrb_int _ax_args[16] = {0}; for (mrb_int _ax = sp_at_exit_count - 1; _ax >= 0; _ax--) sp_proc_call(sp_at_exit_hooks[_ax], _ax_args); }") end emit_raw(" return 0;") emit_raw("}")