cat > bug.d << CODE
void checkAlign()
{
asm
{
naked;
mov RDI, RSP;
and RDI, 0xF;
cmp RDI, 0x8;
je Lpass;
hlt;
Lpass:
ret;
}
}
void foo()
{
}
void main()
{
checkAlign();
scope(exit) checkAlign();
foo();
}
CODE
dmd -run bug
----
The scope exit pushes the address of the return block onto the stack
which breaks the stack alignment.
Comment #1 by code — 2012-06-14T08:42:49Z
https://github.com/D-Programming-Language/dmd/pull/988
This bug affects all calls from a finally block that require an aligned stack.
The "optimization" is also a huge performance hog. Abusing return as indirect jump always incurs a branch misprediction.
Comment #2 by github-bugzilla — 2012-06-22T00:00:02Z