Message ID | 6619e7e2-248e-08bc-6dc5-7b4d11bea3df@auburn.edu |
---|---|
State | New, archived |
Headers |
Received: (qmail 15062 invoked by alias); 19 Mar 2017 21:44:42 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <libc-alpha.sourceware.org> List-Unsubscribe: <mailto:libc-alpha-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:libc-alpha-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 15005 invoked by uid 89); 19 Mar 2017 21:44:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:ip*192.168.1.2, H*Ad:D*auburn.edu, H*F:D*auburn.edu, HX-Microsoft-Antispam-PRVS:sk:SN1PR02 X-HELO: NAM03-DM3-obe.outbound.protection.outlook.com Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=auburn.edu; To: <libc-alpha@sourceware.org> From: Justin Brewer <jzb0012@auburn.edu> Subject: [PATCH] Fix assert() warning in gcc < 4.8 [BZ# 21242] Message-ID: <6619e7e2-248e-08bc-6dc5-7b4d11bea3df@auburn.edu> Date: Sun, 19 Mar 2017 17:44:31 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: CY4PR22CA0045.namprd22.prod.outlook.com (10.172.142.159) To SN1PR02MB2093.namprd02.prod.outlook.com (10.165.227.153) X-MS-Office365-Filtering-Correlation-Id: c7f31e3e-cb54-41ad-5ac5-08d46f1121b4 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:SN1PR02MB2093; X-Microsoft-Exchange-Diagnostics: 1; SN1PR02MB2093; 3:oxONeRfdKaIglsxhgif17OXCR7LhN+vLfY86viBYSodoV7lYf5/koHQSu7P0xVMvtHQp3m4ZPNLFlSZSQcuSsvebac8zSMZK+qmA1Kec84eqIWkEOOuFuKluochQMSMiozLZGytV7/t5zg9Kx21fB2AVRCjkxAc8lJb+usDqDDUeTDmeMNzCstcSZF1/xJSVogqPANyiPthD0g3aMiok+UdiV6673O59EHLkHBLO4PJ6OKOXjYBQIrHhpBv7ohFCETrO32pE9ghuqIGtW9E05Q==; 25:G95v++l+880uqof7Qd6SMXAIWyhthnlsw1oFI0z4xtfiow1BOX2DAyXZ3cILO1rAUUmjeHOW3o3Dodc4eytqmib3gZHChtbPz3bRid0gJAEb7MkOjOwh635ZvdPjJ+rUTE2D5zb1oZYJrHwd2QiCUYDALngCxIpOunA6Dh2Tg7xVm8VEkY9Uv4HZ0Nr1Iv7/CoTJrTU8m9caWvjLvjqOLwZFnBjPWFikfK0W8WK4P4Q4qPr4jgnyve/LeApu+JW9r/ypIdaKGfpEqKlITKoRlGPsUpL4HmKnSOTJ2+K0t0j+1I2/6xBaNszsZXuS06plcrnB9Ey+Cs1I2/YbTYuqXslz6nRVuEusoy91OgXnqdxj1B6oxRmI2FZrnbYT9is5O0HmYGaQYNS/blmMXhBvJNe9pfbbXafBjjs9p0k1ndRt+1z13Twxzt3JAzxEHUPGEvbGhGJzQQ7EZqwi31B+IQ== X-Microsoft-Exchange-Diagnostics: 1; SN1PR02MB2093; 31:2li3en8F2sbtKqiF+jUA0DoHQ0lWv4I6YOwAX/z8odtvpT0Jbdy87A57b1oaigdvRafiJQYAAcZJzCTU7Sy7ffd6ctfY1gTQ1ptkr7AWP2HSBYHMQoflBIEKlVxO4ksrgjIH7vOA57REFvZotZmC1VGMFVSMSwkkeHhI37I/HuM8eLbXpMVWXPRo4TW3+NB4j2moZ68tn6k5+GT/1MvZxns6EONNRwFZDxFraVpdYDYe4CBK2jSxfuJi9CVie5kWfrYR4JSmBU5qEuxDqF91RwePva3BChpXxG0Fiqjgfbs=; 20:astgD+TDgDNn2nrYYf1K3MvlLPWZ+il8lqDsuO1+00MVz/BoIqRxuEwk3DjD91MF/r3/LjNrfwRFhZ+1XCPVRmTv4FrM07L78/nAYM5NY/ol+BNYYktoSM/v4eFFaekR8pC2LBTJ7GhH79dIpkj2Vxrj2a175nmtQXIM337ASGU2y6muV7rvfPQWOE6CTUv9Qz/NvB9XoNq6woJHB5bBB7FgtLxkcVqDy6nID6AzUGXdxDj+9iL/GC9uDo7aKfGza5FjhK0dmwzVGuywHCDwgrHdEdnI+ahr0E5Y8e4BIkGKL9XF2L1p5hMUhwoWY3+9Dj7eR8wdOOt9dG49PPs0MyEL6AQZxDnA88M3E+P0enHKAmF3tXeGJaERnz5dqb9mj/4mZgrrhr1BhecvYkLkDx877iH91pSrtbsQwRgLFtwRU26GPhj2ew0RdNUY0A9DkELgsYVjih6A73xXQrCR8zC9s7XTywyG6u2vzBvpKWydTNmj4B/rs6+q7DDUK6lq X-Microsoft-Antispam-PRVS: <SN1PR02MB2093C1D3DFEB6F70BB8F0280843B0@SN1PR02MB2093.namprd02.prod.outlook.com> X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123555025)(20161123558025)(20161123562025)(20161123564025)(20161123560025)(6072148); SRVR:SN1PR02MB2093; BCL:0; PCL:0; RULEID:; SRVR:SN1PR02MB2093; X-Microsoft-Exchange-Diagnostics: 1; SN1PR02MB2093; 4:i5Vm/5WQ2a9R8GF6R3gIjpQjNY2NZKRWgLqV/S/Do4Aw3EqAxNxUncBexwNll62OWjjqfezumy0HsDWSi7+r5CVGEy1EU9XcHiaM/Wdl54FXOlbyp6UC15E12JD/TFM+16aT2cRdsrSPlvX9OtkcbdFCYURHAVnmhXNxER0crfonu3lPAfVy+3xsvCwi1Ltf4MMA77dk/8M+raY2cdMKlnhtIcVNMJzdVpL6LVCBPekEtcH8N8W0iawxDlLwydpckZUNqDq66ROLIU6VkoLDO1iDDDf/8qKopAsNUu5ZK4q128cZIkFbLGrlPu8kBnxMTf3hhvLF95oSSLboq1tmDMcnRno9kqA5WjC701Ee3jaoG6KnMqwBWzmkJwUW6eFTykeheEgSAB3w5XLcvAaY4wAF3pC9eLjS4b7xZ3urAabCqdtbCYDkRdTiP9kgHr5vHiytzNRb0i0DdA2LomkiSdW8hjNzYfh1HOP8wd+WWiP0zdJX9xgJzgCNvrE23kscwT+M8rI5K5oxndYFrkCuDv8lSmmEtc4Gr6DO6oGdI1htIZ8glCzUl88Pfzb1WpIH9rwmSTRsOiZFcaTneKLZ9/JlB0CBW3r8LTaAZwmdoUo= X-Forefront-PRVS: 025100C802 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(979002)(6009001)(6049001)(39450400003)(77096006)(23676002)(33646002)(25786008)(90366009)(6916009)(6486002)(75432002)(53936002)(4001350100001)(3846002)(6116002)(50466002)(5660300001)(65806001)(305945005)(64126003)(65826007)(66066001)(65956001)(31696002)(8676002)(7736002)(83506001)(2906002)(47776003)(189998001)(110136004)(38730400002)(50986999)(54356999)(81166006)(42186005)(31686004)(2351001)(36756003)(2870700001)(88552002)(117156001)(42262002)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1102; SCL:1; SRVR:SN1PR02MB2093; H:[192.168.1.2]; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtTTjFQUjAyTUIyMDkzOzIzOktBVGp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54+VM7rTW4syDexY6jIb8kycDN40= X-OriginatorOrg: auburn.edu X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2017 21:44:33.3805 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR02MB2093 |
Commit Message
Justin Brewer
March 19, 2017, 9:44 p.m. UTC
When compiling with gcc-4.7 and earlier, with -pedantic but without -ansi, a warning is produced due to the braced group in the assert macro. This warning also occurs in the latest clang. In gcc >= 4.8, no warning is produced. Therefore, further restrict the usage of the braced group version of the macro to gcc 4.8 and later. This patch also fixes the warning in clang, since clang-3.9 sets the __GNUC_* version macros to mimic gcc 4.2.1 main.c: #include <assert.h> int main() { assert(1); } Without patched assert.h: $ gcc-4.8 -pedantic main.c $ gcc-4.7 -pedantic main.c main.c: In function ‘main’: main.c:2:14: warning: ISO C forbids braced-groups within expressions [-pedantic] $ gcc-4.4 -pedantic main.c main.c: In function ‘main’: main.c:2: warning: ISO C forbids braced-groups within expressions $ clang-3.9 -pedantic main.c main.c:2:14: warning: use of GNU statement expression extension [-Wgnu-statement-expression] int main() { assert(1); } ^ /usr/include/assert.h:95:6: note: expanded from macro 'assert' ({ \ ^ 1 warning generated. With patched assert.h: $ gcc-4.8 -pedantic main.c $ gcc-4.7 -pedantic main.c $ gcc-4.4 -pedantic main.c $ clang-3.9 -pedantic main.c --- assert/assert.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 03/19/2017 10:44 PM, Justin Brewer wrote: > -# if !defined __GNUC__ || defined __STRICT_ANSI__ > +# if !(defined __GNUC__ && __GNUC_PREREQ(4,8)) || defined __STRICT_ANSI__ I'm not happy how this disables the useful = warning for clang altogether. Do we have a better option? Is there a way for check for the -pedantic flag? Thanks, Florian
On Tue, 21 Mar 2017, Florian Weimer wrote: > On 03/19/2017 10:44 PM, Justin Brewer wrote: > > -# if !defined __GNUC__ || defined __STRICT_ANSI__ > > +# if !(defined __GNUC__ && __GNUC_PREREQ(4,8)) || defined __STRICT_ANSI__ > > I'm not happy how this disables the useful = warning for clang altogether. > > Do we have a better option? Is there a way for check for the -pedantic flag? By design, warning options such as -pedantic are not meant to affect code generation, so should not have any way to check for them within the code. (Preferably __extension__ should be used, but that runs into the issues with disabling it for the user's expression as discussed earlier for this code <https://sourceware.org/ml/libc-alpha/2016-11/msg00895.html>.)
On 03/21/2017 05:21 PM, Joseph Myers wrote: > On Tue, 21 Mar 2017, Florian Weimer wrote: > >> On 03/19/2017 10:44 PM, Justin Brewer wrote: >>> -# if !defined __GNUC__ || defined __STRICT_ANSI__ >>> +# if !(defined __GNUC__ && __GNUC_PREREQ(4,8)) || defined __STRICT_ANSI__ >> >> I'm not happy how this disables the useful = warning for clang altogether. >> >> Do we have a better option? Is there a way for check for the -pedantic flag? > > By design, warning options such as -pedantic are not meant to affect code > generation, so should not have any way to check for them within the code. > > (Preferably __extension__ should be used, but that runs into the issues > with disabling it for the user's expression as discussed earlier for this > code <https://sourceware.org/ml/libc-alpha/2016-11/msg00895.html>.) I think we can use __extension__ if we also expand the expression without __extension__ in an unevaluated context. The tricky part is to find one that is independent of GNU extensions. Perhaps this would work? # define assert(expr) \ ((void) sizeof ((expr) == 0), __extension__ ({ \ if (expr) \ ; /* empty */ \ else \ __assert_fail (#expr, __FILE__, __LINE__, __FUNCTION__); \ })) sizeof suppresses the evaluation of the first occurrence of expr. The comparison is needed because sizeof cannot be applied to function pointers and bitfields. C11 says that expr is compared to zero, so the (expr) == 0 expression is well-formed. What do you think? Should we make this change? Thanks, Florian
On Sun, 25 Jun 2017, Florian Weimer wrote: > I think we can use __extension__ if we also expand the expression > without __extension__ in an unevaluated context. The tricky part is to > find one that is independent of GNU extensions. > Perhaps this would work? > > # define assert(expr) \ > ((void) sizeof ((expr) == 0), __extension__ ({ \ > if (expr) \ > ; /* empty */ \ > else \ > __assert_fail (#expr, __FILE__, __LINE__, __FUNCTION__); \ > })) > > sizeof suppresses the evaluation of the first occurrence of expr. The > comparison is needed because sizeof cannot be applied to function > pointers and bitfields. C11 says that expr is compared to zero, so the > (expr) == 0 expression is well-formed. > > What do you think? Should we make this change? I think that's reasonable (appropriately commented to explain why it's done that way).
On 06/26/2017 12:56 PM, Joseph Myers wrote: > On Sun, 25 Jun 2017, Florian Weimer wrote: > >> I think we can use __extension__ if we also expand the expression >> without __extension__ in an unevaluated context. The tricky part is to >> find one that is independent of GNU extensions. >> Perhaps this would work? >> >> # define assert(expr) \ >> ((void) sizeof ((expr) == 0), __extension__ ({ \ >> if (expr) \ >> ; /* empty */ \ >> else \ >> __assert_fail (#expr, __FILE__, __LINE__, __FUNCTION__); \ >> })) >> >> sizeof suppresses the evaluation of the first occurrence of expr. The >> comparison is needed because sizeof cannot be applied to function >> pointers and bitfields. C11 says that expr is compared to zero, so the >> (expr) == 0 expression is well-formed. >> >> What do you think? Should we make this change? > > I think that's reasonable (appropriately commented to explain why it's > done that way). This is what I came up with as a patch. I would consider this still appropriate during the freeze. It's something we'd backport to glibc 2.25, too. Thanks, Florian
diff --git a/assert/assert.h b/assert/assert.h index 22f019537c..88dde76414 100644 --- a/assert/assert.h +++ b/assert/assert.h @@ -85,7 +85,7 @@ __END_DECLS /* When possible, define assert so that it does not add extra parentheses around EXPR. Otherwise, those added parentheses would suppress warnings we'd expect to be detected by gcc's -Wparentheses. */ -# if !defined __GNUC__ || defined __STRICT_ANSI__ +# if !(defined __GNUC__ && __GNUC_PREREQ(4,8)) || defined __STRICT_ANSI__ # define assert(expr) \ ((expr) \ ? __ASSERT_VOID_CAST (0) \