attr-malloc.c revision a4996b889ffe46f13e7f81d14a31bc22342ed368
1// 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 {{functions returning a pointer type}} 7 8void returns_void (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}} 9int returns_int (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}} 10int * returns_intptr(void) __attribute((malloc)); // no-warning 11typedef int * iptr; 12iptr returns_iptr (void) __attribute((malloc)); // no-warning 13 14__attribute((malloc)) void *(*f)(); // expected-warning{{'malloc' attribute only applies to functions returning a pointer type}} 15__attribute((malloc)) int (*g)(); // expected-warning{{'malloc' attribute only applies to functions returning a pointer type}} 16 17__attribute((malloc)) 18void * xalloc(unsigned n) { return malloc(n); } // no-warning 19// RUN: grep 'define noalias .* @xalloc(' %t 20 21#define malloc_like __attribute((__malloc__)) 22void * xalloc2(unsigned) malloc_like; 23void * xalloc2(unsigned n) { return malloc(n); } 24// RUN: grep 'define noalias .* @xalloc2(' %t 25 26