blob: 6483ffc4c1a65d7239680beaf4535ff049169b49 [file] [log] [blame]
Daniel Dunbar8ee15dc2009-11-17 10:14:55 +00001// RUN: clang -Xclang -verify -fsyntax-only %s
2// RUN: clang -emit-llvm -S -o %t %s
Ryan Flynn76168e22009-08-09 20:07:29 +00003
4#include <stdlib.h>
5
Ted Kremenek2cff7d12009-08-15 00:51:46 +00006int no_vars __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
Ryan Flynn76168e22009-08-09 20:07:29 +00007
Ted Kremenek2cff7d12009-08-15 00:51:46 +00008void 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}}
Ted Kremenekb1090692009-08-14 22:03:27 +000010int * returns_intptr(void) __attribute((malloc)); // no-warning
Ryan Flynnfd6ad3c2009-08-09 22:36:29 +000011typedef int * iptr;
Ted Kremenekb1090692009-08-14 22:03:27 +000012iptr returns_iptr (void) __attribute((malloc)); // no-warning
13
Ted Kremenek2cff7d12009-08-15 00:51:46 +000014__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}}
Ryan Flynnfd6ad3c2009-08-09 22:36:29 +000016
Ryan Flynn76168e22009-08-09 20:07:29 +000017__attribute((malloc))
Ted Kremenekb1090692009-08-14 22:03:27 +000018void * xalloc(unsigned n) { return malloc(n); } // no-warning
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000019// RUN: grep 'define noalias .* @xalloc(' %t
Ryan Flynn76168e22009-08-09 20:07:29 +000020
Benjamin Kramer73e10b02009-08-11 22:46:25 +000021#define malloc_like __attribute((__malloc__))
22void * xalloc2(unsigned) malloc_like;
Ryan Flynn76168e22009-08-09 20:07:29 +000023void * xalloc2(unsigned n) { return malloc(n); }
24// RUN: grep 'define noalias .* @xalloc2(' %t
25