[Issue 9138] New: Code optimization results in a wrong value

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Dec 10 11:39:05 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9138

           Summary: Code optimization results in a wrong value
           Product: D
           Version: D1 & D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: david.eckardt at sociomantic.com


--- Comment #0 from David Eckardt <david.eckardt at sociomantic.com> 2012-12-10 11:39:05 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list