]> granicus.if.org Git - clang/commitdiff
objective-c modern translator: Further improving the last
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 19 Apr 2012 16:30:28 +0000 (16:30 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 19 Apr 2012 16:30:28 +0000 (16:30 +0000)
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

lib/Rewrite/RewriteModernObjC.cpp
test/Rewriter/rewrite-modern-extern-c-func-decl.mm

index 256e8f6995161d5158565f06e671ab40b5232ca5..2e9941bdd97ac93260b5a14ae856cb174676faae 100644 (file)
@@ -2262,7 +2262,11 @@ void RewriteModernObjC::RewriteBlockLiteralFunctionDecl(FunctionDecl *FD) {
   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 @@ std::string RewriteModernObjC::SynthesizeBlockDescriptor(std::string DescTag,
 /// 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();
-  }
-  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->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();
+  }
+  if (FD->getStorageClassAsWritten() != SC_None)
+    R.RewriteBlockLiteralFunctionDecl(FD);
   return FD->getTypeSpecStartLoc();
 }
 
index e037a6eb2558076fe7226df3bcadc9fa0a1fe7e7..a6cbc7e12a8ccce982e2a30bb752f7088d57d817 100644 (file)
@@ -49,8 +49,19 @@ static char stringtype;
 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();
+    });
+}
+