From ecb7e5c8afe929ee38155db94de6b084ec32a645 Mon Sep 17 00:00:00 2001 From: Roman Divacky Date: Tue, 16 Feb 2010 09:31:36 +0000 Subject: Update clang to r96341. --- tools/scan-build/ccc-analyzer | 7 +++- tools/scan-build/scan-build | 57 +++++++++++---------------- tools/scan-build/set-xcode-analyzer | 77 +++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 36 deletions(-) create mode 100755 tools/scan-build/set-xcode-analyzer (limited to 'tools/scan-build') diff --git a/tools/scan-build/ccc-analyzer b/tools/scan-build/ccc-analyzer index f19dcb4718cb..8c64d3ffefda 100755 --- a/tools/scan-build/ccc-analyzer +++ b/tools/scan-build/ccc-analyzer @@ -403,7 +403,7 @@ if ($Status) { exit($Status >> 8); } # Get the analysis options. my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'}; -if (!defined($Analyses)) { $Analyses = '-checker-cfref'; } +if (!defined($Analyses)) { $Analyses = '-analyzer-check-objc-mem'; } # Get the store model. my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'}; @@ -597,9 +597,12 @@ if ($Action eq 'compile' or $Action eq 'link') { } } + # FileLang still not defined? Skip the file. next if (!defined $FileLang); + + # Language not accepted? next if (!defined $LangsAccepted{$FileLang}); - + my @CmdArgs; my @AnalyzeArgs; diff --git a/tools/scan-build/scan-build b/tools/scan-build/scan-build index f978a888be83..432456b15fe7 100755 --- a/tools/scan-build/scan-build +++ b/tools/scan-build/scan-build @@ -82,52 +82,45 @@ sub DieDiag { # Find 'clang' my $ClangSB = Cwd::realpath("$RealBin/bin/clang"); -my $ClangCXXSB; if (!defined $ClangSB || ! -x $ClangSB) { $ClangSB = Cwd::realpath("$RealBin/clang"); - if (defined $ClangSB) { $ClangCXXSB = $ClangSB . "++"; } } -my $Clang = $ClangSB; -my $ClangCXX = $ClangCXXSB; -# Default to looking for 'clang' in the path. -if (!defined $Clang || ! -x $Clang) { - $Clang = "clang"; - $ClangCXX = "clang++"; +my $Clang; +if (!defined $ClangSB || ! -x $ClangSB) { + # Default to looking for 'clang' in the path. + $Clang = `which clang`; + chomp $Clang; + if ($Clang eq "") { + DieDiag("No 'clang' executable found in path."); + } +} +else { + $Clang = $ClangSB; } +my $ClangCXX = $Clang . "++"; my %AvailableAnalyses; # Query clang for analysis options. -open(PIPE, "-|", $Clang, "-cc1", "--help") or +open(PIPE, "-|", $Clang, "-cc1", "-help") or DieDiag("Cannot execute '$Clang'\n"); -my $FoundAnalysis = 0; - while() { - if ($FoundAnalysis == 0) { - if (/Checks and Analyses/) { - $FoundAnalysis = 1; - } - next; - } - if (/^\s\s\s\s([^\s]+)\s(.+)$/) { - next if ($1 =~ /-dump/ or $1 =~ /-view/ - or $1 =~ /-warn-uninit/); - $AvailableAnalyses{$1} = $2; + if (/(-analyzer-check-[^\s]+)/) { + $AvailableAnalyses{$1} = 1; next; } - last; } close (PIPE); my %AnalysesDefaultEnabled = ( - '-warn-dead-stores' => 1, - '-checker-cfref' => 1, - '-warn-objc-methodsigs' => 1, + '-analyzer-check-dead-stores' => 1, + '-analyzer-check-objc-mem' => 1, + '-analyzer-check-objc-methodsigs' => 1, # Do not enable the missing -dealloc check by default. - # '-warn-objc-missing-dealloc' => 1, - '-warn-objc-unused-ivars' => 1, - '-warn-security-syntactic' => 1 + # '-analyzer-check-objc-missing-dealloc' => 1, + '-analyzer-check-objc-unused-ivars' => 1, + '-analyzer-check-security-syntactic' => 1 ); ##----------------------------------------------------------------------------## @@ -853,10 +846,6 @@ sub RunBuildCommand { # When 'CC' is set, xcodebuild uses it to do all linking, even if we are # linking C++ object files. Set 'LDPLUSPLUS' so that xcodebuild uses 'g++' # when linking such files. - if (!defined $ENV{'CCC_CXX'}) { - $ENV{'CCC_CXX'} = 'g++'; - } - $ENV{'LDPLUSPLUS'} = $ENV{'CCC_CXX'}; } return (system(@$Args) >> 8); @@ -951,7 +940,7 @@ ENDTEXT print " "; } - print " $Analysis $AvailableAnalyses{$Analysis}\n"; + print " $Analysis\n"; } print <= 0: + foundAnalyzer = True + else: + m = re.search('^(\s*ExecPath\s*=\s*")', line) + if m: + line = "".join([m.group(0), pathToChecker, '";\n']) + t.write(line) + t.close() + print "(+) processing:", path + try: + shutil.copy(t.name, path) + os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) + except IOError, why: + print " (-) Cannot update file:", why, "\n" + except OSError, why: + print " (-) Cannot update file:", why, "\n" + os.unlink(t.name) + +def main(): + from optparse import OptionParser + parser = OptionParser('usage: %prog [options]') + parser.set_description(__doc__) + parser.add_option("--use-checker-build", dest="path", + help="Use the Clang located at the provided absolute path, e.g. /Users/foo/checker-1") + parser.add_option("--use-xcode-clang", action="store_const", + const="$(CLANG)", dest="default", + help="Use the Clang bundled with Xcode") + (options, args) = parser.parse_args() + if options.path is None and options.default is None: + parser.error("You must specify a version of Clang to use for static analysis. Specify '-h' for details") + + # determine if Xcode is running + for x in NSWorkspace.sharedWorkspace().runningApplications(): + if x.localizedName().find("Xcode") >= 0: + print "(-) You must quit Xcode first before modifying its configuration files." + return + + if options.path: + # Expand tildes. + path = os.path.expanduser(options.path) + if not path.endswith("clang"): + print "(+) Using Clang bundled with checker build:", path + path = os.path.join(path, "bin", "clang"); + else: + print "(+) Using Clang located at:", path + else: + print "(+) Using the Clang bundled with Xcode" + path = options.default + + for x in FindClangSpecs('/Developer'): + ModifySpec(x, path) + +if __name__ == '__main__': + main() + -- cgit v1.3