diff options
author | Gabor Marton <martongabesz@gmail.com> | 2018-12-07 14:56:02 +0000 |
---|---|---|
committer | Gabor Marton <martongabesz@gmail.com> | 2018-12-07 14:56:02 +0000 |
commit | 9419eb42c45be0e4f540bbcbb6bb93d8876559c6 (patch) | |
tree | 1ca08a4773de8d99eea88c2caa4d5ea049f687c2 | |
parent | b9e65cbddf6f5d7e387aae70a8db3e0ae55c0270 (diff) | |
download | bcm5719-llvm-9419eb42c45be0e4f540bbcbb6bb93d8876559c6.tar.gz bcm5719-llvm-9419eb42c45be0e4f540bbcbb6bb93d8876559c6.zip |
[CTU] Add DisplayCTUProgress analyzer switch
Summary:
With a new switch we may be able to print to stderr if a new TU is being loaded
during CTU. This is very important for higher level scripts (like CodeChecker)
to be able to parse this output so they can create e.g. a zip file in case of
a Clang crash which contains all the related TU files.
Reviewers: xazax.hun, Szelethus, a_sidorin, george.karpenkov
Subscribers: whisperity, baloghadamsoftware, szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp,
Differential Revision: https://reviews.llvm.org/D55135
llvm-svn: 348594
-rw-r--r-- | clang/include/clang/CrossTU/CrossTranslationUnit.h | 5 | ||||
-rw-r--r-- | clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def | 5 | ||||
-rw-r--r-- | clang/lib/CrossTU/CrossTranslationUnit.cpp | 12 | ||||
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/CallEvent.cpp | 4 | ||||
-rw-r--r-- | clang/test/Analysis/analyzer-config.c | 3 | ||||
-rw-r--r-- | clang/test/Analysis/ctu-main.cpp | 8 |
6 files changed, 29 insertions, 8 deletions
diff --git a/clang/include/clang/CrossTU/CrossTranslationUnit.h b/clang/include/clang/CrossTU/CrossTranslationUnit.h index 041f1a8eea5..9a09956bc78 100644 --- a/clang/include/clang/CrossTU/CrossTranslationUnit.h +++ b/clang/include/clang/CrossTU/CrossTranslationUnit.h @@ -108,7 +108,7 @@ public: /// Note that the AST files should also be in the \p CrossTUDir. llvm::Expected<const FunctionDecl *> getCrossTUDefinition(const FunctionDecl *FD, StringRef CrossTUDir, - StringRef IndexName); + StringRef IndexName, bool DisplayCTUProgress = false); /// This function loads a function definition from an external AST /// file. @@ -124,7 +124,8 @@ public: /// Note that the AST files should also be in the \p CrossTUDir. llvm::Expected<ASTUnit *> loadExternalAST(StringRef LookupName, StringRef CrossTUDir, - StringRef IndexName); + StringRef IndexName, + bool DisplayCTUProgress = false); /// This function merges a definition from a separate AST Unit into /// the current one which was created by the compiler instance that diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def index 6d9f948de5c..8e5d8d3ad37 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def @@ -283,6 +283,11 @@ ANALYZER_OPTION(bool, ShouldDisplayMacroExpansions, "expand-macros", "expanded and included in the plist output.", false) +ANALYZER_OPTION(bool, DisplayCTUProgress, "display-ctu-progress", + "Whether to emit verbose output about " + "the analyzer's progress related to ctu.", + false) + //===----------------------------------------------------------------------===// // Unsinged analyzer options. //===----------------------------------------------------------------------===// diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp index 97563b05b00..7d4f0ec9b42 100644 --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -159,7 +159,8 @@ CrossTranslationUnitContext::findFunctionInDeclContext(const DeclContext *DC, llvm::Expected<const FunctionDecl *> CrossTranslationUnitContext::getCrossTUDefinition(const FunctionDecl *FD, StringRef CrossTUDir, - StringRef IndexName) { + StringRef IndexName, + bool DisplayCTUProgress) { assert(FD && "FD is missing, bad call to this function!"); assert(!FD->hasBody() && "FD has a definition in current translation unit!"); ++NumGetCTUCalled; @@ -168,7 +169,7 @@ CrossTranslationUnitContext::getCrossTUDefinition(const FunctionDecl *FD, return llvm::make_error<IndexError>( index_error_code::failed_to_generate_usr); llvm::Expected<ASTUnit *> ASTUnitOrError = - loadExternalAST(LookupFnName, CrossTUDir, IndexName); + loadExternalAST(LookupFnName, CrossTUDir, IndexName, DisplayCTUProgress); if (!ASTUnitOrError) return ASTUnitOrError.takeError(); ASTUnit *Unit = *ASTUnitOrError; @@ -205,7 +206,8 @@ void CrossTranslationUnitContext::emitCrossTUDiagnostics(const IndexError &IE) { } llvm::Expected<ASTUnit *> CrossTranslationUnitContext::loadExternalAST( - StringRef LookupName, StringRef CrossTUDir, StringRef IndexName) { + StringRef LookupName, StringRef CrossTUDir, StringRef IndexName, + bool DisplayCTUProgress) { // FIXME: The current implementation only supports loading functions with // a lookup name from a single translation unit. If multiple // translation units contains functions with the same lookup name an @@ -247,6 +249,10 @@ llvm::Expected<ASTUnit *> CrossTranslationUnitContext::loadExternalAST( ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts())); Unit = LoadedUnit.get(); FileASTUnitMap[ASTFileName] = std::move(LoadedUnit); + if (DisplayCTUProgress) { + llvm::errs() << "CTU loaded AST file: " + << ASTFileName << "\n"; + } } else { Unit = ASTCacheEntry->second.get(); } diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp index 6f90ea02aa8..767116630f4 100644 --- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -560,8 +560,8 @@ RuntimeDefinition AnyFunctionCall::getRuntimeDefinition() const { cross_tu::CrossTranslationUnitContext &CTUCtx = *Engine->getCrossTranslationUnitContext(); llvm::Expected<const FunctionDecl *> CTUDeclOrError = - CTUCtx.getCrossTUDefinition(FD, Opts.CTUDir, - Opts.CTUIndexName); + CTUCtx.getCrossTUDefinition(FD, Opts.CTUDir, Opts.CTUIndexName, + Opts.DisplayCTUProgress); if (!CTUDeclOrError) { handleAllErrors(CTUDeclOrError.takeError(), diff --git a/clang/test/Analysis/analyzer-config.c b/clang/test/Analysis/analyzer-config.c index 96f1e006ade..ed13a85b59f 100644 --- a/clang/test/Analysis/analyzer-config.c +++ b/clang/test/Analysis/analyzer-config.c @@ -21,6 +21,7 @@ // CHECK-NEXT: crosscheck-with-z3 = false // CHECK-NEXT: ctu-dir = "" // CHECK-NEXT: ctu-index-name = externalFnMap.txt +// CHECK-NEXT: display-ctu-progress = false // CHECK-NEXT: eagerly-assume = true // CHECK-NEXT: elide-constructors = true // CHECK-NEXT: expand-macros = false @@ -51,4 +52,4 @@ // CHECK-NEXT: unroll-loops = false // CHECK-NEXT: widen-loops = false // CHECK-NEXT: [stats] -// CHECK-NEXT: num-entries = 48 +// CHECK-NEXT: num-entries = 49 diff --git a/clang/test/Analysis/ctu-main.cpp b/clang/test/Analysis/ctu-main.cpp index fca750c317b..3bd5d24bd05 100644 --- a/clang/test/Analysis/ctu-main.cpp +++ b/clang/test/Analysis/ctu-main.cpp @@ -10,6 +10,14 @@ // RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \ // RUN: -analyzer-config ctu-dir=%t/ctudir \ // RUN: -verify %s +// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu \ +// RUN: -analyzer-checker=core,debug.ExprInspection \ +// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \ +// RUN: -analyzer-config ctu-dir=%t/ctudir \ +// RUN: -analyzer-config display-ctu-progress=true 2>&1 %s | FileCheck %s + +// CHECK: CTU loaded AST file: {{.*}}/ctu-other.cpp +// CHECK: CTU loaded AST file: {{.*}}/ctu-chain.cpp #include "ctu-hdr.h" |