summaryrefslogtreecommitdiffstats
path: root/tools/scan-build
diff options
context:
space:
mode:
Diffstat (limited to 'tools/scan-build')
-rwxr-xr-xtools/scan-build/ccc-analyzer45
-rwxr-xr-xtools/scan-build/scan-build73
2 files changed, 71 insertions, 47 deletions
diff --git a/tools/scan-build/ccc-analyzer b/tools/scan-build/ccc-analyzer
index 60b0185..b463ec0 100755
--- a/tools/scan-build/ccc-analyzer
+++ b/tools/scan-build/ccc-analyzer
@@ -325,11 +325,6 @@ sub Analyze {
my %CompileOptionMap = (
'-nostdinc' => 0,
- '-fblocks' => 0,
- '-fno-builtin' => 0,
- '-fobjc-gc-only' => 0,
- '-fobjc-gc' => 0,
- '-ffreestanding' => 0,
'-include' => 1,
'-idirafter' => 1,
'-imacros' => 1,
@@ -346,18 +341,16 @@ my %LinkerOptionMap = (
);
my %CompilerLinkerOptionMap = (
- '-fobjc-arc' => 0,
- '-fno-objc-arc' => 0,
- '-fobjc-abi-version' => 0, # This is really a 1 argument, but always has '='
- '-fobjc-legacy-dispatch' => 0,
+ '-Wwrite-strings' => 0,
+ '-ftrapv-handler' => 1, # specifically call out separated -f flag
'-mios-simulator-version-min' => 0, # This really has 1 argument, but always has '='
'-isysroot' => 1,
'-arch' => 1,
'-m32' => 0,
'-m64' => 0,
'-stdlib' => 0, # This is really a 1 argument, but always has '='
+ '-target' => 1,
'-v' => 0,
- '-fpascal-strings' => 0,
'-mmacosx-version-min' => 0, # This is really a 1 argument, but always has '='
'-miphoneos-version-min' => 0 # This is really a 1 argument, but always has '='
);
@@ -427,8 +420,8 @@ my %Uniqued;
# Forward arguments to gcc.
my $Status = system($Compiler,@ARGV);
-if (defined $ENV{'CCC_ANALYZER_LOG'}) {
- print "$Compiler @ARGV\n";
+if (defined $ENV{'CCC_ANALYZER_LOG'}) {
+ print STDERR "$Compiler @ARGV\n";
}
if ($Status) { exit($Status >> 8); }
@@ -453,8 +446,8 @@ if (!defined $OutputFormat) { $OutputFormat = "html"; }
# Determine the level of verbosity.
my $Verbose = 0;
-if (defined $ENV{CCC_ANALYZER_VERBOSE}) { $Verbose = 1; }
-if (defined $ENV{CCC_ANALYZER_LOG}) { $Verbose = 2; }
+if (defined $ENV{'CCC_ANALYZER_VERBOSE'}) { $Verbose = 1; }
+if (defined $ENV{'CCC_ANALYZER_LOG'}) { $Verbose = 2; }
# Get the HTML output directory.
my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'};
@@ -491,10 +484,6 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
while ($Cnt > 0) { ++$i; --$Cnt; push @CompileOpts, $ARGV[$i]; }
next;
}
- if ($Arg =~ /-m.*/) {
- push @CompileOpts,$Arg;
- next;
- }
# Handle the case where there isn't a space after -iquote
if ($Arg =~ /-iquote.*/) {
push @CompileOpts,$Arg;
@@ -556,6 +545,11 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
next;
}
+ if ($Arg =~ /-m.*/) {
+ push @CompileOpts,$Arg;
+ next;
+ }
+
# Language.
if ($Arg eq '-x') {
$Lang = $ARGV[$i+1];
@@ -574,6 +568,9 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
if ($Arg eq '-O') { push @LinkOpts,'-O1'; }
elsif ($Arg eq '-Os') { push @LinkOpts,'-O2'; }
else { push @LinkOpts,$Arg; }
+
+ # Must pass this along for the __OPTIMIZE__ macro
+ if ($Arg =~ /^-O/) { push @CompileOpts,$Arg; }
next;
}
@@ -582,12 +579,6 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
next;
}
-# if ($Arg =~ /^-f/) {
-# # FIXME: Not sure if the remaining -fxxxx options have no arguments.
-# push @CompileOpts,$Arg;
-# push @LinkOpts,$Arg; # FIXME: Not sure if these are link opts.
-# }
-
# Get the compiler/link mode.
if ($Arg =~ /^-F(.+)$/) {
my $Tmp = $Arg;
@@ -611,6 +602,12 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
next;
}
+ if ($Arg =~ /^-f/) {
+ push @CompileOpts,$Arg;
+ push @LinkOpts,$Arg;
+ next;
+ }
+
# Handle -Wno-. We don't care about extra warnings, but
# we should suppress ones that we don't want to see.
if ($Arg =~ /^-Wno-/) {
diff --git a/tools/scan-build/scan-build b/tools/scan-build/scan-build
index 35f852e..0f119f6 100755
--- a/tools/scan-build/scan-build
+++ b/tools/scan-build/scan-build
@@ -32,7 +32,9 @@ my $TERM = $ENV{'TERM'};
my $UseColor = (defined $TERM and $TERM =~ 'xterm-.*color' and -t STDOUT
and defined $ENV{'SCAN_BUILD_COLOR'});
-my $UserName = HtmlEscape(getpwuid($<) || 'unknown');
+# Portability: getpwuid is not implemented for Win32 (see Perl language
+# reference, perlport), use getlogin instead.
+my $UserName = HtmlEscape(getlogin() || getpwuid($<) || 'unknown');
my $HostName = HtmlEscape(hostname() || 'unknown');
my $CurrentDir = HtmlEscape(getcwd());
my $CurrentDirSuffix = basename($CurrentDir);
@@ -121,8 +123,7 @@ sub GetHTMLRunDir {
my $Dir = shift @_;
my $TmpMode = 0;
if (!defined $Dir) {
- $Dir = $ENV{'TMPDIR'};
- if (!defined $Dir) { $Dir = "/tmp"; }
+ $Dir = $ENV{'TMPDIR'} || $ENV{'TEMP'} || $ENV{'TMP'} || "/tmp";
$TmpMode = 1;
}
@@ -134,7 +135,13 @@ sub GetHTMLRunDir {
my $year = $CurrentTime[5] + 1900;
my $day = $CurrentTime[3];
my $month = $CurrentTime[4] + 1;
- my $DateString = sprintf("%d-%02d-%02d", $year, $month, $day);
+ my $hour = $CurrentTime[2];
+ my $min = $CurrentTime[1];
+ my $sec = $CurrentTime[0];
+
+ my $TimeString = sprintf("%02d%02d%02d", $hour, $min, $sec);
+ my $DateString = sprintf("%d-%02d-%02d-%s-$$",
+ $year, $month, $day, $TimeString);
# Determine the run number.
my $RunNumber;
@@ -161,9 +168,11 @@ sub GetHTMLRunDir {
next if ($x[0] != $year);
next if ($x[1] != $month);
next if ($x[2] != $day);
+ next if ($x[3] != $TimeString);
+ next if ($x[4] != $$);
- if ($x[3] > $max) {
- $max = $x[3];
+ if ($x[5] > $max) {
+ $max = $x[5];
}
}
@@ -896,6 +905,9 @@ sub SetEnv {
}
}
+# The flag corresponding to the --override-compiler command line option.
+my $OverrideCompiler = 0;
+
sub RunXcodebuild {
my $Args = shift;
my $IgnoreErrors = shift;
@@ -910,7 +922,7 @@ sub RunXcodebuild {
# Detect the version of Xcode. If Xcode 4.6 or higher, use new
# in situ support for analyzer interposition without needed to override
# the compiler.
- open(DETECT_XCODE, "xcodebuild -version |") or
+ open(DETECT_XCODE, "-|", $Args->[0], "-version") or
die "error: cannot detect version of xcodebuild\n";
my $oldBehavior = 1;
@@ -928,6 +940,12 @@ sub RunXcodebuild {
}
close(DETECT_XCODE);
+ # If --override-compiler is explicitely requested, resort to the old
+ # behavior regardless of Xcode version.
+ if ($OverrideCompiler) {
+ $oldBehavior = 1;
+ }
+
if ($oldBehavior == 0) {
my $OutputDir = $Options->{"OUTPUT_DIR"};
my $CLANG = $Options->{"CLANG"};
@@ -976,16 +994,11 @@ sub RunBuildCommand {
my $CCAnalyzer = shift;
my $CXXAnalyzer = shift;
my $Options = shift;
-
- # Get only the part of the command after the last '/'.
- if ($Cmd =~ /\/([^\/]+)$/) {
- $Cmd = $1;
- }
-
- if ($Cmd eq "xcodebuild") {
+
+ if ($Cmd =~ /\bxcodebuild$/) {
return RunXcodebuild($Args, $IgnoreErrors, $CCAnalyzer, $CXXAnalyzer, $Options);
}
-
+
# Setup the environment.
SetEnv($Options);
@@ -1013,10 +1026,10 @@ sub RunBuildCommand {
shift @$Args;
unshift @$Args, $CXXAnalyzer;
}
- elsif ($IgnoreErrors) {
- if ($Cmd eq "make" or $Cmd eq "gmake") {
- AddIfNotPresent($Args, "CC=$CCAnalyzer");
- AddIfNotPresent($Args, "CXX=$CXXAnalyzer");
+ elsif ($Cmd eq "make" or $Cmd eq "gmake") {
+ AddIfNotPresent($Args, "CC=$CCAnalyzer");
+ AddIfNotPresent($Args, "CXX=$CXXAnalyzer");
+ if ($IgnoreErrors) {
AddIfNotPresent($Args,"-k");
AddIfNotPresent($Args,"-i");
}
@@ -1148,6 +1161,10 @@ ADVANCED OPTIONS:
Don't remove the build results directory even if no issues were reported.
+ --override-compiler
+ Always resort to the ccc-analyzer even when better interposition methods
+ are available.
+
CONTROLLING CHECKERS:
A default group of checkers are always run unless explicitly disabled.
@@ -1511,6 +1528,12 @@ while (@ARGV) {
$KeepEmpty = 1;
next;
}
+
+ if ($arg eq "--override-compiler") {
+ shift @ARGV;
+ $OverrideCompiler = 1;
+ next;
+ }
DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/);
@@ -1589,13 +1612,17 @@ my $AbsRealBin = Cwd::realpath($RealBin);
my $Cmd = "$AbsRealBin/libexec/ccc-analyzer";
my $CmdCXX = "$AbsRealBin/libexec/c++-analyzer";
-if (!defined $Cmd || ! -x $Cmd) {
+# Portability: use less strict but portable check -e (file exists) instead of
+# non-portable -x (file is executable). On some windows ports -x just checks
+# file extension to determine if a file is executable (see Perl language
+# reference, perlport)
+if (!defined $Cmd || ! -e $Cmd) {
$Cmd = "$AbsRealBin/ccc-analyzer";
- DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n") if(! -x $Cmd);
+ DieDiag("'ccc-analyzer' does not exist at '$Cmd'\n") if(! -e $Cmd);
}
-if (!defined $CmdCXX || ! -x $CmdCXX) {
+if (!defined $CmdCXX || ! -e $CmdCXX) {
$CmdCXX = "$AbsRealBin/c++-analyzer";
- DieDiag("Executable 'c++-analyzer' does not exist at '$CmdCXX'\n") if(! -x $CmdCXX);
+ DieDiag("'c++-analyzer' does not exist at '$CmdCXX'\n") if(! -e $CmdCXX);
}
Diag("Using '$Clang' for static analysis\n");
OpenPOWER on IntegriCloud