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

            Bug ID: 82585
           Summary: missing -Warray-bounds calling strlen on a member at
                    out-of-bounds offfset
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The following test case should trigger two instances of -Warray-bounds, one in
each function, but it only triggers one.

$ cat a.c && gcc -O2 -S -Wall -Warray-bounds a.c 
struct A { char a[3]; int i; };

extern char a[3];

int f1 (void)
{
  return __builtin_strlen (a + 4);   // -Warray-bounds (good)
}

int f2 (struct A *p)
{
  return __builtin_strlen (p->a + 4);   // missing -Warray-bounds
}

a.c: In function ‘f1’:
a.c:7:10: warning: array subscript is above array bounds [-Warray-bounds]
   return __builtin_strlen (a + 4);   // -Warray-bounds (good)
          ^~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to