www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7026] New: 64 bit optimizer bug

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7026

           Summary: 64 bit optimizer bug
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: code klickverbot.at



---
The following code (reduced varint encoding) works as expected on Linux x86_64
if built without flags or just one of -O and -release, but fails if both -O
-release are specified:
---
import core.stdc.stdio;

ubyte foo(uint n) {
  ubyte[5] buf = void;
  ubyte wsize;

  while (true) {
    if ((n & ~0x7F) == 0) {
      buf[wsize++] = cast(ubyte)n;
      break;
    } else {
      buf[wsize++] = cast(ubyte)((n & 0x7F) | 0x80);
      n >>= 7;
    }
  }

  printf("%hhu\n", wsize);
  return buf[0];
}

void main() {
  printf("%hhx\n", foo(3));
}
---

More specifically, the output (printf()s for shorter assembly) is »1 e0« for
the optimized build instead of »1 3«, and the program crashes most of the time
(different errors: segfaults, illegal instruction, glibc free() assert
triggers, …) – stack corruption?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 28 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7026


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



21:12:23 PST ---
https://github.com/D-Programming-Language/dmd/commit/683624c4d7ae2f58fe2d8164ba7be77e08a4424f

https://github.com/D-Programming-Language/dmd/commit/3d21709860f771a7376eef7e7d5f924941421d02

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