Skip Menu |

This queue is for tickets about the Scalar-List-Utils CPAN distribution.

Report information
The Basics
Id: 132653
Status: open
Priority: 0/
Queue: Scalar-List-Utils

People
Owner: Nobody in particular
Requestors: CHOROBA [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: product -1, 1 throws Floating point exception on some machines
perl -wE 'use List::Util qw{ product }; say product -1, 1' 1483 Floating point exception(core dumped) "${perl[0]}" "$@" Tested on various 64 bit linux machines (blead, 5.26.1). Works in termux (5.30.1 arm-android) (outputs -1).
On Mon May 18 16:57:25 2020, CHOROBA wrote: Show quoted text
> perl -wE 'use List::Util qw{ product }; say product -1, 1' > 1483 Floating point exception(core dumped) "${perl[0]}" "$@" > > Tested on various 64 bit linux machines (blead, 5.26.1). Works in > termux (5.30.1 arm-android) (outputs -1).
product 1, -1 works correctly. From #perl@freenode: <choroba> eval: use List::Util qw{ product }; product -1, 3 <perlbot> choroba: [Died SIGFPE] <ilmari> that's "if (i <= IV_MIN / retiv)" <ilmari> which will overflow if retiv == -1 <gordonfish> Interesting, on a 32-bit centos box, perl -e 'use List::Util qw{ product }; print product -1, 3' yields -3 <gordonfish> choroba: Works (prints -3) on two 32-bit linux machines as well as a 32-bit windows; trying it on a 64-bit windows system caused the whole system to crash..... seems this is a 64-bit problem
On 2020-05-18 21:57:25, CHOROBA wrote: Show quoted text
> perl -wE 'use List::Util qw{ product }; say product -1, 1' > 1483 Floating point exception(core dumped) "${perl[0]}" "$@" > > Tested on various 64 bit linux machines (blead, 5.26.1). Works in > termux (5.30.1 arm-android) (outputs -1).
GDB on a debugging 5.30.0 Debian x86_64 reveals that this happens on ListUtils.xs line 295: if (i <= IV_MIN / retiv) { IV_MIN / retiv overflows IV when retiv == -1. On x86_64 this compiles to: 0x00007ffff7b17796 <+3894>: movabs $0x8000000000000000,%rax 0x00007ffff7b177a0 <+3904>: cqto => 0x00007ffff7b177a2 <+3906>: idivq 0x18(%rsp) 0x00007ffff7b177a7 <+3911>: cmp %rcx,%rax It appears that idivq raises an exception on overflow, while the ARM equivalent might not. - ilmari