Ryan Flynn | 1f1fdc0 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -verify -fsyntax-only %s && |
| 2 | // RUN: clang-cc -emit-llvm -o %t %s && |
| 3 | |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | int no_vars __attribute((malloc)); // expected-warning {{only applies to function types}} |
| 7 | |
Ryan Flynn | e64ffc2 | 2009-08-09 22:36:29 +0000 | [diff] [blame] | 8 | void returns_void (void) __attribute((malloc)); // expected-warning {{functions returning pointer type}} |
| 9 | int returns_int (void) __attribute((malloc)); // expected-warning {{functions returning pointer type}} |
Ted Kremenek | f22c410 | 2009-08-14 22:03:27 +0000 | [diff] [blame^] | 10 | int * returns_intptr(void) __attribute((malloc)); // no-warning |
Ryan Flynn | e64ffc2 | 2009-08-09 22:36:29 +0000 | [diff] [blame] | 11 | typedef int * iptr; |
Ted Kremenek | f22c410 | 2009-08-14 22:03:27 +0000 | [diff] [blame^] | 12 | iptr returns_iptr (void) __attribute((malloc)); // no-warning |
| 13 | |
| 14 | __attribute((malloc)) void *(*f)(); // no-warning |
Ryan Flynn | e64ffc2 | 2009-08-09 22:36:29 +0000 | [diff] [blame] | 15 | |
Ryan Flynn | 1f1fdc0 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 16 | __attribute((malloc)) |
Ted Kremenek | f22c410 | 2009-08-14 22:03:27 +0000 | [diff] [blame^] | 17 | void * xalloc(unsigned n) { return malloc(n); } // no-warning |
Ryan Flynn | 1f1fdc0 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 18 | // RUN: grep 'define noalias .* @xalloc(' %t && |
| 19 | |
Benjamin Kramer | b3788a2 | 2009-08-11 22:46:25 +0000 | [diff] [blame] | 20 | #define malloc_like __attribute((__malloc__)) |
| 21 | void * xalloc2(unsigned) malloc_like; |
Ryan Flynn | 1f1fdc0 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 22 | void * xalloc2(unsigned n) { return malloc(n); } |
| 23 | // RUN: grep 'define noalias .* @xalloc2(' %t |
| 24 | |