https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69224

            Bug ID: 69224
           Summary: -Warray-bounds false positive with -O3 and struct
                    pointer parameter
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nightstrike at gmail dot com
  Target Milestone: ---

There are a lot of -Warray-bounds false positives at -O3, but this one is
interesting:

struct S {
        int a;
        int b;
        int c;
        int d;
        int e;
        float x[5];
        float y[5];      // Comment these two lines out to
        float z[5 - 1];  // remove the warning
};
void f(struct S *s, float a[], float **b, float c[]) {
        if ((s->b == 1) && (s->d > 0)) {
                for (int i = 0; i < s->a; i++) {
                        if (a[i] != 0.0) {
                                for (int j = 0; j < s->d - 1; j++) {
                                        if ((c[i] >= s->x[j]) && (c[i] <=
s->x[j + 1])) {
                                                b[2*j][i] = s->x[j];
                                                break;
                                        }
                                }
                        }
                }
        }
}



If you comment out those two variables in the struct, both of which are unused,
then the warning goes away.

Note that in this particular case, since the loop boundary is passed in at run
time, there's no way for the compiler to ever know if we are exceeding the
array bounds.

I've included a few of the other -Warray-bounds bugs in the See Also lists in
the hopes that maybe some of these would be related.

Reply via email to