Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 1 | // RUN: %clang -Xclang -verify -fsyntax-only %s |
| 2 | // RUN: %clang -emit-llvm -S -o %t %s |
Ryan Flynn | 76168e2 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 3 | |
Chandler Carruth | ba772ba | 2010-11-16 10:26:08 +0000 | [diff] [blame] | 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)); |
Ryan Flynn | 76168e2 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 8 | |
Ted Kremenek | 2cff7d1 | 2009-08-15 00:51:46 +0000 | [diff] [blame] | 9 | int no_vars __attribute((malloc)); // expected-warning {{functions returning a pointer type}} |
Ryan Flynn | 76168e2 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 10 | |
Ted Kremenek | 2cff7d1 | 2009-08-15 00:51:46 +0000 | [diff] [blame] | 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}} |
Ted Kremenek | b109069 | 2009-08-14 22:03:27 +0000 | [diff] [blame] | 13 | int * returns_intptr(void) __attribute((malloc)); // no-warning |
Ryan Flynn | fd6ad3c | 2009-08-09 22:36:29 +0000 | [diff] [blame] | 14 | typedef int * iptr; |
Ted Kremenek | b109069 | 2009-08-14 22:03:27 +0000 | [diff] [blame] | 15 | iptr returns_iptr (void) __attribute((malloc)); // no-warning |
| 16 | |
Ted Kremenek | 2cff7d1 | 2009-08-15 00:51:46 +0000 | [diff] [blame] | 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}} |
Ryan Flynn | fd6ad3c | 2009-08-09 22:36:29 +0000 | [diff] [blame] | 19 | |
Ryan Flynn | 76168e2 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 20 | __attribute((malloc)) |
Ted Kremenek | b109069 | 2009-08-14 22:03:27 +0000 | [diff] [blame] | 21 | void * xalloc(unsigned n) { return malloc(n); } // no-warning |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 22 | // RUN: grep 'define noalias .* @xalloc(' %t |
Ryan Flynn | 76168e2 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 23 | |
Benjamin Kramer | 73e10b0 | 2009-08-11 22:46:25 +0000 | [diff] [blame] | 24 | #define malloc_like __attribute((__malloc__)) |
| 25 | void * xalloc2(unsigned) malloc_like; |
Ryan Flynn | 76168e2 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 26 | void * xalloc2(unsigned n) { return malloc(n); } |
| 27 | // RUN: grep 'define noalias .* @xalloc2(' %t |
| 28 | |