ruby-changes:66272
From: Yusuke <ko1@a...>
Date: Thu, 20 May 2021 19:14:56 +0900 (JST)
Subject: [ruby-changes:66272] 5026f9a5d5 (master): compile.c: stop the jump-jump optimization if the second has any event
https://git.ruby-lang.org/ruby.git/commit/?id=5026f9a5d5 From 5026f9a5d5012248729a0052cd6cec811748291b Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Thu, 20 May 2021 19:13:39 +0900 Subject: compile.c: stop the jump-jump optimization if the second has any event Fixes [Bug #17868] --- compile.c | 3 ++- test/ruby/test_settracefunc.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/compile.c b/compile.c index a9c2f96..e8bb023 100644 --- a/compile.c +++ b/compile.c @@ -2926,7 +2926,8 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal https://github.com/ruby/ruby/blob/trunk/compile.c#L2926 } else if (iobj != diobj && IS_INSN(&diobj->link) && IS_INSN_ID(diobj, jump) && - OPERAND_AT(iobj, 0) != OPERAND_AT(diobj, 0)) { + OPERAND_AT(iobj, 0) != OPERAND_AT(diobj, 0) && + diobj->insn_info.events == 0) { /* * useless jump elimination: * jump LABEL1 diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index fdd5bd2..c8ec81c 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -2386,4 +2386,19 @@ class TestSetTraceFunc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L2386 EOS assert_equal [:return, :unpack], event end + + def test_while_in_while + lines = [] + + TracePoint.new(:line){|tp| + next unless target_thread? + lines << tp.lineno + }.enable{ + n = 3 + while n > 0 + n -= 1 while n > 0 + end + } + assert_equal [__LINE__ - 5, __LINE__ - 4, __LINE__ - 3], lines, 'Bug #17868' + end end -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/