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/55217] New: False -Wstrict-overflow warning


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);
}


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