Bug 291 – Bad code generation for real == 0, !=0 (incorrect for NaN)

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-08-17T02:46:00Z
Last change time
2014-02-15T13:19:19Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
lio+bugzilla

Comments

Comment #0 by lio+bugzilla — 2006-08-17T02:46:35Z
void main() { real a; // printf("%Lf",a); // prints "nan" assert(a==0.0); // unexpected PASS! } DMD v0.164; assertion correctly fails for double and float, but passes for real (really). Uncommenting the printf does not change the behavior. Compiled with -debug -g: image00400000!_Dmain: 00402010 c80c0000 enter 0xc,0x0 00402014 db2d80004100 fld tbyte ptr [000000000081209a] 0040201a db7df4 fstp tbyte ptr [rbp-0xc] 0040201d db6df4 fld tbyte ptr [rbp-0xc] 00402020 d9ee fldz 00402022 dae9 fucompp 00402024 dfe0 fstsw 00402026 9e sahf 00402027 740a jz image00400000!_Dmain+0x23 (00402033) 00402029 b805000000 mov eax,0x5 0040202e e805000000 call image00400000!assert_1t (00402038) 00402033 31c0 xor eax,eax 00402035 c9 leave 00402036 c3 ret The following code is generated when using "double" instead of "real". The assertion correctly fails. image00400000!_Dmain: 00402010 c8080000 enter 0x8,0x0 00402014 dd0580004100 fld qword ptr [image00400000!_xt_z+0x10 (00410080)] 0040201a dd5df8 fstp qword ptr [ebp-0x8] 0040201d 8b45fc mov eax,[ebp-0x4] 00402020 01c0 add eax,eax 00402022 0b45f8 or eax,[ebp-0x8] 00402025 740a jz image00400000!_Dmain+0x21 (00402031) 00402027 b805000000 mov eax,0x5 0040202c e807000000 call image00400000!assert_1t (00402038) 00402031 31c0 xor eax,eax 00402033 c9 leave 00402034 c3 ret
Comment #1 by thomas-dloop — 2006-08-18T02:15:18Z
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] schrieb am 2006-08-17: > http://d.puremagic.com/issues/show_bug.cgi?id=291 > void main() > { > real a; > // printf("%Lf",a); // prints "nan" > assert(a==0.0); // unexpected PASS! > } > > DMD v0.164; assertion correctly fails for double and float, but passes for real > (really). Added to DStress as http://dstress.kuehne.cn/run/f/float_28_A.d http://dstress.kuehne.cn/run/f/float_28_B.d http://dstress.kuehne.cn/run/f/float_28_C.d http://dstress.kuehne.cn/run/f/float_28_D.d http://dstress.kuehne.cn/run/d/double_31_A.d http://dstress.kuehne.cn/run/d/double_31_B.d http://dstress.kuehne.cn/run/d/double_31_C.d http://dstress.kuehne.cn/run/d/double_31_D.d http://dstress.kuehne.cn/run/r/real_27_A.d http://dstress.kuehne.cn/run/r/real_27_B.d http://dstress.kuehne.cn/run/r/real_27_C.d http://dstress.kuehne.cn/run/r/real_27_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFE5QoWLK5blCcjpWoRApCHAJ9V2EGQmZ56yTgm7jmDNkyJ8BXT9gCfWF/u zOWzuZPjRlB/zKkVah37dzs= =7/nH -----END PGP SIGNATURE-----
Comment #2 by thomas-dloop — 2006-10-02T03:11:52Z
*** Bug 365 has been marked as a duplicate of this bug. ***
Comment #3 by clugdbug — 2006-10-02T06:24:27Z
Changed name and severity of this bug, since it applies to !=0 as well as ==. (Taken from bug 365): void main() { real x = real.nan; assert( x!=0 ); // fails if (x==0) assert(0); // fails } It looks to me as though there's a JPE instruction missing, to cover the NaN case. I'm no longer confident that this is a regression. ie, should be jp image00400000!_Dmain+0x23 (00402033) jz image00400000!_Dmain+0x23 (00402033) ---------------------
Comment #4 by bugzilla — 2006-10-04T20:17:25Z
Fixed DMD 0.168