[cfe-commits] r125712 - in /cfe/trunk/tools/scan-build: ccc-analyzer scan-build
Ted Kremenek
kremenek at apple.com
Wed Feb 16 18:28:30 PST 2011
Author: kremenek
Date: Wed Feb 16 20:28:30 2011
New Revision: 125712
URL: http://llvm.org/viewvc/llvm-project?rev=125712&view=rev
Log:
Begin overhaul of scan-build/ccc-analyzer's handling of checker options.
We now rely on 'clang --analyze' to provide the default set of checkers. We're
still working on the new '-analyzer-checker <checker>' interface, and once
that's ready we'll wire it up to scan-build.
Modified:
cfe/trunk/tools/scan-build/ccc-analyzer
cfe/trunk/tools/scan-build/scan-build
Modified: cfe/trunk/tools/scan-build/ccc-analyzer
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build/ccc-analyzer?rev=125712&r1=125711&r2=125712&view=diff
==============================================================================
--- cfe/trunk/tools/scan-build/ccc-analyzer (original)
+++ cfe/trunk/tools/scan-build/ccc-analyzer Wed Feb 16 20:28:30 2011
@@ -115,6 +115,7 @@
##----------------------------------------------------------------------------##
sub GetCCArgs {
+ my $mode = shift;
my $Args = shift;
pipe (FROM_CHILD, TO_PARENT);
@@ -123,7 +124,7 @@
close FROM_CHILD;
open(STDOUT,">&", \*TO_PARENT);
open(STDERR,">&", \*TO_PARENT);
- exec $Clang, "-###", "-fsyntax-only", @$Args;
+ exec $Clang, "-###", $mode, @$Args;
}
close(TO_PARENT);
my $line;
@@ -137,7 +138,7 @@
die "could not find clang line\n" if (!defined $line);
# Strip the newline and initial whitspace
- chomp $line;
+ chomp $line;
$line =~ s/^\s+//;
my @items = quotewords('\s+', 0, $line);
my $cmd = shift @items;
@@ -147,70 +148,72 @@
sub Analyze {
my ($Clang, $Args, $AnalyzeArgs, $Lang, $Output, $Verbose, $HtmlDir,
- $file, $Analyses) = @_;
-
- $Args = GetCCArgs($Args);
+ $file) = @_;
- my $RunAnalyzer = 0;
my $Cmd;
my @CmdArgs;
my @CmdArgsSansAnalyses;
-
+
if ($Lang =~ /header/) {
exit 0 if (!defined ($Output));
$Cmd = 'cp';
- push @CmdArgs,$file;
+ push @CmdArgs, $file;
# Remove the PCH extension.
$Output =~ s/[.]gch$//;
- push @CmdArgs,$Output;
- @CmdArgsSansAnalyses = @CmdArgs;
+ push @CmdArgs, $Output;
+ @CmdArgsSansAnalyses = @CmdArgs;
}
else {
$Cmd = $Clang;
- push @CmdArgs, "-cc1";
- push @CmdArgs,'-DIBOutlet=__attribute__((iboutlet))';
- push @CmdArgs, @$Args;
- @CmdArgsSansAnalyses = @CmdArgs;
- push @CmdArgs,'-analyze';
- push @CmdArgs,"-analyzer-display-progress";
- push @CmdArgs,"-analyzer-eagerly-assume";
- push @CmdArgs,"-analyzer-opt-analyze-nested-blocks";
- push @CmdArgs,(split /\s/,$Analyses);
-
- if (defined $ENV{"CCC_EXPERIMENTAL_CHECKS"}) {
- push @CmdArgs,"-analyzer-experimental-internal-checks";
- push @CmdArgs,"-analyzer-experimental-checks";
+ if ($Lang eq "objective-c" || $Lang eq "objective-c++") {
+ push @$Args,'-DIBOutlet=__attribute__((iboutlet))';
+ push @$Args,'-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection)))';
+ push @$Args,'-DIBAction=void)__attribute__((ibaction)';
}
-
- $RunAnalyzer = 1;
- }
-
- # Add the analysis arguments passed down from scan-build.
- foreach my $Arg (@$AnalyzeArgs) {
- push @CmdArgs, $Arg;
- }
-
- my @PrintArgs;
- my $dir;
- if ($RunAnalyzer) {
+ # Create arguments for doing regular parsing.
+ my $SyntaxArgs = GetCCArgs("-fsyntax-only", $Args);
+ @CmdArgsSansAnalyses = @CmdArgs;
+ push @CmdArgsSansAnalyses, @$SyntaxArgs;
+
+ # Create arguments for doing static analysis.
if (defined $ResultFile) {
- push @CmdArgs,'-o';
- push @CmdArgs, $ResultFile;
+ push @$Args,'-o';
+ push @$Args, $ResultFile;
}
elsif (defined $HtmlDir) {
- push @CmdArgs,'-o';
- push @CmdArgs, $HtmlDir;
+ push @$Args,'-o';
+ push @$Args, $HtmlDir;
+ }
+ push @$Args,"-Xclang";
+ push @$Args,"-analyzer-display-progress";
+
+ foreach my $arg (@$AnalyzeArgs) {
+ push @$Args, "-Xclang";
+ push @$Args, $arg;
}
+
+ # Display Ubiviz graph?
+ if (defined $ENV{'CCC_UBI'}) {
+ push @$Args, "-Xclang";
+ push @$Args,"-analyzer-viz-egraph-ubigraph";
+ }
+
+ my $AnalysisArgs = GetCCArgs("--analyze", $Args);
+ push @CmdArgs, @$AnalysisArgs;
}
-
+
+ my @PrintArgs;
+ my $dir;
+
if ($Verbose) {
$dir = getcwd();
print STDERR "\n[LOCATION]: $dir\n";
push @PrintArgs,"'$Cmd'";
- foreach my $arg (@CmdArgs) { push @PrintArgs,"\'$arg\'"; }
+ foreach my $arg (@CmdArgs) {
+ push @PrintArgs,"\'$arg\'";
+ }
}
-
if ($Verbose == 1) {
# We MUST print to stderr. Some clients use the stdout output of
# gcc for various purposes.
@@ -220,11 +223,7 @@
elsif ($Verbose == 2) {
print STDERR "#SHELL (cd '$dir' && @PrintArgs)\n";
}
-
- if (defined $ENV{'CCC_UBI'}) {
- push @CmdArgs,"--analyzer-viz-egraph-ubigraph";
- }
-
+
# 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
@@ -237,13 +236,13 @@
open(STDERR,">&", \*TO_PARENT);
exec $Cmd, @CmdArgs;
}
-
+
close TO_PARENT;
my ($ofh, $ofile) = tempfile("clang_output_XXXXXX", DIR => $HtmlDir);
while (<FROM_CHILD>) {
print $ofh $_;
- print STDERR $_;
+ print STDERR $_;
}
waitpid($pid,0);
@@ -266,11 +265,11 @@
# Check if there were any unhandled attributes.
if (open(CHILD, $ofile)) {
my %attributes_not_handled;
-
+
# Don't flag warnings about the following attributes that we
# know are currently not supported by Clang.
$attributes_not_handled{"cdecl"} = 1;
-
+
my $ppfile;
while (<CHILD>) {
next if (! /warning: '([^\']+)' attribute ignored/);
@@ -413,15 +412,12 @@
# Get the analysis options.
my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'};
-if (!defined($Analyses)) { $Analyses = '-analyzer-check-objc-mem'; }
# Get the store model.
my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'};
-if (!defined $StoreModel) { $StoreModel = "region"; }
# Get the constraints engine.
my $ConstraintsModel = $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'};
-if (!defined $ConstraintsModel) { $ConstraintsModel = "range"; }
# Get the output format.
my $OutputFormat = $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'};
@@ -628,6 +624,10 @@
if (defined $ConstraintsModel) {
push @AnalyzeArgs, "-analyzer-constraints=$ConstraintsModel";
}
+
+# if (defined $Analyses) {
+# push @AnalyzeArgs, split '\s+', $Analyses;
+# }
if (defined $OutputFormat) {
push @AnalyzeArgs, "-analyzer-output=" . $OutputFormat;
@@ -640,8 +640,8 @@
}
}
- push @CmdArgs, at CompileOpts;
- push @CmdArgs,$file;
+ push @CmdArgs, @CompileOpts;
+ push @CmdArgs, $file;
if (scalar @Archs) {
foreach my $arch (@Archs) {
@@ -650,12 +650,12 @@
push @NewArgs, $arch;
push @NewArgs, @CmdArgs;
Analyze($Clang, \@NewArgs, \@AnalyzeArgs, $FileLang, $Output,
- $Verbose, $HtmlDir, $file, $Analyses);
+ $Verbose, $HtmlDir, $file);
}
}
else {
Analyze($Clang, \@CmdArgs, \@AnalyzeArgs, $FileLang, $Output,
- $Verbose, $HtmlDir, $file, $Analyses);
+ $Verbose, $HtmlDir, $file);
}
}
}
Modified: cfe/trunk/tools/scan-build/scan-build
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build/scan-build?rev=125712&r1=125711&r2=125712&view=diff
==============================================================================
--- cfe/trunk/tools/scan-build/scan-build (original)
+++ cfe/trunk/tools/scan-build/scan-build Wed Feb 16 20:28:30 2011
@@ -99,32 +99,6 @@
}
my $ClangCXX = $Clang . "++";
-my %AvailableAnalyses;
-
-# Query clang for analysis options.
-open(PIPE, "-|", $Clang, "-cc1", "-help") or
- DieDiag("Cannot execute '$Clang'\n");
-
-while(<PIPE>) {
- if (/(-analyzer-check-[^\s]+)/) {
- $AvailableAnalyses{$1} = 1;
- next;
- }
-}
-close (PIPE);
-
-my %AnalysesDefaultEnabled = (
- '-analyzer-check-dead-stores' => 1,
- '-analyzer-check-objc-mem' => 1,
- '-analyzer-check-objc-methodsigs' => 1,
- '-analyzer-check-objc-self-init' => 1,
- # Do not enable the missing -dealloc check by default.
- # '-analyzer-check-objc-missing-dealloc' => 1,
- '-analyzer-check-objc-unused-ivars' => 1,
- '-analyzer-check-security-syntactic' => 1,
- '-analyzer-check-idempotent-operations' => 1
-);
-
##----------------------------------------------------------------------------##
# GetHTMLRunDir - Construct an HTML directory name for the current sub-run.
##----------------------------------------------------------------------------##
@@ -969,8 +943,6 @@
-analyze-headers - Also analyze functions in #included files.
- --experimental-checks - Enable experimental checks that are currently in heavy testing
-
-o - Target directory for HTML report files. Subdirectories
will be created as needed to represent separate "runs" of
the analyzer. If this option is not specified, a directory
@@ -1031,22 +1003,10 @@
-maxloop N - specifiy the number of times a block can be visited before giving
up. Default is 3. Increase for more comprehensive coverage at a
cost of speed.
-
-AVAILABLE ANALYSES (multiple analyses may be specified):
-
ENDTEXT
- foreach my $Analysis (sort keys %AvailableAnalyses) {
- if (defined $AnalysesDefaultEnabled{$Analysis}) {
- print " (+)";
- }
- else {
- print " ";
- }
-
- print " $Analysis\n";
- }
-
+# FIXME: Print out available analyesis.
+
print <<ENDTEXT
NOTE: "(+)" indicates that an analysis is enabled by default unless one
@@ -1131,12 +1091,6 @@
next;
}
- if (defined $AvailableAnalyses{$arg}) {
- shift @ARGV;
- push @AnalysesToRun, $arg;
- next;
- }
-
if ($arg eq "-o") {
shift @ARGV;
@@ -1172,13 +1126,7 @@
$IgnoreErrors = 1;
next;
}
-
- if ($arg eq "--experimental-checks") {
- shift @ARGV;
- $ENV{"CCC_EXPERIMENTAL_CHECKS"} = 1;
- next;
- }
-
+
if ($arg =~ /^--use-cc(=(.+))?$/) {
shift @ARGV;
my $cc;
@@ -1324,12 +1272,6 @@
$ENV{'CCC_ANALYZER_LOG'} = 1;
}
-if (scalar(@AnalysesToRun) == 0) {
- foreach my $key (keys %AnalysesDefaultEnabled) {
- push @AnalysesToRun,$key;
- }
-}
-
if ($AnalyzeHeaders) {
push @AnalysesToRun,"-analyzer-opt-analyze-headers";
}
More information about the cfe-commits
mailing list