This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/30730] New: -Wunsafe-loop-optimizations gives too many warnings


$ cat > warning.c
#if 0
gcc-4.1.1 -c -Os warning.c -Wunsafe-loop-optimizations
exit 0
#endif

void foo(unsigned int n)
{
        while (n > 10)
                n -= 2;
}
^D

$ sh warning.c
warning.c: In function 'foo':
warning.c:8: warning: cannot optimize loop, the loop counter may overflow
warning.c:8: warning: cannot optimize loop, the loop counter may overflow
...

This warning seems to be wrong to me, or at least badly worded. Furthermore,
gcc should notice that the condition states "n >= 10", and n is decremented by
only 2 in each iteration, so the loop _will_ terminate. There won't be any
overflow.

It would also be nice if this warning were only printed once instead of 9
times.


-- 
           Summary: -Wunsafe-loop-optimizations gives too many warnings
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: roland dot illig at gmx dot de
 GCC build triplet: any
  GCC host triplet: any
GCC target triplet: any


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]