Skip to content

Commit

Permalink
Drop eliminated catch-entries
Browse files Browse the repository at this point in the history
Drop catch table entries used in eliminated block, as well as
call_infos.  [Bug #16184]
  • Loading branch information
nobu committed Sep 27, 2019
1 parent 03284fb commit 79d5332
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions compile.c
Expand Up @@ -5118,6 +5118,8 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int
LABEL *then_label, *else_label, *end_label;
VALUE branches = Qfalse;
int ci_size, ci_kw_size;
VALUE catch_table = ISEQ_COMPILE_DATA(iseq)->catch_table_ary;
long catch_table_size = NIL_P(catch_table) ? 0 : RARRAY_LEN(catch_table);

INIT_ANCHOR(cond_seq);
INIT_ANCHOR(then_seq);
Expand All @@ -5132,17 +5134,27 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int
ci_size = body->ci_size;
ci_kw_size = body->ci_kw_size;
CHECK(COMPILE_(then_seq, "then", node_body, popped));
catch_table = ISEQ_COMPILE_DATA(iseq)->catch_table_ary;
if (!then_label->refcnt) {
body->ci_size = ci_size;
body->ci_kw_size = ci_kw_size;
if (!NIL_P(catch_table)) rb_ary_set_len(catch_table, catch_table_size);
}
else {
if (!NIL_P(catch_table)) catch_table_size = RARRAY_LEN(catch_table);
}

ci_size = body->ci_size;
ci_kw_size = body->ci_kw_size;
CHECK(COMPILE_(else_seq, "else", node_else, popped));
catch_table = ISEQ_COMPILE_DATA(iseq)->catch_table_ary;
if (!else_label->refcnt) {
body->ci_size = ci_size;
body->ci_kw_size = ci_kw_size;
if (!NIL_P(catch_table)) rb_ary_set_len(catch_table, catch_table_size);
}
else {
if (!NIL_P(catch_table)) catch_table_size = RARRAY_LEN(catch_table);
}

ADD_SEQ(ret, cond_seq);
Expand Down
15 changes: 15 additions & 0 deletions test/ruby/test_optimization.rb
Expand Up @@ -825,4 +825,19 @@ def test_optimized_empty_ensure
}
end;
end
def test_optimized_rescue
assert_in_out_err("", "#{<<~"begin;"}\n#{<<~'end;'}", [], /END \(RuntimeError\)/)
begin;
if false
begin
require "some_mad_stuff"
rescue LoadError
puts "no mad stuff loaded"
end
end
raise "END"
end;
end
end

0 comments on commit 79d5332

Please sign in to comment.