Commit 14c43aee

14c43aee0945Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 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

@@ -12721,7 +12721,11 @@
1272112721 }
1272212722
1272312723 if @needs_at_exit == 1
12724- emit_raw(" for (mrb_int _ax = sp_at_exit_count - 1; _ax >= 0; _ax--) sp_proc_call(sp_at_exit_hooks[_ax], NULL);")
12724+ # Pass a zero-init args buffer instead of NULL — the proc fn's
12725+ # synthesized `args[0]` read happens even for zero-arity blocks,
12726+ # and reading from NULL is undefined (locally elided by the
12727+ # optimizer; CI gcc/clang/macos all segfaulted on it).
12728+ 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); }")
1272512729 end
1272612730 emit_raw(" return 0;")
1272712731 emit_raw("}")