[for-4.14] compilers/clang: always use _Static_assert with clang
diff mbox series

Message ID 20200602091602.38422-1-roger.pau@citrix.com
State New
Headers show
Series
  • [for-4.14] compilers/clang: always use _Static_assert with clang
Related show

Commit Message

Roger Pau Monné June 2, 2020, 9:16 a.m. UTC
All versions of clang used by Xen support _Static_assert, so use it
unconditionally when building Xen with clang.

No functional change expected.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Not sure whether this fully qualifies as a bugfix, as the current
behavior should also work fine under clang. Note that all versions of
clang from 3.5 to trunk (11) seem to return __GNUC__ == 4 and
__GNUC_MINOR__ == 2.
---
 xen/include/xen/lib.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Wei Liu June 2, 2020, 9:23 a.m. UTC | #1
On Tue, Jun 02, 2020 at 11:16:02AM +0200, Roger Pau Monne wrote:
> All versions of clang used by Xen support _Static_assert, so use it
> unconditionally when building Xen with clang.
> 
> No functional change expected.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

Reviewed-by: Wei Liu <wl@xen.org>

> ---
> Not sure whether this fully qualifies as a bugfix, as the current
> behavior should also work fine under clang. Note that all versions of
> clang from 3.5 to trunk (11) seem to return __GNUC__ == 4 and
> __GNUC_MINOR__ == 2.

IMHO it wouldn't hurt to apply this patch since any breakage is easy to
catch.

> ---
>  xen/include/xen/lib.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
> index e5b0a007b8..076bcfb67d 100644
> --- a/xen/include/xen/lib.h
> +++ b/xen/include/xen/lib.h
> @@ -25,7 +25,9 @@
>  #define BUG_ON(p)  do { if (unlikely(p)) BUG();  } while (0)
>  #define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
>  
> -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
> +/* All clang versions supported by Xen have _Static_assert. */
> +#if defined(__clang__) || \
> +    (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
>  /* Force a compilation error if condition is true */
>  #define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
>  
> -- 
> 2.26.2
>
Paul Durrant June 2, 2020, 9:26 a.m. UTC | #2
> -----Original Message-----
> From: Wei Liu <wl@xen.org>
> Sent: 02 June 2020 10:23
> To: Roger Pau Monne <roger.pau@citrix.com>
> Cc: xen-devel@lists.xenproject.org; paul@xen.org; Andrew Cooper <andrew.cooper3@citrix.com>; George
> Dunlap <george.dunlap@citrix.com>; Ian Jackson <ian.jackson@eu.citrix.com>; Jan Beulich
> <jbeulich@suse.com>; Julien Grall <julien@xen.org>; Stefano Stabellini <sstabellini@kernel.org>; Wei
> Liu <wl@xen.org>
> Subject: Re: [PATCH for-4.14] compilers/clang: always use _Static_assert with clang
> 
> On Tue, Jun 02, 2020 at 11:16:02AM +0200, Roger Pau Monne wrote:
> > All versions of clang used by Xen support _Static_assert, so use it
> > unconditionally when building Xen with clang.
> >
> > No functional change expected.
> >
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> 
> Reviewed-by: Wei Liu <wl@xen.org>
> 
> > ---
> > Not sure whether this fully qualifies as a bugfix, as the current
> > behavior should also work fine under clang. Note that all versions of
> > clang from 3.5 to trunk (11) seem to return __GNUC__ == 4 and
> > __GNUC_MINOR__ == 2.
> 
> IMHO it wouldn't hurt to apply this patch since any breakage is easy to
> catch.

Yes, seems reasonable.

Release-acked-by: Paul Durrant <paul@xen.org>

> 
> > ---
> >  xen/include/xen/lib.h | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
> > index e5b0a007b8..076bcfb67d 100644
> > --- a/xen/include/xen/lib.h
> > +++ b/xen/include/xen/lib.h
> > @@ -25,7 +25,9 @@
> >  #define BUG_ON(p)  do { if (unlikely(p)) BUG();  } while (0)
> >  #define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
> >
> > -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
> > +/* All clang versions supported by Xen have _Static_assert. */
> > +#if defined(__clang__) || \
> > +    (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
> >  /* Force a compilation error if condition is true */
> >  #define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
> >
> > --
> > 2.26.2
> >
Andrew Cooper June 2, 2020, 9:48 a.m. UTC | #3
On 02/06/2020 10:26, Paul Durrant wrote:
>> On Tue, Jun 02, 2020 at 11:16:02AM +0200, Roger Pau Monne wrote:
>>> All versions of clang used by Xen support _Static_assert, so use it
>>> unconditionally when building Xen with clang.
>>>
>>> No functional change expected.
>>>
>>> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
>> Reviewed-by: Wei Liu <wl@xen.org>
>>
>>> ---
>>> Not sure whether this fully qualifies as a bugfix, as the current
>>> behavior should also work fine under clang. Note that all versions of
>>> clang from 3.5 to trunk (11) seem to return __GNUC__ == 4 and
>>> __GNUC_MINOR__ == 2.
>> IMHO it wouldn't hurt to apply this patch since any breakage is easy to
>> catch.
> Yes, seems reasonable.
>
> Release-acked-by: Paul Durrant <paul@xen.org>

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

Patch
diff mbox series

diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index e5b0a007b8..076bcfb67d 100644
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -25,7 +25,9 @@ 
 #define BUG_ON(p)  do { if (unlikely(p)) BUG();  } while (0)
 #define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+/* All clang versions supported by Xen have _Static_assert. */
+#if defined(__clang__) || \
+    (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
 /* Force a compilation error if condition is true */
 #define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })