1  /* { dg-do compile } */
       2  /* { dg-options "-O2 -Warray-bounds" } */
       3  
       4  #include <string.h>
       5  #include <assert.h>
       6  #include <stdio.h>
       7  
       8  static inline __attribute__((__artificial__)) void *a(char *c, const char *d, long n)
       9  {
      10      return __builtin___memcpy_chk(c, d, n, __builtin_object_size(c, 0));
      11  }
      12  typedef struct {
      13      char *data;
      14      int len;
      15  } sb_t;
      16  const char __sb_slop[1];
      17  static void inline set0(sb_t *c)
      18  {
      19      if (c->data != __sb_slop)
      20          c->data[0] = 0;
      21      else
      22          assert (c->data[0] == 0);
      23  }
      24  char buf[5];
      25  sb_t l = {
      26      .data = buf,
      27      .len = 0
      28  };
      29  void o()
      30  {
      31      char *data = "abcd";
      32      sb_t h = l;
      33      set0(&h);
      34      a(h.data, data, strlen(data));
      35      printf("%s\n", h.data);
      36      printf("%d\n", h.data == __sb_slop);
      37      printf("%d\n", h.data == buf);
      38      set0(&h);
      39  }
      40  int main(void) {
      41      o();
      42      return 0;
      43  }