From cc8c4a60b7fbddc04e2e09946a3c70029db35d3d Mon Sep 17 00:00:00 2001 From: eileencodes Date: Tue, 2 Jul 2024 13:31:15 -0400 Subject: [PATCH] Calling into a C func shouldn't fast path when forwarding When we forward calls to C functions if the callsite is a forwarding site it might not always be a splat, so we can't use the fast path. Fixes: [ruby-core:118418] --- bootstraptest/test_method.rb | 15 +++++++++++++++ vm_insnhelper.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bootstraptest/test_method.rb b/bootstraptest/test_method.rb index 846d8e36a9..a5ea35dd4b 100644 --- a/bootstraptest/test_method.rb +++ b/bootstraptest/test_method.rb @@ -1344,3 +1344,18 @@ assert_equal 'ok', %q{ C.new.foo } + +assert_equal 'ok', %q{ + class C + def initialize(a) + end + end + + def foo(...) + C.new(...) + :ok + end + + foo(*["bar"]) + foo("baz") +} diff --git a/vm_insnhelper.c b/vm_insnhelper.c index be43e737fe..88feba74b9 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -3907,7 +3907,7 @@ vm_call_cfunc(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, struct rb const struct rb_callinfo *ci = calling->cd->ci; RB_DEBUG_COUNTER_INC(ccf_cfunc); - if (IS_ARGS_SPLAT(ci)) { + if (IS_ARGS_SPLAT(ci) && !(vm_ci_flag(ci) & VM_CALL_FORWARDING)) { if (!IS_ARGS_KW_SPLAT(ci) && vm_ci_argc(ci) == 1) { // f(*a) CC_SET_FASTPATH(calling->cc, vm_call_cfunc_only_splat, TRUE);