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
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 23fe401..76b99bb 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -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;
+  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(d)) {
+    QualType RetTy = FD->getResultType();  
+    if (RetTy->isAnyPointerType() || RetTy->isBlockPointerType()) {
+      d->addAttr(::new (S.Context) MallocAttr());
+      return;
+    }
   }
 
-  QualType RetTy = FT->getResultType();
-  
-  if (!(RetTy->isAnyPointerType() || RetTy->isBlockPointerType())) {
-    S.Diag(Attr.getLoc(), diag::warn_attribute_malloc_pointer_only);
-    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,