[RFC/PATCH] Optimize code based on asserts even in NDEBUG mode

Dave Korn dk@artimi.com
Tue Apr 13 10:54:00 GMT 2004


> -----Original Message-----
> From: gcc-patches-owner On Behalf Of Richard Guenther
> Sent: 09 April 2004 13:04

> Paolo wrote:
>  > Is this crap?
> 
> I asked for a feature like this before, and I like the feature.  But 
> there are problems with your implementation (as others pointed out). 
> First to just check for const and noreturn function attribute 
> is asking 
> for trouble (as you're doing an invalid transformation).
> 
> Better invent a __builtin_assert() , or even a __builtin_gcc_assert() 
> which could have different semantics than C89 assert().
> 
> The whole point is to invent something that gcc can safely assume a 
> condition is true (or false) at the very end of optimization, so the 
> conditional check can be removed, i.e.
> 
> int f(char *x) {
>    if (__builtin_this_is_false(!(x != NULL)))
>      abort();
>    return x ? *x : 0;
> }
> 
> this may have other uses than a (broken) assert optimization.
> 
> Of course, if in this case x _is_ actually NULL, we create 
> wrong code, 
> but we were asked for this.


  Isn't this what __builtin_expect is for?  Can't anyone who wan't this
functionality just define their own variant assert macro that combines
assert with expect?


    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....



More information about the Gcc-patches mailing list