1651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -verify -fsyntax-only %s 2651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -emit-llvm -o %t %s 331af091f101c08ecb39a00c2b4741bec5cc00150Ryan Flynn 4ec4c5356bd75f868b937a30bec8886c5b488ea3cChandler Carruth#include <stddef.h> 5ec4c5356bd75f868b937a30bec8886c5b488ea3cChandler Carruth 6ec4c5356bd75f868b937a30bec8886c5b488ea3cChandler Carruth// Declare malloc here explicitly so we don't depend on system headers. 7ec4c5356bd75f868b937a30bec8886c5b488ea3cChandler Carruthvoid * malloc(size_t) __attribute((malloc)); 831af091f101c08ecb39a00c2b4741bec5cc00150Ryan Flynn 90e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesint no_vars __attribute((malloc)); // expected-warning {{attribute only applies to functions}} 1031af091f101c08ecb39a00c2b4741bec5cc00150Ryan Flynn 110e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesvoid returns_void (void) __attribute((malloc)); // expected-warning {{attribute only applies to return values that are pointers}} 120e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesint returns_int (void) __attribute((malloc)); // expected-warning {{attribute only applies to return values that are pointers}} 13092f27a40ca0ef18c2be13942879d41a0e9cc6bfTed Kremenekint * returns_intptr(void) __attribute((malloc)); // no-warning 146a7fda0a3b1b7f5229e1121190e009e92f533555Ryan Flynntypedef int * iptr; 15092f27a40ca0ef18c2be13942879d41a0e9cc6bfTed Kremenekiptr returns_iptr (void) __attribute((malloc)); // no-warning 16092f27a40ca0ef18c2be13942879d41a0e9cc6bfTed Kremenek 170e2c34f92f00628d48968dfea096d36381f494cbStephen Hines__attribute((malloc)) void *(*f)(); // expected-warning{{attribute only applies to functions}} 180e2c34f92f00628d48968dfea096d36381f494cbStephen Hines__attribute((malloc)) int (*g)(); // expected-warning{{attribute only applies to functions}} 196a7fda0a3b1b7f5229e1121190e009e92f533555Ryan Flynn 2031af091f101c08ecb39a00c2b4741bec5cc00150Ryan Flynn__attribute((malloc)) 21092f27a40ca0ef18c2be13942879d41a0e9cc6bfTed Kremenekvoid * xalloc(unsigned n) { return malloc(n); } // no-warning 2287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar// RUN: grep 'define .*noalias .* @xalloc(' %t %t 2331af091f101c08ecb39a00c2b4741bec5cc00150Ryan Flynn 24ccb24e856539df521240f909e153f4cf0d43ba9bBenjamin Kramer#define malloc_like __attribute((__malloc__)) 25ccb24e856539df521240f909e153f4cf0d43ba9bBenjamin Kramervoid * xalloc2(unsigned) malloc_like; 2631af091f101c08ecb39a00c2b4741bec5cc00150Ryan Flynnvoid * xalloc2(unsigned n) { return malloc(n); } 2787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar// RUN: grep 'define .*noalias .* @xalloc2(' %t %t 2831af091f101c08ecb39a00c2b4741bec5cc00150Ryan Flynn 29