compilers/clang: always use _Static_assert with clang
PATCH 1/1 compilers/clang: always use _Static_assert with clang
All versions of clang used by Xen support _Static_assert, so use it unconditionally when building Xen with clang.
No functional change expected.
---
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(-)
xen/include/xen/lib.h +3 -1
@@ -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 ")"); })
Signature · 1 line
2.26.2
Quoted 6 lines · Roger Pau Monne
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é <[email protected]>
Quoted 5 lines
---
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.
Quoted 22 lines
--- xen/include/xen/lib.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen/include/xen/lib.h +3
-1@@ -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 ")"); })Signature · 1 line
2.26.2
Quoted 20 lines
-----Original Message-----
From: Wei Liu <[email protected]>
Sent: 02 June 2020 10:23
To: Roger Pau Monne <[email protected]>
Cc: [email protected]; [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Jan Beulich <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH for-4.14] compilers/clang: always use_Static_assertwith clangQuoted 6 lines · Roger Pau Monne
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é <[email protected]>Reviewed-by Wei Liu <[email protected]>
Quoted 8 lines
Quoted 5 lines
---
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.
Quoted 23 lines
Quoted 23 lines
--- xen/include/xen/lib.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen/include/xen/lib.h +3
-2@@ -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
Acked-byQuoted 14 lines · Paul Durrant
Quoted 14 lines · Roger Pau Monne
Quoted 6 lines
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é <[email protected]>Reviewed-by Wei Liu <[email protected]>Quoted 5 lines
---
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.
Quoted 5 lines
Quoted 2 lines
IMHO it wouldn't hurt to apply this patch since any breakage is easy to catch.
Yes, seems reasonable.
Release-acked-by Paul Durrant <[email protected]>