This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
__builtin_expect (setjmp (buf) == 0, 1)) generates broken code
- From: "Ulrich Weigand" <Ulrich dot Weigand at de dot ibm dot com>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 19 Mar 2003 20:39:22 +0100
- Subject: __builtin_expect (setjmp (buf) == 0, 1)) generates broken code
- Sensitivity:
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