[Bug c/56281] New: missed VRP optimization from undefined left shift in ISO C99

vincent-gcc at vinc17 dot net gcc-bugzilla@gcc.gnu.org
Mon Feb 11 00:56:00 GMT 2013


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

             Bug #: 56281
           Summary: missed VRP optimization from undefined left shift in
                    ISO C99
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vincent-gcc@vinc17.net


It seems that GCC is unaware that a left shift is undefined in ISO C99 when it
yields an integer overflow. See the following testcase with -O3 -std=c99:

int foo (int i)
{
  if (i < 0)
    i = -i;
  i *= 2;
  if (i < 0)
    i++;
  return i;
}

int bar (int i)
{
  if (i < 0)
    i = -i;
  i <<= 1;
  if (i < 0)
    i++;
  return i;
}

GCC optimizes foo() at the .065t.vrp1 step, but not bar().



More information about the Gcc-bugs mailing list