From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 836231396D0 for ; Fri, 11 Aug 2017 15:27:57 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E2BDAE0D35; Fri, 11 Aug 2017 15:26:52 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 9FB91E0D29 for ; Fri, 11 Aug 2017 15:26:52 +0000 (UTC) Received: from localhost.localdomain (d202-252.icpnet.pl [109.173.202.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id 4E8C9341779; Fri, 11 Aug 2017 15:26:51 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH 2/3] flag-o-matic.eclass: test-flag-PROG, ignore unused args in clang Date: Fri, 11 Aug 2017 17:26:41 +0200 Message-Id: <20170811152642.24661-3-mgorny@gentoo.org> X-Mailer: git-send-email 2.14.0 In-Reply-To: <20170811152642.24661-1-mgorny@gentoo.org> References: <20170811152642.24661-1-mgorny@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Archives-Salt: 879f5fad-a706-492c-bb0e-ab9fe24892f0 X-Archives-Hash: 1bc0a9d7573a203aee72561c206fe029 By default, clang considers unused arguments as error when -Werror is used. Since flag tests are performed without linking, this causes all tests for linker flags to fail inadvertently and all those flags are stripped as a result. While the correctness of passing unused flags is doubtful, silently stripping them in a few random packages is certainly not the solution to the problem, and also makes the results differ between gcc and clang. To account for that, use clang's -Qunused-arguments option to silence unused argument warnings. To avoid wasting time on testing the compiler, just try passing -Qunused-arguments every time a flag check fails. If clang is not used, the additional call will fail just the same as the previous one (either because of the original flag or because of -Qunused-arguments), so the result will be the same. --- eclass/flag-o-matic.eclass | 9 ++++++++- eclass/tests/flag-o-matic.sh | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass index 0393a30b74c3..79866e04a483 100644 --- a/eclass/flag-o-matic.eclass +++ b/eclass/flag-o-matic.eclass @@ -441,7 +441,14 @@ test-flag-PROG() { cmdline+=( "${flag}" -c -o /dev/null /dev/null ) fi - "${cmdline[@]}" /dev/null + if ! "${cmdline[@]}" /dev/null; then + # -Werror makes clang bail out on unused arguments as well; + # try to add -Qunused-arguments to work-around that + # other compilers don't support it but then, it's failure like + # any other + cmdline+=( -Qunused-arguments ) + "${cmdline[@]}" /dev/null + fi } # @FUNCTION: test-flag-CC diff --git a/eclass/tests/flag-o-matic.sh b/eclass/tests/flag-o-matic.sh index 92c68b82c3c9..5e7ee354bf33 100755 --- a/eclass/tests/flag-o-matic.sh +++ b/eclass/tests/flag-o-matic.sh @@ -143,6 +143,11 @@ tbegin "test-flags-CC (gcc-valid but clang-invalid flags)" out=$(CC=clang test-flags-CC -finline-limit=1200) [[ $? -ne 0 && -z ${out} ]] ftend + +tbegin "test-flags-CC (unused flags w/clang)" +out=$(CC=clang test-flags-CC -Wl,-O1) +[[ $? -eq 0 && ${out} == "-Wl,-O1" ]] +ftend fi texit -- 2.14.0