[Bug c/63445] New: request: make -Wstrict-overflow avoid a class of false positives
jim at meyering dot net
gcc-bugzilla@gcc.gnu.org
Thu Oct 2 20:08:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63445
Bug ID: 63445
Summary: request: make -Wstrict-overflow avoid a class of false
positives
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jim at meyering dot net
Thanks for tending and continually improving gcc.
I see some surprising new warnings when using built-from-git (an hour ago) gcc
to compile coreutils. Here is a reduced test case:
In this example, the code ensures "j - i" will be positive before assigning
that value to an unsigned int "n". Can gcc be taught to avoid this obvious
false positive?
$ cat f.c
int
f (int i, int j)
{
unsigned int c = 0;
if (i < j)
{
unsigned int n = j - i;
for (unsigned int i = 0; i < n; i++)
{
c++;
}
}
return c;
}
$ gcc -O2 -std=c99 -Wstrict-overflow -c f.c
f.c: In function ‘f’:
f.c:9:7: warning: assuming signed overflow does not occur when simplifying
conditional [-Wstrict-overflow]
for (unsigned int i = 0; i < n; i++)
^
$ gcc -v 2>&1|tail -2
gcc version 5.0.0 20141002 (experimental) (GCC)
More information about the Gcc-bugs
mailing list