Skip to content

[modules] Add a flag for TagDecl if it was a definition demoted to a declaration. #3872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3483,6 +3483,23 @@ class TagDecl : public TypeDecl,
/// parameters.
bool isDependentType() const { return isDependentContext(); }

/// Whether this declaration was a definition in some module but was forced
/// to be a declaration.
///
/// Useful for clients checking if a module has a definition of a specific
/// symbol and not interested in the final AST with deduplicated definitions.
bool isThisDeclarationADemotedDefinition() const {
return TagDeclBits.IsThisDeclarationADemotedDefinition;
}

/// Mark a definition as a declaration and maintain information it _was_
/// a definition.
void demoteThisDefinitionToDeclaration() {
assert(isCompleteDefinition() && "Not a definition!");
setCompleteDefinition(false);
TagDeclBits.IsThisDeclarationADemotedDefinition = true;
}

/// Starts the definition of this tag declaration.
///
/// This method should be invoked at the beginning of the definition
Expand Down
6 changes: 5 additions & 1 deletion clang/include/clang/AST/DeclBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1435,10 +1435,14 @@ class DeclContext {
/// Has the full definition of this type been required by a use somewhere in
/// the TU.
uint64_t IsCompleteDefinitionRequired : 1;

/// Whether this tag is a definition which was demoted due to
/// a module merge.
uint64_t IsThisDeclarationADemotedDefinition : 1;
};

/// Number of non-inherited bits in TagDeclBitfields.
enum { NumTagDeclBits = 9 };
enum { NumTagDeclBits = 10 };

/// Stores the bits used by EnumDecl.
/// If modified NumEnumDeclBit and the accessor
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4293,6 +4293,7 @@ TagDecl::TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
setEmbeddedInDeclarator(false);
setFreeStanding(false);
setCompleteDefinitionRequired(false);
TagDeclBits.IsThisDeclarationADemotedDefinition = false;
}

SourceLocation TagDecl::getOuterLocStart() const {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Serialization/ASTReaderDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
}
if (OldDef) {
Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
ED->setCompleteDefinition(false);
ED->demoteThisDefinitionToDeclaration();
Reader.mergeDefinitionVisibility(OldDef, ED);
if (OldDef->getODRHash() != ED->getODRHash())
Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED);
Expand Down