Skip to content

Revert "[modules] Fix miscompilation when using two RecordDecl definitions with the same name." #3369

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

Merged
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
4 changes: 0 additions & 4 deletions clang/include/clang/Serialization/ASTReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -1155,10 +1155,6 @@ class ASTReader
/// definitions. Only populated when using modules in C++.
llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;

/// A mapping from canonical declarations of records to their canonical
/// definitions. Doesn't cover CXXRecordDecl.
llvm::DenseMap<RecordDecl *, RecordDecl *> RecordDefinitions;

/// When reading a Stmt tree, Stmt operands are placed in this stack.
SmallVector<Stmt *, 16> StmtStack;

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Serialization/ASTCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ bool serialization::needsAnonymousDeclarationNumber(const NamedDecl *D) {
// Otherwise, we only care about anonymous class members / block-scope decls.
// FIXME: We need to handle lambdas and blocks within inline / templated
// variables too.
if (D->getDeclName() || !isa<RecordDecl>(D->getLexicalDeclContext()))
if (D->getDeclName() || !isa<CXXRecordDecl>(D->getLexicalDeclContext()))
return false;
return isa<TagDecl>(D) || isa<FieldDecl>(D);
}
38 changes: 2 additions & 36 deletions clang/lib/Serialization/ASTReaderDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ namespace clang {
RedeclarableResult VisitTagDecl(TagDecl *TD);
void VisitEnumDecl(EnumDecl *ED);
RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD);
void VisitRecordDecl(RecordDecl *RD);
void VisitRecordDecl(RecordDecl *RD) { VisitRecordDeclImpl(RD); }
RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D);
void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); }
RedeclarableResult VisitClassTemplateSpecializationDeclImpl(
Expand Down Expand Up @@ -808,34 +808,6 @@ ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) {
return Redecl;
}

void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
VisitRecordDeclImpl(RD);

// Maintain the invariant of a redeclaration chain containing only
// a single definition.
if (RD->isCompleteDefinition()) {
RecordDecl *Canon = static_cast<RecordDecl *>(RD->getCanonicalDecl());
RecordDecl *&OldDef = Reader.RecordDefinitions[Canon];
if (!OldDef) {
// This is the first time we've seen an imported definition. Look for a
// local definition before deciding that we are the first definition.
for (auto *D : merged_redecls(Canon)) {
if (!D->isFromASTFile() && D->isCompleteDefinition()) {
OldDef = D;
break;
}
}
}
if (OldDef) {
Reader.MergedDeclContexts.insert(std::make_pair(RD, OldDef));
RD->setCompleteDefinition(false);
Reader.mergeDefinitionVisibility(OldDef, RD);
} else {
OldDef = RD;
}
}
}

void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
VisitNamedDecl(VD);
// For function declarations, defer reading the type in case the function has
Expand Down Expand Up @@ -2675,7 +2647,7 @@ static bool allowODRLikeMergeInC(NamedDecl *ND) {
if (!ND)
return false;
// TODO: implement merge for other necessary decls.
if (isa<EnumConstantDecl, FieldDecl, IndirectFieldDecl>(ND))
if (isa<EnumConstantDecl>(ND))
return true;
return false;
}
Expand Down Expand Up @@ -3347,9 +3319,6 @@ DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader,
return DD->Definition;
}

if (auto *RD = dyn_cast<RecordDecl>(DC))
return RD->getDefinition();

if (auto *ED = dyn_cast<EnumDecl>(DC))
return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition()
: nullptr;
Expand Down Expand Up @@ -3433,9 +3402,6 @@ ASTDeclReader::getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC) {
if (auto *MD = dyn_cast<ObjCMethodDecl>(D))
if (MD->isThisDeclarationADefinition())
return MD;
if (auto *RD = dyn_cast<RecordDecl>(D))
if (RD->isThisDeclarationADefinition())
return RD;
}

// No merged definition yet.
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

38 changes: 0 additions & 38 deletions clang/test/Modules/merge-record-definition-nonmodular.m

This file was deleted.

18 changes: 0 additions & 18 deletions clang/test/Modules/merge-record-definition-visibility.m

This file was deleted.

28 changes: 0 additions & 28 deletions clang/test/Modules/merge-record-definition.m

This file was deleted.