attr-malloc.c revision b109069995b44f3ef182bcd1b02ad05e9ea9d21d
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 {{only applies to function types}} 7 8void returns_void (void) __attribute((malloc)); // expected-warning {{functions returning pointer type}} 9int returns_int (void) __attribute((malloc)); // expected-warning {{functions returning 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)(); // no-warning 15 16__attribute((malloc)) 17void * xalloc(unsigned n) { return malloc(n); } // no-warning 18// RUN: grep 'define noalias .* @xalloc(' %t && 19 20#define malloc_like __attribute((__malloc__)) 21void * xalloc2(unsigned) malloc_like; 22void * xalloc2(unsigned n) { return malloc(n); } 23// RUN: grep 'define noalias .* @xalloc2(' %t 24 25