Skip to content

Commit

Permalink
Fix scan-build support for sysroot= (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Smjert authored Feb 23, 2020
1 parent 88f0611 commit 203e5d6
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ For the instructions we will use Ubuntu 18.04.

## Prerequisites
```
sudo apt install --no-install-recommends g++-8 gcc-8 automake autoconf gettext bison flex unzip help2man libtool-bin libncurses-dev make ninja-build
sudo apt install --no-install-recommends g++-8 gcc-8 automake autoconf gettext bison flex unzip help2man libtool-bin libncurses-dev make ninja-build patch
```
Then use `update-alternatives` to tell the system that the version of GCC/G++ and CPP is the default we would like to use:
```
Expand Down
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ if [[ ! -d ${LLVM_SRC} ]]; then
mkdir -p `dirname $LLVM_SRC`
cd `dirname $LLVM_SRC`
git clone https://github.com/llvm/llvm-project.git llvm -b llvmorg-$LLVM_VERSION --single-branch --depth 1

## Patch the scan-build script so it works with sysroot= in the link options
cd llvm
patch -p1 < $SCRIPT_DIR/patches/00_scan-build-link-options.patch
patch -p1 < $SCRIPT_DIR/patches/01_scan-build-perl-warning.patch
fi

LLVM_DISABLED_TOOLS="-DLLVM_TOOL_BUGPOINT_BUILD=OFF"
Expand Down
49 changes: 49 additions & 0 deletions patches/00_scan-build-link-options.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
From 473d0d7f569c84446d9880727403524d4a9838eb Mon Sep 17 00:00:00 2001
From: Artem Dergachev <[email protected]>
Date: Thu, 5 Sep 2019 00:44:56 +0000
Subject: [PATCH] [analyzer] scan-build: handle --sysroot=/path in addition to
--sysroot /path.

Current code assumes flags in CompilerLinkerOptionMap don't use =,
which isn't always true.

Patch by Chris Laplante!

Differential Revision: https://reviews.llvm.org/D66569

llvm-svn: 371002
---
clang/tools/scan-build/libexec/ccc-analyzer | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/clang/tools/scan-build/libexec/ccc-analyzer b/clang/tools/scan-build/libexec/ccc-analyzer
index e1635e6c29b8..6d24a1af4539 100755
--- a/clang/tools/scan-build/libexec/ccc-analyzer
+++ b/clang/tools/scan-build/libexec/ccc-analyzer
@@ -498,7 +498,8 @@ my $HasSDK = 0;
# Process the arguments.
foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
my $Arg = $ARGV[$i];
- my ($ArgKey) = split /=/,$Arg,2;
+ my @ArgParts = split /=/,$Arg,2;
+ my $ArgKey = @ArgParts[0];

# Be friendly to "" in the argument list.
if (!defined($ArgKey)) {
@@ -566,10 +567,12 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
push @CompileOpts,$Arg;
push @LinkOpts,$Arg;

- while ($Cnt > 0) {
- ++$i; --$Cnt;
- push @CompileOpts, $ARGV[$i];
- push @LinkOpts, $ARGV[$i];
+ if (scalar @ArgParts == 1) {
+ while ($Cnt > 0) {
+ ++$i; --$Cnt;
+ push @CompileOpts, $ARGV[$i];
+ push @LinkOpts, $ARGV[$i];
+ }
}
next;
}
25 changes: 25 additions & 0 deletions patches/01_scan-build-perl-warning.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From ea27b932b58cb6cf9d2f1ad1eddd187ee34b9a90 Mon Sep 17 00:00:00 2001
From: Sylvestre Ledru <[email protected]>
Date: Fri, 13 Sep 2019 09:31:19 +0000
Subject: [PATCH] Fix a perl warning: Scalar value @ArgParts[0] better written
as $ArgParts[0] at /usr/share/clang/scan-build-10/libexec/ccc-analyzer line
502.

llvm-svn: 371832
---
clang/tools/scan-build/libexec/ccc-analyzer | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/scan-build/libexec/ccc-analyzer b/clang/tools/scan-build/libexec/ccc-analyzer
index 6d24a1af4539..800f38b5ba24 100755
--- a/clang/tools/scan-build/libexec/ccc-analyzer
+++ b/clang/tools/scan-build/libexec/ccc-analyzer
@@ -499,7 +499,7 @@ my $HasSDK = 0;
foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
my $Arg = $ARGV[$i];
my @ArgParts = split /=/,$Arg,2;
- my $ArgKey = @ArgParts[0];
+ my $ArgKey = $ArgParts[0];

# Be friendly to "" in the argument list.
if (!defined($ArgKey)) {

0 comments on commit 203e5d6

Please sign in to comment.