Created attachment 1367
sample code
The attached example compiled with dmd 2.065 (flags: -m32 -O -inline) generates wrong code for negative of a SysTime value:
8093c76: 89 c2 mov %eax,%edx
8093c78: 8b 45 f8 mov -0x8(%ebp),%eax <-- lower part in eax
8093c7b: f7 d8 neg %eax
8093c7d: 89 55 c4 mov %edx,-0x3c(%ebp)
8093c80: 8b 55 fc mov -0x4(%ebp),%edx <-- higher part in eax
8093c83: f7 da neg %edx
8093c85: 19 da sbb %ebx,%edx <-- ERROR: eax carry was overwritten by the previous negation
Even Baz is not used in foo, the error is present only if foo.d is compiled together with baz.d (foo.d baz.d -c).
With DMD master/HEAD the bug is not reproducible, because the generated code is quite different.
Comment #1 by yebblies — 2014-09-12T08:09:40Z
I can reproduce in a single file with this:
================
import std.datetime;
import core.time;
class Foo
{
SysTime getFooTime(SysTime time)
{
Bar bar = new Bar;
auto time2 = time + bar.barDuration() - dur!"seconds"(120);
if (fooBool)
return SysTime.max;
return time2;
}
bool fooBool()
{
return false;
}
}
void main()
{
auto now = Clock.currTime;
auto foo = new Foo();
assert(now == foo.getFooTime(now) + dur!"seconds"(120));
}
class Bar
{
Duration barDuration()
{
return dur!"seconds"(0);
}
SysTime bazTime = SysTime.max;
}
================
But with druntime and phobos imports I don't have the energy to try and reduce this further at the moment.