branchless float comparison triggers SIGFPE on NaN
Original Reporter info from Mantis: BeniBela @benibela
-
Reporter name: Benito van der Zander
Original Reporter info from Mantis: BeniBela @benibela
- Reporter name: Benito van der Zander
Description:
Boolean operations with float are not short-circuit evaluated anymore
Steps to reproduce:
program testnan;
{$mode objfpc}{$H+}
uses math;
var d: double;
temp: Boolean;
begin
d := NaN;
temp := IsNan(d) or (d = 0);
writeln(temp);
end.
prints TRUE on 3.0.4 and makes a SIGFPE on 3.3.1
Additional information:
Program received signal SIGFPE, Arithmetic exception.
0x00000000004010cc in main () at testnan.lpr:10
10 temp := IsNan(d) or (d = 0);
...
0x0000000000401096 <+6>: lea 0x5ff63(%rip),%rax # 0x461000
0x000000000040109d <+13>: lea 0x8734c(%rip),%rdx # 0x4883f0 <U_$P$TESTNAN_$$_D>
0x00000000004010a4 <+20>: mov (%rax),%rax
0x00000000004010a7 <+23>: mov %rax,(%rdx)
0x00000000004010aa <+26>: lea 0x8733f(%rip),%rax # 0x4883f0 <U_$P$TESTNAN_$$_D>
0x00000000004010b1 <+33>: movsd (%rax),%xmm0
0x00000000004010b5 <+37>: callq 0x429d80 <MATH_$$_ISNAN$DOUBLE$$BOOLEAN>
0x00000000004010ba <+42>: lea 0x5ff47(%rip),%rdx # 0x461008
0x00000000004010c1 <+49>: movsd (%rdx),%xmm0
0x00000000004010c5 <+53>: lea 0x87324(%rip),%rdx # 0x4883f0 <U_$P$TESTNAN_$$_D>
=> 0x00000000004010cc <+60>: comisd (%rdx),%xmm0
0x00000000004010d0 <+64>: setnp %dl
0x00000000004010d3 <+67>: sete %cl
0x00000000004010d6 <+70>: and %dl,%cl
0x00000000004010d8 <+72>: or %cl,%al
0x00000000004010da <+74>: lea 0x8731f(%rip),%rdx # 0x488400 <U_$P$TESTNAN_$$_TEMP>
Mantis conversion info:
- Mantis ID: 37398
- OS: linux
- OS Build: opensuse
- Build: r45819
- Platform: amd64
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 45824 (#5da913de)
- Monitored by: » @MageSlayer (Denis Golovan), » @CuriousKit (J. Gareth Moreton)