ruby-changes:51048
From: nobu <ko1@a...>
Date: Wed, 25 Apr 2018 15:45:10 +0900 (JST)
Subject: [ruby-changes:51048] nobu:r63255 (trunk): compile.c: fix unconditional branch optimization
nobu 2018-04-25 15:45:05 +0900 (Wed, 25 Apr 2018) New Revision: 63255 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63255 Log: 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] Modified files: trunk/compile.c trunk/test/ruby/test_optimization.rb Index: compile.c =================================================================== --- compile.c (revision 63254) +++ compile.c (revision 63255) @@ -2893,6 +2893,10 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2893 ELEM_INSERT_NEXT(&iobj->link, &pobj->link); } 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); goto again; } Index: test/ruby/test_optimization.rb =================================================================== --- test/ruby/test_optimization.rb (revision 63254) +++ test/ruby/test_optimization.rb (revision 63255) @@ -764,4 +764,11 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L764 assert_equal(42, obj.foo {result = 42}) assert_equal(42, result) end + + def test_unconditional_branch_to_leave_block + assert_valid_syntax("#{<<~"begin;"}\n#{<<~'end;'}") + begin; + tap {true || tap {}} + end; + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/