]> granicus.if.org Git - clang/commitdiff
Fix couple of rewriter bugs related to rewriting a
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 31 Mar 2011 22:49:32 +0000 (22:49 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 31 Mar 2011 22:49:32 +0000 (22:49 +0000)
__block block declaration. //rdar://9204669

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128682 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Rewrite/RewriteObjC.cpp
test/Rewriter/rewrite-block-pointer.mm

index 36ae3953f356513146311fd9eda3fc4916a85f22..54d6fbb236fe625d268f5d65d2ae2cefdd9f5f3f 100644 (file)
@@ -5142,8 +5142,11 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) {
     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 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) {
       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;
index abb2f136183c7a8a4fd0a1d70a4e3e847da75760..c3876e9fa0747c67d0882c615046a6bbc03a3f01 100644 (file)
@@ -88,3 +88,11 @@ void  test8608902() {
   ppp(1, 0);
 }
 
+void test9204669() {
+   __attribute__((__blocks__(byref))) char (^addChangeToData)();
+
+   addChangeToData = ^() {
+      return 'b';
+   };
+}
+