Per Eli Friedman's feedback, handle attribute 'malloc' being applied to

declarations of function pointers.

llvm-svn: 79053
This commit is contained in:
Ted Kremenek 2009-08-14 22:03:27 +00:00
parent 2e4a46b745
commit f22c410efa
2 changed files with 10 additions and 8 deletions

View File

@ -437,16 +437,16 @@ static void HandleMallocAttr(Decl *d, const AttributeList &Attr, Sema &S) {
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
return;
}
const FunctionDecl *FD = dyn_cast<FunctionDecl>(d);
if (!FD) {
const FunctionType *FT = getFunctionType(d, false);
if (!FT) {
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
<< Attr.getName() << 0 /*function*/;
return;
}
QualType RetTy = FD->getResultType();
QualType RetTy = FT->getResultType();
if (!(RetTy->isAnyPointerType() || RetTy->isBlockPointerType())) {
S.Diag(Attr.getLoc(), diag::warn_attribute_malloc_pointer_only);

View File

@ -7,12 +7,14 @@ int no_vars __attribute((malloc)); // expected-warning {{only applies to functio
void returns_void (void) __attribute((malloc)); // expected-warning {{functions returning pointer type}}
int returns_int (void) __attribute((malloc)); // expected-warning {{functions returning pointer type}}
int * returns_intptr(void) __attribute((malloc));
int * returns_intptr(void) __attribute((malloc)); // no-warning
typedef int * iptr;
iptr returns_iptr (void) __attribute((malloc));
iptr returns_iptr (void) __attribute((malloc)); // no-warning
__attribute((malloc)) void *(*f)(); // no-warning
__attribute((malloc))
void * xalloc(unsigned n) { return malloc(n); }
void * xalloc(unsigned n) { return malloc(n); } // no-warning
// RUN: grep 'define noalias .* @xalloc(' %t &&
#define malloc_like __attribute((__malloc__))