Comment #0 by safety0ff.bugz — 2014-06-23T10:29:42Z
DMD outputs xchg RDX, RAX when you ask for xchg RDX, R8
/// CODE:
ulong bug(ulong a, ulong b, ulong c)
{
version (D_InlineAsm_X86_64)
{
// RDI = c RSI = b RDX = a
// RAX = return value
// Scratch: RAX, RCX, R8, R9
version (linux)
asm
{
naked;
// Let's return c using iasm
mov RAX, RDI;
// DMD outputs: REX.W+90+rd XCHG r64, RAX
// instead of: REX.W+87/r XCHG r/m64,r64
xchg RDX, R8;
// Interestingly, DMD outputs:
// xchg RDX,RDI
// and xchg RDX,R9 correctly
ret;
}
}
}
ulong nobug(ulong a, ulong b, ulong c)
{
version (D_InlineAsm_X86_64)
{
version (linux)
asm
{
naked;
mov RAX, RDI; // Let's return c using iasm
db 0x4c; db 0x87; db 0xC2; // xchg RDX, R8;
ret;
}
}
}
void main()
{
import std.stdio;
writeln(bug(1, 2, 3)); // ERROR: outputs 1
writeln(nobug(1, 2, 3)); // outputs 3 as it should
assert(bug(1, 2, 3) == 3);// should pass but fails
}
Comment #1 by blah38621 — 2014-06-23T20:03:47Z
Provided I understand the code correctly, I believe the offending code is backend/cod3.c line 5128. Now I just have to figure out why it's reaching there.
(In reply to Orvid King from comment #2)
> Well, it appears I don't understand the right format to get it to
> auto-reference the PR here, so I'll do it manually instead.
>
> https://github.com/D-Programming-Language/dmd/pull/3690
There is no auto reference, only the message when the commit is merged.