r349866 - [driver] [analyzer] Fix --analyze -Xanalyzer after r349863.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 20 17:11:21 PST 2018


Author: dergachev
Date: Thu Dec 20 17:11:21 2018
New Revision: 349866

URL: http://llvm.org/viewvc/llvm-project?rev=349866&view=rev
Log:
[driver] [analyzer] Fix --analyze -Xanalyzer after r349863.

If an -analyzer-config is passed through -Xanalyzer, it is not found while
looking for -Xclang.

Additionally, don't emit -analyzer-config-compatibility-mode for *every*
-analyzer-config flag we encounter; one is enough.

https://reviews.llvm.org/D55823

rdar://problem/46504165

Modified:
    cfe/trunk/lib/Driver/ToolChains/Clang.cpp
    cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
    cfe/trunk/test/Analysis/invalid-analyzer-config-value.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=349866&r1=349865&r2=349866&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Dec 20 17:11:21 2018
@@ -3738,9 +3738,20 @@ void Clang::ConstructJob(Compilation &C,
   // Enable compatilibily mode to avoid analyzer-config related errors.
   // Since we can't access frontend flags through hasArg, let's manually iterate
   // through them.
+  bool FoundAnalyzerConfig = false;
   for (auto Arg : Args.filtered(options::OPT_Xclang))
-    if (StringRef(Arg->getValue()) == "-analyzer-config")
-      CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
+    if (StringRef(Arg->getValue()) == "-analyzer-config") {
+      FoundAnalyzerConfig = true;
+      break;
+    }
+  if (!FoundAnalyzerConfig)
+    for (auto Arg : Args.filtered(options::OPT_Xanalyzer))
+      if (StringRef(Arg->getValue()) == "-analyzer-config") {
+        FoundAnalyzerConfig = true;
+        break;
+      }
+  if (FoundAnalyzerConfig)
+    CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
 
   CheckCodeGenerationOptions(D, Args);
 

Modified: cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c?rev=349866&r1=349865&r2=349866&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c (original)
+++ cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c Thu Dec 20 17:11:21 2018
@@ -74,6 +74,10 @@
 // even if -analyze isn't specified.
 // RUN: %clang -fsyntax-only -Xclang -analyzer-config\
 // RUN:                      -Xclang remember=TheVasa %s
+// RUN: %clang -fsyntax-only -Xanalyzer -analyzer-config\
+// RUN:                      -Xanalyzer remember=TheVasa %s
+// RUN: %clang --analyze -Xanalyzer -analyzer-config\
+// RUN:                  -Xanalyzer remember=TheVasa %s
 
 // expected-no-diagnostics
 

Modified: cfe/trunk/test/Analysis/invalid-analyzer-config-value.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/invalid-analyzer-config-value.c?rev=349866&r1=349865&r2=349866&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/invalid-analyzer-config-value.c (original)
+++ cfe/trunk/test/Analysis/invalid-analyzer-config-value.c Thu Dec 20 17:11:21 2018
@@ -70,6 +70,10 @@
 // even if -analyze isn't specified.
 // RUN: %clang -fsyntax-only -Xclang -analyzer-config\
 // RUN:                      -Xclang remember=TheVasa %s
+// RUN: %clang -fsyntax-only -Xanalyzer -analyzer-config\
+// RUN:                      -Xanalyzer remember=TheVasa %s
+// RUN: %clang --analyze -Xanalyzer -analyzer-config\
+// RUN:                  -Xanalyzer remember=TheVasa %s
 
 // expected-no-diagnostics
 




More information about the cfe-commits mailing list