From patchwork Sun Nov 5 10:07:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 834320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-465961-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IFTAspu/"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVBGJ57Hzz9t34 for ; Sun, 5 Nov 2017 21:08:07 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=xVA9Fp0io1S6r9aFfgJGEj/m225x1JY/mYvxWnomgauI47Api6 kKOGRgv1sk1uQjPvNChBByWRQyqcgN3pVU/9o0Tmy/xD2fwcqGPNQo74x+LKeOA3 1AT087tdmlzBQx4CCdpFi7TwgaBVkfWIthWItSLtYqDHd6w/lAsJj/BKM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; s= default; bh=3bgwmkllz7k78nMXvxVIPhKqB14=; b=IFTAspu/56BbYd77ozq5 109ha6c95m7WB854rluwCdwGLC5axy/oR93FKfhP/Sa3Z9pCznFwhHZ4KWgLIm67 wyPv4pu+dOa45VS+kJ1L5ilQyAPxJ58qon9FleOvg29UVSow7P90DTwoI40Wbaqm HQ3+diTwh1Jk2o0ZE7QFdN8= Received: (qmail 12145 invoked by alias); 5 Nov 2017 10:07:57 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 12134 invoked by uid 89); 5 Nov 2017 10:07:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=explained X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 05 Nov 2017 10:07:55 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1eBHqL-0000hV-Db from Tom_deVries@mentor.com ; Sun, 05 Nov 2017 02:07:53 -0800 Received: from [172.30.72.166] (137.202.0.87) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Sun, 5 Nov 2017 10:07:49 +0000 From: Tom de Vries Subject: [PATCH 7/7][committed] Remove semicolon after do {} while (0) in DEF_SANITIZER_BUILTIN To: GCC Patches CC: Jakub Jelinek , Marek Polacek Message-ID: <9ca07b87-338f-5154-c946-3e04cbe23dc1@mentor.com> Date: Sun, 5 Nov 2017 11:07:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) Hi, Consider this code in gcc/asan.c: ... #define DEF_SANITIZER_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ do { \ decl = add_builtin_function ("__builtin_" NAME, TYPE, ENUM, \ BUILT_IN_NORMAL, NAME, \ NULL_TREE); \ set_call_expr_flags (decl, ATTRS); \ set_builtin_decl (ENUM, decl, true); \ } while (0); #include "sanitizer.def" if ((flag_sanitize & SANITIZE_OBJECT_SIZE) && !builtin_decl_implicit_p (BUILT_IN_OBJECT_SIZE)) DEF_SANITIZER_BUILTIN (BUILT_IN_OBJECT_SIZE, "object_size", BT_FN_SIZE_CONST_PTR_INT, ATTR_PURE_NOTHROW_LEAF_LIST) ... As explained here ( https://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html ), we can wrap a multi-statement macro body in a "do {} while (0)" in order to be able to use the macro call as if it were a single statement. However, adding a semicolon after that "do {} while (0)", as is done in DEF_SANITIZER_BUILTIN means you can no longer use it as a single statement (compiling "if DEF_SANITIZER_BUILTIN (...); else ...;" will give an "else without a previous if" compiler error). This problem is then handled in the if stmt by leaving out the semicolon after DEF_SANITIZER_BUILTIN, which is awkward. OTOH, we use .def files with lists of macro calls to generate tables and code. When generating code, it's natural to use a semicolon as the last part of the macro body, in order to separate statements. This patch factors out DEF_SANITIZER_BUILTIN_1 from DEF_SANITIZER_BUILTIN, and uses DEF_SANITIZER_BUILTIN_1 in the if statement as a normal single statement, as made possible by the "do {} while (0)". The original DEF_SANITIZER_BUILTIN is still used with the .def file, as before. Committed as obvious. Thanks, - Tom 2017-11-02 Tom de Vries PR other/82784 * asan.c (DEF_SANITIZER_BUILTIN_1): Factor out of ... (DEF_SANITIZER_BUILTIN): ... here. (initialize_sanitizer_builtins): Use DEF_SANITIZER_BUILTIN_1 instead of DEF_SANITIZER_BUILTIN in if stmt. Add missing semicolon. Signed-off-by: Tom de Vries --- gcc/asan.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gcc/asan.c b/gcc/asan.c index d5128aa..61e1e7a 100644 --- a/gcc/asan.c +++ b/gcc/asan.c @@ -2804,14 +2804,17 @@ initialize_sanitizer_builtins (void) #define ATTR_PURE_NOTHROW_LEAF_LIST ECF_PURE | ATTR_NOTHROW_LEAF_LIST #undef DEF_BUILTIN_STUB #define DEF_BUILTIN_STUB(ENUM, NAME) -#undef DEF_SANITIZER_BUILTIN -#define DEF_SANITIZER_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ +#undef DEF_SANITIZER_BUILTIN_1 +#define DEF_SANITIZER_BUILTIN_1(ENUM, NAME, TYPE, ATTRS) \ do { \ decl = add_builtin_function ("__builtin_" NAME, TYPE, ENUM, \ BUILT_IN_NORMAL, NAME, NULL_TREE); \ set_call_expr_flags (decl, ATTRS); \ set_builtin_decl (ENUM, decl, true); \ - } while (0); + } while (0) +#undef DEF_SANITIZER_BUILTIN +#define DEF_SANITIZER_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ + DEF_SANITIZER_BUILTIN_1 (ENUM, NAME, TYPE, ATTRS); #include "sanitizer.def" @@ -2820,10 +2823,11 @@ initialize_sanitizer_builtins (void) DEF_SANITIZER_BUILTIN here only as a convenience macro. */ if ((flag_sanitize & SANITIZE_OBJECT_SIZE) && !builtin_decl_implicit_p (BUILT_IN_OBJECT_SIZE)) - DEF_SANITIZER_BUILTIN (BUILT_IN_OBJECT_SIZE, "object_size", - BT_FN_SIZE_CONST_PTR_INT, - ATTR_PURE_NOTHROW_LEAF_LIST) + DEF_SANITIZER_BUILTIN_1 (BUILT_IN_OBJECT_SIZE, "object_size", + BT_FN_SIZE_CONST_PTR_INT, + ATTR_PURE_NOTHROW_LEAF_LIST); +#undef DEF_SANITIZER_BUILTIN_1 #undef DEF_SANITIZER_BUILTIN #undef DEF_BUILTIN_STUB }