Skip to content

Conversation

egorzhdan
Copy link

Original PR by @j-hui: llvm#161933, cherry-picking to resolve rdar://161999293.

Previously, we were only called RD->addedMember(MD) to notify RD that MD (an implicit member) was added, but MD is never actually added as a child of RD. (Interestingly, MD still thinks RD is its parent.)

We end up with a broken AST that Clang itself seems to be robust to, but causes issues for users of libclang like Swift's ClangImporter.

This patch tries to maintain a well-formed AST by replacing calls to RD->addedMember(MD) with RD->addHiddenDecl(MD) for member function decls (addHiddenDecl() internally calls addedMember() to keep member metadata up to date). Most of the code is there to check that RD doesn't already contain the same decl as MD, which may be declared in and deserialized from another module. We fall back to the original behavior of calling addedMember() for non-function members: it's unclear what scenario leads to that (if any), nor how we should best handle that.

Note that we call addHiddenDecl() instead of addDecl() because the latter can sometimes lead to an assertion failure.

rdar://161931408

…ation

Previously, we were only called RD->addedMember(MD) to notify RD that MD
(an implicit member) was added, but MD is never actually added as
a child of RD. (Interestingly, MD still thinks RD is its parent.)

We end up with a broken AST that Clang itself seems to be robust to, but
causes issues for users of libclang like Swift's ClangImporter.

This patch tries to maintain a well-formed AST by replacing calls to
RD->addedMember(MD) with RD->addHiddenDecl(MD) for member function decls
(addHiddenDecl() internally calls addedMember() to keep member metadata
up to date). Most of the code is there to check that RD doesn't already
contain the same decl as MD, which may be declared in and deserialized
from another module. We fall back to the original behavior of calling
addedMember() for non-function members: it's unclear what scenario leads
to that (if any), nor how we should best handle that.

Note that we call addHiddenDecl() instead of addDecl() because the
latter can sometimes lead to an assertion failure.

rdar://161931408
@egorzhdan
Copy link
Author

swiftlang/swift#84806

@swift-ci please test

@egorzhdan egorzhdan requested a review from vsapsai October 10, 2025 12:02
@egorzhdan egorzhdan merged commit 01cd1cd into stable/21.x Oct 10, 2025
3 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/21.x-default-ctor-fix branch October 10, 2025 22:12
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.

2 participants