[Mesa-dev] [PATCH mesa] u_debug: do not compile asserts when they are disabled

Pekka Paalanen ppaalanen at gmail.com
Fri Dec 1 10:03:18 UTC 2017


On Thu, 30 Nov 2017 12:16:06 +0000
Eric Engestrom <eric.engestrom at imgtec.com> wrote:

> Commit f0ba7d897d1c22202531a added this code to expose asserts to the
> compiler in an attempt to hide 'unused variable' warnings, incorrectly
> claiming it was a no-op. This has two bad effects:
> - any assert with side-effects are executed when they should be
>   disabled

Hi,

I believe that is not true. Your patch has:

> -#define debug_assert(expr) (void)(0 && (expr))

which, as I understand, means that (expr) is never evaluated because
the 0 short-circuits the && operator.


Thanks,
pq


> - the whole content of the assert must be understandable by the
>   compiler, which isn't true if variable or members are correctly
>   guarded by NDEBUG
> 
> Fix this by effectively reverting f0ba7d897d1c22202531a.
> 
> Unused variables warnings can be addressed by marking the variables as
> MAYBE_UNUSED instead, as is done in the rest of Mesa.
> 
> Fixes: f0ba7d897d1c22202531a "util: better fix for unused variable
>        warnings with asserts"
> Cc: Keith Whitwell <keithw at vmware.com>
> Reported-by: Gert Wollny <gw.fossdev at gmail.com>
> Signed-off-by: Eric Engestrom <eric.engestrom at imgtec.com>
> ---
>  src/gallium/auxiliary/util/u_debug.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h
> index d2ea89f59c10e1bc0944..88e9bb8a29d63826167e 100644
> --- a/src/gallium/auxiliary/util/u_debug.h
> +++ b/src/gallium/auxiliary/util/u_debug.h
> @@ -188,7 +188,7 @@ void _debug_assert_fail(const char *expr,
>  #ifndef NDEBUG
>  #define debug_assert(expr) ((expr) ? (void)0 : _debug_assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__))
>  #else
> -#define debug_assert(expr) (void)(0 && (expr))
> +#define debug_assert(expr) ((void)0)
>  #endif
>  
>  

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20171201/3f275a8f/attachment-0001.sig>


More information about the mesa-dev mailing list