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 {{attribute only applies to functions}} |
10 | |
11 | void returns_void (void) __attribute((malloc)); // expected-warning {{attribute only applies to return values that are pointers}} |
12 | int returns_int (void) __attribute((malloc)); // expected-warning {{attribute only applies to return values that are pointers}} |
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{{attribute only applies to functions}} |
18 | __attribute((malloc)) int (*g)(); // expected-warning{{attribute only applies to functions}} |
19 | |
20 | __attribute((malloc)) |
21 | void * xalloc(unsigned n) { return malloc(n); } // no-warning |
22 | // RUN: grep 'define .*noalias .* @xalloc(' %t %t |
23 | |
24 | #define malloc_like __attribute((__malloc__)) |
25 | void * xalloc2(unsigned) malloc_like; |
26 | void * xalloc2(unsigned n) { return malloc(n); } |
27 | // RUN: grep 'define .*noalias .* @xalloc2(' %t %t |
28 | |
29 | |