Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fsyntax-only %s |
| 2 | // RUN: %clang_cc1 -emit-llvm -o %t %s |
Ryan Flynn | 31af091 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 3 | |
Chandler Carruth | ec4c535 | 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 | 31af091 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 8 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 9 | int no_vars __attribute((malloc)); // expected-warning {{attribute only applies to functions}} |
Ryan Flynn | 31af091 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 10 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 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}} |
Ted Kremenek | 092f27a | 2009-08-14 22:03:27 +0000 | [diff] [blame] | 13 | int * returns_intptr(void) __attribute((malloc)); // no-warning |
Ryan Flynn | 6a7fda0 | 2009-08-09 22:36:29 +0000 | [diff] [blame] | 14 | typedef int * iptr; |
Ted Kremenek | 092f27a | 2009-08-14 22:03:27 +0000 | [diff] [blame] | 15 | iptr returns_iptr (void) __attribute((malloc)); // no-warning |
| 16 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 17 | __attribute((malloc)) void *(*f)(); // expected-warning{{attribute only applies to functions}} |
| 18 | __attribute((malloc)) int (*g)(); // expected-warning{{attribute only applies to functions}} |
Ryan Flynn | 6a7fda0 | 2009-08-09 22:36:29 +0000 | [diff] [blame] | 19 | |
Ryan Flynn | 31af091 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 20 | __attribute((malloc)) |
Ted Kremenek | 092f27a | 2009-08-14 22:03:27 +0000 | [diff] [blame] | 21 | void * xalloc(unsigned n) { return malloc(n); } // no-warning |
Daniel Dunbar | a4996b8 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 22 | // RUN: grep 'define noalias .* @xalloc(' %t |
Ryan Flynn | 31af091 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 23 | |
Benjamin Kramer | ccb24e8 | 2009-08-11 22:46:25 +0000 | [diff] [blame] | 24 | #define malloc_like __attribute((__malloc__)) |
| 25 | void * xalloc2(unsigned) malloc_like; |
Ryan Flynn | 31af091 | 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 | |