From: Vincent Pit Date: Sat, 1 Nov 2014 21:39:16 +0000 (-0200) Subject: Also mark the unstack ops in our peephole optimizer X-Git-Tag: rt99458^0 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=7112826bde64279aa69215293b5c94cc584d7388;p=perl%2Fmodules%2Fautovivification.git Also mark the unstack ops in our peephole optimizer This prevents infinite recursion at compile time for ... while 1 constructs, where the body may not contain neither nextstates nor stubs. This fixes RT #99458 and RT #99904. --- diff --git a/autovivification.xs b/autovivification.xs index 37b6d65..f0e0047 100644 --- a/autovivification.xs +++ b/autovivification.xs @@ -1024,6 +1024,7 @@ STATIC void a_peep_rec(pTHX_ OP *o, ptable *seen) { case OP_NEXTSTATE: case OP_DBSTATE: case OP_STUB: + case OP_UNSTACK: if (ptable_fetch(seen, o)) return; ptable_seen_store(seen, o, o); diff --git a/t/43-peep.t b/t/43-peep.t index a91b5f4..88d2afd 100644 --- a/t/43-peep.t +++ b/t/43-peep.t @@ -8,7 +8,7 @@ use Test::More; use lib 't/lib'; use VPIT::TestHelpers; -plan tests => 11 + 1 * 2 + 5 * 3; +plan tests => 11 + 5 * 2 + 5 * 3; { my $desc = 'peephole optimization of conditionals'; @@ -113,8 +113,9 @@ plan tests => 11 + 1 * 2 + 5 * 3; } { + my $base_desc = 'peephole optimization of infinite'; my %infinite_tests = ( - 'peephole optimization of infinite for loops (RT #64435)' => <<' TESTCASE', + "$base_desc for loops (RT #64435)" => <<' TESTCASE', no autovivification; my $ret = 0; for (;;) { @@ -123,6 +124,36 @@ plan tests => 11 + 1 * 2 + 5 * 3; } exit $ret; TESTCASE + "$base_desc while loops" => <<' TESTCASE', + no autovivification; + my $ret = 0; + while (1) { + ++$ret; + exit $ret; + } + exit $ret; + TESTCASE + "$base_desc postfix while (RT #99458)" => <<' TESTCASE', + no autovivification; + my $ret = 0; + ++$ret && exit $ret while 1; + exit $ret; + TESTCASE + "$base_desc until loops" => <<' TESTCASE', + no autovivification; + my $ret = 0; + until (0) { + ++$ret; + exit $ret; + } + exit $ret; + TESTCASE + "$base_desc postfix until" => <<' TESTCASE', + no autovivification; + my $ret = 0; + ++$ret && exit $ret until 0; + exit $ret; + TESTCASE ); for my $desc (keys %infinite_tests) {