Adjust sp for x = false; y = (return until x unless x) [Bug #16695]

This commit is contained in:
wanabe 2020-08-08 08:37:52 +09:00
parent b68c22b3c6
commit ce7a053475
Notes: git 2025-04-09 13:49:37 +00:00
2 changed files with 12 additions and 5 deletions

View File

@ -2855,7 +2855,6 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
goto again; goto again;
} }
else if (IS_INSN_ID(diobj, leave)) { else if (IS_INSN_ID(diobj, leave)) {
INSN *pop;
/* /*
* jump LABEL * jump LABEL
* ... * ...
@ -2863,7 +2862,6 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
* leave * leave
* => * =>
* leave * leave
* pop
* ... * ...
* LABEL: * LABEL:
* leave * leave
@ -2873,9 +2871,6 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
iobj->insn_id = BIN(leave); iobj->insn_id = BIN(leave);
iobj->operand_size = 0; iobj->operand_size = 0;
iobj->insn_info = diobj->insn_info; iobj->insn_info = diobj->insn_info;
/* adjust stack depth */
pop = new_insn_body(iseq, diobj->insn_info.line_no, BIN(pop), 0);
ELEM_INSERT_NEXT(&iobj->link, &pop->link);
goto again; goto again;
} }
else if (IS_INSN(iobj->link.prev) && else if (IS_INSN(iobj->link.prev) &&
@ -5382,6 +5377,9 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int
branches); branches);
end_label = NEW_LABEL(line); end_label = NEW_LABEL(line);
ADD_INSNL(then_seq, line, jump, end_label); ADD_INSNL(then_seq, line, jump, end_label);
if (!popped) {
ADD_INSN(then_seq, line, pop);
}
} }
ADD_SEQ(ret, then_seq); ADD_SEQ(ret, then_seq);
} }

View File

@ -1388,6 +1388,15 @@ eom
assert_nil obj.test assert_nil obj.test
end end
def test_assignment_return_in_loop
obj = Object.new
def obj.test
x = nil
y = (return until x unless x)
end
assert_nil obj.test, "[Bug #16695]"
end
def test_method_call_location def test_method_call_location
line = __LINE__+5 line = __LINE__+5
e = assert_raise(NoMethodError) do e = assert_raise(NoMethodError) do