Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 49445e6

Browse files
author
Reini Urban
committed
aelem_u: fix loop oob for padav
fix the wrong lexical index check for loop oob elimination: we checked the wrong aelem pad for the index.
1 parent 013b8b5 commit 49445e6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

op.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15225,10 +15225,10 @@ Perl_rpeep(pTHX_ OP *o)
1522515225
OP *kid = cUNOPx(to)->op_first;
1522615226
OP *loop, *iter, *body, *o2;
1522715227
SV *idx = MUTABLE_SV(PL_defgv);
15228+
#ifdef DEBUGGING
1522815229
const char *aname = kid->op_type == OP_GV ? GvNAME_get(kSVOP_sv)
1522915230
: kid->op_type == OP_PADAV ? PAD_COMPNAME_PV(kid->op_targ)
1523015231
: "";
15231-
#ifdef DEBUGGING
1523215232
char *iname = (char*)"_";
1523315233
#endif
1523415234
/* array can be global: gv -> rv2av, or rv2av(?), or lexical: padav */
@@ -15273,11 +15273,13 @@ Perl_rpeep(pTHX_ OP *o)
1527315273
/* here aelem might not be already optimized to multideref.
1527415274
aelem_u is faster, but does no deref so far. */
1527515275
if (type == OP_AELEM
15276-
&& OP_TYPE_IS(cUNOPx(o2)->op_first, OP_PADAV)
15277-
&& kid->op_targ == cUNOPx(o2)->op_first->op_targ /* same lex array */
15276+
&& OP_TYPE_IS(cBINOPx(o2)->op_first, OP_PADAV)
15277+
&& kid->op_targ == cBINOPx(o2)->op_first->op_targ /* same lex array */
1527815278
&& !(o2->op_private & (OPpLVAL_DEFER|OPpLVAL_INTRO|OPpDEREF))) {
1527915279
/* same lex. index */
15280-
if (o2->op_targ && o2->op_targ == loop->op_targ) {
15280+
if (cBINOPx(o2)->op_last->op_targ
15281+
&& cBINOPx(o2)->op_last->op_targ == loop->op_targ)
15282+
{
1528115283
DEBUG_k(Perl_deb(aTHX_ "loop oob: aelem %s[my %s] => aelem_u\n",
1528215284
aname, iname));
1528315285
OpTYPE_set(o2, OP_AELEM_U);

pod/perlcdelta.pod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ multideref stringification.
4949
C<MDEREF_MASK> changed to 0x10F, the C<MDEREF_SHIFT> size from 7 to 8.
5050
The shift can also use faster intrinsics now.
5151

52+
The loop out-of-bounds elimination was fixed for simple lexical
53+
indices (e.g. C<for my $i (0..$#a){ $a[$i] }>, which leads now to
54+
more aelem_u ops and subsequent mderef_u optimizations also.
55+
5256
=item *
5357

5458
The new C<strQEc>/C<strNEc> macros are used instead of

0 commit comments

Comments
 (0)