From 428db8240313f3af7ca3eb4359110563d108fbd3 Mon Sep 17 00:00:00 2001 From: nagachika Date: Fri, 17 Aug 2018 15:48:46 +0000 Subject: merge revision(s) 63255: [Backport #14708] 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@64419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- compile.c | 4 ++++ test/ruby/test_optimization.rb | 7 +++++++ version.h | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/compile.c b/compile.c index 8f4a6dcc87..2f1e46aaa1 100644 --- a/compile.c +++ b/compile.c @@ -2647,6 +2647,10 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal 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; } diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index d3eb531e1b..ecc4ba425f 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -723,4 +723,11 @@ class TestRubyOptimization < Test::Unit::TestCase end assert_equal(:ok, obj.a()) end + + def test_unconditional_branch_to_leave_block + assert_valid_syntax("#{<<~"begin;"}\n#{<<~'end;'}") + begin; + tap {true || tap {}} + end; + end end diff --git a/version.h b/version.h index d078ca4f62..24c0c93b35 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.5.2" #define RUBY_RELEASE_DATE "2018-08-18" -#define RUBY_PATCHLEVEL 69 +#define RUBY_PATCHLEVEL 70 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 8 -- cgit v1.2.3