aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatt Turner <[email protected]>2014-09-30 16:24:39 -0700
committerMatt Turner <[email protected]>2014-10-23 16:20:07 -0700
commit2695891088d5b910edd9ec4d3ad81f0e3469205c (patch)
treea22f1620f273283aa39cff284d601c479598cd8b /src
parentbbe93161e7781c303de7d83bc601601f675b56f9 (diff)
util: Add assume() macro.
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/util/macros.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/macros.h b/src/util/macros.h
index 40ebf02da84..ff37a7d63e6 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