declarations (and not function pointers). This is consistent with GCC. Accepting
this attribute on function pointers means that the attribute should be treated
as a type qualifier, which apparently is not what GCC does. We obviously can
change this later should we desire to enhance the 'malloc' attribute in this
way.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79060
91177308-0d34-0410-b5e6-
96231b3b80d8
def warn_attribute_nonnull_no_pointers : Warning<
"'nonnull' attribute applied to function with no pointer arguments">;
def warn_attribute_malloc_pointer_only : Warning<
- "'malloc' attribute only applies to functions returning pointer type">;
+ "'malloc' attribute only applies to functions returning a pointer type">;
def warn_transparent_union_nonpointer : Warning<
"'transparent_union' attribute support incomplete; only supported for "
"pointer unions">;
return;
}
- 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 = FT->getResultType();
-
- if (!(RetTy->isAnyPointerType() || RetTy->isBlockPointerType())) {
- S.Diag(Attr.getLoc(), diag::warn_attribute_malloc_pointer_only);
- return;
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(d)) {
+ QualType RetTy = FD->getResultType();
+ if (RetTy->isAnyPointerType() || RetTy->isBlockPointerType()) {
+ d->addAttr(::new (S.Context) MallocAttr());
+ return;
+ }
}
- d->addAttr(::new (S.Context) MallocAttr());
+ S.Diag(Attr.getLoc(), diag::warn_attribute_malloc_pointer_only);
}
static bool HandleCommonNoReturnAttr(Decl *d, const AttributeList &Attr,
#include <stdlib.h>
-int no_vars __attribute((malloc)); // expected-warning {{only applies to function types}}
+int no_vars __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
-void returns_void (void) __attribute((malloc)); // expected-warning {{functions returning pointer type}}
-int returns_int (void) __attribute((malloc)); // expected-warning {{functions returning pointer type}}
+void returns_void (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
+int returns_int (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
int * returns_intptr(void) __attribute((malloc)); // no-warning
typedef int * iptr;
iptr returns_iptr (void) __attribute((malloc)); // no-warning
-__attribute((malloc)) void *(*f)(); // no-warning
-__attribute((malloc)) int (*g)(); // expected-warning{{'malloc' attribute only applies to functions returning pointer type}}
+__attribute((malloc)) void *(*f)(); // expected-warning{{'malloc' attribute only applies to functions returning a pointer type}}
+__attribute((malloc)) int (*g)(); // expected-warning{{'malloc' attribute only applies to functions returning a pointer type}}
__attribute((malloc))
void * xalloc(unsigned n) { return malloc(n); } // no-warning
// RUN: clang-cc -verify -fsyntax-only -fblocks %s
@interface TestAttrMallocOnMethods {}
-- (id) test1 __attribute((malloc)); // expected-warning{{'malloc' attribute only applies to function types}}
-- (int) test2 __attribute((malloc)); // expected-warning{{'malloc' attribute only applies to function types}}
+- (id) test1 __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
+- (int) test2 __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
@end
id bar(void) __attribute((malloc)); // no-warning
typedef void (^bptr)(void);
bptr baz(void) __attribute((malloc)); // no-warning
-__attribute((malloc)) id (*f)(); // no-warning
-__attribute((malloc)) bptr (*g)(); // no-warning
+__attribute((malloc)) id (*f)(); // expected-warning {{functions returning a pointer type}}
+__attribute((malloc)) bptr (*g)(); // expected-warning {{functions returning a pointer type}}
+__attribute((malloc)) void *(^h)(); // expected-warning {{functions returning a pointer type}}