[cfe-commits] r128682 - in /cfe/trunk: lib/Rewrite/RewriteObjC.cpp test/Rewriter/rewrite-block-pointer.mm

Fariborz Jahanian fjahanian at apple.com
Thu Mar 31 15:49:33 PDT 2011


Author: fjahanian
Date: Thu Mar 31 17:49:32 2011
New Revision: 128682

URL: http://llvm.org/viewvc/llvm-project?rev=128682&view=rev
Log:
Fix couple of rewriter bugs related to rewriting a
__block block declaration. //rdar://9204669

Modified:
    cfe/trunk/lib/Rewrite/RewriteObjC.cpp
    cfe/trunk/test/Rewriter/rewrite-block-pointer.mm

Modified: cfe/trunk/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteObjC.cpp?rev=128682&r1=128681&r2=128682&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteObjC.cpp Thu Mar 31 17:49:32 2011
@@ -5142,8 +5142,11 @@
     ByrefType += " void (*__Block_byref_id_object_copy)(void*, void*);\n";
     ByrefType += " void (*__Block_byref_id_object_dispose)(void*);\n";
   }
-  
-  Ty.getAsStringInternal(Name, Context->PrintingPolicy);
+
+  QualType T = Ty;
+  (void)convertBlockPointerToFunctionPointer(T);
+  T.getAsStringInternal(Name, Context->PrintingPolicy);
+    
   ByrefType += " " + Name + ";\n";
   ByrefType += "};\n";
   // Insert this type in global scope. It is needed by helper function.
@@ -5201,7 +5204,12 @@
       ByrefType += utostr(flag);
     }
     ByrefType += "};\n";
-    ReplaceText(DeclLoc, endBuf-startBuf+Name.size(), ByrefType);
+    unsigned nameSize = Name.size();
+    // for block or function pointer declaration. Name is aleady
+    // part of the declaration.
+    if (Ty->isBlockPointerType() || Ty->isFunctionPointerType())
+      nameSize = 1;
+    ReplaceText(DeclLoc, endBuf-startBuf+nameSize, ByrefType);
   }
   else {
     SourceLocation startLoc;

Modified: cfe/trunk/test/Rewriter/rewrite-block-pointer.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-block-pointer.mm?rev=128682&r1=128681&r2=128682&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-block-pointer.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-block-pointer.mm Thu Mar 31 17:49:32 2011
@@ -88,3 +88,11 @@
   ppp(1, 0);
 }
 
+void test9204669() {
+   __attribute__((__blocks__(byref))) char (^addChangeToData)();
+
+   addChangeToData = ^() {
+      return 'b';
+   };
+}
+





More information about the cfe-commits mailing list