[Mesa-dev] [PATCH 1/2] util: Add assume() macro.

Kenneth Graunke kenneth at whitecape.org
Thu Oct 2 13:58:25 PDT 2014


On Tuesday, September 30, 2014 04:24:39 PM Matt Turner wrote:
> ---
>  src/util/macros.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/src/util/macros.h b/src/util/macros.h
> index 40ebf02..77055e8 100644
> --- a/src/util/macros.h
> +++ b/src/util/macros.h
> @@ -75,6 +75,19 @@ 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
> 

This doesn't work.  I think the precedence rules are biting you here.

+#define assume(expr) ((expr) ? ((void) 0) \
+                             : (assert(!"assumption failed"), \
+                                __builtin_unreachable()))

fixes your second patch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20141002/eed63983/attachment.sig>


More information about the mesa-dev mailing list