Bug fix in StmtPrinter to handle pretty-printing ObjCMessageExprs involving variadic methods (also did some cosmetic cleanups in the printing output).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50583 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index f838633..bd6d0d4 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -822,15 +822,21 @@
   Expr *receiver = Mess->getReceiver();
   if (receiver) PrintExpr(receiver);
   else OS << Mess->getClassName()->getName();
+  OS << ' ';
   Selector selector = Mess->getSelector();
   if (selector.isUnarySelector()) {
-    OS << " " << selector.getIdentifierInfoForSlot(0)->getName();
+    OS << selector.getIdentifierInfoForSlot(0)->getName();
   } else {
     for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
-      if (selector.getIdentifierInfoForSlot(i))
-        OS << selector.getIdentifierInfoForSlot(i)->getName() << ":";
-      else
-         OS << ":";
+      if (i < selector.getNumArgs()) {
+        if (i > 0) OS << ' ';
+        if (selector.getIdentifierInfoForSlot(i))
+          OS << selector.getIdentifierInfoForSlot(i)->getName() << ":";
+        else
+           OS << ":";
+      }
+      else OS << ", "; // Handle variadic methods.
+      
       PrintExpr(Mess->getArg(i));
     }
   }