www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22089] New: inline messes up RVO-ed object

https://issues.dlang.org/show_bug.cgi?id=22089

          Issue ID: 22089
           Summary: inline messes up RVO-ed object
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: mail skoppe.eu

In the concurrency package I am relying on RVO being performed, essentially I
want to ensure placement of a struct on the callee's stack. I am aware I cannot
get 100% guarantee of RVO since the compiler is free to perform a blit anywhere
it likes.

Regardless, I have tests that ensure it applies RVO. It works fine on all 3
compilers until I turn on DMD's -inline.

I am aware RVO isn't guaranteed to be performed, but since it works fine
without inlining, I suspect there is something afoul there (since, by
definition, if it is inlined it need not blit anymore).

As a workaround I am using NVRO.

---
struct S {
     disable this(ref return scope typeof(this) rhs);
     disable this(this);
    void* cons;
    this(int i) {
        cons = cast(void*)&this;
    }
    void start() {
        void* s = cast(void*)&this;
        assert(cons == s);  // fails on dmd when build with -inline
    }
}

auto fun() {
//    auto s = S(42); // NVRO does work though...
//    return s;
    return S(42);
}

void main() {
    auto op = fun();
    op.start();
}
---

--
Jun 28 2021