Bug 9138 – Code optimization results in a wrong value
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86_64
OS
Linux
Creation time
2012-12-10T11:39:00Z
Last change time
2014-02-15T02:18:30Z
Assigned to
nobody
Creator
david.eckardt
Comments
Comment #0 by david.eckardt — 2012-12-10T11:39:05Z
Compiling this code example with -O makes the assertion fail:
---
module opt;
int f ( int x )
{
int n = x <= 0;
for (auto i = x; i; i /= 10) { }
return n;
}
void main ( )
{
assert(f(0));
}
---
Omitting the 'for' loop or the "i /= 10" or reading n after the 'for' loop makes the example run correctly. Changing the types of x and n and the return type of f() doesn't change the behaviour as well as assigning the value of the "f(0)" call to a variable and passing that variable to assert(). Debugging shows that n is 0.
Comment #1 by maxim — 2012-12-11T00:05:24Z
It work with -O option with git head dmd.
Comment #2 by david.eckardt — 2012-12-12T05:00:58Z