diff --git a/clang/include/clang/CrossTU/CrossTranslationUnit.h b/clang/include/clang/CrossTU/CrossTranslationUnit.h --- a/clang/include/clang/CrossTU/CrossTranslationUnit.h +++ b/clang/include/clang/CrossTU/CrossTranslationUnit.h @@ -163,6 +163,7 @@ void emitCrossTUDiagnostics(const IndexError &IE); private: + bool checkThresholdReached() const; void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU); ASTImporter &getOrCreateASTImporter(ASTContext &From); template diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -340,6 +340,14 @@ } } +bool CrossTranslationUnitContext::checkThresholdReached() const { + if (NumASTLoaded >= CTULoadThreshold) { + ++NumASTLoadThresholdReached; + return true; + } + return false; +} + llvm::Expected CrossTranslationUnitContext::loadExternalAST( StringRef LookupName, StringRef CrossTUDir, StringRef IndexName, bool DisplayCTUProgress) { @@ -348,11 +356,10 @@ // translation units contains decls with the same lookup name an // error will be returned. - if (NumASTLoaded >= CTULoadThreshold) { - ++NumASTLoadThresholdReached; + // If import threshold is reached, don't import anything. + if (checkThresholdReached()) return llvm::make_error( index_error_code::load_threshold_reached); - } ASTUnit *Unit = nullptr; auto NameUnitCacheEntry = NameASTUnitMap.find(LookupName);