attr-malloc.c revision ba772ba69ba0661f059f49c58395f870eb5c4df3
1// RUN: %clang -Xclang -verify -fsyntax-only %s 2// RUN: %clang -emit-llvm -S -o %t %s 3 4#include <stddef.h> 5 6// Declare malloc here explicitly so we don't depend on system headers. 7void * malloc(size_t) __attribute((malloc)); 8 9int no_vars __attribute((malloc)); // expected-warning {{functions returning a pointer type}} 10 11void 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}} 13int * returns_intptr(void) __attribute((malloc)); // no-warning 14typedef int * iptr; 15iptr returns_iptr (void) __attribute((malloc)); // no-warning 16 17__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}} 19 20__attribute((malloc)) 21void * xalloc(unsigned n) { return malloc(n); } // no-warning 22// RUN: grep 'define noalias .* @xalloc(' %t 23 24#define malloc_like __attribute((__malloc__)) 25void * xalloc2(unsigned) malloc_like; 26void * xalloc2(unsigned n) { return malloc(n); } 27// RUN: grep 'define noalias .* @xalloc2(' %t 28 29