mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
compile.c: fix unconditional branch optimization
* compile.c (iseq_peephole_optimize): add dummy `putnil` after a `jump` replacing an unconditional branch, to adjust removed `dup`. [ruby-core:86666] [Bug #14708] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b768dc2207
commit
067066fc9b
2 changed files with 11 additions and 0 deletions
|
@ -2893,6 +2893,10 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
|
||||||
ELEM_INSERT_NEXT(&iobj->link, &pobj->link);
|
ELEM_INSERT_NEXT(&iobj->link, &pobj->link);
|
||||||
}
|
}
|
||||||
if (cond) {
|
if (cond) {
|
||||||
|
if (prev_dup) {
|
||||||
|
pobj = new_insn_core(iseq, pobj->insn_info.line_no, BIN(putnil), 0, NULL);
|
||||||
|
ELEM_INSERT_NEXT(&iobj->link, &pobj->link);
|
||||||
|
}
|
||||||
iobj->insn_id = BIN(jump);
|
iobj->insn_id = BIN(jump);
|
||||||
goto again;
|
goto again;
|
||||||
}
|
}
|
||||||
|
|
|
@ -764,4 +764,11 @@ class TestRubyOptimization < Test::Unit::TestCase
|
||||||
assert_equal(42, obj.foo {result = 42})
|
assert_equal(42, obj.foo {result = 42})
|
||||||
assert_equal(42, result)
|
assert_equal(42, result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_unconditional_branch_to_leave_block
|
||||||
|
assert_valid_syntax("#{<<~"begin;"}\n#{<<~'end;'}")
|
||||||
|
begin;
|
||||||
|
tap {true || tap {}}
|
||||||
|
end;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue