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
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 >
> -----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 > >
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>
© 2016 - 2024 Red Hat, Inc.