ASTPrinter: Objective-C method declarations don't need a space after
the return type

rdar://32332039

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304553 91177308-0d34-0410-b5e6-96231b3b80d8
(cherry picked from commit b4530cfcf71b67629177695d40973b21cd57e3d9)
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp
index e7a276d..c7f3558 100644
--- a/lib/AST/DeclPrinter.cpp
+++ b/lib/AST/DeclPrinter.cpp
@@ -1168,7 +1168,9 @@
   for (const auto *PI : OMD->parameters()) {
     // FIXME: selector is missing here!
     pos = name.find_first_of(':', lastPos);
-    Out << " " << name.substr(lastPos, pos - lastPos) << ':';
+    if (lastPos != 0)
+      Out << " ";
+    Out << name.substr(lastPos, pos - lastPos) << ':';
     PrintObjCMethodType(OMD->getASTContext(), 
                         PI->getObjCDeclQualifier(),
                         PI->getType());
@@ -1177,7 +1179,7 @@
   }
 
   if (OMD->param_begin() == OMD->param_end())
-    Out << " " << name;
+    Out << name;
 
   if (OMD->isVariadic())
       Out << ", ...";
diff --git a/test/Misc/ast-print-objectivec.m b/test/Misc/ast-print-objectivec.m
index e419237..cb5aacc 100644
--- a/test/Misc/ast-print-objectivec.m
+++ b/test/Misc/ast-print-objectivec.m
@@ -17,25 +17,30 @@
 @implementation I
 - (void)MethP __attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2))) {}
 - (void)MethI __attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2))) {}
+
+- (void)methodWithArg:(int)x andAnotherOne:(int)y { }
 @end
 
 // CHECK: @protocol P
-// CHECK: - (void) MethP __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2)));
+// CHECK: - (void)MethP __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2)));
 // CHECK: @end
 
 // CHECK: @interface I : NSObject<P> 
-// CHECK: - (void) MethI __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2)));
+// CHECK: - (void)MethI __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2)));
 // CHECK: @end
 
 // CHECK: @interface I(CAT)
-// CHECK: - (void) MethCAT __attribute__((availability(macos, introduced=10_1_0, deprecated=10_2)));
+// CHECK: - (void)MethCAT __attribute__((availability(macos, introduced=10_1_0, deprecated=10_2)));
 // CHECK: @end
 
 // CHECK: @implementation I
-// CHECK: - (void) MethP __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))) {
+// CHECK: - (void)MethP __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))) {
 // CHECK: }
 
-// CHECK: - (void) MethI __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))) {
+// CHECK: - (void)MethI __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))) {
+// CHECK: }
+
+// CHECK: - (void)methodWithArg:(int)x andAnotherOne:(int)y {
 // CHECK: }
 
 // CHECK: @end
diff --git a/test/Modules/lookup.m b/test/Modules/lookup.m
index edf7063..b22e41f 100644
--- a/test/Modules/lookup.m
+++ b/test/Modules/lookup.m
@@ -14,7 +14,7 @@
 // expected-note@Inputs/lookup_right.h:3{{also found}}
 }
 
-// CHECK-PRINT: - (int) method;
-// CHECK-PRINT: - (double) method
+// CHECK-PRINT: - (int)method;
+// CHECK-PRINT: - (double)method
 // CHECK-PRINT: void test(id x)
 
diff --git a/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/DeclPrinterTest.cpp
index e5a09a3..ae6d0f0 100644
--- a/unittests/AST/DeclPrinterTest.cpp
+++ b/unittests/AST/DeclPrinterTest.cpp
@@ -1228,7 +1228,7 @@
     "@end\n",
     namedDecl(hasName("A:inRange:"),
               hasDescendant(namedDecl(hasName("printThis")))).bind("id"),
-    "- (int) A:(id)anObject inRange:(long)range"));
+    "- (int)A:(id)anObject inRange:(long)range"));
 }
 
 TEST(DeclPrinter, TestObjCProtocol1) {