summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2015-08-17 16:47:04 +0100
committerDavid Mitchell <davem@iabyn.com>2015-08-19 08:52:54 +0100
commitb13702a2b676b84fd7641c481a27970b9259f5ff (patch)
treec057beb120dea4fe32ac1f78ee76bddb65ec710d
parent92792a1c986f2a3bca788ec0500359ab8a53cc39 (diff)
downloadperl-b13702a2b676b84fd7641c481a27970b9259f5ff.tar.gz
ck_refassign: selectively copy OPpPAD_INTRO/STATE
Previously this function unconditionally copied the OPpLVAL_INTRO and OPpPAD_STATE flags from the LH var op to the refassign op, even when those flag bits weren't used or meant something different. This commit makes the copying more selective. It also makes clear by code comments and asserts, that the refassign op uses bit 6, OPpPAD_STATE, to mean either that or OPpOUR_INTRO depending on the type of LHS. I couldn't think of any test that would would break under the old regime, but this future-proofs the code against new flags and meanings.
-rw-r--r--op.c11
-rw-r--r--regen/op_private6
2 files changed, 16 insertions, 1 deletions
diff --git a/op.c b/op.c
index 2d51b6ddaa..ff2848a290 100644
--- a/op.c
+++ b/op.c
@@ -10466,7 +10466,11 @@ Perl_ck_refassign(pTHX_ OP *o)
assert (left);
assert (left->op_type == OP_SREFGEN);
- o->op_private = varop->op_private & (OPpLVAL_INTRO|OPpPAD_STATE);
+ o->op_private = 0;
+ /* we use OPpPAD_STATE in refassign to mean either of those things,
+ * and the code assumes the two flags occupy the same bit position
+ * in the various ops below */
+ assert(OPpPAD_STATE == OPpOUR_INTRO);
switch (varop->op_type) {
case OP_PADAV:
@@ -10474,12 +10478,15 @@ Perl_ck_refassign(pTHX_ OP *o)
goto settarg;
case OP_PADHV:
o->op_private |= OPpLVREF_HV;
+ /* FALLTHROUGH */
case OP_PADSV:
settarg:
+ o->op_private |= (varop->op_private & (OPpLVAL_INTRO|OPpPAD_STATE));
o->op_targ = varop->op_targ;
varop->op_targ = 0;
PAD_COMPNAME_GEN_set(o->op_targ, PERL_INT_MAX);
break;
+
case OP_RV2AV:
o->op_private |= OPpLVREF_AV;
goto checkgv;
@@ -10489,6 +10496,7 @@ Perl_ck_refassign(pTHX_ OP *o)
/* FALLTHROUGH */
case OP_RV2SV:
checkgv:
+ o->op_private |= (varop->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO));
if (cUNOPx(varop)->op_first->op_type != OP_GV) goto bad;
detach_and_stack:
/* Point varop to its GV kid, detached. */
@@ -10511,6 +10519,7 @@ Perl_ck_refassign(pTHX_ OP *o)
}
case OP_AELEM:
case OP_HELEM:
+ o->op_private |= (varop->op_private & OPpLVAL_INTRO);
o->op_private |= OPpLVREF_ELEM;
op_null(varop);
stacked = TRUE;
diff --git a/regen/op_private b/regen/op_private
index 54980f0630..51e01b6ccc 100644
--- a/regen/op_private
+++ b/regen/op_private
@@ -477,6 +477,11 @@ addbits($_, 7 => qw(OPpPV_IS_UTF8 UTF)) for qw(last redo next goto dump);
+# note that for refassign, this bit can mean either OPpPAD_STATE or
+# OPpOUR_INTRO depending on the type of the LH child, .e.g.
+# \our $foo = ...
+# \state $foo = ...
+
addbits($_, 6 => qw(OPpPAD_STATE STATE)) for qw(padav padhv padsv lvavref
lvref refassign pushmark);
@@ -748,6 +753,7 @@ addbits($_,
3 OPpLVREF_CV CV
)],
},
+ #6 => qw(OPpPAD_STATE STATE),
#7 => qw(OPpLVAL_INTRO LVINTRO),
) for 'refassign', 'lvref';