summaryrefslogtreecommitdiffstats
path: root/tools/scan-build
diff options
context:
space:
mode:
Diffstat (limited to 'tools/scan-build')
-rw-r--r--tools/scan-build/c++-analyzer.bat1
-rwxr-xr-xtools/scan-build/ccc-analyzer24
-rw-r--r--tools/scan-build/ccc-analyzer.bat1
-rwxr-xr-xtools/scan-build/scan-build171
4 files changed, 112 insertions, 85 deletions
diff --git a/tools/scan-build/c++-analyzer.bat b/tools/scan-build/c++-analyzer.bat
new file mode 100644
index 0000000..69f048a
--- /dev/null
+++ b/tools/scan-build/c++-analyzer.bat
@@ -0,0 +1 @@
+perl -S c++-analyzer %*
diff --git a/tools/scan-build/ccc-analyzer b/tools/scan-build/ccc-analyzer
index 4c8f648..9de38d4 100755
--- a/tools/scan-build/ccc-analyzer
+++ b/tools/scan-build/ccc-analyzer
@@ -42,9 +42,17 @@ my $DefaultCCompiler;
my $DefaultCXXCompiler;
my $IsCXX;
+# If on OSX, use xcrun to determine the SDK root.
+my $UseXCRUN = 0;
+
if (`uname -a` =~ m/Darwin/) {
$DefaultCCompiler = 'clang';
$DefaultCXXCompiler = 'clang++';
+ # Older versions of OSX do not have xcrun to
+ # query the SDK location.
+ if (-x "/usr/bin/xcrun") {
+ $UseXCRUN = 1;
+ }
} else {
$DefaultCCompiler = 'gcc';
$DefaultCXXCompiler = 'g++';
@@ -478,6 +486,7 @@ my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'};
my %DisabledArchs = ('ppc' => 1, 'ppc64' => 1);
my %ArchsSeen;
my $HadArch = 0;
+my $HasSDK = 0;
# Process the arguments.
foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
@@ -500,6 +509,12 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
next;
}
+ # On OSX/iOS, record if an SDK path was specified. This
+ # is innocuous for other platforms, so the check just happens.
+ if ($Arg =~ /^-isysroot/) {
+ $HasSDK = 1;
+ }
+
# Options with possible arguments that should pass through to compiler.
if (defined $CompileOptionMap{$ArgKey}) {
my $Cnt = $CompileOptionMap{$ArgKey};
@@ -644,6 +659,15 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
}
}
+# If we are on OSX and have an installation where the
+# default SDK is inferred by xcrun use xcrun to infer
+# the SDK.
+if (not $HasSDK and $UseXCRUN) {
+ my $sdk = `/usr/bin/xcrun --show-sdk-path -sdk macosx`;
+ chomp $sdk;
+ push @CompileOpts, "-isysroot", $sdk;
+}
+
if ($Action eq 'compile' or $Action eq 'link') {
my @Archs = keys %ArchsSeen;
# Skip the file if we don't support the architectures specified.
diff --git a/tools/scan-build/ccc-analyzer.bat b/tools/scan-build/ccc-analyzer.bat
new file mode 100644
index 0000000..2a85376
--- /dev/null
+++ b/tools/scan-build/ccc-analyzer.bat
@@ -0,0 +1 @@
+perl -S ccc-analyzer %*
diff --git a/tools/scan-build/scan-build b/tools/scan-build/scan-build
index 153be2d..d52d8f5 100755
--- a/tools/scan-build/scan-build
+++ b/tools/scan-build/scan-build
@@ -1056,7 +1056,7 @@ sub RunBuildCommand {
shift @$Args;
unshift @$Args, $CXXAnalyzer;
}
- elsif ($Cmd eq "make" or $Cmd eq "gmake") {
+ elsif ($Cmd eq "make" or $Cmd eq "gmake" or $Cmd eq "mingw32-make") {
AddIfNotPresent($Args, "CC=$CCAnalyzer");
AddIfNotPresent($Args, "CXX=$CXXAnalyzer");
if ($IgnoreErrors) {
@@ -1221,104 +1221,104 @@ LOADING CHECKERS:
-load-plugin [plugin library]
ENDTEXT
-# Query clang for list of checkers that are enabled.
-
-# create a list to load the plugins via the 'Xclang' command line
-# argument
-my @PluginLoadCommandline_xclang;
-foreach my $param ( @PluginsToLoad ) {
- push ( @PluginLoadCommandline_xclang, "-Xclang" );
- push ( @PluginLoadCommandline_xclang, $param );
-}
-my %EnabledCheckers;
-foreach my $lang ("c", "objective-c", "objective-c++", "c++") {
- pipe(FROM_CHILD, TO_PARENT);
- my $pid = fork();
- if ($pid == 0) {
- close FROM_CHILD;
- open(STDOUT,">&", \*TO_PARENT);
- open(STDERR,">&", \*TO_PARENT);
- exec $Clang, ( @PluginLoadCommandline_xclang, '--analyze', '-x', $lang, '-', '-###');
- }
- close(TO_PARENT);
- while(<FROM_CHILD>) {
- foreach my $val (split /\s+/) {
- $val =~ s/\"//g;
- if ($val =~ /-analyzer-checker\=([^\s]+)/) {
- $EnabledCheckers{$1} = 1;
+ # Query clang for list of checkers that are enabled.
+
+ # create a list to load the plugins via the 'Xclang' command line
+ # argument
+ my @PluginLoadCommandline_xclang;
+ foreach my $param ( @PluginsToLoad ) {
+ push ( @PluginLoadCommandline_xclang, "-Xclang" );
+ push ( @PluginLoadCommandline_xclang, $param );
+ }
+ my %EnabledCheckers;
+ foreach my $lang ("c", "objective-c", "objective-c++", "c++") {
+ pipe(FROM_CHILD, TO_PARENT);
+ my $pid = fork();
+ if ($pid == 0) {
+ close FROM_CHILD;
+ open(STDOUT,">&", \*TO_PARENT);
+ open(STDERR,">&", \*TO_PARENT);
+ exec $Clang, ( @PluginLoadCommandline_xclang, '--analyze', '-x', $lang, '-', '-###');
+ }
+ close(TO_PARENT);
+ while(<FROM_CHILD>) {
+ foreach my $val (split /\s+/) {
+ $val =~ s/\"//g;
+ if ($val =~ /-analyzer-checker\=([^\s]+)/) {
+ $EnabledCheckers{$1} = 1;
+ }
}
}
- }
- waitpid($pid,0);
- close(FROM_CHILD);
-}
-
-# Query clang for complete list of checkers.
-if (defined $Clang && -x $Clang) {
- pipe(FROM_CHILD, TO_PARENT);
- my $pid = fork();
- if ($pid == 0) {
- close FROM_CHILD;
- open(STDOUT,">&", \*TO_PARENT);
- open(STDERR,">&", \*TO_PARENT);
- exec $Clang, ('-cc1', @PluginsToLoad , '-analyzer-checker-help');
- }
- close(TO_PARENT);
- my $foundCheckers = 0;
- while(<FROM_CHILD>) {
- if (/CHECKERS:/) {
- $foundCheckers = 1;
- last;
+ waitpid($pid,0);
+ close(FROM_CHILD);
+ }
+
+ # Query clang for complete list of checkers.
+ if (defined $Clang && -x $Clang) {
+ pipe(FROM_CHILD, TO_PARENT);
+ my $pid = fork();
+ if ($pid == 0) {
+ close FROM_CHILD;
+ open(STDOUT,">&", \*TO_PARENT);
+ open(STDERR,">&", \*TO_PARENT);
+ exec $Clang, ('-cc1', @PluginsToLoad , '-analyzer-checker-help');
}
- }
- if (!$foundCheckers) {
- print " *** Could not query Clang for the list of available checkers.";
- }
- else {
- print("\nAVAILABLE CHECKERS:\n\n");
- my $skip = 0;
+ close(TO_PARENT);
+ my $foundCheckers = 0;
while(<FROM_CHILD>) {
- if (/experimental/) {
- $skip = 1;
- next;
- }
- if ($skip) {
- next if (!/^\s\s[^\s]/);
- $skip = 0;
+ if (/CHECKERS:/) {
+ $foundCheckers = 1;
+ last;
}
- s/^\s\s//;
- if (/^([^\s]+)/) {
- # Is the checker enabled?
- my $checker = $1;
- my $enabled = 0;
- my $aggregate = "";
- foreach my $domain (split /\./, $checker) {
- $aggregate .= $domain;
- if ($EnabledCheckers{$aggregate}) {
- $enabled =1;
- last;
- }
- # append a dot, if an additional domain is added in the next iteration
- $aggregate .= ".";
+ }
+ if (!$foundCheckers) {
+ print " *** Could not query Clang for the list of available checkers.";
+ }
+ else {
+ print("\nAVAILABLE CHECKERS:\n\n");
+ my $skip = 0;
+ while(<FROM_CHILD>) {
+ if (/experimental/) {
+ $skip = 1;
+ next;
+ }
+ if ($skip) {
+ next if (!/^\s\s[^\s]/);
+ $skip = 0;
}
+ s/^\s\s//;
+ if (/^([^\s]+)/) {
+ # Is the checker enabled?
+ my $checker = $1;
+ my $enabled = 0;
+ my $aggregate = "";
+ foreach my $domain (split /\./, $checker) {
+ $aggregate .= $domain;
+ if ($EnabledCheckers{$aggregate}) {
+ $enabled =1;
+ last;
+ }
+ # append a dot, if an additional domain is added in the next iteration
+ $aggregate .= ".";
+ }
- if ($enabled) {
- print " + ";
+ if ($enabled) {
+ print " + ";
+ }
+ else {
+ print " ";
+ }
}
else {
print " ";
}
+ print $_;
}
- else {
- print " ";
- }
- print $_;
+ print "\nNOTE: \"+\" indicates that an analysis is enabled by default.\n"
}
- print "\nNOTE: \"+\" indicates that an analysis is enabled by default.\n"
+ waitpid($pid,0);
+ close(FROM_CHILD);
}
- waitpid($pid,0);
- close(FROM_CHILD);
-}
print <<ENDTEXT
@@ -1533,6 +1533,7 @@ while (@ARGV) {
}
if ($arg eq "-no-failure-reports") {
+ shift @ARGV;
$ENV{"CCC_REPORT_FAILURES"} = 0;
next;
}
OpenPOWER on IntegriCloud