Index: include/clang/Serialization/ASTReader.h =================================================================== --- include/clang/Serialization/ASTReader.h +++ include/clang/Serialization/ASTReader.h @@ -842,6 +842,9 @@ /// \brief Whether we have tried loading the global module index yet. bool TriedLoadingGlobalIndex; + ///\brief Whether we are currently processing update records. + bool ProcessingUpdateRecords; + typedef llvm::DenseMap SwitchCaseMapTy; /// \brief Mapping from switch-case IDs in the chain to switch-case statements /// @@ -1041,6 +1044,23 @@ ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; } }; + /// \brief RAII object to mark the start of processing updates. + class ProcessingUpdatesRAIIObj { + ASTReader &Reader; + bool PrevState; + + ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete; + void operator=(const ProcessingUpdatesRAIIObj &) = delete; + + public: + ProcessingUpdatesRAIIObj(ASTReader &reader) + : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) { + Reader.ProcessingUpdateRecords = true; + } + + ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; } + }; + /// \brief Suggested contents of the predefines buffer, after this /// PCH file has been processed. /// @@ -2129,6 +2149,8 @@ /// \brief Loads comments ranges. void ReadComments() override; + + bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; } }; /// \brief Helper class that saves the current stream position and Index: lib/Serialization/ASTReader.cpp =================================================================== --- lib/Serialization/ASTReader.cpp +++ lib/Serialization/ASTReader.cpp @@ -8637,6 +8637,7 @@ auto Updates = std::move(PendingExceptionSpecUpdates); PendingExceptionSpecUpdates.clear(); for (auto Update : Updates) { + ProcessingUpdatesRAIIObj ProcessingUpdates(*this); auto *FPT = Update.second->getType()->castAs(); auto ESI = FPT->getExtProtoInfo().ExceptionSpec; if (auto *Listener = Context.getASTMutationListener()) @@ -8707,6 +8708,7 @@ AllowConfigurationMismatch(AllowConfigurationMismatch), ValidateSystemInputs(ValidateSystemInputs), UseGlobalIndex(UseGlobalIndex), TriedLoadingGlobalIndex(false), + ProcessingUpdateRecords(false), CurrSwitchCaseStmts(&SwitchCaseStmts), NumSLocEntriesRead(0), TotalNumSLocEntries(0), NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), NumIdentifierLookups(0), Index: lib/Serialization/ASTReaderDecl.cpp =================================================================== --- lib/Serialization/ASTReaderDecl.cpp +++ lib/Serialization/ASTReaderDecl.cpp @@ -3483,6 +3483,7 @@ // The declaration may have been modified by files later in the chain. // If this is the case, read the record containing the updates from each file // and pass it to ASTDeclReader to make the modifications. + ProcessingUpdatesRAIIObj ProcessingUpdates(*this); DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID); if (UpdI != DeclUpdateOffsets.end()) { auto UpdateOffsets = std::move(UpdI->second); @@ -3901,11 +3902,8 @@ } case UPD_DECL_MARKED_USED: { - // FIXME: This doesn't send the right notifications if there are - // ASTMutationListeners other than an ASTWriter. - // Maintain AST consistency: any later redeclarations are used too. - D->setIsUsed(); + D->markUsed(Reader.Context); break; } @@ -3929,11 +3927,8 @@ Exported = TD->getDefinition(); Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr; if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { - // FIXME: This doesn't send the right notifications if there are - // ASTMutationListeners other than an ASTWriter. - Reader.getContext().mergeDefinitionIntoModule( - cast(Exported), Owner, - /*NotifyListeners*/ false); + Reader.getContext().mergeDefinitionIntoModule(cast(Exported), + Owner); Reader.PendingMergedDefinitionsToDeduplicate.insert( cast(Exported)); } else if (Owner && Owner->NameVisibility != Module::AllVisible) { Index: lib/Serialization/ASTWriter.cpp =================================================================== --- lib/Serialization/ASTWriter.cpp +++ lib/Serialization/ASTWriter.cpp @@ -5636,6 +5636,7 @@ } void ASTWriter::CompletedTagDefinition(const TagDecl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(D->isCompleteDefinition()); assert(!WritingAST && "Already writing the AST!"); if (auto *RD = dyn_cast(D)) { @@ -5662,7 +5663,8 @@ } void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { - assert(DC->isLookupContext() && + if (Chain && Chain->isProcessingUpdateRecords()) return; + assert(DC->isLookupContext() && "Should not add lookup results to non-lookup contexts!"); // TU is handled elsewhere. @@ -5696,6 +5698,7 @@ } void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(D->isImplicit()); // We're only interested in cases where a local declaration is added to an @@ -5713,6 +5716,7 @@ } void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); if (!Chain) return; Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { @@ -5727,6 +5731,7 @@ } void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!Chain) return; Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { @@ -5737,6 +5742,7 @@ void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, const FunctionDecl *Delete) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); assert(Delete && "Not given an operator delete"); if (!Chain) return; @@ -5746,6 +5752,7 @@ } void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!D->isFromASTFile()) return; // Declaration not imported from PCH. @@ -5755,6 +5762,7 @@ } void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!D->isFromASTFile()) return; @@ -5763,6 +5771,7 @@ } void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!D->isFromASTFile()) return; @@ -5775,6 +5784,7 @@ } void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!D->isFromASTFile()) return; @@ -5785,6 +5795,7 @@ void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, const ObjCInterfaceDecl *IFD) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!IFD->isFromASTFile()) return; // Declaration not imported from PCH. @@ -5795,6 +5806,7 @@ } void ASTWriter::DeclarationMarkedUsed(const Decl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); // If there is *any* declaration of the entity that's not from an AST file, @@ -5808,6 +5820,7 @@ } void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!D->isFromASTFile()) return; @@ -5817,6 +5830,7 @@ void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D, const Attr *Attr) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!D->isFromASTFile()) return; @@ -5826,6 +5840,7 @@ } void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); assert(D->isHidden() && "expected a hidden declaration"); DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); @@ -5833,6 +5848,7 @@ void ASTWriter::AddedAttributeToRecord(const Attr *Attr, const RecordDecl *Record) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!Record->isFromASTFile()) return; Index: test/Modules/Inputs/PR28332/TextualInclude.h =================================================================== --- /dev/null +++ test/Modules/Inputs/PR28332/TextualInclude.h @@ -0,0 +1,7 @@ +#ifndef LLVM_ADT_SMALLVECTORIMPL_H +#define LLVM_ADT_SMALLVECTORIMPL_H +class SmallVectorImpl { +public: + ~SmallVectorImpl(); +}; +#endif \ No newline at end of file Index: test/Modules/Inputs/PR28332/a.h =================================================================== --- /dev/null +++ test/Modules/Inputs/PR28332/a.h @@ -0,0 +1,8 @@ +#include "b.h" + +class A { + SmallVector LegalIntWidths; + A() {} +}; + +#include "c.h" Index: test/Modules/Inputs/PR28332/b.h =================================================================== --- /dev/null +++ test/Modules/Inputs/PR28332/b.h @@ -0,0 +1,3 @@ +#include "TextualInclude.h" +template class SmallVector : SmallVectorImpl {}; + Index: test/Modules/Inputs/PR28332/c.h =================================================================== --- /dev/null +++ test/Modules/Inputs/PR28332/c.h @@ -0,0 +1,2 @@ +#include "TextualInclude.h" + Index: test/Modules/Inputs/PR28332/module.modulemap =================================================================== --- /dev/null +++ test/Modules/Inputs/PR28332/module.modulemap @@ -0,0 +1,3 @@ +module "c.h" { header "c.h" export * } +module "b.h" { header "b.h" export * } +module "a.h" { header "a.h" } Index: test/Modules/pr28332.cpp =================================================================== --- /dev/null +++ test/Modules/pr28332.cpp @@ -0,0 +1,8 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -std=c++11 -I%S/Inputs/PR28332 -verify %s +// RUN: %clang_cc1 -std=c++11 -fmodules -fmodule-map-file=%S/Inputs/PR28332/module.modulemap -fmodules-cache-path=%t -I%S/Inputs/PR28332 -verify %s + +#include "a.h" + +// expected-no-diagnostics +