[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] use C11's _Static_assert() for BUILD_BUG_ON etc when available


  • To: xen-changelog@xxxxxxxxxxxxxxxxxxx
  • From: Xen patchbot-unstable <patchbot@xxxxxxx>
  • Date: Sat, 28 Jul 2012 03:00:27 +0000
  • Delivery-date: Sat, 28 Jul 2012 03:00:34 +0000
  • List-id: "Change log for Mercurial \(receive only\)" <xen-changelog.lists.xen.org>

# HG changeset patch
# User Jan Beulich <jbeulich@xxxxxxxx>
# Date 1343375965 -7200
# Node ID 70cf2aa3083ca69d4568b11e3b1243cff670422b
# Parent  3298156d6cfa9bfe3db5a7c8f175a753c62550d4
use C11's _Static_assert() for BUILD_BUG_ON etc when available

This produces a more meaningful compiler diagnostic in case it happens
to trigger.

As a minor piece of cleanup, at once also use BUILD_BUG_ON_ZERO() to
actually define BUILD_BUG_ON() in the legacy case, slightly reducing
redundancy.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Acked-by: Keir Fraser <keir@xxxxxxx>
---


diff -r 3298156d6cfa -r 70cf2aa3083c xen/include/xen/lib.h
--- a/xen/include/xen/lib.h     Fri Jul 27 09:57:20 2012 +0200
+++ b/xen/include/xen/lib.h     Fri Jul 27 09:59:25 2012 +0200
@@ -14,14 +14,20 @@ void __warn(char *file, int line);
 #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)
 /* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(condition) ((void)sizeof(struct { int:-!!(condition); }))
+#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
 
 /* Force a compilation error if condition is true, but also produce a
    result (of value 0 and type size_t), so the expression can be used
    e.g. in a structure initializer (or where-ever else comma expressions
    aren't permitted). */
-#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
+#define BUILD_BUG_ON_ZERO(cond) \
+    sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })
+#else
+#define BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); })
+#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond))
+#endif
 
 #ifndef assert_failed
 #define assert_failed(p)                                        \

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.