(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
ubsan/
nonnull-5.c
       1  /* { dg-do run } */
       2  /* { dg-shouldfail "ubsan" } */
       3  /* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */
       4  
       5  int q, r;
       6  void *a, *b, *c = (void *) &q, *d, *e, *f = (void *) &q, *g, *h;
       7  
       8  __attribute__((returns_nonnull, nonnull (1, 3)))
       9  void *
      10  foo (void *p, void *q, void *r)
      11  {
      12    a = p;
      13    b = r;
      14    return q;
      15  }
      16  
      17  int
      18  bar (const void *a, const void *b)
      19  {
      20    int c = *(const int *) a;
      21    int d = *(const int *) b;
      22    return c - d;
      23  }
      24  
      25  int
      26  main ()
      27  {
      28    asm volatile ("" : : : "memory");
      29    d = foo (c, (void *) &r, c);
      30    e = foo (e, c, f);
      31    g = foo (c, f, g);
      32    __builtin_memset (d, '\0', q);
      33    return 0;
      34  }