[PATCH for-4.14] compilers/clang: always use _Static_assert with clang

Roger Pau Monne posted 1 patch 3 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/xen tags/patchew/20200602091602.38422-1-roger.pau@citrix.com
xen/include/xen/lib.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH for-4.14] compilers/clang: always use _Static_assert with clang
Posted by Roger Pau Monne 3 years, 10 months ago
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(-)

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


Re: [PATCH for-4.14] compilers/clang: always use _Static_assert with clang
Posted by Wei Liu 3 years, 10 months ago
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
> 

RE: [PATCH for-4.14] compilers/clang: always use _Static_assert with clang
Posted by Paul Durrant 3 years, 10 months ago
> -----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
> >


Re: [PATCH for-4.14] compilers/clang: always use _Static_assert with clang
Posted by Andrew Cooper 3 years, 10 months ago
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>