diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb index 1a552a10747ec2..6b6ea6619e3787 100644 --- a/test/ruby/test_yjit.rb +++ b/test/ruby/test_yjit.rb @@ -1042,6 +1042,22 @@ def foo RUBY end + def test_bug_19316 + n = 2 ** 64 + # foo's extra param and the splats are relevant + assert_compiles(<<~'RUBY', result: [[n, -n], [n, -n]]) + def foo(_, a, b, c) + [a & b, ~c] + end + + n = 2 ** 64 + args = [0, -n, n, n-1] + + GC.stress = true + [foo(*args), foo(*args)] + RUBY + end + private def code_gc_helpers diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index f99c592e184488..a7c2b37eeb3cbc 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -5181,6 +5181,10 @@ fn gen_send_iseq( if builtin_argc + 1 < (C_ARG_OPNDS.len() as i32) { asm.comment("inlined leaf builtin"); + // Save the PC and SP because the callee may allocate + // e.g. Integer#abs on a bignum + jit_prepare_routine_call(jit, ctx, asm); + // Call the builtin func (ec, recv, arg1, arg2, ...) let mut args = vec![EC];