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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
      Known to work|                            |7.3.0
           Keywords|                            |diagnostic
   Last reconfirmed|                            |2018-09-13
                 CC|                            |msebor at gcc dot gnu.org
     Ever confirmed|0                           |1
            Summary|-Wstringop-overflow false   |-Wstringop-overflow false
                   |positive                    |positive due to bogus
                   |                            |MEM_REF type
      Known to fail|                            |8.2.0, 9.0

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed with the simplified C test case below.  The warning sees a MEM_REF
(char[4], ...) as the destination of the strncpy call.  Why the type is char[4]
is a mystery to me.  I guess the type in MEM_REF really can't be trusted.


gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout pr87296.c 

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

g (struct S * p, const char * s)
{
  void * _1;
  char[4] * _2;

  <bb 2> [local count: 1073741824]:
  _1 = &MEM[(void *)p_3(D) + 4B];
  _2 = &p_3(D)->a;
  f (_2, _1);
  __builtin_strncpy (_1, s_6(D), 6); [tail call]
  return;

}


pr87296.c: In function ‘g’:
pr87296.c:11:3: warning: ‘__builtin_strncpy’ writing 6 bytes into a region of
size 4 overflows the destination [-Wstringop-overflow=]
11 |   __builtin_strncpy (p->b, s, sizeof p->b);
   |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to