www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9138] New: Code optimization results in a wrong value

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: david.eckardt sociomantic.com



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: -------
Dec 10 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9138


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |maxim maxim-fomin.ru
         Resolution|                            |WORKSFORME



---
It work with -O option with git head dmd.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 11 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9138


David Eckardt <david.eckardt sociomantic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|D1 & D2                     |1.057



05:00:58 PST ---
OK, apparently a DMD 1 bug.

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