xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen Devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Glenn Enright <glenn@rimuhosting.com>
Subject: [PATCH XTF 1/4] build: Support BUILD_BUG_ON() with compilers lacking _Static_assert()
Date: Thu, 28 Sep 2017 11:59:29 +0100	[thread overview]
Message-ID: <1506596372-24393-1-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <cc900311-2e53-390a-a6b3-f5d6e53a4ae6@rimuhosting.com>

Implement enough compatibility so the code can use Clang's __has_extension()
logic when compiled with GCC.

Reported-by: Glenn Enright <glenn@rimuhosting.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 include/xtf/compiler-gcc.h | 31 +++++++++++++++++++++++++++++++
 include/xtf/compiler.h     |  4 ++++
 include/xtf/lib.h          |  7 ++++++-
 3 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 include/xtf/compiler-gcc.h

diff --git a/include/xtf/compiler-gcc.h b/include/xtf/compiler-gcc.h
new file mode 100644
index 0000000..2d3bc89
--- /dev/null
+++ b/include/xtf/compiler-gcc.h
@@ -0,0 +1,31 @@
+#ifndef XTF_COMPILER_GCC_H
+#define XTF_COMPILER_GCC_H
+
+#define GCC_VER (__GNUC__ * 10000 +		\
+		 __GNUC_MINOR__ * 100 +		\
+		 __GNUC_PATCHLEVEL__)
+
+/*
+ * The Clang __has_*() infrastructure is a very clean way to identify
+ * compiler support, without resorting to version checks.  Fake up
+ * enough support for XTF code to use, even on non-clang compilers.
+ */
+
+#ifndef __has_extension
+
+#define GCC_HAS_c_static_assert (GCC_VER >= 40600) /* _Static_assert() */
+
+#define __has_extension(x) GCC_HAS_ ## x
+#endif /* __has_extension */
+
+#endif /* XTF_COMPILER_GCC_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xtf/compiler.h b/include/xtf/compiler.h
index 9dd6734..aa5fd6b 100644
--- a/include/xtf/compiler.h
+++ b/include/xtf/compiler.h
@@ -1,6 +1,10 @@
 #ifndef XTF_COMPILER_H
 #define XTF_COMPILER_H
 
+#ifdef __GNUC__
+#include <xtf/compiler-gcc.h>
+#endif
+
 #define __alias(x)            __attribute__((__alias__(x)))
 #define __aligned(x)          __attribute__((__aligned__(x)))
 #define __noreturn            __attribute__((__noreturn__))
diff --git a/include/xtf/lib.h b/include/xtf/lib.h
index d792a8d..abf8f25 100644
--- a/include/xtf/lib.h
+++ b/include/xtf/lib.h
@@ -28,8 +28,13 @@ void __noreturn panic(const char *fmt, ...) __printf(1, 2);
                   #cond, __FILE__, __LINE__);           \
     } while ( 0 )
 
-#define BUILD_BUG_ON(cond)                              \
+#if __has_extension(c_static_assert)
+# define BUILD_BUG_ON(cond)                             \
     _Static_assert(!(cond), "!(" #cond ")")
+#else
+# define BUILD_BUG_ON(cond)                             \
+    ((void)sizeof(struct { char: -!!(cond); }))
+#endif
 
 #define min(a, b)                                       \
     ({                                                  \
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-09-28 10:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-28  1:43 Building xtf on older distros Glenn Enright
2017-09-28  8:45 ` Wei Liu
2017-09-28  8:51   ` Andrew Cooper
2017-09-28  8:53     ` Wei Liu
2017-09-28 10:59 ` Andrew Cooper [this message]
2017-09-28 10:59   ` [PATCH XTF 2/4] build: Drop unnecessary register clobbers Andrew Cooper
2017-09-28 12:33     ` Jan Beulich
2017-09-28 10:59   ` [PATCH XTF 3/4] build: Opencode vmfunc as bytes Andrew Cooper
2017-09-28 12:34     ` Jan Beulich
2017-09-28 10:59   ` [PATCH XTF 4/4] build: Avoid using initialisers for anonymous unions Andrew Cooper
2017-09-28 12:37     ` Jan Beulich
2017-09-28 16:56       ` Andrew Cooper
2017-09-28 17:10         ` [PATCH XTF v2 " Andrew Cooper
2017-10-01 21:04           ` Glenn Enright
2017-09-28 12:32   ` [PATCH XTF 1/4] build: Support BUILD_BUG_ON() with compilers lacking _Static_assert() Jan Beulich
2017-09-28 12:34     ` Andrew Cooper
2017-09-28 12:50       ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1506596372-24393-1-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=glenn@rimuhosting.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).