This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/55217] New: False -Wstrict-overflow warning
- From: "mattiase at acm dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 05 Nov 2012 20:21:14 +0000
- Subject: [Bug c/55217] New: False -Wstrict-overflow warning
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55217
Bug #: 55217
Summary: False -Wstrict-overflow warning
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: mattiase@acm.org
This code yields a false -Wstrict-overflow warning in gcc 4.7.2:
void h(int *s);
void f(int n, int s)
{
int r = 1;
for (int i = 1; i < n; i++)
if (r)
r++;
if (r * s >= s + 3) // warning here
for (int j = 0; j < r; j++)
h(&s);
}
beta.c:8:12: warning: assuming signed overflow does not occur when assuming
that (X + c) < X is always false [-Wstrict-overflow]
The condition is not on the form X+c<X, and can legitimately go either way.
Here is a variant with s hard-wired to 0. The call to g() seems necessary:
void g(void);
void h(int *s);
void f(int n)
{
int s = 0;
int r = 1;
g();
for (int i = 1; i < n; i++)
if (r)
r++;
if (r * s >= s + 3) // warning here
for (int j = 0; j < r; j++)
h(&s);
}