Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 2/3] flag-o-matic.eclass: test-flag-PROG, ignore unused args in clang
Date: Fri, 11 Aug 2017 15:27:57
Message-Id: 20170811152642.24661-3-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH] flag-o-matic.eclass: LDFLAGS stripping, take two by "Michał Górny"
1 By default, clang considers unused arguments as error when -Werror is
2 used. Since flag tests are performed without linking, this causes all
3 tests for linker flags to fail inadvertently and all those flags
4 are stripped as a result.
5
6 While the correctness of passing unused flags is doubtful, silently
7 stripping them in a few random packages is certainly not the solution
8 to the problem, and also makes the results differ between gcc and clang.
9 To account for that, use clang's -Qunused-arguments option to silence
10 unused argument warnings.
11
12 To avoid wasting time on testing the compiler, just try passing
13 -Qunused-arguments every time a flag check fails. If clang is not used,
14 the additional call will fail just the same as the previous one (either
15 because of the original flag or because of -Qunused-arguments), so
16 the result will be the same.
17 ---
18 eclass/flag-o-matic.eclass | 9 ++++++++-
19 eclass/tests/flag-o-matic.sh | 5 +++++
20 2 files changed, 13 insertions(+), 1 deletion(-)
21
22 diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass
23 index 0393a30b74c3..79866e04a483 100644
24 --- a/eclass/flag-o-matic.eclass
25 +++ b/eclass/flag-o-matic.eclass
26 @@ -441,7 +441,14 @@ test-flag-PROG() {
27 cmdline+=( "${flag}" -c -o /dev/null /dev/null )
28 fi
29
30 - "${cmdline[@]}" </dev/null &>/dev/null
31 + if ! "${cmdline[@]}" </dev/null &>/dev/null; then
32 + # -Werror makes clang bail out on unused arguments as well;
33 + # try to add -Qunused-arguments to work-around that
34 + # other compilers don't support it but then, it's failure like
35 + # any other
36 + cmdline+=( -Qunused-arguments )
37 + "${cmdline[@]}" </dev/null &>/dev/null
38 + fi
39 }
40
41 # @FUNCTION: test-flag-CC
42 diff --git a/eclass/tests/flag-o-matic.sh b/eclass/tests/flag-o-matic.sh
43 index 92c68b82c3c9..5e7ee354bf33 100755
44 --- a/eclass/tests/flag-o-matic.sh
45 +++ b/eclass/tests/flag-o-matic.sh
46 @@ -143,6 +143,11 @@ tbegin "test-flags-CC (gcc-valid but clang-invalid flags)"
47 out=$(CC=clang test-flags-CC -finline-limit=1200)
48 [[ $? -ne 0 && -z ${out} ]]
49 ftend
50 +
51 +tbegin "test-flags-CC (unused flags w/clang)"
52 +out=$(CC=clang test-flags-CC -Wl,-O1)
53 +[[ $? -eq 0 && ${out} == "-Wl,-O1" ]]
54 +ftend
55 fi
56
57 texit
58 --
59 2.14.0