[PATCH] D10356: scan-build: Add --analyzer-target option

Honggyu Kim hong.gyu.kim at lge.com
Sun Aug 2 23:58:20 PDT 2015


honggyu.kim retitled this revision from "scan-build: Add --triple option to scan-build" to "scan-build: Add --analyzer-target option".
honggyu.kim updated the summary for this revision.
honggyu.kim updated this revision to Diff 31215.

http://reviews.llvm.org/D10356

Files:
  tools/scan-build/ccc-analyzer
  tools/scan-build/scan-build

Index: tools/scan-build/scan-build
===================================================================
--- tools/scan-build/scan-build
+++ tools/scan-build/scan-build
@@ -1145,10 +1145,21 @@
    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
 
@@ -1462,6 +1473,24 @@
     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++;
Index: tools/scan-build/ccc-analyzer
===================================================================
--- tools/scan-build/ccc-analyzer
+++ tools/scan-build/ccc-analyzer
@@ -68,6 +68,7 @@
 my $DefaultCCompiler;
 my $DefaultCXXCompiler;
 my $IsCXX;
+my $AnalyzerTarget;
 
 # If on OSX, use xcrun to determine the SDK root.
 my $UseXCRUN = 0;
@@ -104,6 +105,8 @@
   $IsCXX = 0
 }
 
+$AnalyzerTarget = $ENV{'CLANG_ANALYZER_TARGET'};
+
 ##===----------------------------------------------------------------------===##
 # Cleanup.
 ##===----------------------------------------------------------------------===##
@@ -245,6 +248,10 @@
       push @Args, "-Xclang", "-analyzer-viz-egraph-ubigraph";
     }
 
+    if (defined $AnalyzerTarget) {
+      push @Args, "-target", $AnalyzerTarget;
+    }
+
     my $AnalysisArgs = GetCCArgs($HtmlDir, "--analyze", \@Args);
     @CmdArgs = @$AnalysisArgs;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10356.31215.patch
Type: text/x-patch
Size: 2455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150803/d2bfebb9/attachment.bin>


More information about the cfe-commits mailing list