[Bug tree-optimization/53265] Warn when undefined behavior implies smaller iteration count

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Mar 12 11:30:00 GMT 2013


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

--- Comment #16 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-03-12 11:30:02 UTC ---
First issue is (with -Werror -O2) error on attribs.c.  Reduced testcase:
const void *a, *b, *c, *d, *e;
const void *f[4];
void
foo (void)
{
  unsigned long i;
  f[0] = a; f[1] = b; f[2] = c; f[3] = d;
  for (i = 0; i < (sizeof (f) / sizeof (f[0])); i++)
    if (f[i] == __null)
      f[i] = e;
}

In function ‘void foo()’:
cc1plus: warning: iteration 3ul invokes undefined behavior
[-Waggressive-loop-optimizations]
/tmp/attribs.ii:8:3: note: containing loop
   for (i = 0; i < (sizeof (f) / sizeof (f[0])); i++)
   ^

We'd better not have false positives on testcases as simple as this.



More information about the Gcc-bugs mailing list