[Bug tree-optimization/91830] [10 Regression] Bogus -Warray-bounds on strcpy into a member of a subobject compiling binutils

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Sep 20 16:55:00 GMT 2019


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
   Target Milestone|---                         |10.0
            Summary|Bogus -Warray-bounds        |[10 Regression] Bogus
                   |warning compiling binutils  |-Warray-bounds on strcpy
                   |                            |into a member of a
                   |                            |subobject compiling
                   |                            |binutils

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
Reduced test case.  The warning code uses the MEM_REF type, or struct A here,
to validate the access to B::A::a at offset 4, without adjusting the offset by
that of B::a (or rather, the offset of B::A::a from B).

$ cat pr91830.c && gcc -O2 -S -Wall -fdump-tree-wrestrict=/dev/stdout pr91830.c
struct A { char a[3]; int i; };
struct B { int j; struct A a; };

void g (struct B *p, const char *s)
{
  struct A *q = &p->a;
  __builtin_strcpy (q->a, s);
}

;; Function g (g, funcdef_no=0, decl_uid=1931, cgraph_uid=1, symbol_order=0)

pr91830.c: In function ‘g’:
pr91830.c:7:3: warning: ‘__builtin_strcpy’ offset 4 from the object at ‘p’ is
out of the bounds of referenced subobject ‘a’ with type ‘char[3]’ at offset 0
[-Warray-bounds]
    7 |   __builtin_strcpy (q->a, s);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~
pr91830.c:1:17: note: subobject ‘a’ declared here
    1 | struct A { char a[3]; int i; };
      |                 ^
g (struct B * p, const char * s)
{
  char[3] * _1;

  <bb 2> [local count: 1073741824]:
  _1 = &MEM[(struct A *)p_2(D) + 4B].a;
  __builtin_strcpy (_1, s_4(D));
  return;
}


More information about the Gcc-bugs mailing list