D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6537 - OS X optimizer bug (?)
Summary: OS X optimizer bug (?)
Status: RESOLVED DUPLICATE of issue 5364
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Mac OS X
: P2 critical
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-08-20 06:47 UTC by David Nadlinger
Modified: 2011-11-18 08:32 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Nadlinger 2011-08-20 06:47:28 UTC
to!string() seems to produce wrong results with -O using current DMD here on my OS X Lion box:

---
import std.conv;
import std.stdio;

void main() {
  writefln("%s %s", long.min, to!string(long.min));
}
---

If I build the snippet without compiler flags, it prints (as expected):
-9223372036854775808 -9223372036854775808

If I add -O, however, the output becomes:
-9223372036854775808 -9223372032559808512

It seems like the lower 32 bits are zeroed out in the to!string() version (the problem occurs also when to!string is used in isolation, the writefln is just for demonstrative purposes).

Interestingly, this only occurs on my OS X box, I can't reproduce this in a Linux VM (neither on x86 nor x86_64).
Comment 1 David Nadlinger 2011-08-20 07:02:42 UTC
This also happens when explicitly using GCC 4.2, so it's not a case of DMD getting miscompiled by LLVM-GCC/Clang.
Comment 2 Jacob Carlborg 2011-08-20 08:26:16 UTC
I can reproduce it on Mac OS X 10.6.8.
Comment 3 David Nadlinger 2011-08-20 08:28:40 UTC
Thanks Jacob, raising the importance to critical.

It seems to happen for numbers smaller than int.min, but I haven't scanned the whole range or anything.
Comment 4 David Nadlinger 2011-08-20 08:31:14 UTC
Forgot to mention: I'm at DMD c98b611, druntime a59dd37, Phobos dff57f1.
Comment 5 Jacob Carlborg 2011-08-20 08:53:54 UTC
I'm using the 2.054 release.
Comment 6 Don 2011-10-13 23:18:02 UTC
This sounds a lot like bug 5364.
Comment 7 Walter Bright 2011-11-18 00:59:46 UTC
(In reply to comment #6)
> This sounds a lot like bug 5364.

Since 5364 is fixed now, please try it again on OS X.
Comment 8 David Nadlinger 2011-11-18 08:32:03 UTC
Fixed in Git master.

*** This issue has been marked as a duplicate of issue 5364 ***