view gcc/testsuite/gcc.dg/Warray-bounds-27.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
line wrap: on
line source

/* { dg-do compile }
   { dg-options "-O2 -Wall -Wextra -Warray-bounds -Wrestrict" } */

typedef __SIZE_TYPE__ size_t;

extern void* memcpy (void* restrict, const void* restrict, size_t);

extern void sink (void*, ...);

struct Data {
  size_t n;
  void *p;
};

void test_copy (void)
{
  struct Data d;
  sink (&d);

  char dp1[sizeof d + 1];
  char d2x[2 * sizeof d];
  char d2xp1[2 * sizeof d + 1];

  /* During development the following would incorrectly trigger:
     warning: 'memcpy' forming offset [17, 25] is out of the bounds [0, 16]
	      of object ā€˜dā€™ with type 'struct Data' [-Warray-bounds]
     that wasn't caught by the test suite.  Make sure it is.  */
  memcpy (&dp1, d.p, sizeof dp1);       /* { dg-bogus "\\\[-Warray-bounds" } */

  /* Likewise.  */
  memcpy (&d2x, d.p, sizeof d2x);       /* { dg-bogus "\\\[-Warray-bounds" } */
  memcpy (&d2xp1, d.p, sizeof d2xp1);   /* { dg-bogus "\\\[-Warray-bounds" } */

  sink (&d, &dp1, &d2x, &d2xp1);
}