diff --git a/mjit_compile.c b/mjit_compile.c index 2d426b39fc..29b76f8b3d 100644 --- a/mjit_compile.c +++ b/mjit_compile.c @@ -370,7 +370,7 @@ mjit_compile_body(FILE *f, const rb_iseq_t *iseq, struct compile_status *status) if (body->param.flags.has_opt) { int i; fprintf(f, "\n"); - fprintf(f, " switch (reg_cfp->pc - reg_cfp->ISEQ_BODY(iseq)->iseq_encoded) {\n"); + fprintf(f, " switch (reg_cfp->pc - ISEQ_BODY(reg_cfp->iseq)->iseq_encoded) {\n"); for (i = 0; i <= body->param.opt_num; i++) { VALUE pc_offset = body->param.opt_table[i]; fprintf(f, " case %"PRIdVALUE":\n", pc_offset); diff --git a/test/ruby/test_mjit.rb b/test/ruby/test_mjit.rb index 6f1ccc8402..9037dc3d80 100644 --- a/test/ruby/test_mjit.rb +++ b/test/ruby/test_mjit.rb @@ -621,6 +621,16 @@ class TestMJIT < Test::Unit::TestCase end; end + def test_compile_opt_pc + assert_eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", stdout: 'hello', success_count: 1) + begin; + def test(arg = 'hello') + print arg + end + test + end; + end + def test_mjit_output out, err = eval_with_jit('5.times { puts "MJIT" }', verbose: 1, min_calls: 5) assert_equal("MJIT\n" * 5, out)