summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2021-05-20 19:13:39 +0900
committerYusuke Endoh <mame@ruby-lang.org>2021-05-20 19:13:39 +0900
commit5026f9a5d5012248729a0052cd6cec811748291b (patch)
treeb88b850fe54c2b49b2778bcdd15b273c12bb3fb4
parent821e3c128f8e9efce9dbd2b1b96abc22d0312a60 (diff)
compile.c: stop the jump-jump optimization if the second has any event
Fixes [Bug #17868]
-rw-r--r--compile.c3
-rw-r--r--test/ruby/test_settracefunc.rb15
2 files changed, 17 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index a9c2f96781..e8bb023b78 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
}
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 fdd5bd2dce..c8ec81c72a 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -2386,4 +2386,19 @@ class TestSetTraceFunc < Test::Unit::TestCase
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