This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC/PATCH] Optimize code based on asserts even in NDEBUG mode
- From: Paul Brook <paul at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: "Dave Korn" <dk at artimi dot com>
- Date: Tue, 13 Apr 2004 12:13:03 +0100
- Subject: Re: [RFC/PATCH] Optimize code based on asserts even in NDEBUG mode
- Organization: CodeSourcery
- References: <NUTMEGRVgiyqt9lT1bj00000427@NUTMEG.CAM.ARTIMI.COM>
> > 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?
No. __builtin_expect says what the most likely value is. It does not indicate
that other values are impossible.
In the case above we would not be able to eliminate the null check, just
structure the code such that the fast path is taken when x != NULL.
Paul