From d49c5c35b7e897b0b127ee0bc1ea77beaa7432fd Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sat, 4 Sep 2021 01:35:22 -0700 Subject: [PATCH] Allow calling variadic cfuncs with many args We have a check to ensure we don't have to push args on the stack to call a cfunc with many args. However we never need to use the stack for variadic cfuncs, so we shouldn't care about the number of arguments. --- test/ruby/test_yjit.rb | 14 ++++++++++++++ yjit_codegen.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb index 94989dae9e..20f8046df7 100644 --- a/test/ruby/test_yjit.rb +++ b/test/ruby/test_yjit.rb @@ -204,6 +204,20 @@ def to_s RUBY end + # Tests calling a variadic cfunc with many args + def test_build_large_struct + assert_compiles(<<~RUBY, insns: %i[opt_send_without_block], min_calls: 2) + ::Foo = Struct.new(:a, :b, :c, :d, :e, :f, :g, :h) + + def build_foo + ::Foo.new(:a, :b, :c, :d, :e, :f, :g, :h) + end + + build_foo + build_foo + RUBY + end + def test_fib_recursion assert_compiles(<<~'RUBY', insns: %i[opt_le opt_minus opt_plus opt_send_without_block], result: 34) def fib(n) diff --git a/yjit_codegen.c b/yjit_codegen.c index c90610794c..bfc6064ba3 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -2830,7 +2830,7 @@ gen_send_cfunc(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const } // Don't JIT functions that need C stack arguments for now - if (argc + 1 > NUM_C_ARG_REGS) { + if (cfunc->argc >= 0 && argc + 1 > NUM_C_ARG_REGS) { GEN_COUNTER_INC(cb, send_cfunc_toomany_args); return YJIT_CANT_COMPILE; }