From patchwork Tue Apr 11 07:54:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 9674675 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E23E360234 for ; Tue, 11 Apr 2017 07:57:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE08228179 for ; Tue, 11 Apr 2017 07:57:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF67F28450; Tue, 11 Apr 2017 07:57:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4CE1828179 for ; Tue, 11 Apr 2017 07:57:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxqdj-0003GG-3f; Tue, 11 Apr 2017 07:55:03 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxqdi-0003GA-0G for xen-devel@lists.xenproject.org; Tue, 11 Apr 2017 07:55:02 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id D6/CF-01936-5DB8CE85; Tue, 11 Apr 2017 07:55:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpikeJIrShJLcpLzFFi42JxWrohUvdK95s Ig8mvNSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ox1X+eyFnwTr7j08QF7A+NlwS5GDg4JAX+J JfNFuxg5OdgEdCQuzt3JBhIWEVCRuL3XAMRkFiiXmHEjHqRCWMBdYveqycwgNouAqsTpjTsYQ WxeAUuJhfsngtkSAnoSbye+gIoLSpyc+YQFxGYW0JRo3f6bHcKWl2jeOhtsjpCAokT/vAdsEx h5ZiFpmYWkZRaSlgWMzKsYNYpTi8pSi3SNDfSSijLTM0pyEzNzdA0NTPVyU4uLE9NTcxKTivW S83M3MQLDpp6BgXEH44RVfocYJTmYlER5A2a+jhDiS8pPqcxILM6ILyrNSS0+xCjDwaEkwavf 9SZCSLAoNT21Ii0zBxjAMGkJDh4lEd4akDRvcUFibnFmOkTqFKOilDivOUhCACSRUZoH1waLm kuMslLCvIwMDAxCPAWpRbmZJajyrxjFORiVhHkTQabwZOaVwE1/BbSYCWjxmV0vQRaXJCKkpB oY57z9YXSFifnfhXuRE0qat/eY2e5w23pqRm1PsFLcuguqmmy/3Zo+GRz8fGtby7bebdo5G+7 tSmJvNzrNePSpx+5ajo11z9k+5T0Ut9hhMmuByaTeeJbjSuHNvzfveOolkt1XwzNf44hLuex6 6Qutv07H17Uzz5J5Jc6ZdKsqonSu1i+mS/ohSizFGYmGWsxFxYkAxJT++pUCAAA= X-Env-Sender: prvs=267e7865b=roger.pau@citrix.com X-Msg-Ref: server-2.tower-206.messagelabs.com!1491897298!72282467!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17109 invoked from network); 11 Apr 2017 07:55:00 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-2.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 11 Apr 2017 07:55:00 -0000 X-IronPort-AV: E=Sophos;i="5.37,184,1488844800"; d="scan'208";a="418551642" From: Roger Pau Monne To: Date: Tue, 11 Apr 2017 08:54:20 +0100 Message-ID: <20170411075420.55018-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.11.0 (Apple Git-81) MIME-Version: 1.0 Cc: Andrew Cooper , Jan Beulich , Roger Pau Monne Subject: [Xen-devel] [PATCH] clang: disable the gcc-compat warnings for read_atomic X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP clang gcc-compat warnings can wrongly fire when certain constructions are used, at least the following flow: switch ( ... ) { case ...: while ( ({ int x; switch ( foo ) { case 1: x = 1; break; } x }) ) { ... Will cause clang to emit the following warning "'break' is bound to loop, GCC binds it to switch", which is a false positive, and both gcc and clang bound the break to the inner switch. In order to workaround this issue, disable the gcc-compat checks for the usage of the read_atomic macro. This has been reported upstream as http://bugs.llvm.org/show_bug.cgi?id=32595. Signed-off-by: Roger Pau Monné Acked-by: Jan Beulich --- Cc: Jan Beulich Cc: Andrew Cooper --- xen/include/asm-x86/atomic.h | 2 ++ xen/include/xen/compiler.h | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h index 2fbe705518..b997a1726b 100644 --- a/xen/include/asm-x86/atomic.h +++ b/xen/include/asm-x86/atomic.h @@ -45,6 +45,7 @@ void __bad_atomic_size(void); #define read_atomic(p) ({ \ unsigned long x_; \ + CLANG_DISABLE_WARN_GCC_COMPAT_START \ switch ( sizeof(*(p)) ) { \ case 1: x_ = read_u8_atomic((uint8_t *)(p)); break; \ case 2: x_ = read_u16_atomic((uint16_t *)(p)); break; \ @@ -52,6 +53,7 @@ void __bad_atomic_size(void); case 8: x_ = read_u64_atomic((uint64_t *)(p)); break; \ default: x_ = 0; __bad_atomic_size(); break; \ } \ + CLANG_DISABLE_WARN_GCC_COMPAT_END \ (typeof(*(p)))x_; \ }) diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h index 16aeeea7f1..17d1f33a2d 100644 --- a/xen/include/xen/compiler.h +++ b/xen/include/xen/compiler.h @@ -100,4 +100,31 @@ # define ASM_FLAG_OUT(yes, no) no #endif +/* + * NB: we need to disable the gcc-compat warnings for clang in some places or + * else it will complain with: "'break' is bound to loop, GCC binds it to + * switch" when a switch is used inside of a while expression inside of a + * switch statement, ie: + * + * switch ( ... ) + * { + * case ...: + * while ( ({ int x; switch ( foo ) { case 1: x = 1; break; } x }) ) + * { + * ... + * + * This has already been reported upstream: + * http://bugs.llvm.org/show_bug.cgi?id=32595 + */ +#ifdef __clang__ +# define CLANG_DISABLE_WARN_GCC_COMPAT_START \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") +# define CLANG_DISABLE_WARN_GCC_COMPAT_END \ + _Pragma("clang diagnostic pop") +#else +# define CLANG_DISABLE_WARN_GCC_COMPAT_START +# define CLANG_DISABLE_WARN_GCC_COMPAT_END +#endif + #endif /* __LINUX_COMPILER_H */