[analyzer] Add check for when block is called with too few arguments.

The CallAndMessageChecker has an existing check for when a function pointer
is called with too few arguments. Extend this logic to handle the block
case, as well. While we're at it, do a drive-by grammar correction
("less" --> "fewer") on the diagnostic text.

llvm-svn: 287001
diff --git a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
index 5126716..f474857 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
@@ -356,7 +356,6 @@
   }
 }
 
-
 void CallAndMessageChecker::checkPreCall(const CallEvent &Call,
                                          CheckerContext &C) const {
   ProgramStateRef State = C.getState();
@@ -389,11 +388,10 @@
   }
 
   const Decl *D = Call.getDecl();
-  const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
-  if (FD) {
-    // If we have a declaration, we can make sure we pass enough parameters to
-    // the function.
-    unsigned Params = FD->getNumParams();
+  if (D && (isa<FunctionDecl>(D) || isa<BlockDecl>(D))) {
+    // If we have a function or block declaration, we can make sure we pass
+    // enough parameters.
+    unsigned Params = Call.parameters().size();
     if (Call.getNumArgs() < Params) {
       ExplodedNode *N = C.generateErrorNode();
       if (!N)
@@ -403,8 +401,14 @@
 
       SmallString<512> Str;
       llvm::raw_svector_ostream os(Str);
-      os << "Function taking " << Params << " argument"
-         << (Params == 1 ? "" : "s") << " is called with less ("
+      if (isa<FunctionDecl>(D)) {
+        os << "Function ";
+      } else {
+        assert(isa<BlockDecl>(D));
+        os << "Block ";
+      }
+      os << "taking " << Params << " argument"
+         << (Params == 1 ? "" : "s") << " is called with fewer ("
          << Call.getNumArgs() << ")";
 
       C.emitReport(
@@ -425,6 +429,7 @@
   else
     BT = &BT_call_arg;
 
+  const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
   for (unsigned i = 0, e = Call.getNumArgs(); i != e; ++i) {
     const ParmVarDecl *ParamDecl = nullptr;
     if(FD && i < FD->getNumParams())