blob: 36e8b1d69947095cbd8fbdb86f1537d8ad836304 [file] [log] [blame]
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00001// RUN: clang-cc -verify -fsyntax-only %s &&
2// RUN: clang-cc -emit-llvm -o %t %s &&
3
4#include <stdlib.h>
5
6int no_vars __attribute((malloc)); // expected-warning {{only applies to function types}}
7
Ryan Flynne64ffc22009-08-09 22:36:29 +00008void returns_void (void) __attribute((malloc)); // expected-warning {{functions returning pointer type}}
9int returns_int (void) __attribute((malloc)); // expected-warning {{functions returning pointer type}}
Ted Kremenekf22c4102009-08-14 22:03:27 +000010int * returns_intptr(void) __attribute((malloc)); // no-warning
Ryan Flynne64ffc22009-08-09 22:36:29 +000011typedef int * iptr;
Ted Kremenekf22c4102009-08-14 22:03:27 +000012iptr returns_iptr (void) __attribute((malloc)); // no-warning
13
14__attribute((malloc)) void *(*f)(); // no-warning
Ryan Flynne64ffc22009-08-09 22:36:29 +000015
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000016__attribute((malloc))
Ted Kremenekf22c4102009-08-14 22:03:27 +000017void * xalloc(unsigned n) { return malloc(n); } // no-warning
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000018// RUN: grep 'define noalias .* @xalloc(' %t &&
19
Benjamin Kramerb3788a22009-08-11 22:46:25 +000020#define malloc_like __attribute((__malloc__))
21void * xalloc2(unsigned) malloc_like;
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000022void * xalloc2(unsigned n) { return malloc(n); }
23// RUN: grep 'define noalias .* @xalloc2(' %t
24