[Bug 154] Compiler emits invalid assembly when compiled with -O2
via D.gnu
d.gnu at puremagic.com
Mon Aug 25 06:52:49 PDT 2014
http://bugzilla.gdcproject.org/show_bug.cgi?id=154
art.08.09 at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |art.08.09 at gmail.com
Resolution|--- |INVALID
--- Comment #1 from art.08.09 at gmail.com ---
> asm {"
> mov %2, %0;
> lock;
> xadd %0, (%1);
>
> "
> : "=r"(retVal)
> : "r"(counter), "r"(addition)
> : "memory"; }
> when compiling with -O2 the exchangeAndAdd function assembly is the same but
> it is also inlined into main like so (invalid assembly):
>
> 406614: ba 02 00 00 00 mov $0x2,%edx
> 406619: 48 c7 44 24 08 0a 00 movq $0xa,0x8(%rsp)
> 406620: 00 00
> 406622: 48 8d 44 24 08 lea 0x8(%rsp),%rax
> 406627: 48 89 d0 mov %rdx,%rax
> 40662a: f0 48 0f c1 00 lock xadd %rax,(%rax)
>
> This obviously segfaults as rax is garbaged.
That happens because you're modifying the output before using the inputs.
Not a bug; you need to mark the output as an earlyclobber:
ulong /*RAX*/ exchangeAndAdd(ulong * counter /*RSI*/, ulong addition /*RDI*/)
{
ulong retVal = void;
asm {"
mov %2, %0;
lock;
xadd %0, (%1);
"
: "=&r"(retVal)
: "r"(counter), "r"(addition)
: "memory"; }
return retVal;
}
--
You are receiving this mail because:
You are watching all bug changes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d.gnu/attachments/20140825/91a8c333/attachment.html>
More information about the D.gnu
mailing list