[Bug tree-optimization/95353] [10/11 Regression] GCC can't build binutils

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed May 27 15:15:54 GMT 2020


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |88443
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning is due to a limitation of the compute_objsize() function.  A small
"supported" test case (one that doesn't depend on a trailing array of non-zero
size being treated as a flexible array member) that I think reproduces the
Binutils warning is below.  In this case the function doesn't work hard enough
to determine that the pointer points to a trailing array member and instead
uses the the array's actual size.  It needs to be improved or preferably
rewritten as discussed in pr94335 comment 7.

As suggested, using a flexible array member instead of the one-element (or
zero-length) array avoids the warning.

$ cat z.c && gcc -O2 -S -Wall -fdump-tree-strlen=/dev/stdout z.c
struct S {
  char n, a[0];
};


void f (struct S *p)
{
  char *q = p->a;
  q[1] = 1;    // no warning
}

void g (struct S *p, int i)
{
  char *q = p->a + i;
  q[1] = 1;    // spurious -Wstringop-overflow
}

;; Function f (f, funcdef_no=0, decl_uid=1933, cgraph_uid=1, symbol_order=0)

;; 1 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 2
;; 2 succs { 1 }
f (struct S * p)
{
  <bb 2> [local count: 1073741824]:
  MEM[(char *)p_1(D) + 2B] = 1;
  return;

}



;; Function g (g, funcdef_no=1, decl_uid=1938, cgraph_uid=2, symbol_order=1)

;; 1 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 2
;; 2 succs { 1 }
z.c: In function ‘g’:
z.c:15:8: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
   15 |   q[1] = 1;    // spurious -Wstringop-overflow
      |   ~~~~~^~~
g (struct S * p, int i)
{
  char * q;
  char[0:] * _1;
  sizetype _2;

  <bb 2> [local count: 1073741824]:
  _1 = &p_3(D)->a;             <<< doesn't consider that a is a trailing array
  _2 = (sizetype) i_4(D);
  q_5 = _1 + _2;              
  MEM[(char *)q_5 + 1B] = 1;   <<< warning here
  return;

}


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443
[Bug 88443] [meta-bug] bogus/missing -Wstringop-overflow warnings


More information about the Gcc-bugs mailing list