[cfe-commits] r96352 - /cfe/trunk/lib/Frontend/RewriteObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Tue Feb 16 08:21:26 PST 2010


Author: fjahanian
Date: Tue Feb 16 10:21:26 2010
New Revision: 96352

URL: http://llvm.org/viewvc/llvm-project?rev=96352&view=rev
Log:
Fix rewriter bug when function call inside block with block parameter 
causes C++ compile error (radar 7651312).

Modified:
    cfe/trunk/lib/Frontend/RewriteObjC.cpp

Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=96352&r1=96351&r2=96352&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Tue Feb 16 10:21:26 2010
@@ -2196,6 +2196,36 @@
   }
 }
 
+// FIXME. Consolidate this routine with RewriteBlockPointerType.
+static void RewriteBlockPointerTypeVariable(std::string& Str, ValueDecl *VD) {
+  QualType Type = VD->getType();
+  std::string TypeString(Type.getAsString());
+  const char *argPtr = TypeString.c_str();
+  int paren = 0;
+  while (*argPtr) {
+    switch (*argPtr) {
+      case '(':
+        Str += *argPtr;
+        paren++;
+        break;
+      case ')':
+        Str += *argPtr;
+        paren--;
+        break;
+      case '^':
+        Str += '*';
+        if (paren == 1)
+          Str += VD->getNameAsString();
+        break;
+      default:
+        Str += *argPtr;
+        break;
+    }
+    argPtr++;
+  }
+}
+
+
 void RewriteObjC::RewriteBlockLiteralFunctionDecl(FunctionDecl *FD) {
   SourceLocation FunLocStart = FD->getTypeSpecStartLoc();
   const FunctionType *funcType = FD->getType()->getAs<FunctionType>();
@@ -3899,11 +3929,18 @@
     //     myImportedClosure(); // import and invoke the closure
     //   };
     //
-    if (isTopLevelBlockPointerType((*I)->getType()))
-      S += "struct __block_impl *";
-    else
+    if (isTopLevelBlockPointerType((*I)->getType())) {
+      RewriteBlockPointerTypeVariable(S, (*I));
+      S += " = (";
+      RewriteBlockPointerType(S, (*I)->getType());
+      S += ")";
+      S += "__cself->" + (*I)->getNameAsString() + "; // bound by copy\n";
+    }
+    else {
       (*I)->getType().getAsStringInternal(Name, Context->PrintingPolicy);
-    S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by copy\n";
+      S += Name + " = __cself->" + 
+                              (*I)->getNameAsString() + "; // bound by copy\n";
+    }
   }
   std::string RewrittenStr = RewrittenBlockExprs[CE];
   const char *cstr = RewrittenStr.c_str();





More information about the cfe-commits mailing list