]> granicus.if.org Git - clang/commitdiff
[static analyzer] Define __clang_analyzer__ macro in driver
authorJan Korous <jkorous@apple.com>
Tue, 24 Sep 2019 00:33:47 +0000 (00:33 +0000)
committerJan Korous <jkorous@apple.com>
Tue, 24 Sep 2019 00:33:47 +0000 (00:33 +0000)
Differential Revision: https://reviews.llvm.org/D67938

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372679 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/Clang.cpp
lib/Frontend/InitPreprocessor.cpp
test/Analysis/misc-driver.c [new file with mode: 0644]
test/Analysis/misc-ps.m

index aa17efbee32bb591ea4d367cdd65c40d05803c39..6453af73b0a5da5b33a907a6ceadd11676dd072e 100644 (file)
@@ -3896,8 +3896,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   if (Args.hasArg(options::OPT_municode))
     CmdArgs.push_back("-DUNICODE");
 
-  if (isa<AnalyzeJobAction>(JA))
+  if (isa<AnalyzeJobAction>(JA)) {
     RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
+    CmdArgs.push_back("-D__clang_analyzer__");
+  }
 
   // Enable compatilibily mode to avoid analyzer-config related errors.
   // Since we can't access frontend flags through hasArg, let's manually iterate
index 95d9f62c6087e637d753626d475cb758e21d27a8..9da37e0a446d6c772541a763af980f3c3b2550b8 100644 (file)
@@ -990,10 +990,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
   else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
     Builder.defineMacro("__SSP_ALL__", "3");
 
-  // Define a macro that exists only when using the static analyzer.
-  if (FEOpts.ProgramAction == frontend::RunAnalysis)
-    Builder.defineMacro("__clang_analyzer__");
-
   if (LangOpts.FastRelaxedMath)
     Builder.defineMacro("__FAST_RELAXED_MATH__");
 
diff --git a/test/Analysis/misc-driver.c b/test/Analysis/misc-driver.c
new file mode 100644 (file)
index 0000000..f9e7fe3
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: %clang --analyze %s
+
+#ifndef __clang_analyzer__
+#error __clang_analyzer__ not defined
+#endif
index 9a75cfd87b62358db6753e75877bde638175538c..1cfd2eb1caf27cd08ef20db484a9a588875e3d52 100644 (file)
@@ -2,10 +2,6 @@
 // RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-store=region -verify -fblocks -Wno-unreachable-code -Wno-null-dereference -Wno-objc-root-class %s
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-store=region -verify -fblocks -Wno-unreachable-code -Wno-null-dereference -Wno-objc-root-class %s
 
-#ifndef __clang_analyzer__
-#error __clang_analyzer__ not defined
-#endif
-
 typedef struct objc_ivar *Ivar;
 typedef struct objc_selector *SEL;
 typedef signed char BOOL;