aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/nonnull-5.c
blob: fefbdc3b4ca564513941a998a08b762e0a5a4d15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* { dg-do run } */
/* { dg-shouldfail "ubsan" } */
/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */

int q, r;
void *a, *b, *c = (void *) &q, *d, *e, *f = (void *) &q, *g, *h;

__attribute__((returns_nonnull, nonnull (1, 3)))
void *
foo (void *p, void *q, void *r)
{
  a = p;
  b = r;
  return q;
}

int
bar (const void *a, const void *b)
{
  int c = *(const int *) a;
  int d = *(const int *) b;
  return c - d;
}

int
main ()
{
  asm volatile ("" : : : "memory");
  d = foo (c, (void *) &r, c);
  e = foo (e, c, f);
  g = foo (c, f, g);
  __builtin_memset (d, '\0', q);
  return 0;
}