summaryrefslogtreecommitdiffstats
path: root/src/util/macros.h
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2014-11-21 13:50:14 -0800
committerMatt Turner <mattst88@gmail.com>2014-11-24 14:09:23 -0800
commit99cebffda9cd2d42edd6c1cbeceb994e6b320c5a (patch)
treecc3cdae0a5a860cc9b514ea18c83dc4b66bc53cd /src/util/macros.h
parent56ac25918aea37a3c2c52f99fc285f2475be9128 (diff)
downloadexternal_mesa3d-99cebffda9cd2d42edd6c1cbeceb994e6b320c5a.zip
external_mesa3d-99cebffda9cd2d42edd6c1cbeceb994e6b320c5a.tar.gz
external_mesa3d-99cebffda9cd2d42edd6c1cbeceb994e6b320c5a.tar.bz2
util: Implement assume() for clang.
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Diffstat (limited to 'src/util/macros.h')
-rw-r--r--src/util/macros.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/util/macros.h b/src/util/macros.h
index da5daff..5fc6729 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(expr); \
+ __builtin_assume(expr); \
+} while (0)
+#elif defined HAVE___BUILTIN_UNREACHABLE
#define assume(expr) ((expr) ? ((void) 0) \
: (assert(!"assumption failed"), \
__builtin_unreachable()))