mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
fix peephole optimization.
* compile.c (iseq_peephole_optimize): do not need to put `pop` instruction. * test/ruby/test_optimization.rb (test_peephole_optimization_without_trace): This code "def foo; 1.times{|(a), &b| nil && a}; end" fails to compile by stack underflow because of above bug (fixed by this patch). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2b60e342bd
commit
976b6df959
2 changed files with 7 additions and 3 deletions
|
@ -2324,13 +2324,10 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
|
|||
* LABEL:
|
||||
* leave
|
||||
*/
|
||||
INSN *popiobj = new_insn_core(iseq, iobj->line_no,
|
||||
BIN(pop), 0, 0);
|
||||
/* replace */
|
||||
unref_destination(iobj, 0);
|
||||
iobj->insn_id = BIN(leave);
|
||||
iobj->operand_size = 0;
|
||||
INSERT_ELEM_NEXT(&iobj->link, &popiobj->link);
|
||||
goto again;
|
||||
}
|
||||
else if ((piobj = (INSN *)get_prev_insn(iobj)) != 0 &&
|
||||
|
|
|
@ -640,4 +640,11 @@ class TestRubyOptimization < Test::Unit::TestCase
|
|||
assert_equal 0, foo{$SAFE}
|
||||
END
|
||||
end
|
||||
|
||||
def test_peephole_optimization_without_trace
|
||||
assert_separately [], <<-END
|
||||
RubyVM::InstructionSequence.compile_option = {trace_instruction: false}
|
||||
eval "def foo; 1.times{|(a), &b| nil && a}; end"
|
||||
END
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue