Skip to content

Commit 5566d9e

Browse files
committed
Add pushtoarray insn to fix segfault with forwarding + splat
Example insns diff for `def x = [3]; def a(...) = b(*x, 2, 3, ...)` == disasm: #<ISeq:a@-e:1 (1,13)-(1,42)> local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] "..."@0 0000 putself ( 1)[Ca] 0000 putself 0000 opt_send_without_block <calldata!mid:x, argc:0, FCALL|VCALL|ARGS_SIMPLE> 0000 splatarray true 0000 putobject 2 0000 putobject 3 +0000 pushtoarray 2 0000 getlocal_WC_0 "..."@0 0000 sendforward <calldata!mid:b, argc:1, ARGS_SPLAT|ARGS_SPLAT_MUT|FCALL|FORWARDING>, nil 0000 leave [Re] This matches the insns produced by parse.y
1 parent b722d37 commit 5566d9e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

bootstraptest/test_method.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,3 +1427,10 @@ def test(*, kw: false)
14271427
14281428
test
14291429
RUBY
1430+
1431+
assert_equal '[1, 2, 3]', %q{
1432+
def target(*args) = args
1433+
def x = [1]
1434+
def forwarder(...) = target(*x, 2, ...)
1435+
forwarder(3).inspect
1436+
}, '[Bug #21832] post-splat args before forwarding'

prism_compile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,11 @@ pm_setup_args_core(const pm_arguments_node_t *arguments_node, const pm_node_t *b
18551855
PUSH_INSN(ret, location, concatarray);
18561856
break;
18571857
}
1858+
case PM_FORWARDING_ARGUMENTS_NODE: {
1859+
// foo(*a, b, ...) - push into splat for correct stack layout
1860+
PUSH_INSN1(ret, location, pushtoarray, INT2FIX(post_splat_counter));
1861+
break;
1862+
}
18581863
default:
18591864
break;
18601865
}

0 commit comments

Comments
 (0)