From 0628973435abeccf676f3c2563579b3dbab06976 Mon Sep 17 00:00:00 2001 From: nagachika Date: Mon, 1 Oct 2018 12:02:17 +0000 Subject: merge revision(s) 63868,63870: [Backport #14897] Fix a bug of peephole optimization ``` if L1 L0: jump L2 L1: ... L2: ``` was wrongly optimized to: ``` unless L2 L0: L1: ... L2: ``` To make it conservative, this optimization is now disabled when there is any label between `if` and `jump` instructions. Fixes [Bug #14897]. compile.c: remove unreachable jump only * compile.c (iseq_peephole_optimize): remove unreachable jump instruction only. if it is labeled and referred from other instructions, it is reachable and must not be removed. [ruby-core:87830] [Bug #14897] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@64893 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_optimization.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index ecc4ba425f..d4557ddbbb 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -730,4 +730,17 @@ class TestRubyOptimization < Test::Unit::TestCase tap {true || tap {}} end; end + + def test_jump_elimination_with_optimized_out_block + x = Object.new + def x.bug(obj) + if obj || obj + obj = obj + else + raise "[ruby-core:87830] [Bug #14897]" + end + obj + end + assert_equal(:ok, x.bug(:ok)) + end end -- cgit v1.2.3