util: Add assume() macro.
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
@@ -75,6 +75,20 @@ do { \
|
|||||||
#define unreachable(str)
|
#define unreachable(str)
|
||||||
#endif
|
#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
|
#ifdef HAVE_FUNC_ATTRIBUTE_FLATTEN
|
||||||
#define FLATTEN __attribute__((__flatten__))
|
#define FLATTEN __attribute__((__flatten__))
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user