Bug 13007 – Wrong x86 code: long negate

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2014-06-29T17:21:00Z
Last change time
2015-08-24T23:01:27Z
Keywords
wrong-code
Assigned to
nobody
Creator
dragoscarp

Attachments

IDFilenameSummaryContent-TypeSize
1367negative64bit.tar.gzsample codeapplication/gzip635

Comments

Comment #0 by dragoscarp — 2014-06-29T17:21:13Z
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.
Comment #2 by bugzilla — 2015-08-22T20:35:20Z
Comment #3 by github-bugzilla — 2015-08-23T07:09:56Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/83d93a0a1113aeec60c196db2dc338abadb1f3c5 fix Issue 13007 - Wrong x86 code: long negate https://github.com/D-Programming-Language/dmd/commit/4fe3fb8958b6ecf11c2fb3d2f28d661ce204a176 Merge pull request #4920 from WalterBright/fix13007 fix Issue 13007 - Wrong x86 code: long negate
Comment #4 by github-bugzilla — 2015-08-24T23:01:27Z
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1922b7336fda4aec97e38743b007d63d5912146f Merge pull request #4920 from WalterBright/fix13007 fix Issue 13007 - Wrong x86 code: long negate