Skip to content

Fix #23605 - extern(C++) destructor uses wrong ABI on x86 in derived … - #23606

Open
tim-dlang wants to merge 1 commit into
dlang:masterfrom
tim-dlang:issue23605
Open

Fix #23605 - extern(C++) destructor uses wrong ABI on x86 in derived …#23606
tim-dlang wants to merge 1 commit into
dlang:masterfrom
tim-dlang:issue23605

Conversation

@tim-dlang

Copy link
Copy Markdown
Contributor

…class

Destructors in a C++ vtbl need C++ linkage.

Comment thread compiler/src/dmd/dsymbolsem.d Outdated

// Destructors, which could be placed in a C++ vtbl, need C++ linkage
if (ad.isClassDeclaration() && ad.classKind == ClassKind.cpp && ad.ident != Id.ticppdtor)
sc.linkage = LINK.cpp;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this looks like user dtors might get their linkage overridden here too. I don't see a way to detect the generated aggrDtor here, or rather, that wouldn't be enough, in case it isn't needed (a single user dtor to call, no fields to destruct and no base dtor to call). So I think this should be handled in buildDtors(), generating an extern(C++) wrapper in that specific case too, as proposed in ldc-developers/ldc#5260 (comment) (the case with a single dtor to call, but no matching linkage).

If overriding the linkage cannot be done there directly, I'd suggest doing it like for the Windows C++ dtor, with an extra scope:

dmd/compiler/src/dmd/clone.d

Lines 1131 to 1139 in 6caf6a7

auto sc2 = sc.push();
sc2.stc &= ~STC.static_; // not a static destructor
sc2.linkage = LINK.cpp;
ad.members.push(func);
func.addMember(sc2, ad);
func.dsymbolSemantic(sc2);
sc2.pop();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this looks like user dtors might get their linkage overridden here too. I don't see a way to detect the generated aggrDtor here, or rather, that wouldn't be enough, in case it isn't needed (a single user dtor to call, no fields to destruct and no base dtor to call). So I think this should be handled in buildDtors(), generating an extern(C++) wrapper in that specific case too, as proposed in ldc-developers/ldc#5260 (comment) (the case with a single dtor to call, but no matching linkage).

Yes, this also sets the linkage for the user dtors. The different dtor types can be distinguished using ad.ident. I have excluded the dtor used for the type info with ad.ident != Id.ticppdtor.

Using a new scope is a good idea and would be more consistent with other generated destructors. I can try to do it that way.

…ived class

Destructors in a C++ vtbl need C++ linkage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants