www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18758] New: RVO ignores asm writing to return value


          Issue ID: 18758
           Summary: RVO ignores asm writing to return value
           Product: D
           Version: D2
          Hardware: All
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: r.sagitario gmx.de

This code assert for both x86 and x64:

struct S { int x; int y; int z; }

S foo()
        S s;
                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.

Apr 13 2018