1 /* { dg-do run } */
2 /* { dg-shouldfail "ubsan" } */
3 /* { dg-options "-fsanitize=undefined -fno-sanitize-recover=undefined" } */
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 *
foo(void * p,void * q,void * r)10 foo (void *p, void *q, void *r)
11 {
12   a = p;
13   b = r;
14   return q;
15 }
16 
17 int
bar(const void * a,const void * b)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
main()26 main ()
27 {
28   asm volatile ("" : : : "memory");
29   d = foo (c, b, c);
30   e = foo (e, c, f);
31   g = foo (c, f, g);
32   __builtin_memset (d, '\0', q);
33   return 0;
34 }
35 
36 /* { dg-output "\.c:14:\[0-9]*:\[^\n\r]*null pointer returned from function declared to never return null" } */
37