From 3a787bf977b214b7615fcfbc9cfca2f8a4c3044c Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 15 Jul 2008 17:06:13 +0000 Subject: [PATCH] scan-build now interrogates clang for a list of available analyses, and presents these as options to the user of scan-build. llvm-svn: 53618 --- clang/utils/scan-build | 102 +++++++++++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/clang/utils/scan-build b/clang/utils/scan-build index f2d66c60e6ba..575bf25cc57c 100755 --- a/clang/utils/scan-build +++ b/clang/utils/scan-build @@ -29,6 +29,10 @@ my $BuildDate; my $UseColor = ((($ENV{'TERM'} eq 'xterm-color') and -t STDOUT) and defined($ENV{'SCAN_BUILD_COLOR'})); +##----------------------------------------------------------------------------## +# Diagnostics +##----------------------------------------------------------------------------## + sub Diag { if ($UseColor) { print BOLD, MAGENTA "$Prog: @_"; @@ -51,6 +55,53 @@ sub DieDiag { exit(0); } +##----------------------------------------------------------------------------## +# Some initial preprocessing of Clang options. +##----------------------------------------------------------------------------## + +my $ClangSB = "$RealBin/clang"; +my $Clang = $ClangSB; + +if (! -x $ClangSB) { + $Clang = "clang"; +} + +my %AvailableAnalyses; + +# Query clang for analysis options. +open(PIPE, "$Clang --help |") or + DieDiag("Cannot execute '$Clang'"); + +my $FoundAnalysis = 0; + +while() { + if ($FoundAnalysis == 0) { + if (/Available Source Code Analyses/) { + $FoundAnalysis = 1; + } + + next; + } + + if (/^\s\s\s\s([^\s]+)\s(.+)$/) { + next if ($1 =~ /-dump/ or $1 =~ /-view/ + or $1 =~ /-checker-simple/ or $1 =~ /-warn-uninit/); + + $AvailableAnalyses{$1} = $2; + next; + } + + last; +} + +close (PIPE); + +my %AnalysesDefaultEnabled = ( + '-warn-dead-stores' => 1, + '-checker-cfref' => 1, + '-warn-objc-methodsigs' => 1 +); + ##----------------------------------------------------------------------------## # GetHTMLRunDir - Construct an HTML directory name for the current run. ##----------------------------------------------------------------------------## @@ -592,9 +643,6 @@ ENDTEXT print <= 3) { $ENV{'CCC_ANALYZER_LOG'} = 1; } -if (defined($Analysis)) { - $ENV{'CCC_ANALYZER_ANALYSIS'} = $Analysis; +if (scalar(@AnalysesToRun)) { + $ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun; } # Run the build.