← Back to index
|
Original Bugzilla link
Bug 18001 – Wrong code on signed 32-bit compare of INT_MIN with zero
Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-11-21T16:33:34Z
Last change time
2018-02-28T20:13:43Z
Keywords
wrong-code
Assigned to
No Owner
Creator
yebblies
Comments
Comment #0
by yebblies — 2017-11-21T16:33:34Z
The following code prints "result: 1 -2147483648" extern(C) int printf(const char* format, ...); uint get() { return 0x80000000; } void test(bool b, int v) { printf("result: %d %d\n", b, v); } void main() { test(cast(int)get() > 0, get()); } This happens because the codegen for the compare is using the identity (a > 0) === (-a < 0) which doesn't hold for INT_MIN. 0000000000000000 <_Dmain>: 0: 55 push %rbp 1: 48 8b ec mov %rsp,%rbp 4: 48 83 ec 10 sub $0x10,%rsp 8: e8 00 00 00 00 callq d <_Dmain+0xd> 9: R_X86_64_PC32 _D5testx3getFZk-0x4 d: 48 89 c6 mov %rax,%rsi 10: f7 de neg %esi 12: c1 ee 1f shr $0x1f,%esi 15: 48 89 75 f8 mov %rsi,-0x8(%rbp) 19: e8 00 00 00 00 callq 1e <_Dmain+0x1e> 1a: R_X86_64_PC32 _D5testx3getFZk-0x4 1e: 48 89 c7 mov %rax,%rdi 21: 48 8b 75 f8 mov -0x8(%rbp),%rsi 25: e8 00 00 00 00 callq 2a <_Dmain+0x2a> 26: R_X86_64_PC32 _D5testx4testFbiZv-0x4 2a: 31 c0 xor %eax,%eax 2c: c9 leaveq 2d: c3 retq ...
Comment #1
by ag0aep6g — 2018-02-28T20:13:43Z
*** This issue has been marked as a duplicate of issue 18315 ***