objective-c modern translator: Further improving the last
patch fixing writing a spurious 'static' into
the wrong place. // rdar://11275241


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155130 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Rewrite/RewriteModernObjC.cpp b/lib/Rewrite/RewriteModernObjC.cpp
index 256e8f6..2e9941b 100644
--- a/lib/Rewrite/RewriteModernObjC.cpp
+++ b/lib/Rewrite/RewriteModernObjC.cpp
@@ -2262,7 +2262,11 @@
   if (i+1 < numArgs)
     FdStr += ", ";
   }
-  FdStr +=  ");\n";
+  if (FD->isVariadic()) {
+    FdStr +=  (numArgs > 0) ? ", ...);\n" : "...);\n";
+  }
+  else
+    FdStr +=  ");\n";
   InsertText(FunLocStart, FdStr);
 }
 
@@ -4007,19 +4011,15 @@
 /// extern "C" or extern "C" {...}
 static SourceLocation getFunctionSourceLocation (RewriteModernObjC &R,
                                                  FunctionDecl *FD) {
-  if (!FD->isExternC() || FD->isMain()) {
-    if (FD->getStorageClassAsWritten() != SC_None)
-      R.RewriteBlockLiteralFunctionDecl(FD);
-    return FD->getTypeSpecStartLoc();
+  if (FD->isExternC()  && !FD->isMain()) {
+    const DeclContext *DC = FD->getDeclContext();
+    if (const LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(DC))
+      // if it is extern "C" {...}, return function decl's own location.
+      if (!LSD->getRBraceLoc().isValid())
+        return LSD->getExternLoc();
   }
-  const DeclContext *DC = FD->getDeclContext();
-  if (const LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(DC)) {
-    SourceLocation BodyRBrace = LSD->getRBraceLoc();
-    // if it is extern "C" {...}, return function decl's own location.
-    if (BodyRBrace.isValid())
-      return FD->getTypeSpecStartLoc();
-    return LSD->getExternLoc();
-  }
+  if (FD->getStorageClassAsWritten() != SC_None)
+    R.RewriteBlockLiteralFunctionDecl(FD);
   return FD->getTypeSpecStartLoc();
 }
 
diff --git a/test/Rewriter/rewrite-modern-extern-c-func-decl.mm b/test/Rewriter/rewrite-modern-extern-c-func-decl.mm
index e037a6e..a6cbc7e 100644
--- a/test/Rewriter/rewrite-modern-extern-c-func-decl.mm
+++ b/test/Rewriter/rewrite-modern-extern-c-func-decl.mm
@@ -49,8 +49,19 @@
 char CFStringGetTypeID();
 void x(void (^)());
 
-static void initStatics() {
+static void initStatics(int arg, ...) {
     x(^{
         stringtype = CFStringGetTypeID();
     });
 }
+static void initStatics1(...) {
+    x(^{
+        stringtype = CFStringGetTypeID();
+    });
+}
+static void initStatics2() {
+    x(^{
+        stringtype = CFStringGetTypeID();
+    });
+}
+