[Mesa-dev] [PATCH] util: Implement assume() for clang.
Matt Turner
mattst88 at gmail.com
Fri Nov 21 15:17:00 PST 2014
---
src/util/macros.h | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/util/macros.h b/src/util/macros.h
index da5daff..b67596d 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -29,6 +29,10 @@
# define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#endif
+/* For compatibility with Clang's __has_builtin() */
+#ifndef __has_builtin
+# define __has_builtin(x) 0
+#endif
/**
* __builtin_expect macros
@@ -85,7 +89,13 @@ do { \
* Assume macro. Useful for expressing our assumptions to the compiler,
* typically for purposes of silencing warnings.
*/
-#ifdef HAVE___BUILTIN_UNREACHABLE
+#if __has_builtin(__builtin_assume)
+#define assume(expr) \
+do { \
+ assert(!"assumption failed"); \
+ __builtin_assume(expr); \
+} while (0)
+#elif defined HAVE___BUILTIN_UNREACHABLE
#define assume(expr) ((expr) ? ((void) 0) \
: (assert(!"assumption failed"), \
__builtin_unreachable()))
--
2.0.4
More information about the mesa-dev
mailing list