blob: 2cec84de496918f1ff957cf0e9b843c294370a52 [file] [log] [blame]
Daniel Dunbar5618e982009-12-15 22:01:24 +00001// RUN: %clang -Xclang -verify -fsyntax-only %s
2// RUN: %clang -emit-llvm -S -o %t %s
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00003
Chandler Carruthb1928932010-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 Flynn1f1fdc02009-08-09 20:07:29 +00008
Ted Kremenek08479ae2009-08-15 00:51:46 +00009int no_vars __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000010
Ted Kremenek08479ae2009-08-15 00:51:46 +000011void returns_void (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
12int returns_int (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
Ted Kremenekf22c4102009-08-14 22:03:27 +000013int * returns_intptr(void) __attribute((malloc)); // no-warning
Ryan Flynne64ffc22009-08-09 22:36:29 +000014typedef int * iptr;
Ted Kremenekf22c4102009-08-14 22:03:27 +000015iptr returns_iptr (void) __attribute((malloc)); // no-warning
16
Ted Kremenek08479ae2009-08-15 00:51:46 +000017__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 Flynne64ffc22009-08-09 22:36:29 +000019
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000020__attribute((malloc))
Ted Kremenekf22c4102009-08-14 22:03:27 +000021void * xalloc(unsigned n) { return malloc(n); } // no-warning
Daniel Dunbar8b576972009-11-08 01:45:36 +000022// RUN: grep 'define noalias .* @xalloc(' %t
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000023
Benjamin Kramerb3788a22009-08-11 22:46:25 +000024#define malloc_like __attribute((__malloc__))
25void * xalloc2(unsigned) malloc_like;
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000026void * xalloc2(unsigned n) { return malloc(n); }
27// RUN: grep 'define noalias .* @xalloc2(' %t
28