Skip to content

Commit

Permalink
Make sure to rpeep() the body of catch {} blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Jan 20, 2022
1 parent 0b66d70 commit cc49818
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions op.c
Expand Up @@ -17924,6 +17924,12 @@ Perl_rpeep(pTHX_ OP *o)
DEFER(cLOGOPo->op_other);
break;

case OP_ENTERTRYCATCH:
assert(cLOGOPo->op_other->op_type == OP_CATCH);
/* catch body is the ->op_other of the OP_CATCH */
DEFER(cLOGOPx(cLOGOPo->op_other)->op_other);
break;

case OP_SUBST:
if ((o->op_flags & OPf_WANT) == OPf_WANT_SCALAR)
S_check_for_bool_cxt(o, 1, OPpTRUEBOOL, 0);
Expand Down
12 changes: 12 additions & 0 deletions t/perf/opcount.t
Expand Up @@ -674,6 +674,18 @@ test_opcount(0, "multiconcat: local assign",
sassign => 1,
});

{
use feature 'try';
no warnings 'experimental::try';

test_opcount(0, "try/catch: catch block is optimized",
sub { my @a; try {} catch($e) { $a[0] } },
{
aelemfast_lex => 1,
aelem => 0,
});
}

{
use feature 'defer';
no warnings 'experimental::defer';
Expand Down

0 comments on commit cc49818

Please sign in to comment.