Mesa (master): util: Add assume() macro.
Matt Turner
mattst88 at kemper.freedesktop.org
Thu Oct 23 23:19:00 UTC 2014
Module: Mesa
Branch: master
Commit: 2695891088d5b910edd9ec4d3ad81f0e3469205c
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=2695891088d5b910edd9ec4d3ad81f0e3469205c
Author: Matt Turner <mattst88 at gmail.com>
Date: Tue Sep 30 16:24:39 2014 -0700
util: Add assume() macro.
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/util/macros.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/util/macros.h b/src/util/macros.h
index 40ebf02..ff37a7d 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -75,6 +75,20 @@ do { \
#define unreachable(str)
#endif
+/**
+ * Assume macro. Useful for expressing our assumptions to the compiler,
+ * typically for purposes of silencing warnings.
+ */
+#ifdef HAVE___BUILTIN_UNREACHABLE
+#define assume(expr) ((expr) ? ((void) 0) \
+ : (assert(!"assumption failed"), \
+ __builtin_unreachable()))
+#elif _MSC_VER >= 1200
+#define assume(expr) __assume(expr)
+#else
+#define assume(expr) assert(expr)
+#endif
+
#ifdef HAVE_FUNC_ATTRIBUTE_FLATTEN
#define FLATTEN __attribute__((__flatten__))
#else
More information about the mesa-commit
mailing list