This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: __builtin_expect (setjmp (buf) == 0, 1)) generates broken code


> 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]