[Bug middle-end/93582] New: -Warray-bounds gives error: array subscript 0 is outside array bounds of struct E[1]

mpolacek at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Feb 4 18:25:00 GMT 2020


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

            Bug ID: 93582
           Summary: -Warray-bounds gives error: array subscript 0 is
                    outside array bounds of struct E[1]
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

Reduced from libXt:

struct E {
} e;

struct A {
  unsigned long *l;
};

struct C {
  unsigned long *l;
} c;

void
bar (struct E *ep)
{
  c.l = ((struct A*) ((ep) + 1))->l;
}

void
f ()
{
  bar (&e);
}

$ ./cc1 -quiet -O3 x.c -Warray-bounds
x.c: In function ‘f’:
x.c:15:33: warning: array subscript 0 is outside array bounds of ‘struct E[1]’
[-Warray-bounds]
   15 |   c.l = ((struct A*) ((ep) + 1))->l;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~
x.c:2:3: note: while referencing ‘e’
    2 | } e;
      |   ^


More information about the Gcc-bugs mailing list