2014-01-15 09:08:07 +00:00
|
|
|
// RUN: %clang_cc1 -verify -fsyntax-only %s
|
|
|
|
// RUN: %clang_cc1 -emit-llvm -o %t %s
|
2009-08-09 20:07:29 +00:00
|
|
|
|
2010-11-16 10:26:08 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
// Declare malloc here explicitly so we don't depend on system headers.
|
|
|
|
void * malloc(size_t) __attribute((malloc));
|
2009-08-09 20:07:29 +00:00
|
|
|
|
2015-02-04 07:23:21 +00:00
|
|
|
int no_vars __attribute((malloc)); // expected-warning {{attribute only applies to functions}}
|
2009-08-09 20:07:29 +00:00
|
|
|
|
2015-02-04 07:23:21 +00:00
|
|
|
void returns_void (void) __attribute((malloc)); // expected-warning {{attribute only applies to return values that are pointers}}
|
|
|
|
int returns_int (void) __attribute((malloc)); // expected-warning {{attribute only applies to return values that are pointers}}
|
2009-08-14 22:03:27 +00:00
|
|
|
int * returns_intptr(void) __attribute((malloc)); // no-warning
|
2009-08-09 22:36:29 +00:00
|
|
|
typedef int * iptr;
|
2009-08-14 22:03:27 +00:00
|
|
|
iptr returns_iptr (void) __attribute((malloc)); // no-warning
|
|
|
|
|
2022-02-03 16:39:21 -05:00
|
|
|
__attribute((malloc)) void *(*f)(void); // expected-warning{{attribute only applies to functions}}
|
|
|
|
__attribute((malloc)) int (*g)(void); // expected-warning{{attribute only applies to functions}}
|
2009-08-09 22:36:29 +00:00
|
|
|
|
2009-08-09 20:07:29 +00:00
|
|
|
__attribute((malloc))
|
2009-08-14 22:03:27 +00:00
|
|
|
void * xalloc(unsigned n) { return malloc(n); } // no-warning
|
2015-06-29 17:29:50 +00:00
|
|
|
// RUN: grep 'define .*noalias .* @xalloc(' %t %t
|
2009-08-09 20:07:29 +00:00
|
|
|
|
2009-08-11 22:46:25 +00:00
|
|
|
#define malloc_like __attribute((__malloc__))
|
|
|
|
void * xalloc2(unsigned) malloc_like;
|
2009-08-09 20:07:29 +00:00
|
|
|
void * xalloc2(unsigned n) { return malloc(n); }
|
2015-06-29 17:29:50 +00:00
|
|
|
// RUN: grep 'define .*noalias .* @xalloc2(' %t %t
|
2009-08-09 20:07:29 +00:00
|
|
|
|