blob: 6af15d2f682e6c3818a6cc7e164805622b8ba1f4 [file] [log] [blame]
Chandler Carruthb6531312014-01-15 09:08:07 +00001// RUN: %clang_cc1 -verify -fsyntax-only %s
2// RUN: %clang_cc1 -emit-llvm -o %t %s
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00003
Chandler Carruthb1928932010-11-16 10:26:08 +00004#include <stddef.h>
5
6// Declare malloc here explicitly so we don't depend on system headers.
7void * malloc(size_t) __attribute((malloc));
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00008
David Majnemer631a90b2015-02-04 07:23:21 +00009int no_vars __attribute((malloc)); // expected-warning {{attribute only applies to functions}}
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000010
David Majnemer631a90b2015-02-04 07:23:21 +000011void returns_void (void) __attribute((malloc)); // expected-warning {{attribute only applies to return values that are pointers}}
12int returns_int (void) __attribute((malloc)); // expected-warning {{attribute only applies to return values that are pointers}}
Ted Kremenekf22c4102009-08-14 22:03:27 +000013int * returns_intptr(void) __attribute((malloc)); // no-warning
Ryan Flynne64ffc22009-08-09 22:36:29 +000014typedef int * iptr;
Ted Kremenekf22c4102009-08-14 22:03:27 +000015iptr returns_iptr (void) __attribute((malloc)); // no-warning
16
David Majnemer631a90b2015-02-04 07:23:21 +000017__attribute((malloc)) void *(*f)(); // expected-warning{{attribute only applies to functions}}
18__attribute((malloc)) int (*g)(); // expected-warning{{attribute only applies to functions}}
Ryan Flynne64ffc22009-08-09 22:36:29 +000019
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000020__attribute((malloc))
Ted Kremenekf22c4102009-08-14 22:03:27 +000021void * xalloc(unsigned n) { return malloc(n); } // no-warning
David Blaikieea3e51d2015-06-29 17:29:50 +000022// RUN: grep 'define .*noalias .* @xalloc(' %t %t
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000023
Benjamin Kramerb3788a22009-08-11 22:46:25 +000024#define malloc_like __attribute((__malloc__))
25void * xalloc2(unsigned) malloc_like;
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000026void * xalloc2(unsigned n) { return malloc(n); }
David Blaikieea3e51d2015-06-29 17:29:50 +000027// RUN: grep 'define .*noalias .* @xalloc2(' %t %t
Ryan Flynn1f1fdc02009-08-09 20:07:29 +000028