[cfe-commits] r79060 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp test/Sema/attr-malloc.c test/SemaObjC/attr-malloc.m
Ted Kremenek
kremenek at apple.com
Fri Aug 14 17:51:46 PDT 2009
Author: kremenek
Date: Fri Aug 14 19:51:46 2009
New Revision: 79060
URL: http://llvm.org/viewvc/llvm-project?rev=79060&view=rev
Log:
Change handling of attribute 'malloc' to only accept the attribute on function
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.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/attr-malloc.c
cfe/trunk/test/SemaObjC/attr-malloc.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=79060&r1=79059&r2=79060&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Aug 14 19:51:46 2009
@@ -612,7 +612,7 @@
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">;
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=79060&r1=79059&r2=79060&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Aug 14 19:51:46 2009
@@ -438,22 +438,15 @@
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,
Modified: cfe/trunk/test/Sema/attr-malloc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-malloc.c?rev=79060&r1=79059&r2=79060&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-malloc.c (original)
+++ cfe/trunk/test/Sema/attr-malloc.c Fri Aug 14 19:51:46 2009
@@ -3,16 +3,16 @@
#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
Modified: cfe/trunk/test/SemaObjC/attr-malloc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/attr-malloc.m?rev=79060&r1=79059&r2=79060&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/attr-malloc.m (original)
+++ cfe/trunk/test/SemaObjC/attr-malloc.m Fri Aug 14 19:51:46 2009
@@ -1,8 +1,8 @@
// 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
@@ -10,6 +10,7 @@
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}}
More information about the cfe-commits
mailing list