view gcc/testsuite/c-c++-common/Warray-bounds-5.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children
line wrap: on
line source

/* Exercise that -Warray-bounds is handled correctly for subobjects.
   Test case derived from the halt_fast_timekeeper function in Linux
   kernel/time/timekeeping.c.
   { dg-do compile }
   { dg-options "-O2 -Warray-bounds=2 -Wno-stringop-overflow -ftrack-macro-expansion=0" }  */

struct A
{
  int i;
  void *p;
  int j;
};

struct B
{
  struct A a;

  int i;
};

void sink (void*);

static void halt_fast_timekeeper (struct B *b)
{
  static struct A a;

  struct A *pa = &b->a;

  __builtin_memcpy (&a, pa, sizeof *pa);   /* { dg-bogus "\\\[-Warray-bounds" } */
  sink (&a);
}

struct C { int i; struct B b; } c;

void timekeeping_suspend (void)
{
  struct B *p = &c.b;

  halt_fast_timekeeper (p);
}