From 822ac874ae99f326b59eb340bd47e96f69c0cf3b Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 31 Mar 2011 22:49:32 +0000 Subject: [PATCH] Fix couple of rewriter bugs related to rewriting a __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 | 14 +++++++++++--- test/Rewriter/rewrite-block-pointer.mm | 8 ++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Rewrite/RewriteObjC.cpp b/lib/Rewrite/RewriteObjC.cpp index 36ae3953f3..54d6fbb236 100644 --- a/lib/Rewrite/RewriteObjC.cpp +++ b/lib/Rewrite/RewriteObjC.cpp @@ -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; diff --git a/test/Rewriter/rewrite-block-pointer.mm b/test/Rewriter/rewrite-block-pointer.mm index abb2f13618..c3876e9fa0 100644 --- a/test/Rewriter/rewrite-block-pointer.mm +++ b/test/Rewriter/rewrite-block-pointer.mm @@ -88,3 +88,11 @@ void test8608902() { ppp(1, 0); } +void test9204669() { + __attribute__((__blocks__(byref))) char (^addChangeToData)(); + + addChangeToData = ^() { + return 'b'; + }; +} + -- 2.40.0