[clang-scan-deps] Support for clang --analyze in clang-scan-deps
The goal is to have 100% fidelity in clang-scan-deps behavior when
--analyze is present in compilation command.
At the same time I don't want to break clang-tidy which expects
__static_analyzer__ macro defined as built-in.
I introduce new cc1 options (-setup-static-analyzer) that controls
the macro definition and is conditionally set in driver.
Differential Revision: https://reviews.llvm.org/D68093
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@374815 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/clang-tidy/ClangTidy.cpp b/clang-tidy/ClangTidy.cpp
index 21984ae..91e8ebe 100644
--- a/clang-tidy/ClangTidy.cpp
+++ b/clang-tidy/ClangTidy.cpp
@@ -33,6 +33,7 @@
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Rewrite/Frontend/FixItRewriter.h"
#include "clang/Rewrite/Frontend/FrontendActions.h"
#include "clang/Tooling/Core/Diagnostic.h"
@@ -539,10 +540,8 @@
FileManager *Files,
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
DiagnosticConsumer *DiagConsumer) override {
- // Explicitly set ProgramAction to RunAnalysis to make the preprocessor
- // define __clang_analyzer__ macro. The frontend analyzer action will not
- // be called here.
- Invocation->getFrontendOpts().ProgramAction = frontend::RunAnalysis;
+ // Explicitly ask to define __clang_analyzer__ macro.
+ Invocation->getPreprocessorOpts().SetUpStaticAnalyzer = true;
return FrontendActionFactory::runInvocation(
Invocation, Files, PCHContainerOps, DiagConsumer);
}