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]

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


Hello,

current glibc contains constructs like:

if (__builtin_expect (setjmp (buf) == 0, 1))
  func ();

On targets without setcc instructions (like s390), expand_expr generates
code for this statement that looks like this:

temp = 0;
if (setjmp (buf) == 0)
  temp = 1;

if (__builtin_expect (temp, 1))
  func (buf);

Reload then spills the temporary to the stack because setjmp is marked
as clobbering all caller-saved registers.

However, when this code is executed, the following happens: the first call
to setjmp returns 0, so temp is set to 1 on the stack.  Therefore, func
is called.  When func performs a longjmp (buf), control is transferred
back to the return of setjmp.  As the return value now is non-zero,
the 'temp = 1;' is not executed.  Unfortunately, the value of temp on
the stack *still* contains 1 from the first pass through, and so fnuc
is called again ...

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?


Mit freundlichen Gruessen / Best Regards

Ulrich Weigand

--
  Dr. Ulrich Weigand
  Linux for S/390 Design & Development
  IBM Deutschland Entwicklung GmbH, Schoenaicher Str. 220, 71032 Boeblingen
  Phone: +49-7031/16-3727   ---   Email: Ulrich dot Weigand at de dot ibm dot com


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