summaryrefslogtreecommitdiffstats
path: root/clang/tools
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre@debian.org>2018-09-17 06:31:46 +0000
committerSylvestre Ledru <sylvestre@debian.org>2018-09-17 06:31:46 +0000
commitae48d78054b0f8482995bab426e950382b644714 (patch)
tree30dad5b444f2e7c46d9d8a4fb8a8f4516df566f3 /clang/tools
parent00f51c0904dac4983d196e04bffac062edb25511 (diff)
downloadbcm5719-llvm-ae48d78054b0f8482995bab426e950382b644714.tar.gz
bcm5719-llvm-ae48d78054b0f8482995bab426e950382b644714.zip
scan-build: Add support of the option --exclude like in scan-build-py
Summary: To exclude thirdparty code. To test: With /tmp/foo.c ``` void test() { int x; x = 1; // warn } ``` ``` $ scan-build --exclude non-existing/ --exclude /tmp/ -v gcc -c foo.c scan-build: Using '/usr/lib/llvm-7/bin/clang' for static analysis scan-build: Emitting reports for this run to '/tmp/scan-build-2018-09-16-214531-8410-1'. foo.c:3:3: warning: Value stored to 'x' is never read x = 1; // warn ^ ~ 1 warning generated. scan-build: File '/tmp/foo.c' deleted: part of an ignored directory. scan-build: 0 bugs found. ``` Reviewers: jroelofs Reviewed By: jroelofs Subscribers: whisperity, cfe-commits Differential Revision: https://reviews.llvm.org/D52153 llvm-svn: 342359
Diffstat (limited to 'clang/tools')
-rwxr-xr-xclang/tools/scan-build/bin/scan-build30
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/tools/scan-build/bin/scan-build b/clang/tools/scan-build/bin/scan-build
index 6aebc7b18b2..5500421c8c6 100755
--- a/clang/tools/scan-build/bin/scan-build
+++ b/clang/tools/scan-build/bin/scan-build
@@ -58,6 +58,7 @@ my %Options = (
KeepEmpty => 0, # Don't remove output directory even with 0 results.
EnableCheckers => {},
DisableCheckers => {},
+ Excludes => [],
UseCC => undef, # C compiler to use for compilation.
UseCXX => undef, # C++ compiler to use for compilation.
AnalyzerTarget => undef,
@@ -420,6 +421,20 @@ sub ScanFile {
# The file no longer exists: use the original path.
$BugFile = $1;
}
+
+ # Get just the path
+ my $p = dirname($BugFile);
+ # Check if the path is found in the list of exclude
+ if (grep { $p =~ m/$_/ } @{$Options{Excludes}}) {
+ if ($Options{Verbose}) {
+ Diag("File '$BugFile' deleted: part of an ignored directory.\n");
+ }
+
+ # File in an ignored directory. Remove it
+ unlink("$Dir/$FName");
+ return;
+ }
+
UpdatePrefix($BugFile);
}
elsif (/<!-- BUGPATHLENGTH (.*) -->$/) {
@@ -1194,6 +1209,12 @@ OPTIONS:
command. Specifying this option causes the exit status of scan-build to be 1
if it found potential bugs and 0 otherwise.
+ --exclude <path>
+
+ Do not run static analyzer against files found in this
+ directory (You can specify this option multiple times).
+ Could be useful when project contains 3rd party libraries.
+
--use-cc [compiler path]
--use-cc=[compiler path]
@@ -1698,6 +1719,15 @@ sub ProcessArgs {
next;
}
+ if ($arg eq "--exclude") {
+ shift @$Args;
+ my $arg = shift @$Args;
+ # Remove the trailing slash if any
+ $arg =~ s|/$||;
+ push @{$Options{Excludes}}, $arg;
+ next;
+ }
+
if ($arg eq "-load-plugin") {
shift @$Args;
push @{$Options{PluginsToLoad}}, shift @$Args;
OpenPOWER on IntegriCloud