summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclAttr.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-08-15 00:51:46 +0000
committerTed Kremenek <kremenek@apple.com>2009-08-15 00:51:46 +0000
commit08479ae7fe590ac0d60a282b3e69823caec809bc (patch)
tree522925ad67c0d238f350a90d8c037bd76164ed65 /clang/lib/Sema/SemaDeclAttr.cpp
parent8dc7626f9c73802925c8d63d6dcaf36f4f867875 (diff)
downloadbcm5719-llvm-08479ae7fe590ac0d60a282b3e69823caec809bc.tar.gz
bcm5719-llvm-08479ae7fe590ac0d60a282b3e69823caec809bc.zip
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. llvm-svn: 79060
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp21
1 files changed, 7 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 23fe4010fb0..76b99bb33f1 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -438,22 +438,15 @@ static void HandleMallocAttr(Decl *d, const AttributeList &Attr, Sema &S) {
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,
OpenPOWER on IntegriCloud