2008-07-19 10:11:04 +04:00
|
|
|
#!/usr/bin/env perl
|
2008-03-26 01:35:32 +03:00
|
|
|
#
|
|
|
|
# The LLVM Compiler Infrastructure
|
|
|
|
#
|
|
|
|
# This file is distributed under the University of Illinois Open Source
|
|
|
|
# License. See LICENSE.TXT for details.
|
|
|
|
#
|
|
|
|
##===----------------------------------------------------------------------===##
|
|
|
|
#
|
2008-07-19 10:11:04 +04:00
|
|
|
# A script designed to interpose between the build system and gcc. It invokes
|
|
|
|
# both gcc and the static analyzer.
|
2008-03-26 01:35:32 +03:00
|
|
|
#
|
|
|
|
##===----------------------------------------------------------------------===##
|
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2008-09-21 23:56:14 +04:00
|
|
|
use Cwd qw/ getcwd abs_path /;
|
2008-08-09 00:46:42 +04:00
|
|
|
use File::Temp qw/ tempfile /;
|
|
|
|
use File::Path qw / mkpath /;
|
2009-01-21 03:42:24 +03:00
|
|
|
use File::Basename;
|
2008-08-26 00:44:31 +04:00
|
|
|
|
|
|
|
my $CC = $ENV{'CCC_CC'};
|
|
|
|
if (!defined $CC) { $CC = "gcc"; }
|
2009-01-21 03:42:24 +03:00
|
|
|
my $CleanupFile;
|
|
|
|
my $ResultFile;
|
|
|
|
|
|
|
|
# Remove any stale files at exit.
|
|
|
|
END {
|
|
|
|
if (defined $CleanupFile && -z $CleanupFile) {
|
|
|
|
`rm -f $CleanupFile`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-09 00:46:42 +04:00
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
# Process Clang Crashes.
|
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
|
|
|
|
sub GetPPExt {
|
|
|
|
my $Lang = shift;
|
|
|
|
if ($Lang =~ /objective-c/) { return ".mi"; }
|
|
|
|
return ".i";
|
|
|
|
}
|
|
|
|
|
2009-01-27 04:19:08 +03:00
|
|
|
my $ParserRejects = "Parser Rejects";
|
2009-02-18 02:31:05 +03:00
|
|
|
my $AttributeIgnored = "Attribute Ignored";
|
2009-01-27 04:19:08 +03:00
|
|
|
|
2008-08-18 22:38:29 +04:00
|
|
|
sub ProcessClangFailure {
|
2008-09-25 04:51:44 +04:00
|
|
|
my ($Clang, $Lang, $file, $Args, $HtmlDir, $ErrorType, $ofile) = @_;
|
2009-02-18 02:31:05 +03:00
|
|
|
my $Dir = "$HtmlDir/failures";
|
2008-08-09 00:46:42 +04:00
|
|
|
mkpath $Dir;
|
2009-01-27 04:19:08 +03:00
|
|
|
|
|
|
|
my $prefix = "clang_crash";
|
2009-02-18 02:31:05 +03:00
|
|
|
if ($ErrorType eq $ParserRejects) {
|
|
|
|
$prefix = "clang_parser_rejects";
|
|
|
|
}
|
|
|
|
elsif ($ErrorType eq $AttributeIgnored) {
|
|
|
|
$prefix = "clang_attribute_ignored";
|
|
|
|
}
|
2008-09-25 04:51:44 +04:00
|
|
|
|
|
|
|
# Generate the preprocessed file with cc (i.e., gcc).
|
2009-01-27 04:19:08 +03:00
|
|
|
my ($PPH, $PPFile) = tempfile( $prefix . "_XXXXXX",
|
|
|
|
SUFFIX => GetPPExt($Lang),
|
|
|
|
DIR => $Dir);
|
2008-08-09 00:46:42 +04:00
|
|
|
|
2008-08-26 00:44:31 +04:00
|
|
|
system $CC, @$Args, "-E", "-o", $PPFile;
|
2008-08-09 00:46:42 +04:00
|
|
|
close ($PPH);
|
2008-09-25 04:51:44 +04:00
|
|
|
|
|
|
|
# Generate the preprocessed file with clang.
|
|
|
|
my $PPFile_Clang = $PPFile;
|
|
|
|
$PPFile_Clang =~ s/[.](.+)$/.clang.$1/;
|
|
|
|
system $Clang, @$Args, "-E", "-o", "$PPFile_Clang";
|
|
|
|
|
|
|
|
# Create the info file.
|
2008-09-25 04:25:16 +04:00
|
|
|
open (OUT, ">", "$PPFile.info.txt") or die "Cannot open $PPFile.info.txt\n";
|
2008-09-21 22:04:49 +04:00
|
|
|
print OUT abs_path($file), "\n";
|
2008-08-18 22:38:29 +04:00
|
|
|
print OUT "$ErrorType\n";
|
2008-08-19 00:55:25 +04:00
|
|
|
print OUT "@$Args\n";
|
2008-08-09 00:46:42 +04:00
|
|
|
close OUT;
|
2008-09-25 04:25:16 +04:00
|
|
|
`uname -a >> $PPFile.info.txt 2>&1`;
|
|
|
|
`$CC -v >> $PPFile.info.txt 2>&1`;
|
2008-09-13 02:49:36 +04:00
|
|
|
system 'mv',$ofile,"$PPFile.stderr.txt";
|
2009-02-18 02:31:05 +03:00
|
|
|
return (basename $PPFile);
|
2008-08-09 00:46:42 +04:00
|
|
|
}
|
2008-03-26 01:35:32 +03:00
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
# Running the analyzer.
|
|
|
|
##----------------------------------------------------------------------------##
|
2008-03-26 01:35:32 +03:00
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
sub Analyze {
|
|
|
|
my ($Clang, $Args, $Lang, $Output, $Verbose, $HtmlDir, $file, $Analyses) = @_;
|
2008-04-04 15:02:21 +04:00
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
# Skip anything related to C++.
|
|
|
|
return if ($Lang =~ /c[+][+]/);
|
2008-08-18 22:38:29 +04:00
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
my $RunAnalyzer = 0;
|
|
|
|
my $Cmd;
|
|
|
|
my @CmdArgs;
|
2008-08-09 00:46:42 +04:00
|
|
|
my @CmdArgsSansAnalyses;
|
2008-07-19 10:11:04 +04:00
|
|
|
|
|
|
|
if ($Lang =~ /header/) {
|
|
|
|
exit 0 if (!defined ($Output));
|
|
|
|
$Cmd = 'cp';
|
|
|
|
push @CmdArgs,$file;
|
|
|
|
# Remove the PCH extension.
|
|
|
|
$Output =~ s/[.]gch$//;
|
|
|
|
push @CmdArgs,$Output;
|
2008-08-09 00:46:42 +04:00
|
|
|
@CmdArgsSansAnalyses = @CmdArgs;
|
2008-07-19 10:11:04 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$Cmd = $Clang;
|
|
|
|
push @CmdArgs,'-DIBOutlet=__attribute__((iboutlet))';
|
|
|
|
push @CmdArgs,@$Args;
|
2008-08-09 00:46:42 +04:00
|
|
|
@CmdArgsSansAnalyses = @CmdArgs;
|
2009-02-18 02:31:05 +03:00
|
|
|
push @CmdArgs,'-analyze';
|
|
|
|
push @CmdArgs,"-analyzer-display-progress";
|
|
|
|
push @CmdArgs,"-disable-free";
|
2008-08-09 00:46:42 +04:00
|
|
|
push @CmdArgs,(split /\s/,$Analyses);
|
2008-07-19 10:11:04 +04:00
|
|
|
$RunAnalyzer = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my @PrintArgs;
|
|
|
|
my $dir;
|
2008-05-24 19:58:54 +04:00
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
if ($Verbose) {
|
|
|
|
$dir = getcwd();
|
|
|
|
print STDERR "\n[LOCATION]: $dir\n";
|
|
|
|
push @PrintArgs,"'$Cmd'";
|
|
|
|
foreach my $arg (@CmdArgs) { push @PrintArgs,"\'$arg\'"; }
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($Verbose == 1) {
|
2008-05-24 19:58:54 +04:00
|
|
|
# We MUST print to stderr. Some clients use the stdout output of
|
|
|
|
# gcc for various purposes.
|
2008-07-19 10:11:04 +04:00
|
|
|
print STDERR join(' ',@PrintArgs);
|
|
|
|
print STDERR "\n";
|
|
|
|
}
|
|
|
|
elsif ($Verbose == 2) {
|
|
|
|
print STDERR "#SHELL (cd '$dir' && @PrintArgs)\n";
|
|
|
|
}
|
2008-05-24 19:58:54 +04:00
|
|
|
|
2009-01-21 03:42:24 +03:00
|
|
|
if ($RunAnalyzer) {
|
|
|
|
if (defined $ResultFile) {
|
|
|
|
push @CmdArgs,'-o';
|
|
|
|
push @CmdArgs, $ResultFile;
|
|
|
|
}
|
|
|
|
elsif (defined $HtmlDir) {
|
|
|
|
push @CmdArgs,'-o';
|
|
|
|
push @CmdArgs, $HtmlDir;
|
|
|
|
}
|
2008-07-19 10:11:04 +04:00
|
|
|
}
|
2008-08-28 02:30:34 +04:00
|
|
|
|
|
|
|
if (defined $ENV{'CCC_UBI'}) {
|
|
|
|
push @CmdArgs,"--analyzer-viz-egraph-ubigraph";
|
|
|
|
}
|
2008-08-09 00:46:42 +04:00
|
|
|
|
2008-09-04 04:02:34 +04:00
|
|
|
# Capture the STDERR of clang and send it to a temporary file.
|
|
|
|
# Capture the STDOUT of clang and reroute it to ccc-analyzer's STDERR.
|
|
|
|
# We save the output file in the 'crashes' directory if clang encounters
|
|
|
|
# any problems with the file.
|
2008-09-12 03:05:26 +04:00
|
|
|
pipe (FROM_CHILD, TO_PARENT);
|
2008-09-04 04:02:34 +04:00
|
|
|
my $pid = fork();
|
|
|
|
if ($pid == 0) {
|
2008-09-12 03:05:26 +04:00
|
|
|
close FROM_CHILD;
|
|
|
|
open(STDOUT,">&", \*TO_PARENT);
|
|
|
|
open(STDERR,">&", \*TO_PARENT);
|
2008-09-04 04:02:34 +04:00
|
|
|
exec $Cmd, @CmdArgs;
|
|
|
|
}
|
2008-09-12 03:05:26 +04:00
|
|
|
|
|
|
|
close TO_PARENT;
|
|
|
|
my ($ofh, $ofile) = tempfile("clang_output_XXXXXX", DIR => $HtmlDir);
|
|
|
|
|
|
|
|
while (<FROM_CHILD>) {
|
|
|
|
print $ofh $_;
|
|
|
|
print STDERR $_;
|
|
|
|
}
|
|
|
|
|
|
|
|
waitpid($pid,0);
|
2008-09-04 04:02:34 +04:00
|
|
|
my $Result = $?;
|
|
|
|
|
|
|
|
# Did the command die because of a signal?
|
|
|
|
if ($Result & 127 and $Cmd eq $Clang and defined $HtmlDir) {
|
2008-09-25 04:51:44 +04:00
|
|
|
ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses, $HtmlDir,
|
2008-09-04 04:02:34 +04:00
|
|
|
"Crash", $ofile);
|
|
|
|
}
|
|
|
|
elsif ($Result) {
|
2008-09-25 04:51:44 +04:00
|
|
|
ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses, $HtmlDir,
|
2009-01-27 04:19:08 +03:00
|
|
|
$ParserRejects, $ofile);
|
2008-09-04 04:02:34 +04:00
|
|
|
}
|
2009-02-18 02:31:05 +03:00
|
|
|
else {
|
|
|
|
# Check if there were any unhandled attributes.
|
|
|
|
if (open(CHILD, $ofile)) {
|
|
|
|
my %attributes_not_handled;
|
|
|
|
my $ppfile;
|
|
|
|
while (<CHILD>) {
|
|
|
|
next if (! /warning: '([^\']+)' attribute ignored/);
|
|
|
|
|
|
|
|
# Have we already spotted this unhandled attribute?
|
|
|
|
next if (defined $attributes_not_handled{$1});
|
|
|
|
$attributes_not_handled{$1} = 1;
|
|
|
|
|
2009-02-21 07:46:20 +03:00
|
|
|
# Get the name of the attribute file.
|
|
|
|
my $dir = "$HtmlDir/failures";
|
|
|
|
my $afile = "$dir/attribute_ignored_$1.txt";
|
|
|
|
|
|
|
|
# Only create another preprocessed file if the attribute file
|
|
|
|
# doesn't exist yet.
|
|
|
|
next if (-e $afile);
|
|
|
|
|
2009-02-18 02:31:05 +03:00
|
|
|
# Add this file to the list of files that contained this attribute.
|
|
|
|
# Generate a preprocessed file if we haven't already.
|
|
|
|
if (!(defined $ppfile)) {
|
|
|
|
$ppfile = ProcessClangFailure($Clang, $Lang, $file,
|
|
|
|
\@CmdArgsSansAnalyses,
|
|
|
|
$HtmlDir, $AttributeIgnored, $ofile);
|
|
|
|
}
|
|
|
|
|
|
|
|
mkpath $dir;
|
2009-02-21 07:46:20 +03:00
|
|
|
open(AFILE, ">$afile");
|
2009-02-18 02:31:05 +03:00
|
|
|
print AFILE "$ppfile\n";
|
|
|
|
close(AFILE);
|
|
|
|
}
|
|
|
|
close CHILD;
|
|
|
|
}
|
|
|
|
}
|
2008-09-04 04:02:34 +04:00
|
|
|
|
|
|
|
`rm -f $ofile`;
|
2008-07-19 10:11:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
# Lookup tables.
|
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
|
|
|
|
my %CompileOptionMap = (
|
|
|
|
'-nostdinc' => 0,
|
2008-12-19 23:56:23 +03:00
|
|
|
'-fblocks' => 0,
|
2008-07-19 10:11:04 +04:00
|
|
|
'-fobjc-gc-only' => 0,
|
|
|
|
'-fobjc-gc' => 0,
|
|
|
|
'-include' => 1,
|
|
|
|
'-idirafter' => 1,
|
|
|
|
'-iprefix' => 1,
|
|
|
|
'-iquote' => 1,
|
|
|
|
'-isystem' => 1,
|
|
|
|
'-iwithprefix' => 1,
|
|
|
|
'-iwithprefixbefore' => 1
|
|
|
|
);
|
|
|
|
|
|
|
|
my %LinkerOptionMap = (
|
|
|
|
'-framework' => 1
|
|
|
|
);
|
|
|
|
|
|
|
|
my %CompilerLinkerOptionMap = (
|
|
|
|
'-isysroot' => 1,
|
|
|
|
'-arch' => 1,
|
2008-09-30 02:45:28 +04:00
|
|
|
'-v' => 0,
|
2008-10-01 03:40:25 +04:00
|
|
|
'-fpascal-strings' => 0,
|
|
|
|
'-mmacosx-version-min' => 0 # This is really a 1 argument, but always has '='
|
2008-07-19 10:11:04 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
my %IgnoredOptionMap = (
|
2008-07-24 07:52:21 +04:00
|
|
|
'-MT' => 1, # Ignore these preprocessor options.
|
|
|
|
'-MF' => 1,
|
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
'-fsyntax-only' => 0,
|
|
|
|
'-save-temps' => 0,
|
|
|
|
'-install_name' => 1,
|
|
|
|
'-exported_symbols_list' => 1,
|
|
|
|
'-current_version' => 1,
|
|
|
|
'-compatibility_version' => 1,
|
|
|
|
'-init' => 1,
|
|
|
|
'-e' => 1,
|
|
|
|
'-seg1addr' => 1,
|
|
|
|
'-bundle_loader' => 1,
|
|
|
|
'-multiply_defined' => 1,
|
|
|
|
'-sectorder' => 3,
|
|
|
|
'--param' => 1,
|
|
|
|
'-u' => 1
|
|
|
|
);
|
|
|
|
|
|
|
|
my %LangMap = (
|
|
|
|
'c' => 'c',
|
|
|
|
'cpp' => 'c++',
|
|
|
|
'cc' => 'c++',
|
|
|
|
'i' => 'c-cpp-output',
|
|
|
|
'm' => 'objective-c',
|
|
|
|
'mi' => 'objective-c-cpp-output'
|
|
|
|
);
|
|
|
|
|
2008-09-29 20:15:20 +04:00
|
|
|
my %UniqueOptions = (
|
|
|
|
'-isysroot' => 0
|
|
|
|
);
|
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
# Main Logic.
|
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
|
|
|
|
my $Action = 'link';
|
|
|
|
my @CompileOpts;
|
|
|
|
my @LinkOpts;
|
|
|
|
my @Files;
|
|
|
|
my $Lang;
|
|
|
|
my $Output;
|
2008-09-29 20:15:20 +04:00
|
|
|
my %Uniqued;
|
2008-07-19 10:11:04 +04:00
|
|
|
|
|
|
|
# Forward arguments to gcc.
|
2008-08-22 01:47:09 +04:00
|
|
|
my $Status = system($CC,@ARGV);
|
2008-08-28 05:18:44 +04:00
|
|
|
if ($Status) { exit($Status >> 8); }
|
2008-07-19 10:11:04 +04:00
|
|
|
|
|
|
|
# Get the analysis options.
|
|
|
|
my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'};
|
|
|
|
if (!defined($Analyses)) { $Analyses = '-checker-cfref'; }
|
|
|
|
|
2008-10-27 17:26:32 +03:00
|
|
|
# Get the store model.
|
|
|
|
my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'};
|
2009-02-17 07:27:41 +03:00
|
|
|
if (!defined $StoreModel) { $StoreModel = "basic"; }
|
|
|
|
|
|
|
|
# Get the constraints engine.
|
|
|
|
my $ConstraintsModel = $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'};
|
2009-02-21 00:49:22 +03:00
|
|
|
if (!defined $ConstraintsModel) { $ConstraintsModel = "range"; }
|
2008-10-27 17:26:32 +03:00
|
|
|
|
2008-11-04 03:02:53 +03:00
|
|
|
# Get the output format.
|
|
|
|
my $OutputFormat = $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'};
|
2009-02-17 08:01:10 +03:00
|
|
|
if (!defined $OutputFormat) { $OutputFormat = "html"; }
|
2008-11-04 03:02:53 +03:00
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
# Determine the level of verbosity.
|
|
|
|
my $Verbose = 0;
|
|
|
|
if (defined $ENV{CCC_ANALYZER_VERBOSE}) { $Verbose = 1; }
|
|
|
|
if (defined $ENV{CCC_ANALYZER_LOG}) { $Verbose = 2; }
|
|
|
|
|
|
|
|
# Determine what clang executable to use.
|
|
|
|
my $Clang = $ENV{'CLANG'};
|
|
|
|
if (!defined $Clang) { $Clang = 'clang'; }
|
|
|
|
|
|
|
|
# Get the HTML output directory.
|
|
|
|
my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'};
|
|
|
|
|
2009-02-25 01:07:12 +03:00
|
|
|
my %DisabledArchs = ('ppc' => 1, 'ppc64' => 1);
|
2008-09-26 00:17:57 +04:00
|
|
|
my %ArchsSeen;
|
2009-02-25 01:07:12 +03:00
|
|
|
my $HadArch = 0;
|
2008-07-19 10:11:04 +04:00
|
|
|
|
|
|
|
# Process the arguments.
|
|
|
|
foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
|
2008-10-19 10:42:38 +04:00
|
|
|
my $Arg = $ARGV[$i];
|
|
|
|
my ($ArgKey) = split /=/,$Arg,2;
|
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
# Modes ccc-analyzer supports
|
|
|
|
if ($Arg eq '-E') { $Action = 'preprocess'; }
|
|
|
|
elsif ($Arg eq '-c') { $Action = 'compile'; }
|
|
|
|
elsif ($Arg =~ /^-print-prog-name/) { exit 0; }
|
2008-09-26 00:17:57 +04:00
|
|
|
|
|
|
|
# Specially handle duplicate cases of -arch
|
|
|
|
if ($Arg eq "-arch") {
|
|
|
|
my $arch = $ARGV[$i+1];
|
2009-02-25 01:07:12 +03:00
|
|
|
# We don't want to process 'ppc' because of Clang's lack of support
|
|
|
|
# for Altivec (also some #defines won't likely be defined correctly, etc.)
|
|
|
|
if (!(defined $DisabledArchs{$arch})) { $ArchsSeen{$arch} = 1; }
|
|
|
|
$HadArch = 1;
|
2008-09-26 00:17:57 +04:00
|
|
|
++$i;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
# Options with possible arguments that should pass through to compiler.
|
2008-10-19 10:42:38 +04:00
|
|
|
if (defined $CompileOptionMap{$ArgKey}) {
|
|
|
|
my $Cnt = $CompileOptionMap{$ArgKey};
|
2008-07-19 10:11:04 +04:00
|
|
|
push @CompileOpts,$Arg;
|
|
|
|
while ($Cnt > 0) { ++$i; --$Cnt; push @CompileOpts, $ARGV[$i]; }
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Options with possible arguments that should pass through to linker.
|
2008-10-19 10:42:38 +04:00
|
|
|
if (defined $LinkerOptionMap{$ArgKey}) {
|
|
|
|
my $Cnt = $LinkerOptionMap{$ArgKey};
|
2008-07-19 10:11:04 +04:00
|
|
|
push @LinkOpts,$Arg;
|
|
|
|
while ($Cnt > 0) { ++$i; --$Cnt; push @LinkOpts, $ARGV[$i]; }
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Options with possible arguments that should pass through to both compiler
|
|
|
|
# and the linker.
|
2008-10-19 10:42:38 +04:00
|
|
|
if (defined $CompilerLinkerOptionMap{$ArgKey}) {
|
|
|
|
my $Cnt = $CompilerLinkerOptionMap{$ArgKey};
|
2008-09-30 03:06:09 +04:00
|
|
|
|
2008-09-29 20:15:20 +04:00
|
|
|
# Check if this is an option that should have a unique value, and if so
|
|
|
|
# determine if the value was checked before.
|
|
|
|
if ($UniqueOptions{$Arg}) {
|
|
|
|
if (defined $Uniqued{$Arg}) {
|
|
|
|
$i += $Cnt;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$Uniqued{$Arg} = 1;
|
|
|
|
}
|
|
|
|
|
2008-09-30 03:06:09 +04:00
|
|
|
push @CompileOpts,$Arg;
|
|
|
|
push @LinkOpts,$Arg;
|
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
while ($Cnt > 0) {
|
|
|
|
++$i; --$Cnt;
|
|
|
|
push @CompileOpts, $ARGV[$i];
|
|
|
|
push @LinkOpts, $ARGV[$i];
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2008-05-24 19:58:54 +04:00
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
# Ignored options.
|
2008-10-19 10:42:38 +04:00
|
|
|
if (defined $IgnoredOptionMap{$ArgKey}) {
|
|
|
|
my $Cnt = $IgnoredOptionMap{$ArgKey};
|
2008-07-19 10:11:04 +04:00
|
|
|
while ($Cnt > 0) {
|
|
|
|
++$i; --$Cnt;
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2008-05-24 19:58:54 +04:00
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
# Compile mode flags.
|
|
|
|
if ($Arg =~ /^-[D,I,U](.*)$/) {
|
|
|
|
my $Tmp = $Arg;
|
|
|
|
if ($1 eq '') {
|
|
|
|
# FIXME: Check if we are going off the end.
|
|
|
|
++$i;
|
|
|
|
$Tmp = $Arg . $ARGV[$i];
|
|
|
|
}
|
|
|
|
push @CompileOpts,$Tmp;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Language.
|
|
|
|
if ($Arg eq '-x') {
|
|
|
|
$Lang = $ARGV[$i+1];
|
|
|
|
++$i; next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Output file.
|
|
|
|
if ($Arg eq '-o') {
|
|
|
|
++$i;
|
|
|
|
$Output = $ARGV[$i];
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get the link mode.
|
|
|
|
if ($Arg =~ /^-[l,L,O]/) {
|
|
|
|
if ($Arg eq '-O') { push @LinkOpts,'-O1'; }
|
|
|
|
elsif ($Arg eq '-Os') { push @LinkOpts,'-O2'; }
|
|
|
|
else { push @LinkOpts,$Arg; }
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($Arg =~ /^-std=/) {
|
|
|
|
push @CompileOpts,$Arg;
|
|
|
|
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;
|
|
|
|
if ($1 eq '') {
|
|
|
|
# FIXME: Check if we are going off the end.
|
|
|
|
++$i;
|
|
|
|
$Tmp = $Arg . $ARGV[$i];
|
|
|
|
}
|
|
|
|
push @CompileOpts,$Tmp;
|
|
|
|
push @LinkOpts,$Tmp;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Input files.
|
|
|
|
if ($Arg eq '-filelist') {
|
|
|
|
# FIXME: Make sure we aren't walking off the end.
|
|
|
|
open(IN, $ARGV[$i+1]);
|
|
|
|
while (<IN>) { s/\015?\012//; push @Files,$_; }
|
|
|
|
close(IN);
|
|
|
|
++$i; next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!($Arg =~ /^-/)) {
|
|
|
|
push @Files,$Arg; next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($Action eq 'compile' or $Action eq 'link') {
|
2009-02-25 01:07:12 +03:00
|
|
|
my @Archs = keys %ArchsSeen;
|
|
|
|
# Skip the file if we don't support the architectures specified.
|
2009-02-25 03:10:37 +03:00
|
|
|
exit 0 if ($HadArch && scalar(@Archs) == 0);
|
2009-02-25 01:07:12 +03:00
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
foreach my $file (@Files) {
|
|
|
|
# Determine the language for the file.
|
|
|
|
my $FileLang = $Lang;
|
|
|
|
|
|
|
|
if (!defined($FileLang)) {
|
|
|
|
# Infer the language from the extension.
|
|
|
|
if ($file =~ /[.]([^.]+)$/) {
|
|
|
|
$FileLang = $LangMap{$1};
|
|
|
|
}
|
|
|
|
}
|
2008-05-15 00:26:52 +04:00
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
next if (!defined $FileLang);
|
|
|
|
|
|
|
|
my @AnalyzeArgs;
|
|
|
|
|
|
|
|
if ($FileLang ne 'unknown') {
|
|
|
|
push @AnalyzeArgs,'-x';
|
|
|
|
push @AnalyzeArgs,$FileLang;
|
|
|
|
}
|
2008-05-24 19:58:54 +04:00
|
|
|
|
2008-10-27 17:26:32 +03:00
|
|
|
if (defined $StoreModel) {
|
2009-02-17 07:27:41 +03:00
|
|
|
push @AnalyzeArgs, "-analyzer-store=$StoreModel";
|
2008-10-27 17:26:32 +03:00
|
|
|
}
|
2009-02-17 07:27:41 +03:00
|
|
|
|
|
|
|
if (defined $ConstraintsModel) {
|
|
|
|
push @AnalyzeArgs, "-analyzer-constraints=$ConstraintsModel";
|
|
|
|
}
|
|
|
|
|
2008-11-04 03:02:53 +03:00
|
|
|
if (defined $OutputFormat) {
|
2009-02-17 07:27:41 +03:00
|
|
|
push @AnalyzeArgs, "-analyzer-output=" . $OutputFormat;
|
2009-01-21 03:42:24 +03:00
|
|
|
if ($OutputFormat eq "plist") {
|
|
|
|
# Change "Output" to be a file.
|
|
|
|
my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => ".plist",
|
|
|
|
DIR => $HtmlDir);
|
|
|
|
$ResultFile = $f;
|
|
|
|
$CleanupFile = $f;
|
|
|
|
}
|
2008-11-04 03:02:53 +03:00
|
|
|
}
|
2008-10-27 17:26:32 +03:00
|
|
|
|
2008-07-19 10:11:04 +04:00
|
|
|
push @AnalyzeArgs,@CompileOpts;
|
|
|
|
push @AnalyzeArgs,$file;
|
2008-10-27 17:26:32 +03:00
|
|
|
|
2008-09-26 00:17:57 +04:00
|
|
|
if (scalar @Archs) {
|
|
|
|
foreach my $arch (@Archs) {
|
|
|
|
my @NewArgs;
|
|
|
|
push @NewArgs, '-arch';
|
|
|
|
push @NewArgs, $arch;
|
|
|
|
push @NewArgs, @AnalyzeArgs;
|
|
|
|
Analyze($Clang, \@NewArgs, $FileLang, $Output,
|
|
|
|
$Verbose, $HtmlDir, $file, $Analyses);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Analyze($Clang, \@AnalyzeArgs, $FileLang, $Output,
|
|
|
|
$Verbose, $HtmlDir, $file, $Analyses);
|
|
|
|
}
|
2008-07-19 10:11:04 +04:00
|
|
|
}
|
|
|
|
}
|
2008-03-26 01:35:32 +03:00
|
|
|
|
2008-08-28 02:30:34 +04:00
|
|
|
exit($Status >> 8);
|
|
|
|
|