Skip to content

Commit 203e5d6

Browse files
authored
Fix scan-build support for sysroot= (#17)
1 parent 88f0611 commit 203e5d6

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ For the instructions we will use Ubuntu 18.04.
3636

3737
## Prerequisites
3838
```
39-
sudo apt install --no-install-recommends g++-8 gcc-8 automake autoconf gettext bison flex unzip help2man libtool-bin libncurses-dev make ninja-build
39+
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
4040
```
4141
Then use `update-alternatives` to tell the system that the version of GCC/G++ and CPP is the default we would like to use:
4242
```

build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ if [[ ! -d ${LLVM_SRC} ]]; then
296296
mkdir -p `dirname $LLVM_SRC`
297297
cd `dirname $LLVM_SRC`
298298
git clone https://github.com/llvm/llvm-project.git llvm -b llvmorg-$LLVM_VERSION --single-branch --depth 1
299+
300+
## Patch the scan-build script so it works with sysroot= in the link options
301+
cd llvm
302+
patch -p1 < $SCRIPT_DIR/patches/00_scan-build-link-options.patch
303+
patch -p1 < $SCRIPT_DIR/patches/01_scan-build-perl-warning.patch
299304
fi
300305

301306
LLVM_DISABLED_TOOLS="-DLLVM_TOOL_BUGPOINT_BUILD=OFF"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From 473d0d7f569c84446d9880727403524d4a9838eb Mon Sep 17 00:00:00 2001
2+
From: Artem Dergachev <[email protected]>
3+
Date: Thu, 5 Sep 2019 00:44:56 +0000
4+
Subject: [PATCH] [analyzer] scan-build: handle --sysroot=/path in addition to
5+
--sysroot /path.
6+
7+
Current code assumes flags in CompilerLinkerOptionMap don't use =,
8+
which isn't always true.
9+
10+
Patch by Chris Laplante!
11+
12+
Differential Revision: https://reviews.llvm.org/D66569
13+
14+
llvm-svn: 371002
15+
---
16+
clang/tools/scan-build/libexec/ccc-analyzer | 13 ++++++++-----
17+
1 file changed, 8 insertions(+), 5 deletions(-)
18+
19+
diff --git a/clang/tools/scan-build/libexec/ccc-analyzer b/clang/tools/scan-build/libexec/ccc-analyzer
20+
index e1635e6c29b8..6d24a1af4539 100755
21+
--- a/clang/tools/scan-build/libexec/ccc-analyzer
22+
+++ b/clang/tools/scan-build/libexec/ccc-analyzer
23+
@@ -498,7 +498,8 @@ my $HasSDK = 0;
24+
# Process the arguments.
25+
foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
26+
my $Arg = $ARGV[$i];
27+
- my ($ArgKey) = split /=/,$Arg,2;
28+
+ my @ArgParts = split /=/,$Arg,2;
29+
+ my $ArgKey = @ArgParts[0];
30+
31+
# Be friendly to "" in the argument list.
32+
if (!defined($ArgKey)) {
33+
@@ -566,10 +567,12 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
34+
push @CompileOpts,$Arg;
35+
push @LinkOpts,$Arg;
36+
37+
- while ($Cnt > 0) {
38+
- ++$i; --$Cnt;
39+
- push @CompileOpts, $ARGV[$i];
40+
- push @LinkOpts, $ARGV[$i];
41+
+ if (scalar @ArgParts == 1) {
42+
+ while ($Cnt > 0) {
43+
+ ++$i; --$Cnt;
44+
+ push @CompileOpts, $ARGV[$i];
45+
+ push @LinkOpts, $ARGV[$i];
46+
+ }
47+
}
48+
next;
49+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From ea27b932b58cb6cf9d2f1ad1eddd187ee34b9a90 Mon Sep 17 00:00:00 2001
2+
From: Sylvestre Ledru <[email protected]>
3+
Date: Fri, 13 Sep 2019 09:31:19 +0000
4+
Subject: [PATCH] Fix a perl warning: Scalar value @ArgParts[0] better written
5+
as $ArgParts[0] at /usr/share/clang/scan-build-10/libexec/ccc-analyzer line
6+
502.
7+
8+
llvm-svn: 371832
9+
---
10+
clang/tools/scan-build/libexec/ccc-analyzer | 2 +-
11+
1 file changed, 1 insertion(+), 1 deletion(-)
12+
13+
diff --git a/clang/tools/scan-build/libexec/ccc-analyzer b/clang/tools/scan-build/libexec/ccc-analyzer
14+
index 6d24a1af4539..800f38b5ba24 100755
15+
--- a/clang/tools/scan-build/libexec/ccc-analyzer
16+
+++ b/clang/tools/scan-build/libexec/ccc-analyzer
17+
@@ -499,7 +499,7 @@ my $HasSDK = 0;
18+
foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
19+
my $Arg = $ARGV[$i];
20+
my @ArgParts = split /=/,$Arg,2;
21+
- my $ArgKey = @ArgParts[0];
22+
+ my $ArgKey = $ArgParts[0];
23+
24+
# Be friendly to "" in the argument list.
25+
if (!defined($ArgKey)) {

0 commit comments

Comments
 (0)