Author: jkorous
Date: Mon Oct 14 13:15:01 2019
New Revision: 374815
URL: http://llvm.org/viewvc/llvm-project?rev=374815=rev
Log:
[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
Added:
cfe/trunk/test/Analysis/preprocessor-setup.c
cfe/trunk/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
cfe/trunk/test/ClangScanDeps/static-analyzer.c
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Lex/PreprocessorOptions.h
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=374815=374814=374815=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Oct 14 13:15:01 2019
@@ -846,6 +846,8 @@ def preamble_bytes_EQ : Joined<["-"], "p
"covering the first N bytes of the main file">;
def detailed_preprocessing_record : Flag<["-"],
"detailed-preprocessing-record">,
HelpText<"include a detailed record of preprocessing actions">;
+def setup_static_analyzer : Flag<["-"], "setup-static-analyzer">,
+ HelpText<"Set up preprocessor for static analyzer (done automatically when
static analyzer is run).">;
//===--===//
// OpenCL Options
Modified: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorOptions.h?rev=374815=374814=374815=diff
==
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h Mon Oct 14 13:15:01 2019
@@ -181,6 +181,9 @@ public:
ExcludedPreprocessorDirectiveSkipMapping
*ExcludedConditionalDirectiveSkipMappings = nullptr;
+ /// Set up preprocessor for RunAnalysis action.
+ bool SetUpStaticAnalyzer = false;
+
public:
PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {}
Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=374815=374814=374815=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Oct 14 13:15:01 2019
@@ -3803,6 +3803,10 @@ void Clang::ConstructJob(Compilation ,
if (isa(JA))
RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
+ if (isa(JA) ||
+ (isa(JA) && Args.hasArg(options::OPT__analyze)))
+CmdArgs.push_back("-setup-static-analyzer");
+
// Enable compatilibily mode to avoid analyzer-config related errors.
// Since we can't access frontend flags through hasArg, let's manually
iterate
// through them.
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=374815=374814=374815=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Oct 14 13:15:01 2019
@@ -3349,6 +3349,8 @@ static void ParsePreprocessorArgs(Prepro
// "editor placeholder in source file" error in PP only mode.
if (isStrictlyPreprocessorAction(Action))
Opts.LexEditorPlaceholders = false;
+
+ Opts.SetUpStaticAnalyzer = Args.hasArg(OPT_setup_static_analyzer);
}
static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions ,
Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=374815=374814=374815=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Oct 14 13:15:01 2019
@@ -560,6 +560,7 @@ static void InitializeCPlusPlusFeatureTe
static void InitializePredefinedMacros(const TargetInfo ,
const LangOptions ,
const FrontendOptions ,
+ const PreprocessorOptions ,
MacroBuilder ) {
//