D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20716 - Wrong code/ABI for extern(C++) interface method that returns non-POD
Summary: Wrong code/ABI for extern(C++) interface method that returns non-POD
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 major
Assignee: No Owner
URL:
Keywords: backend, C++, pull, wrong-code
Depends on:
Blocks:
 
Reported: 2020-04-01 02:34 UTC by Илья Ярошенко
Modified: 2020-11-09 01:15 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Илья Ярошенко 2020-04-01 02:34:43 UTC
// OS: Linux, macOS

extern(C++, "foo"):

struct S
{
    void* s;
    ~this() {}
    // or this(this) {}
}

interface I
{
    S x();
}

final class C : I
{
    long l = 3;

    S x()
    {
        assert(l == 3); //fails
        return S.init;
    }
}

extern(D)
void main()
{
    auto s = new C().I.x;
}
Comment 1 Илья Ярошенко 2020-04-01 02:35:29 UTC
works well with LDC
Comment 2 Walter Bright 2020-09-07 05:56:56 UTC
Curiously, this works on Windows.
Comment 3 Walter Bright 2020-09-07 08:27:09 UTC
The problem here is the "adjustor thunk" generated does not take into account the size of the hidden pointer parameter, and winds up adjusting the hidden pointer rather than the `this` pointer.
Comment 4 Dlang Bot 2020-09-07 09:28:04 UTC
@WalterBright created dlang/dmd pull request #11703 "fix Issue 20716 - Wrong code/ABI for extern(C++) interface method tha…" fixing this issue:

- fix Issue 20716 - Wrong code/ABI for extern(C++) interface method that returns non-POD

https://github.com/dlang/dmd/pull/11703
Comment 5 Dlang Bot 2020-11-09 01:15:32 UTC
dlang/dmd pull request #11703 "fix Issue 20716 - Wrong code/ABI for extern(C++) interface method tha…" was merged into master:

- 9ad79f65edba40925c4f4d92c5603fb5711cd85a by Walter Bright:
  fix Issue 20716 - Wrong code/ABI for extern(C++) interface method that returns non-POD

https://github.com/dlang/dmd/pull/11703