diff --git a/lib/mjit/compiler.rb b/lib/mjit/compiler.rb index 9e6ea0a119..db8327b863 100644 --- a/lib/mjit/compiler.rb +++ b/lib/mjit/compiler.rb @@ -446,9 +446,10 @@ module RubyVM::MJIT def compile_invokebuiltin(f, insn, stack_size, sp_inc, body, operands) bf = C.RB_BUILTIN.new(operands[0]) if bf.compiler > 0 + index = (insn.name == :invokebuiltin ? -1 : operands[1]) C.fprintf(f, "{\n") C.fprintf(f, " VALUE val;\n") - C.builtin_compiler(f, bf, operands[1], stack_size, body.builtin_inline_p) + C.builtin_compiler(f, bf, index, stack_size, body.builtin_inline_p) C.fprintf(f, " stack[#{stack_size + sp_inc - 1}] = val;\n") C.fprintf(f, "}\n") return true diff --git a/test/ruby/test_mjit.rb b/test/ruby/test_mjit.rb index 4c6cc6f39f..2fc878154b 100644 --- a/test/ruby/test_mjit.rb +++ b/test/ruby/test_mjit.rb @@ -24,9 +24,6 @@ class TestMJIT < Test::Unit::TestCase # not supported yet :defineclass, - # to be tested - :invokebuiltin, - # never used :opt_invokebuiltin_delegate, ].each do |insn| @@ -600,6 +597,15 @@ class TestMJIT < Test::Unit::TestCase assert_compile_once("'true' =~ /true/", result_inspect: '0', insns: %i[opt_regexpmatch2]) end + def test_compile_insn_invokebuiltin + iseq = eval(EnvUtil.invoke_ruby(['-e', <<~'EOS'], '', true).first) + p RubyVM::InstructionSequence.of([].method(:sample)).to_a + EOS + insns = collect_insns(iseq) + mark_tested_insn(:invokebuiltin, used_insns: insns) + assert_eval_with_jit('print [].sample(1)', stdout: '[]', success_count: 1) + end + def test_compile_insn_opt_invokebuiltin_delegate_leave iseq = eval(EnvUtil.invoke_ruby(['-e', <<~'EOS'], '', true).first) p RubyVM::InstructionSequence.of("\x00".method(:unpack)).to_a