diff options
author | nagachika <nagachika@ruby-lang.org> | 2023-03-21 12:10:35 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2023-03-21 12:10:35 +0900 |
commit | c660aaf439dcd609e4e23253372c8ec6d567ce10 (patch) | |
tree | f6ac54cb2ca452002b1dd9aa7492afee7913e73f /yjit_codegen.c | |
parent | 159930b7857bd3fe603840f686edffb54693d2a7 (diff) |
merge revision(s) aeddc19340c7116d48fac3080553fbb823857d16: [Backport #19316]
YJIT: Save PC and SP before calling leaf builtins (#7090)
Previously, we did not update `cfp->sp` before calling the C function of
ISEQs marked with `Primitive.attr! "inline"` (leaf builtins). This
caused the GC to miss temporary values on the stack in case the function
allocates and triggers a GC run. Right now, there is only a few leaf
builtins in numeric.rb on Integer methods such as `Integer#~`. Since
these methods only allocate when operating on big numbers, we missed
this issue.
Fix by saving PC and SP before calling the functions -- our usual
protocol for calling C functions that may allocate on the GC heap.
[Bug #19316]
---
test/ruby/test_yjit.rb | 16 ++++++++++++++++
yjit/src/codegen.rs | 4 ++++
2 files changed, 20 insertions(+)
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r-- | yjit_codegen.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c index 21e4813c19..7b333b9096 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -3638,6 +3638,8 @@ gen_send_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r if (leaf_builtin && !block && leaf_builtin->argc + 1 <= NUM_C_ARG_REGS) { ADD_COMMENT(cb, "inlined leaf builtin"); + jit_prepare_routine_call(jit, ctx, REG0); + // Call the builtin func (ec, recv, arg1, arg2, ...) mov(cb, C_ARG_REGS[0], REG_EC); |