[Issue 12164] New: Function returning ptrdiff_t.min in 64-bit returning 0 when -O is set.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Feb 14 17:58:09 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12164
Summary: Function returning ptrdiff_t.min in 64-bit returning 0
when -O is set.
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: wrong-code
Severity: major
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: opantm2+dbugs at gmail.com
--- Comment #0 from Kapps <opantm2+dbugs at gmail.com> 2014-02-14 17:58:07 PST ---
The title isn't very descriptive, but perhaps the sample is more useful.
Reduced from std.variant.
Uncommenting the writeln, using -m32, commenting out the if(*rhsPA == *zis)
return 0, or not passing in -O causes the problem to not occur. Otherwise
compile the below with -O -m64 to have it occur.
Sample:
import std.stdio, std.exception, std.c.string;
struct Foo {
ubyte[32] store;
this(A value) {
memcpy(&store, &value, value.sizeof);
}
static ptrdiff_t compare(A* rhsPA, A* zis) {
if (*rhsPA == *zis)
return 0;
//writeln("Returning min");
return ptrdiff_t.min;
}
bool opEquals(Foo rhs) const {
auto zis = cast(A*)&store;
auto rhsPA = cast(A*)&rhs.store;
// Below prints 0 if previous writeln line is commented and -O is set.
// Otherwise prints -9223372036854775808 as expected.
writeln(compare(rhsPA, zis));
return compare(rhsPA, zis) == 0;
}
}
static struct A { int a; }
void main() {
enforce(Foo(A(3)) != Foo(A(4)));
}
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list