Bug 18758 – RVO ignores asm writing to return value
Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2018-04-13T07:27:16Z
Last change time
2023-04-03T17:13:48Z
Assigned to
No Owner
Creator
Rainer Schuetze
Comments
Comment #0 by r.sagitario — 2018-04-13T07:27:16Z
This code assert for both x86 and x64:
struct S { int x; int y; int z; }
S foo()
{
S s;
asm
{
mov EAX, 42;
mov [s], EAX;
}
return s;
}
void main()
{
S s;
s = foo();
assert(s.x == 42);
}
A workaround seems to be to assign the return value to a temporary first, but this seems brittle when optimizations might remove the unnecessary copy.
Comment #1 by razvan.nitu1305 — 2023-04-03T14:56:01Z
I cannot reproduce this. On Linux, 64-bit, latest dmd compiles and runs successfully.
Closing as WORKSFORME. Please reopen if you can still reproduce.