This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: __builtin_expect (setjmp (buf) == 0, 1)) generates broken code
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Zack Weinberg <zack at codesourcery dot com>
- Cc: Geoff Keating <geoffk at geoffk dot org>, "Ulrich Weigand" <Ulrich dot Weigand at de dot ibm dot com>, gcc at gcc dot gnu dot org, Richard dot Earnshaw at arm dot com
- Date: Thu, 20 Mar 2003 11:15:44 +0000
- Subject: Re: __builtin_expect (setjmp (buf) == 0, 1)) generates broken code
- Organization: ARM Ltd.
- Reply-to: Richard dot Earnshaw at arm dot com
> Geoff Keating <geoffk at geoffk dot org> writes:
>
> >> The question is, what's broken here. Is this combination of setjmp
> >> with __builtin_expect valid in the first place? If so, how could
> >> this be fixed?
> >
> > Yes, it's invalid. The C standard is pretty clear on the places that
> > you can put setjmp, and this isn't one of them (see C99 7.13.1.1
> > paragraph 4), for exactly this sort of reason.
>
> I don't agree -- __builtin_expect is a special case, it should have no
> effect on code generation other than to tag the surrounding if
> construct with a probability estimate. Wherever we fail to achieve
> that, it's a bug.
Strictly speaking whether or not we want to support this is our choice.
C99 doesn't have __builtin_expect, so it can't say whether or not it is
safe to use it with setjmp. (another dark corner that we've invented for
ourselves :-)
I think I'm in agreement with Zack. __builtin_expect (expr, val) should
be semantically equivalent at all times to writing "expr" on its own. The
only difference is that the compiler may understand that the expression
expr will most likely have the result val at that point.
However, I really think that wrapping this is unnecessary. GCC should
know that setjmp will normally return zero without requiring the user to
annotate it.
R.