[Mesa-dev] [PATCH mesa 16/16] util: use NDEBUG to guard asserts

Eric Engestrom eric.engestrom at imgtec.com
Thu Nov 30 12:15:53 UTC 2017


On Tuesday, 2017-11-28 20:19:46 +0100, Gert Wollny wrote:
> Am Dienstag, den 28.11.2017, 10:53 +0000 schrieb Eric Engestrom:
> > 
> > > The parameters to a preprocessor macro are (basically) just
> > > text.  They are not evaluated until after the macro is
> > > expanded.  I'm 93.2% sure removing the guards around the assert()
> > > should be fine in this case.
> > 
> > 100% sure :)
> > look at /usr/include/assert.h:
> > 
> > #ifdef NDEBUG
> > #define assert(expr) ((void) (0))
> > #endif
> > 
> > The compiler doesn't even see the contents of `assert(foo)`, it's
> > gone by the time the pre-compiler has done its job.
> 
> 
> Unfortunately right now I had to learn the hard way that someone
> decided to override the standard assert macro in
> 
>   gallium/auxiliary/util/u_debug.h 
> 
> so that now it expands to debug_assert, which in turn expands to 
> 
>    #define debug_assert(expr) (void)(0 && (expr))

Oh wow, this is bad.

> 
> if NDEBUG is defined, which means all of "expr" must be known to the
> compiler. 
> 
> IMHO either the " && (expr)" part of that macro should be removed or

I just inspected all the callers, and luckily none of them have side
effects, so we can simply drop this and align the code with both its
comment just above and the general expectation. I'll send a patch for
this in a minute.

> assert should not be redefined if NDEBUG is given. 

asserts are part of the standard and should not be overridden like this
IMO, but that's a separate issue.
I'll send a separate patch for this, which I expect might get more
resistance than the one above.

Thanks for spotting this :)

> 
> Best, 
> Gert 
> 
> 


More information about the mesa-dev mailing list