[PATCH] scan-build: Add --triple option to scan-build
Honggyu Kim
hong.gyu.kim at lge.com
Sun Jun 7 03:41:05 PDT 2015
Hi all,
I wrote this patch because I had some problem generating a clang static analysis report for ARM Linux kernel code. Since it uses
some target specific flags for ARM, I got the following error message during analysis.
error: unknown target CPU 'armv7-a'
I have checked scan-build script, but there was no way to pass target triple information to clang, so clang thinks that the source
code can be compiled for host machine, x86_64. This patch adds --triple option to fix this problem.
With this patch, I was able to generate clang static analysis report for ARM Linux kernel code with the following command:
$ scan-build --use-cc=arm-linux-gcc --triple=arm-linux-gnueabi make ARCH=arm CROSS_COMPILE=arm-linux-
Please correct me if my patch or description has something wrong.
And I would also like to know the proper way to send a patch to clang community. Sorry but I'm only familiar with Linux kernel way
using git send-email.
I appreciate all your comments.
Thanks,
Honggyu
> -----Original Message-----
> From: Honggyu Kim [mailto:hong.gyu.kim at lge.com]
> Sent: Sunday, June 07, 2015 7:17 PM
> To: cfe-commits at cs.uiuc.edu
> Cc: kremenek at apple.com; Honggyu Kim
> Subject: [PATCH] scan-build: Add --triple option to scan-build
>
> Currently scan-build cannot pass any triple information to clang. This
> makes analysis failure when the build script has target specific
> compiler flags.
> This patch adds --triple option to support analysis for other targets.
>
> --triple [target triple name]
> --triple=[target triple name]
>
> This provides target triple information to clang.
>
> Signed-off-by: Honggyu Kim <hong.gyu.kim at lge.com>
> ---
> tools/scan-build/ccc-analyzer | 10 ++++++++++
> tools/scan-build/scan-build | 23 +++++++++++++++++++++++
> 2 files changed, 33 insertions(+)
>
> diff --git a/tools/scan-build/ccc-analyzer b/tools/scan-build/ccc-analyzer
> index 4549b29..5d9eac0 100755
> --- a/tools/scan-build/ccc-analyzer
> +++ b/tools/scan-build/ccc-analyzer
> @@ -41,6 +41,7 @@ my $Clang;
> my $DefaultCCompiler;
> my $DefaultCXXCompiler;
> my $IsCXX;
> +my $Triple;
>
> # If on OSX, use xcrun to determine the SDK root.
> my $UseXCRUN = 0;
> @@ -77,6 +78,9 @@ else {
> $IsCXX = 0
> }
>
> +$Triple = $ENV{'CLANG_TRIPLE'};
> +#if (!defined $Triple || ! -x $Triple) { $Triple = ''; }
> +
> ##===----------------------------------------------------------------------===##
> # Cleanup.
> ##===----------------------------------------------------------------------===##
> @@ -237,6 +241,12 @@ sub Analyze {
> my @PrintArgs;
> my $dir;
>
> + if (!defined $Triple || ! -x $Triple) {
> + else
> + push @CmdArgs, "-triple";
> + push @CmdArgs, $Triple;
> + }
> +
> if ($Verbose) {
> $dir = getcwd();
> print STDERR "\n[LOCATION]: $dir\n";
> diff --git a/tools/scan-build/scan-build b/tools/scan-build/scan-build
> index d52d8f5..ea18536 100755
> --- a/tools/scan-build/scan-build
> +++ b/tools/scan-build/scan-build
> @@ -1150,6 +1150,11 @@ OPTIONS:
>
> This is the same as "-use-cc" but for C++ code.
>
> + --triple [target triple name]
> + --triple=[target triple name]
> +
> + This provides target triple information to clang.
> +
> -v
>
> Enable verbose output from scan-build. A second and third '-v' increases
> @@ -1479,6 +1484,24 @@ while (@ARGV) {
> next;
> }
>
> + if ($arg =~ /^--triple(=(.+))?$/) {
> + shift @ARGV;
> + my $triple;
> +
> + if (!defined $2 || $2 eq "") {
> + if (!@ARGV) {
> + DieDiag("'--triple' option requires a triple name.\n");
> + }
> + $triple = shift @ARGV;
> + }
> + else {
> + $triple = $2;
> + }
> +
> + $ENV{"CLANG_TRIPLE"} = $triple;
> + next;
> + }
> +
> if ($arg eq "-v") {
> shift @ARGV;
> $Verbose++;
> --
> 1.7.9.5
More information about the cfe-commits
mailing list