attr-malloc.c revision 917a5538f40618cf7a626cb2d3c9e96557bf1b1e
1// RUN: clang -Xclang -verify -fsyntax-only %s 2// RUN: clang -emit-llvm -S -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