diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-08-15 00:51:46 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-08-15 00:51:46 +0000 |
commit | 2cff7d16fe58e6d6447ec9cad2af083beb20d6b5 (patch) | |
tree | 4a3fb8525b2a639282e23b80df81ace47c0b2be5 /lib | |
parent | ec18ddd33d5dc2cba5f64fa903bac7a83dc1e01e (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79060 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 23fe4010fb..76b99bb33f 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/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, |