[Bug c/45649] New: -Wunsafe-loop-optimizations fail to recognize finite loop

dimhen at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Sep 11 17:49:00 GMT 2010


gcc version 4.6.0 20100911 (experimental) [trunk revision 164213] (GCC)

FAIL with up cycle bound 35 and PASS with 34.

# gcc -Wunsafe-loop-optimizations  -O3 -c unsafe_loop.c
unsafe_loop.c: In function ‘foo_35’:
unsafe_loop.c:14:5: warning: cannot optimize loop, the loop counter may
overflow [-Wunsafe-loop-optimizations]

# cat unsafe_loop.c
void
foo_34(char *ptr, unsigned size)
{
    unsigned i;
    for(i=0; i*2 < size && i*2 < 34; i++ ) {
        *ptr++ = 0;
    }
}

foo_35(char *ptr, unsigned size)
{
    unsigned i;
    for(i=0; i*2 < size && i*2 < 35; i++ ) {
        *ptr++ = 0;
    }
}


-- 
           Summary: -Wunsafe-loop-optimizations fail to recognize finite
                    loop
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dimhen at gmail dot com
 GCC build triplet: i686-redhat-linux
  GCC host triplet: i686-redhat-linux
GCC target triplet: i686-redhat-linux


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



More information about the Gcc-bugs mailing list