[Mesa-dev] [PATCH mesa] u_debug: do not compile asserts when they are disabled
Gert Wollny
gw.fossdev at gmail.com
Fri Dec 1 07:23:07 UTC 2017
There was actually some ping-pong about this issue:
d885c9dad (Keith Whitwell) introduced it,
7a2271c65 (José Fonseca) removed it , and
f0ba7d897 (Keith Whitwell) introduced it again.
Given this I would give some preference to not to forward standard
assert instead, but don't really see it as an issue to change
debug_assert.
With a31d289de6091 José Fonseca introduced p_debug.h which would
eventually become u_debug,h, and there assert is already channeled to
debug_assert, but it is not clear why it was seen as problematic to
used the standard C assert in 2008.
In any case:
Reviewed-By: Gert Wollny <gw.fossdev at gmail.com>
Am Donnerstag, den 30.11.2017, 12:16 +0000 schrieb Eric Engestrom:
> 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
> - 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
>
>
More information about the mesa-dev
mailing list