Author: Gabor Marton Date: 2020-07-09T15:36:33+02:00 New Revision: d12d0b73f1c9c3a711c5cc15266a2b493cd712e9
URL: https://github.com/llvm/llvm-project/commit/d12d0b73f1c9c3a711c5cc15266a2b493cd712e9 DIFF: https://github.com/llvm/llvm-project/commit/d12d0b73f1c9c3a711c5cc15266a2b493cd712e9.diff LOG: [analyzer] Add CTUImportCppThreshold for C++ files Summary: The default CTUImportThreshold (8) seems to be too conservative with C projects. We increase this value to 24 and we introduce another threshold for C++ source files (defaulted to 8) because their AST is way more compilcated than C source files. Differential Revision: https://reviews.llvm.org/D83475 Added: Modified: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def clang/lib/CrossTU/CrossTranslationUnit.cpp clang/test/Analysis/analyzer-config.c clang/test/Analysis/ctu-import-threshold.c clang/unittests/CrossTU/CrossTranslationUnitTest.cpp Removed: ################################################################################ diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def index 9ee113c0dcaf..f0359d2dbb3c 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def @@ -321,9 +321,16 @@ ANALYZER_OPTION(bool, ShouldDisplayCheckerNameForText, "display-checker-name", ANALYZER_OPTION(unsigned, CTUImportThreshold, "ctu-import-threshold", "The maximal amount of translation units that is considered " "for import when inlining functions during CTU analysis. " - "Lowering this threshold can alleviate the memory burder of " + "Lowering this threshold can alleviate the memory burden of " "analysis with many interdependent definitions located in " - "various translation units.", + "various translation units. This is valid only for non C++ " + "source files.", + 24u) + +ANALYZER_OPTION(unsigned, CTUImportCppThreshold, "ctu-import-cpp-threshold", + "The maximal amount of translation units that is considered " + "for import when inlining functions during CTU analysis of C++ " + "source files.", 8u) ANALYZER_OPTION( diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp index 11cc2afbc36d..80465c41d151 100644 --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -367,7 +367,9 @@ CrossTranslationUnitContext::ASTUnitStorage::ASTUnitStorage( CompilerInstance &CI) : Loader(CI, CI.getAnalyzerOpts()->CTUDir, CI.getAnalyzerOpts()->CTUInvocationList), - LoadGuard(CI.getAnalyzerOpts()->CTUImportThreshold) {} + LoadGuard(CI.getASTContext().getLangOpts().CPlusPlus + ? CI.getAnalyzerOpts()->CTUImportCppThreshold + : CI.getAnalyzerOpts()->CTUImportThreshold) {} llvm::Expected<ASTUnit *> CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFile( diff --git a/clang/test/Analysis/analyzer-config.c b/clang/test/Analysis/analyzer-config.c index 7599cb052d44..d286f1258c21 100644 --- a/clang/test/Analysis/analyzer-config.c +++ b/clang/test/Analysis/analyzer-config.c @@ -43,7 +43,8 @@ // CHECK-NEXT: cplusplus.SmartPtrModeling:ModelSmartPtrDereference = false // CHECK-NEXT: crosscheck-with-z3 = false // CHECK-NEXT: ctu-dir = "" -// CHECK-NEXT: ctu-import-threshold = 8 +// CHECK-NEXT: ctu-import-cpp-threshold = 8 +// CHECK-NEXT: ctu-import-threshold = 24 // CHECK-NEXT: ctu-index-name = externalDefMap.txt // CHECK-NEXT: ctu-invocation-list = invocations.yaml // CHECK-NEXT: deadcode.DeadStores:ShowFixIts = false diff --git a/clang/test/Analysis/ctu-import-threshold.c b/clang/test/Analysis/ctu-import-threshold.c index 82711b873d10..62bbeda20d5b 100644 --- a/clang/test/Analysis/ctu-import-threshold.c +++ b/clang/test/Analysis/ctu-import-threshold.c @@ -1,5 +1,6 @@ // Ensure analyzer option 'ctu-import-threshold' is a recognized option. // // RUN: %clang_cc1 -analyze -analyzer-config ctu-import-threshold=30 -verify %s +// RUN: %clang_cc1 -analyze -analyzer-config ctu-import-cpp-threshold=30 -verify %s // // expected-no-diagnostics diff --git a/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp b/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp index ceb1437f2520..5495f27f5b32 100644 --- a/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp +++ b/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp @@ -147,6 +147,7 @@ class CTUAction : public clang::ASTFrontendAction { std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &CI, StringRef) override { CI.getAnalyzerOpts()->CTUImportThreshold = OverrideLimit; + CI.getAnalyzerOpts()->CTUImportCppThreshold = OverrideLimit; return std::make_unique<CTUASTConsumer>(CI, Success); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits