1 // RUN: %clang_cc1 -verify -fsyntax-only %s
2 // RUN: %clang_cc1 -emit-llvm -o %t %s
3 
4 #include <stddef.h>
5 
6 // Declare malloc here explicitly so we don't depend on system headers.
7 void * malloc(size_t) __attribute((malloc));
8 
9 int no_vars __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
10 
11 void  returns_void  (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
12 int   returns_int   (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
13 int * returns_intptr(void) __attribute((malloc)); // no-warning
14 typedef int * iptr;
15 iptr  returns_iptr  (void) __attribute((malloc)); // no-warning
16 
17 __attribute((malloc)) void *(*f)(); //  expected-warning{{'malloc' attribute only applies to functions returning a pointer type}}
18 __attribute((malloc)) int (*g)(); // expected-warning{{'malloc' attribute only applies to functions returning a pointer type}}
19 
20 __attribute((malloc))
xalloc(unsigned n)21 void * xalloc(unsigned n) { return malloc(n); } // no-warning
22 // RUN: grep 'define noalias .* @xalloc(' %t
23 
24 #define malloc_like __attribute((__malloc__))
25 void * xalloc2(unsigned) malloc_like;
xalloc2(unsigned n)26 void * xalloc2(unsigned n) { return malloc(n); }
27 // RUN: grep 'define noalias .* @xalloc2(' %t
28 
29