Bug 12051 – Wrong code with ?: resulting in char on x86-64
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2014-01-31T15:44:00Z
Last change time
2015-06-09T05:11:53Z
Keywords
pull, wrong-code
Assigned to
yebblies
Creator
yazan.dabain
Comments
Comment #0 by yazan.dabain — 2014-01-31T15:44:51Z
A wrong code issue was found in DCD project commit e7f3952.
The code where the compiler fails to produce correct code is in astconverter.d:558
foreach (i, s; importInfo.importParts)
{
immutable kind = i + 1 < importInfo.importParts.length ?
CompletionKind.packageName : CompletionKind.moduleName;
// Begin compiler bug workaround (this is part of the next commit, not e7f3952)
if (kind == 'L') std.stdio.writeln("ERROR ", kind);
...
}
CompletionKind is a char enum (located in messages.d), CompletionKind.packageName = 'P', CompletionKind.moduleName = 'M'
--------------------------------------------------
The assembly produced for this part of the code:
lea 0x1(%rbx),%rcx
cmp -0x1c0(%rbp),%rcx
sbb %rsi,%rsi
and $0x3,%dh <---------- wrong register, should be sil, not dh
add $0x4d,%sil
This code is the same on commit e7f3952 in an optimized build and on commit 2745763 in a non-optimized build.
However it is different in an optimized for commit 2745763.
The optimized code is:
lea 0x1(%r12),%rcx
cmp -0xa0(%rbp),%rcx
sbb %r13,%r13
and $0x3,%r13b
add $0x4d,%r13b
The code in the optimized build doesn't have the issue. And it runs as expected.
--------------------------------------------------
Original discussion https://github.com/Hackerpilot/DCD/issues/92
Comment #1 by yazan.dabain — 2014-01-31T15:58:08Z
BTW, inline and possibly other flags are not required to reproduce the issue. And removing it from the build script will speed up the compilation greatly.