Skip to content

Commit

Permalink
[PRISM] Stop catch table entries being deleted by the optimiser
Browse files Browse the repository at this point in the history
  • Loading branch information
eightbitraptor authored and jemmaissroff committed Dec 7, 2023
1 parent 3081c83 commit 41b299d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
13 changes: 4 additions & 9 deletions prism_compile.c
Expand Up @@ -2678,6 +2678,8 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
case PM_FOR_NODE: {
pm_for_node_t *for_node = (pm_for_node_t *)node;

ISEQ_COMPILE_DATA(iseq)->catch_except_p = true;

const rb_iseq_t *child_iseq;
const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;

Expand All @@ -2700,15 +2702,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
ADD_SEND_WITH_BLOCK(ret, &dummy_line_node, idEach, INT2FIX(0), child_iseq);

INSN *iobj;
LINK_ELEMENT *last_elem = LAST_ELEMENT(ret);
iobj = IS_INSN(last_elem) ? (INSN *)last_elem : (INSN *)get_prev_insn((INSN*)last_elem);
while (INSN_OF(iobj) != BIN(send) &&
INSN_OF(iobj) != BIN(invokesuper)) {
iobj = (INSN *)get_prev_insn(iobj);
}
ELEM_INSERT_NEXT(&iobj->link, (LINK_ELEMENT*)retry_end_l);

ADD_LABEL(ret, retry_end_l);
PM_POP_IF_POPPED;

ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
Expand Down Expand Up @@ -4327,6 +4321,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;

/* wide range catch handler must put at last */
ISEQ_COMPILE_DATA(iseq)->catch_except_p = true;
ADD_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, NULL, start);
ADD_CATCH_ENTRY(CATCH_TYPE_NEXT, start, end, NULL, end);
break;
Expand Down
1 change: 1 addition & 0 deletions test/ruby/test_compile_prism.rb
Expand Up @@ -742,6 +742,7 @@ def test_BeginNode
def test_BreakNode
assert_prism_eval("while true; break; end")
assert_prism_eval("while true; break 1; end")
assert_prism_eval("[].each { break }")
end

def test_EnsureNode
Expand Down

0 comments on commit 41b299d

Please sign in to comment.