[Issue 19841] New: Wrong ABI for C++ functions taking a struct by value

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 2 12:11:58 UTC 2019


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

          Issue ID: 19841
           Summary: Wrong ABI for C++ functions taking a struct by value
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: atila.neves at gmail.com

Code:

------------------------
extern(C++) {
    struct Foo {
        void[32] _;
    }

    struct Bar {
        this(Foo foo);
    }
}


void oops() {
    auto foo = Foo();
    auto bar = Bar(foo);
}
--------------------------


The assembly for oops doesn't even mention the RSI register where the address
of `foo` should be passed in (RDI contains the address of where to construct
`bar`). It tries to pass `foo` to the `Bar` constructor on the stack.

The equivalent C++ code passes `foo` as an address in RSI. Calling the C++
implementation results in segfault.

The bug is weirdly present in ldc and gdc as well.

--


More information about the Digitalmars-d-bugs mailing list