blob: 5351d757a23f4d553bcbe71d2571d01b00f11313 [file] [log] [blame]
Stephen Hines651f13c2014-04-23 16:59:28 -07001// RUN: %clang_cc1 -verify -fsyntax-only %s
2// RUN: %clang_cc1 -emit-llvm -o %t %s
Ryan Flynn31af0912009-08-09 20:07:29 +00003
Chandler Carruthec4c5352010-11-16 10:26:08 +00004#include <stddef.h>
5
6// Declare malloc here explicitly so we don't depend on system headers.
7void * malloc(size_t) __attribute((malloc));
Ryan Flynn31af0912009-08-09 20:07:29 +00008
Stephen Hines0e2c34f2015-03-23 12:09:02 -07009int no_vars __attribute((malloc)); // expected-warning {{attribute only applies to functions}}
Ryan Flynn31af0912009-08-09 20:07:29 +000010
Stephen Hines0e2c34f2015-03-23 12:09:02 -070011void returns_void (void) __attribute((malloc)); // expected-warning {{attribute only applies to return values that are pointers}}
12int returns_int (void) __attribute((malloc)); // expected-warning {{attribute only applies to return values that are pointers}}
Ted Kremenek092f27a2009-08-14 22:03:27 +000013int * returns_intptr(void) __attribute((malloc)); // no-warning
Ryan Flynn6a7fda02009-08-09 22:36:29 +000014typedef int * iptr;
Ted Kremenek092f27a2009-08-14 22:03:27 +000015iptr returns_iptr (void) __attribute((malloc)); // no-warning
16
Stephen Hines0e2c34f2015-03-23 12:09:02 -070017__attribute((malloc)) void *(*f)(); // expected-warning{{attribute only applies to functions}}
18__attribute((malloc)) int (*g)(); // expected-warning{{attribute only applies to functions}}
Ryan Flynn6a7fda02009-08-09 22:36:29 +000019
Ryan Flynn31af0912009-08-09 20:07:29 +000020__attribute((malloc))
Ted Kremenek092f27a2009-08-14 22:03:27 +000021void * xalloc(unsigned n) { return malloc(n); } // no-warning
Daniel Dunbara4996b82009-11-08 01:45:36 +000022// RUN: grep 'define noalias .* @xalloc(' %t
Ryan Flynn31af0912009-08-09 20:07:29 +000023
Benjamin Kramerccb24e82009-08-11 22:46:25 +000024#define malloc_like __attribute((__malloc__))
25void * xalloc2(unsigned) malloc_like;
Ryan Flynn31af0912009-08-09 20:07:29 +000026void * xalloc2(unsigned n) { return malloc(n); }
27// RUN: grep 'define noalias .* @xalloc2(' %t
28