In perl.git, the branch blead has been updated <https://perl5.git.perl.org/perl.git/commitdiff/d6139ec4a9065ae249ab512398326a70dfb2fea2?hp=747c94edea492266c6c728a9dfe08ab31180e02f>
- Log ----------------------------------------------------------------- commit d6139ec4a9065ae249ab512398326a70dfb2fea2 Author: David Mitchell <da...@iabyn.com> Date: Wed Oct 17 15:10:10 2018 +0100 fix 'for reverse @array' bug on AIX RT #133558 Due to what appears to be a compiler bug on AIX (or perhaps it's undefined behaviour which happens to work on other platforms), this line of code in pp_iter(): inc = 1 - (PL_op->op_private & OPpITER_REVERSED); was setting inc to 4294967295 rather than to the expected -1 (inc was a 64-bit signed long). Fix it with a couple of judicious (IV) casts (which ought to be a NOOP). ----------------------------------------------------------------------- Summary of changes: pp_hot.c | 4 ++-- t/op/for.t | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pp_hot.c b/pp_hot.c index 56e3cbe6e1..dc02612042 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -3932,7 +3932,7 @@ PP(pp_iter) case CXt_LOOP_LIST: /* for (1,2,3) */ assert(OPpITER_REVERSED == 2); /* so inc becomes -1 or 1 */ - inc = 1 - (PL_op->op_private & OPpITER_REVERSED); + inc = (IV)1 - (IV)(PL_op->op_private & OPpITER_REVERSED); ix = (cx->blk_loop.state_u.stack.ix += inc); if (UNLIKELY(inc > 0 ? ix > cx->blk_oldsp @@ -3947,7 +3947,7 @@ PP(pp_iter) case CXt_LOOP_ARY: /* for (@ary) */ av = cx->blk_loop.state_u.ary.ary; - inc = 1 - (PL_op->op_private & OPpITER_REVERSED); + inc = (IV)1 - (IV)(PL_op->op_private & OPpITER_REVERSED); ix = (cx->blk_loop.state_u.ary.ix += inc); if (UNLIKELY(inc > 0 ? ix > AvFILL(av) diff --git a/t/op/for.t b/t/op/for.t index a114180f0b..f34fbd8b56 100644 --- a/t/op/for.t +++ b/t/op/for.t @@ -5,7 +5,7 @@ BEGIN { require "./test.pl"; } -plan(124); +plan(126); # A lot of tests to check that reversed for works. @@ -664,3 +664,17 @@ is(fscope(), 1, 'return via loop in sub'); } is($foo, "outside", "RT #123994 array outside"); } + +# RT #133558 'reverse' under AIX was causing loop to terminate +# immediately, probably due to compiler bug + +{ + my @a = qw(foo); + my @b; + push @b, $_ for (reverse @a); + is "@b", "foo", " RT #133558 reverse array"; + + @b = (); + push @b, $_ for (reverse 'bar'); + is "@b", "bar", " RT #133558 reverse list"; +} -- Perl5 Master Repository