Following testcase distilled from x86_64 glibc clock_gettime.c is miscompiled
on the trunk since r128833.  CSE1 removes all the c's return value checks
and assumes it wasn't small negative value:

extern void abort (void);
int (*fnp) (int, void *);
unsigned long bar (int, void *);

int
foo (int x, void *y)
{
  long int b;
  int (*c) (int, void *) = fnp;
  if (c)
    {
      b = c (x, y);
      if ((unsigned long) b < -4095L)
        return b;
      if (-b != 38)
        goto lab;
    }
  unsigned long d = bar (x, y);
  b = (long) d;
  if ((unsigned long) b >= -4095L)
    {
    lab:
      b = -1L;
    }
  return b;
}

int
__attribute__((noinline))
baz (int x, void *y)
{
  return -x;
}

unsigned long
__attribute__((noinline))
bar (int x, void *y)
{
  if (x != 38)
    abort ();
  return 0;
}

int
main (void)
{
  fnp = baz;
  if (foo (39, 0) != -1)
    abort ();
  if (foo (38, 0) != 0)
    abort ();
  return 0;
}


-- 
           Summary: [4.3 Regression] r128833 causes miscompilation of glibc
                    clock_gettime.c
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at gcc dot gnu dot org
GCC target triplet: x86_64-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34490

Reply via email to