Author: hans Date: Tue Jul 26 10:57:30 2016 New Revision: 276757 URL: http://llvm.org/viewvc/llvm-project?rev=276757&view=rev Log: Merging r276473: ------------------------------------------------------------------------ r276473 | vvassilev | 2016-07-22 14:08:24 -0700 (Fri, 22 Jul 2016) | 13 lines
[modules] Teach the ASTWriter to ignore mutations coming from the ASTReader. Processing update records (and loading a module, in general) might trigger unexpected calls to the ASTWriter (being a mutation listener). Now we have a mechanism to suppress those calls to the ASTWriter but notify other possible mutation listeners. Fixes https://llvm.org/bugs/show_bug.cgi?id=28332 Patch by Cristina Cristescu and me. Reviewed by Richard Smith (D21800). ------------------------------------------------------------------------ Added: cfe/branches/release_39/test/Modules/Inputs/PR28332/ - copied from r276473, cfe/trunk/test/Modules/Inputs/PR28332/ cfe/branches/release_39/test/Modules/pr28332.cpp - copied unchanged from r276473, cfe/trunk/test/Modules/pr28332.cpp Modified: cfe/branches/release_39/ (props changed) cfe/branches/release_39/include/clang/Serialization/ASTReader.h cfe/branches/release_39/lib/Serialization/ASTReader.cpp cfe/branches/release_39/lib/Serialization/ASTReaderDecl.cpp cfe/branches/release_39/lib/Serialization/ASTWriter.cpp Propchange: cfe/branches/release_39/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Tue Jul 26 10:57:30 2016 @@ -1,4 +1,4 @@ /cfe/branches/type-system-rewrite:134693-134817 -/cfe/trunk:275880,275967,276361 +/cfe/trunk:275880,275967,276361,276473 /cfe/trunk/test:170344 /cfe/trunk/test/SemaTemplate:126920 Modified: cfe/branches/release_39/include/clang/Serialization/ASTReader.h URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/include/clang/Serialization/ASTReader.h?rev=276757&r1=276756&r2=276757&view=diff ============================================================================== --- cfe/branches/release_39/include/clang/Serialization/ASTReader.h (original) +++ cfe/branches/release_39/include/clang/Serialization/ASTReader.h Tue Jul 26 10:57:30 2016 @@ -843,6 +843,9 @@ private: /// \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<unsigned, SwitchCase *> SwitchCaseMapTy; /// \brief Mapping from switch-case IDs in the chain to switch-case statements /// @@ -1042,6 +1045,23 @@ private: ~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. /// @@ -2130,6 +2150,8 @@ public: /// \brief Loads comments ranges. void ReadComments() override; + + bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; } }; /// \brief Helper class that saves the current stream position and Modified: cfe/branches/release_39/lib/Serialization/ASTReader.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Serialization/ASTReader.cpp?rev=276757&r1=276756&r2=276757&view=diff ============================================================================== --- cfe/branches/release_39/lib/Serialization/ASTReader.cpp (original) +++ cfe/branches/release_39/lib/Serialization/ASTReader.cpp Tue Jul 26 10:57:30 2016 @@ -8637,6 +8637,7 @@ void ASTReader::FinishedDeserializing() auto Updates = std::move(PendingExceptionSpecUpdates); PendingExceptionSpecUpdates.clear(); for (auto Update : Updates) { + ProcessingUpdatesRAIIObj ProcessingUpdates(*this); auto *FPT = Update.second->getType()->castAs<FunctionProtoType>(); auto ESI = FPT->getExtProtoInfo().ExceptionSpec; if (auto *Listener = Context.getASTMutationListener()) @@ -8707,6 +8708,7 @@ ASTReader::ASTReader( 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), Modified: cfe/branches/release_39/lib/Serialization/ASTReaderDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Serialization/ASTReaderDecl.cpp?rev=276757&r1=276756&r2=276757&view=diff ============================================================================== --- cfe/branches/release_39/lib/Serialization/ASTReaderDecl.cpp (original) +++ cfe/branches/release_39/lib/Serialization/ASTReaderDecl.cpp Tue Jul 26 10:57:30 2016 @@ -3484,6 +3484,7 @@ void ASTReader::loadDeclUpdateRecords(se // 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); @@ -3902,11 +3903,8 @@ void ASTDeclReader::UpdateDecl(Decl *D, } 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; } @@ -3930,11 +3928,8 @@ void ASTDeclReader::UpdateDecl(Decl *D, 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<NamedDecl>(Exported), Owner, - /*NotifyListeners*/ false); + Reader.getContext().mergeDefinitionIntoModule(cast<NamedDecl>(Exported), + Owner); Reader.PendingMergedDefinitionsToDeduplicate.insert( cast<NamedDecl>(Exported)); } else if (Owner && Owner->NameVisibility != Module::AllVisible) { Modified: cfe/branches/release_39/lib/Serialization/ASTWriter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Serialization/ASTWriter.cpp?rev=276757&r1=276756&r2=276757&view=diff ============================================================================== --- cfe/branches/release_39/lib/Serialization/ASTWriter.cpp (original) +++ cfe/branches/release_39/lib/Serialization/ASTWriter.cpp Tue Jul 26 10:57:30 2016 @@ -5637,6 +5637,7 @@ void ASTWriter::ModuleRead(serialization } 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<CXXRecordDecl>(D)) { @@ -5663,7 +5664,8 @@ static bool isImportedDeclContext(ASTRea } 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. @@ -5697,6 +5699,7 @@ void ASTWriter::AddedVisibleDecl(const D } 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 @@ -5714,6 +5717,7 @@ void ASTWriter::AddedCXXImplicitMember(c } 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) { @@ -5728,6 +5732,7 @@ void ASTWriter::ResolvedExceptionSpec(co } 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) { @@ -5738,6 +5743,7 @@ void ASTWriter::DeducedReturnType(const 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; @@ -5747,6 +5753,7 @@ void ASTWriter::ResolvedOperatorDelete(c } 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. @@ -5756,6 +5763,7 @@ void ASTWriter::CompletedImplicitDefinit } void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!D->isFromASTFile()) return; @@ -5764,6 +5772,7 @@ void ASTWriter::FunctionDefinitionInstan } void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!D->isFromASTFile()) return; @@ -5776,6 +5785,7 @@ void ASTWriter::StaticDataMemberInstanti } void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!D->isFromASTFile()) return; @@ -5786,6 +5796,7 @@ void ASTWriter::DefaultArgumentInstantia 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. @@ -5796,6 +5807,7 @@ void ASTWriter::AddedObjCCategoryToInter } 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, @@ -5809,6 +5821,7 @@ void ASTWriter::DeclarationMarkedUsed(co } void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!D->isFromASTFile()) return; @@ -5818,6 +5831,7 @@ void ASTWriter::DeclarationMarkedOpenMPT void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D, const Attr *Attr) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!D->isFromASTFile()) return; @@ -5827,6 +5841,7 @@ void ASTWriter::DeclarationMarkedOpenMPD } 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)); @@ -5834,6 +5849,7 @@ void ASTWriter::RedefinedHiddenDefinitio void ASTWriter::AddedAttributeToRecord(const Attr *Attr, const RecordDecl *Record) { + if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); if (!Record->isFromASTFile()) return; _______________________________________________ llvm-branch-commits mailing list [email protected] http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
