warn, as gcc does, if __attribute__((malloc)) applied to function returning non-pointer type

llvm-svn: 78542
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 2f86fe1..9d1b084 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -437,6 +437,13 @@
     return;
   }
 
+  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(d)) {
+    if (!FD->getResultType()->isPointerType()) {
+      S.Diag(Attr.getLoc(), diag::warn_attribute_malloc_pointer_only);
+      return;
+    }
+  }
+
   d->addAttr(::new (S.Context) MallocAttr());
 }