gamesh411 created this revision.
Herald added subscribers: cfe-commits, Szelethus, dkrupp.
Herald added a reviewer: martong.
Herald added a project: clang.
Herald added a subscriber: rnkovacs.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64748

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===================================================================
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -340,6 +340,14 @@
   }
 }
 
+bool CrossTranslationUnitContext::checkThresholdReached() const {
+  if (NumASTLoaded >= CTULoadThreshold) {
+    ++NumASTLoadThresholdReached;
+    return true;
+  }
+  return false;
+}
+
 llvm::Expected<ASTUnit *> 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<IndexError>(
         index_error_code::load_threshold_reached);
-  }
 
   ASTUnit *Unit = nullptr;
   auto NameUnitCacheEntry = NameASTUnitMap.find(LookupName);
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===================================================================
--- clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ 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 <typename T>


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===================================================================
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -340,6 +340,14 @@
   }
 }
 
+bool CrossTranslationUnitContext::checkThresholdReached() const {
+  if (NumASTLoaded >= CTULoadThreshold) {
+    ++NumASTLoadThresholdReached;
+    return true;
+  }
+  return false;
+}
+
 llvm::Expected<ASTUnit *> 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<IndexError>(
         index_error_code::load_threshold_reached);
-  }
 
   ASTUnit *Unit = nullptr;
   auto NameUnitCacheEntry = NameASTUnitMap.find(LookupName);
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===================================================================
--- clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ 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 <typename T>
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to