Compile this with -O2 -W -Wall and you should not get a warning but you get an
overflow warning which is a false positive as this condition can never be false
even with overflow (as shown by doing -Dint=unsigned):
int bar(int);

int f(int x)
{
  int y;
  if (x<=4)  y = 1;
  else y = x/4;
  return y <=  0;
}

---------------- CUT -------------------
t.c: In function 'f':
t.c:8: warning: assuming signed overflow does not occur when simplifying
conditional to constant

How can x/4 cause an overflow when x>4 and never negative?

Also when I do -Dint=unsigned or even -fwrapv, VRP still is able to say y is
always greater than 0.


-- 
           Summary: [4.3 Regression] False overflow warning with division
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org


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

Reply via email to