Skip to content

Commit 71b0d20

Browse files
committed
compile.c: fix peephole optimization
* compile.c (iseq_peephole_optimize): should `pop` before jump instruction which succeeds to `newarray` of a literal object, not after. [ruby-core:89536] [Bug #15245] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent cd0181d commit 71b0d20

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
29132913
}
29142914
else if (!iseq_pop_newarray(iseq, pobj)) {
29152915
pobj = new_insn_core(iseq, pobj->insn_info.line_no, BIN(pop), 0, NULL);
2916-
ELEM_INSERT_NEXT(&iobj->link, &pobj->link);
2916+
ELEM_INSERT_PREV(&iobj->link, &pobj->link);
29172917
}
29182918
if (cond) {
29192919
if (prev_dup) {

test/ruby/test_optimization.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,4 +794,10 @@ def x.bug(obj)
794794
end
795795
assert_equal(:ok, x.bug(:ok))
796796
end
797+
798+
def test_peephole_jump_after_newarray
799+
i = 0
800+
%w(1) || 2 while (i += 1) < 100
801+
assert_equal(100, i)
802+
end
797803
end

0 commit comments

Comments
 (0)