This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t allow OPpTARGET_MY on postdec/inc
authorFather Chrysostomos <sprout@cpan.org>
Sun, 9 Nov 2014 20:50:54 +0000 (12:50 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 9 Nov 2014 20:50:54 +0000 (12:50 -0800)
commit3baa0581042942aae9615e055ff2f1ac123840db
treef4a91711ce738963fd55fad57ccce5a5556577b2
parent1a5644fdf09df9d44c36dcd1dfee4adbe1d64af7
Don’t allow OPpTARGET_MY on postdec/inc

I was wrong in 9e319cc4f.  postfix ++/-- writes to its return value
before reading its argument.  If we optimise away the scalar
assignment in

    $a = $b++;

(that’s what OPpTARGET_MY does), then $a gets written to before $b is
read.  If $a and $b are the same, we get the wrong answer.  This bug
has been present under ‘use integer’ since 5.6.0.  I accidentally
extended it to non-integer ++/-- in 9e319cc4f.

(It’s not likely that someone will write $a = $b++, but it could hap-
pen inadvertently in more complex code.)
lib/B/Op_private.pm
opcode.h
pp.c
regen/opcodes
t/op/inc.t