r349824 - [driver] [analyzer] Fix a backward compatibility issue after r348038.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 20 13:26:40 PST 2018


Author: dergachev
Date: Thu Dec 20 13:26:40 2018
New Revision: 349824

URL: http://llvm.org/viewvc/llvm-project?rev=349824&view=rev
Log:
[driver] [analyzer] Fix a backward compatibility issue after r348038.

Since r348038 we emit an error every time an -analyzer-config option is not
found. The driver, however, suppresses this error with another flag,
-analyzer-config-compatibility-mode, so backwards compatibility is maintained,
while analyzer developers still enjoy the new typo-free experience.

The backwards compatibility turns out to be still broken when the -analyze
action is not specified; it is still possible to specify -analyzer-config
in that case. This should be fixed now.

Patch by Kristóf Umann!

Differential Revision: https://reviews.llvm.org/D55823

rdar://problem/46504165

Added:
    cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c
Modified:
    cfe/trunk/lib/Driver/ToolChains/Clang.cpp
    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=349824&r1=349823&r2=349824&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Dec 20 13:26:40 2018
@@ -2360,9 +2360,6 @@ static void RenderAnalyzerOptions(const
   // Treat blocks as analysis entry points.
   CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks");
 
-  // Enable compatilibily mode to avoid analyzer-config related errors.
-  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
-
   // Add default argument set.
   if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
     CmdArgs.push_back("-analyzer-checker=core");
@@ -3738,6 +3735,16 @@ void Clang::ConstructJob(Compilation &C,
   if (isa<AnalyzeJobAction>(JA))
     RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 
+  // Enable compatilibily mode to avoid analyzer-config related errors.
+  // Since we can't access frontend flags through hasArg, let's manually iterate
+  // through them.
+  for (size_t Index = 0; Index < Args.size(); ++Index) {
+    if (StringRef(Args.getArgString(Index)).contains("-analyzer-config")) {
+      CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
+      break;
+    }
+  }
+
   CheckCodeGenerationOptions(D, Args);
 
   unsigned FunctionAlignment = ParseFunctionAlignment(TC, Args);

Added: 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=349824&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c (added)
+++ cfe/trunk/test/Analysis/invalid-a-na-ly-zer-con-fig-value.c Thu Dec 20 13:26:40 2018
@@ -0,0 +1,79 @@
+// Same as invalid-analyzer-config-value.c but without -analyzer-config
+// in the file name, so that argument string pattern matching
+// didn't accidentally match it.
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config notes-as-events=yesplease \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-BOOL-INPUT
+
+// CHECK-BOOL-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-BOOL-INPUT-SAME:        'notes-as-events', that expects a boolean value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config notes-as-events=yesplease
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config max-inlinable-size=400km/h \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UINT-INPUT
+
+// CHECK-UINT-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-UINT-INPUT-SAME:        'max-inlinable-size', that expects an unsigned
+// CHECK-UINT-INPUT-SAME:        value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config max-inlinable-size=400km/h
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config ctu-dir=0123012301230123 \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-FILENAME-INPUT
+
+// CHECK-FILENAME-INPUT: (frontend): invalid input for analyzer-config option
+// CHECK-FILENAME-INPUT-SAME:        'ctu-dir', that expects a filename
+// CHECK-FILENAME-INPUT-SAME:        value
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config ctu-dir=0123012301230123
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config no-false-positives=true \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-CFG
+
+// CHECK-UNKNOWN-CFG: (frontend): unknown analyzer-config 'no-false-positives'
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config no-false-positives=true
+
+
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// no longer causing an error on input error.
+// RUN: %clang --analyze %s
+
+// RUN: not %clang --analyze %s \
+// RUN:   -Xclang -analyzer-config -Xclang no-false-positives=true \
+// RUN:   -Xclang -analyzer-config-compatibility-mode=false \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-NO-COMPAT
+
+// CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
+
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -Xclang -analyzer-config -Xclang remember=TheVasa %s
+
+// expected-no-diagnostics
+
+int main() {}

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=349824&r1=349823&r2=349824&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/invalid-analyzer-config-value.c (original)
+++ cfe/trunk/test/Analysis/invalid-analyzer-config-value.c Thu Dec 20 13:26:40 2018
@@ -66,6 +66,10 @@
 
 // CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
 
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -Xclang -analyzer-config -Xclang remember=TheVasa %s
+
 // expected-no-diagnostics
 
 int main() {}




More information about the cfe-commits mailing list