diff options
-rw-r--r-- | bootstraptest/test_flow.rb | 10 | ||||
-rw-r--r-- | compile.c | 9 | ||||
-rw-r--r-- | test/ruby/test_optimization.rb | 13 | ||||
-rw-r--r-- | version.h | 8 |
4 files changed, 35 insertions, 5 deletions
diff --git a/bootstraptest/test_flow.rb b/bootstraptest/test_flow.rb index 0390062a24..9da6d45cbd 100644 --- a/bootstraptest/test_flow.rb +++ b/bootstraptest/test_flow.rb @@ -589,3 +589,13 @@ assert_equal "foo", %q{ end Bug6460.new.m1 }, '[ruby-dev:46372]' + +assert_equal "foo", %q{ + obj = "foo" + if obj || any1 + any2 = any2 + else + raise obj.inspect + end + obj +}, '[ruby-core:87830]' @@ -2469,6 +2469,8 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal IS_INSN_ID(piobj, branchunless))) { INSN *pdiobj = (INSN *)get_destination_insn(piobj); if (niobj == pdiobj) { + int refcnt = IS_LABEL(piobj->link.next) ? + ((LABEL *)piobj->link.next)->refcnt : 0; /* * useless jump elimination (if/unless destination): * if L1 @@ -2486,7 +2488,12 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal piobj->insn_id = (IS_INSN_ID(piobj, branchif)) ? BIN(branchunless) : BIN(branchif); replace_destination(piobj, iobj); - ELEM_REMOVE(&iobj->link); + if (refcnt <= 1) { + ELEM_REMOVE(&iobj->link); + } + else { + /* TODO: replace other branch destinations too */ + } return COMPILE_OK; } else if (diobj == pdiobj) { 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 @@ -1,10 +1,10 @@ #define RUBY_VERSION "2.5.2" -#define RUBY_RELEASE_DATE "2018-09-03" -#define RUBY_PATCHLEVEL 90 +#define RUBY_RELEASE_DATE "2018-10-01" +#define RUBY_PATCHLEVEL 91 #define RUBY_RELEASE_YEAR 2018 -#define RUBY_RELEASE_MONTH 9 -#define RUBY_RELEASE_DAY 3 +#define RUBY_RELEASE_MONTH 10 +#define RUBY_RELEASE_DAY 1 #include "ruby/version.h" |