From patchwork Mon Apr 10 16:46:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 9673433 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 B77FE600CB for ; Mon, 10 Apr 2017 16:49:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 233C02845D for ; Mon, 10 Apr 2017 16:49:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17EA02848B; Mon, 10 Apr 2017 16:49:41 +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 8B1A02845D for ; Mon, 10 Apr 2017 16:49:39 +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 1cxcSm-0000jn-4q; Mon, 10 Apr 2017 16:46:48 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxcSl-0000jh-Ab for xen-devel@lists.xenproject.org; Mon, 10 Apr 2017 16:46:47 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id 75/8E-03648-6F6BBE85; Mon, 10 Apr 2017 16:46:46 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGIsWRWlGSWpSXmKPExsWyU9JRQvfbttc RBhf6OSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1owVk24yFmzTrZh4s5O5gfGZQhcjJ4eEgJ/E pj3L2LoYOThYBFQlLk/MBAmzCehIXJy7kw3EFhFQluj99ZsFxGYWCJDou3iLHaRcWMBeYvura pAwr4CnxLQXV5m7GLk4hATmMEq8P72cFSIhKHFy5hOoXh2JBbs/ga1iFpCWWP6PAyTMCTRm3s Uz7CC2qICKxMbXr5hBbCEBRYn+eQ/YIK5Ml9j69xfzBEb+WUimzkIydRbC1AWMzKsYNYpTi8p Si3QNLfWSijLTM0pyEzNzdA0NzPRyU4uLE9NTcxKTivWS83M3MQLDjwEIdjD+WBZwiFGSg0lJ lDdg5usIIb6k/JTKjMTijPii0pzU4kOMMhwcShK817YC5QSLUtNTK9Iyc4CRAJOW4OBREuGdB ZLmLS5IzC3OTIdInWJUlBLnFQDGj5AASCKjNA+uDRZ9lxhlpYR5GYEOEeIpSC3KzSxBlX/FKM 7BqCTM2w0yniczrwRu+iugxUxAi8/segmyuCQRISXVwJj0YZluRG9GGt8+vWWst+bu/3/w9fE KuXzv2Qempth2r3A41aKW8npvC4vuk/orv6z+f01ckSvw9kFcXXqt1nk+4zsep3/y/wiJWcEb HP7gG5vRPgHzxdfUOwX/b9uhsX+3E3NdWMpM7WXqdg4R+Rnb9pTOmnlg8gLRyRHzKh+u929pv LesRl+JpTgj0VCLuag4EQAP3wsguQIAAA== X-Env-Sender: prvs=266d97a94=roger.pau@citrix.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1491842805!56462876!1 X-Originating-IP: [185.25.65.24] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30326 invoked from network); 10 Apr 2017 16:46:46 -0000 Received: from smtp.ctxuk.citrix.com (HELO SMTP.EU.CITRIX.COM) (185.25.65.24) by server-10.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 10 Apr 2017 16:46:46 -0000 X-IronPort-AV: E=Sophos;i="5.37,182,1488844800"; d="scan'208";a="44061354" Date: Mon, 10 Apr 2017 17:46:10 +0100 From: Roger Pau Monne To: Jan Beulich Message-ID: <20170410164610.7cty25z4y3wedcy4@dhcp-3-128.uk.xensource.com> References: <20170410133435.51728-1-roger.pau@citrix.com> <20170410133435.51728-2-roger.pau@citrix.com> <58EBBEB8020000780014F7FE@prv-mh.provo.novell.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <58EBBEB8020000780014F7FE@prv-mh.provo.novell.com> User-Agent: NeoMutt/20170306 (1.8.0) X-ClientProxiedBy: AMSPEX02CAS01.citrite.net (10.69.22.112) To AMSPEX02CL02.citrite.net (10.69.22.126) Cc: Andrew Cooper , xen-devel@lists.xenproject.org Subject: Re: [Xen-devel] [PATCH for-4.9 v3 2/3] x86/atomic: fix clang build 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 On Mon, Apr 10, 2017 at 09:19:52AM -0600, Jan Beulich wrote: > >>> On 10.04.17 at 15:34, wrote: > > --- a/xen/include/asm-x86/atomic.h > > +++ b/xen/include/asm-x86/atomic.h > > @@ -41,20 +41,42 @@ build_add_sized(add_u64_sized, "q", uint64_t, "ri") > > #undef build_write_atomic > > #undef build_add_sized > > > > -void __bad_atomic_size(void); > > +/* > > + * NB: read_atomic needs to be a static inline function because clang doesn't > > + * like breaks inside of expressions, even when there's an inner switch where > > + * those breaks should apply, and complains with "'break' is bound to loop, GCC > > + * binds it to switch", so the following code: > > + * > > + * while ( read_atomic(&foo) ) { ... } > > + * > > + * Doesn't work if read_atomic is a macro with an inner switch. > > + */ > > +static inline unsigned long readatomic(const void *p, size_t s) > > +{ > > + switch ( s ) > > + { > > + case 1: > > + return read_u8_atomic((uint8_t *)p); > > + case 2: > > + return read_u16_atomic((uint16_t *)p); > > + case 4: > > + return read_u32_atomic((uint32_t *)p); > > + case 8: > > + return read_u64_atomic((uint64_t *)p); > > By going though void as the function's parameter type I don't think > you need the bogus casts here anymore. > > > + default: > > + ASSERT_UNREACHABLE(); > > + return 0; > > + } > > +} > > > > -#define read_atomic(p) ({ \ > > - unsigned long x_; \ > > - switch ( sizeof(*(p)) ) { \ > > - case 1: x_ = read_u8_atomic((uint8_t *)(p)); break; \ > > - case 2: x_ = read_u16_atomic((uint16_t *)(p)); break; \ > > - case 4: x_ = read_u32_atomic((uint32_t *)(p)); break; \ > > - case 8: x_ = read_u64_atomic((uint64_t *)(p)); break; \ > > - default: x_ = 0; __bad_atomic_size(); break; \ > > - } \ > > - (typeof(*(p)))x_; \ > > +#define read_atomic(p) ({ \ > > + BUILD_BUG_ON(sizeof(*(p)) != 1 && sizeof(*(p)) != 2 && \ > > + sizeof(*(p)) != 4 && sizeof(*(p)) != 8); \ > > + (typeof(*(p)))readatomic(p, sizeof(*(p))); \ > > }) > > So did you take a look at whether / how much generated code > changes? No, I haven't looked. > In any event, while this is better than dealing with it at the use > site(s) of the macro, I still don't think this is really acceptable, > mainly because it still doesn't scale: What if tomorrow I use > write_atomic() in a context that clang doesn't like? And perhaps > we have a few more such constructs, or may be gaining them > at any time going forward. I'm honestly not convinced of the > usefulness of keeping our code clang compliant, if they have > such fundamental issues with the understanding of the > language spec. Well, I think clang has proven useful in the past for detecting issues that gcc didn't catch. Those should all be considered bugs, and IMHO clang is quite good at solving them. I never had issues sending bug reports upstream, and getting them fixed. I cannot sadly say the same about gcc. In any case, I don't think it's reasonable to expect no bugs (like Xen also has bugs). I understand your reluctance to merge this because it pollutes the code just to fix a bug that's not even ours, but I don't see any other way to solve this. I have a (I think) less intrusive fix, which relies on using _Pragma, pasted below. Let me know what you think, and I can formally submit it. ---8<--- diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h index 2fbe705518..d24e30c3df 100644 --- a/xen/include/asm-x86/atomic.h +++ b/xen/include/asm-x86/atomic.h @@ -43,8 +43,23 @@ build_add_sized(add_u64_sized, "q", uint64_t, "ri") void __bad_atomic_size(void); +/* + * NB: we need to disable the gcc-compat warnings for clang in read_atomic or + * else it will complain with: "'break' is bound to loop, GCC binds it to + * switch" when read_atomic is used inside of a while expression inside of a + * switch statement, ie: + * + * switch (...) + * { + * case ...: + * while ( read_atomic(&foo) ) { ... } + * + * This has already been reported upstream: + * http://bugs.llvm.org/show_bug.cgi?id=32595 + */ #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 +67,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..569dcb70d6 100644 --- a/xen/include/xen/compiler.h +++ b/xen/include/xen/compiler.h @@ -100,4 +100,15 @@ # define ASM_FLAG_OUT(yes, no) no #endif +#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 */