From 2dc39e2fd45aacd5fcd33ed80f602bd6f2ddb504 Mon Sep 17 00:00:00 2001 From: "NARUSE, Yui" Date: Tue, 2 Feb 2021 17:50:00 +0900 Subject: merge revision(s) 1b89b99941548fdb65305dd9a412082e7fdba45a: [Backport #17534] Mark pattern labels as unremoveable Peephole optimization doesn't play well with find pattern at least. The only case when a pattern matching could have unreachable patterns is when we have lasgn/dasgn node, which shouldn't happen in real-life. Fixes https://bugs.ruby-lang.org/issues/17534 --- compile.c | 2 +- test/ruby/test_pattern_matching.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) --- compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index c62deafd23..a5e082f46d 100644 --- a/compile.c +++ b/compile.c @@ -6400,11 +6400,11 @@ compile_case3(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const orig_no int pat_line = nd_line(pattern); LABEL *next_pat = NEW_LABEL(pat_line); ADD_INSN (cond_seq, pat_line, dup); - // NOTE: set deconstructed_pos to the current cached value location // (it's "under" the matchee value, so it's position is 2) CHECK(iseq_compile_pattern_each(iseq, cond_seq, pattern, l1, next_pat, FALSE, 2)); ADD_LABEL(cond_seq, next_pat); + LABEL_UNREMOVABLE(next_pat); } else { COMPILE_ERROR(ERROR_ARGS "unexpected node"); -- cgit v1.2.3