Skip to contentSkip to conversation

compilers/clang: always use _Static_assert with clang

PATCH In review Roger Pau Monne 4 participants 4 messages Jun 2, 2020

lore
Share & tools
lore
#0 lore raw

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
index e5b0a007b8..076bcfb67d 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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.

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
index e5b0a007b8..076bcfb67d 100644
@@ -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
#2 lore raw
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_assert with clang

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.

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
index e5b0a007b8..076bcfb67d 100644
@@ -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

Acked-by
#3 lore raw
Quoted 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.

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.