[clang] 0b2a922 - [analyzer] scan-build: Fix silencing multiple core checkers.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 18 10:37:11 PDT 2020


Author: Artem Dergachev
Date: 2020-07-18T10:37:00-07:00
New Revision: 0b2a92224630f6e177d091b8391cfa943764aba5

URL: https://github.com/llvm/llvm-project/commit/0b2a92224630f6e177d091b8391cfa943764aba5
DIFF: https://github.com/llvm/llvm-project/commit/0b2a92224630f6e177d091b8391cfa943764aba5.diff

LOG: [analyzer] scan-build: Fix silencing multiple core checkers.

It was only silencing one checker because -analyzer-config flags
can only carry one value at a time.

Added: 
    clang/test/Analysis/scan-build/Inputs/null_dereference_and_division_by_zero.c
    clang/test/Analysis/scan-build/silence-core-checkers.test

Modified: 
    clang/tools/scan-build/bin/scan-build

Removed: 
    


################################################################################
diff  --git a/clang/test/Analysis/scan-build/Inputs/null_dereference_and_division_by_zero.c b/clang/test/Analysis/scan-build/Inputs/null_dereference_and_division_by_zero.c
new file mode 100644
index 000000000000..438af79c90bb
--- /dev/null
+++ b/clang/test/Analysis/scan-build/Inputs/null_dereference_and_division_by_zero.c
@@ -0,0 +1,8 @@
+int test(int x) {
+  if (x) {
+    int *p = 0;
+    return *p; // Null dereference.
+  } else {
+    return 1 / x; // Division by zero.
+  }
+}

diff  --git a/clang/test/Analysis/scan-build/silence-core-checkers.test b/clang/test/Analysis/scan-build/silence-core-checkers.test
new file mode 100644
index 000000000000..6d9a3017fcd6
--- /dev/null
+++ b/clang/test/Analysis/scan-build/silence-core-checkers.test
@@ -0,0 +1,30 @@
+// FIXME: Actually, "perl".
+REQUIRES: shell
+
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -o %t.output_dir \
+RUN:   %clang -S %S/Inputs/null_dereference_and_division_by_zero.c \
+RUN:   | FileCheck %s -check-prefix CHECK-TWO-BUGS
+
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -o %t.output_dir \
+RUN:   -disable-checker core.DivideZero \
+RUN:   %clang -S %S/Inputs/null_dereference_and_division_by_zero.c \
+RUN:   | FileCheck %s -check-prefix CHECK-ONE-BUG
+
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -o %t.output_dir \
+RUN:   -disable-checker core.NullDereference \
+RUN:   %clang -S %S/Inputs/null_dereference_and_division_by_zero.c \
+RUN:   | FileCheck %s -check-prefix CHECK-ONE-BUG
+
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -o %t.output_dir \
+RUN:   -disable-checker core.NullDereference \
+RUN:   -disable-checker core.DivideZero \
+RUN:   %clang -S %S/Inputs/null_dereference_and_division_by_zero.c \
+RUN:   | FileCheck %s -check-prefix CHECK-NO-BUGS
+
+CHECK-NO-BUGS: scan-build: No bugs found.
+CHECK-ONE-BUG: scan-build: 1 bug found.
+CHECK-TWO-BUGS: scan-build: 2 bugs found.

diff  --git a/clang/tools/scan-build/bin/scan-build b/clang/tools/scan-build/bin/scan-build
index 11334a0b9626..aed8c417b6cc 100755
--- a/clang/tools/scan-build/bin/scan-build
+++ b/clang/tools/scan-build/bin/scan-build
@@ -1973,11 +1973,13 @@ my $CCC_ANALYZER_ANALYSIS = join ' ', @AnalysesToRun;
 my $CCC_ANALYZER_PLUGINS = join ' ', map { "-load ".$_ } @{$Options{PluginsToLoad}};
 my $CCC_ANALYZER_CONFIG = join ' ', map { "-analyzer-config ".$_ } @{$Options{ConfigOptions}};
 
-foreach (sort { $Options{SilenceCheckers}{$a} <=> $Options{SilenceCheckers}{$b} }
-         keys %{$Options{SilenceCheckers}}) {
-  # Add checkers in order they were silenced.
+if (%{$Options{SilenceCheckers}}) {
   $CCC_ANALYZER_CONFIG =
-      $CCC_ANALYZER_CONFIG." -analyzer-config silence-checkers=".$_;
+      $CCC_ANALYZER_CONFIG." -analyzer-config silence-checkers="
+                          .join(';', sort {
+                                            $Options{SilenceCheckers}{$a} <=>
+                                            $Options{SilenceCheckers}{$b}
+                                          } keys %{$Options{SilenceCheckers}});
 }
 
 my %EnvVars = (


        


More information about the cfe-commits mailing list