Skip to content

Commit

Permalink
[Static Analyzer] Add --analyzer-target option to scan-build.
Browse files Browse the repository at this point in the history
When interposing on a compiler doing cross-compilation, scan-build
does not infer the target triple needed to pass to clang for
doing static analysis.  The --analyzer-target option allows one
to manually specify the target triple used during static analysis
(and only static analysis) for such cases.

Patch by Honggyu Kim!

Reviewed in http://reviews.llvm.org/D10356.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244400 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tkremenek committed Aug 8, 2015
1 parent df20ae3 commit 3c9c162
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tools/scan-build/ccc-analyzer
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ my $Clang;
my $DefaultCCompiler;
my $DefaultCXXCompiler;
my $IsCXX;
my $AnalyzerTarget;

# If on OSX, use xcrun to determine the SDK root.
my $UseXCRUN = 0;
Expand Down Expand Up @@ -104,6 +105,8 @@ else {
$IsCXX = 0
}

$AnalyzerTarget = $ENV{'CLANG_ANALYZER_TARGET'};

##===----------------------------------------------------------------------===##
# Cleanup.
##===----------------------------------------------------------------------===##
Expand Down Expand Up @@ -245,6 +248,10 @@ sub Analyze {
push @Args, "-Xclang", "-analyzer-viz-egraph-ubigraph";
}

if (defined $AnalyzerTarget) {
push @Args, "-target", $AnalyzerTarget;
}

my $AnalysisArgs = GetCCArgs($HtmlDir, "--analyze", \@Args);
@CmdArgs = @$AnalysisArgs;
}
Expand Down
31 changes: 30 additions & 1 deletion tools/scan-build/scan-build
Original file line number Diff line number Diff line change
Expand Up @@ -1145,10 +1145,21 @@ OPTIONS:
scan-build to use a specific compiler for *compilation* then you can use
this option to specify a path to that compiler.
If the given compiler is a cross compiler, you may also need to provide
--analyzer-target option to properly analyze the source code because static
analyzer runs as if the code is compiled for the host machine by default.
--use-c++ [compiler path]
--use-c++=[compiler path]
This is the same as "-use-cc" but for C++ code.
This is the same as "--use-cc" but for C++ code.
--analyzer-target [target triple name for analysis]
--analyzer-target=[target triple name for analysis]
This provides target triple information to clang static analyzer.
It only changes the target for analysis but doesn't change the target of a
real compiler given by --use-cc and --use-c++ options.
-v
Expand Down Expand Up @@ -1462,6 +1473,24 @@ while (@ARGV) {
next;
}
if ($arg =~ /^--analyzer-target(=(.+))?$/) {
shift @ARGV;
my $AnalyzerTarget;
if (!defined $2 || $2 eq "") {
if (!@ARGV) {
DieDiag("'--analyzer-target' option requires a target triple name.\n");
}
$AnalyzerTarget = shift @ARGV;
}
else {
$AnalyzerTarget = $2;
}
$ENV{"CLANG_ANALYZER_TARGET"} = $AnalyzerTarget;
next;
}
if ($arg eq "-v") {
shift @ARGV;
$Verbose++;
Expand Down

0 comments on commit 3c9c162

Please sign in to comment.