[Bug rtl-optimization/41239] New: Scheduler reorders division by zero before a call that might not return
jakub at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Thu Sep 3 08:29:00 GMT 2009
This testcase distilled from postgresql fails at runtime on s390x-linux with
-O2 -march=z9-109 -mtune=z10:
/* { dg-do run } */
/* { dg-options "-O2" } */
/* { dg-options "-O2 -march=z9-109 -mtune=z10" { target s390x-linux } } */
struct S
{
short nargs;
unsigned long arg[2];
};
extern void abort (void);
extern void exit (int);
extern char errstart (int, const char *, int, const char *, const char *);
extern void errfinish (int, ...);
extern int errcode (int);
extern int errmsg (const char *fmt, ...) __attribute__ ((format (printf, 1,
2)));
unsigned long
test (struct S *x)
{
signed int arg1 = x->arg[0];
long int arg2 = x->arg[1];
if (arg2 == 0)
(errstart (20, "int8.c", 924, __func__, ((void *) 0))
? (errfinish (errcode (0x2040082), errmsg ("division by zero")))
: (void) 0);
return (long int) arg1 / arg2;
}
int
main (void)
{
struct S s = { 2, { 5, 0 } };
test (&s);
abort ();
}
__attribute__((noinline)) char
errstart (int x, const char *y, int z, const char *w, const char *v)
{
asm volatile ("" : "+r" (x) : "r" (y), "r" (z), "r" (w), "r" (v) : "memory");
return x;
}
__attribute__((noinline)) int
errcode (int x)
{
asm volatile ("" : "+r" (x) : : "memory");
return x;
}
__attribute__((noinline)) int
errmsg (const char *x, ...)
{
asm volatile ("" : "+r" (x) : : "memory");
return *x;
}
__attribute__((noinline)) void
errfinish (int x, ...)
{
asm volatile ("" : "+r" (x) : : "memory");
if (x)
/* Could be a longjmp or throw too. */
exit (0);
}
The problem is that 2nd scheduler pass reorders the division before some of the
calls. If the calls were guaranteed to return, that would be fine, the program
would crash sooner or later, but as shown in the testcase the call can not
return (exit, longjmp, throw) and in that case whether the division is
scheduled before or after the call matters.
--
Summary: Scheduler reorders division by zero before a call that
might not return
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jakub at gcc dot gnu dot org
GCC target triplet: s390x-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41239
More information about the Gcc-bugs
mailing list