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

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
I think the following test case reproduces what's going on in decNumber.c. 
Both GCC 8 and 9 issue the warning (IIRC, the warning was added in GCC 7 for
writes but enhanced to reads in GCC 8).

$ cat a.c && gcc -O3 -S -Wall -fdump-tree-optimized=/dev/stdout a.c
struct S
{
  int n, a[1];
};

static inline void f (int *d, const struct S *p)
{
  const int *e = p->n > 1 ? p->a + p->n : p->a + 1;

  for (const int *s = p->a + 1; s < e; ++s, ++d)
    *d = *s;
}

void g (struct S*);

void h (int *d)
{
  struct S s = { 0 };
  g (&s);
  f (d, &s);
}

;; Function h (h, funcdef_no=1, decl_uid=1920, cgraph_uid=2, symbol_order=1)

Removing basic block 6
Removing basic block 7
h (int * d)
{
  struct S s;
  int _6;
  long unsigned int _7;
  long unsigned int _8;
  const int * iftmp.0_9;
  unsigned long _15;
  unsigned long _16;
  sizetype _20;
  unsigned long _23;
  sizetype _24;
  unsigned long _25;
  unsigned long _26;

  <bb 2> [local count: 118111600]:
  s = {};
  g (&s);
  _6 = s.n;
  if (_6 > 1)
    goto <bb 3>; [59.00%]
  else
    goto <bb 5>; [41.00%]

  <bb 3> [local count: 69685844]:
  _7 = (long unsigned int) _6;
  _8 = _7 * 4;
  iftmp.0_9 = &s.a + _8;
  if (&MEM[(void *)&s + 8B] < iftmp.0_9)
    goto <bb 4>; [93.20%]
  else
    goto <bb 5>; [6.80%]

  <bb 4> [local count: 64949629]:
  _26 = (unsigned long) iftmp.0_9;
  _16 = (unsigned long) &MEM[(void *)&s + 8B];
  _15 = ~_16;
  _23 = _15 + _26;
  _25 = _23 >> 2;
  _24 = _25 + 1;
  _20 = _24 * 4;
  __builtin_memcpy (d_4(D), &MEM[(void *)&s + 8B], _20); [tail call]

  <bb 5> [local count: 118111601]:
  s ={v} {CLOBBER};
  return;

}


a.c: In function ‘h’:
cc1: warning: ‘__builtin_memcpy’ reading 4 or more bytes from a region of size
0 [-Wstringop-overflow=]

Reply via email to