]> granicus.if.org Git - clang/commitdiff
Fix an objective-c rewriter bug rewriting a __block
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 27 Jan 2011 23:18:15 +0000 (23:18 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 27 Jan 2011 23:18:15 +0000 (23:18 +0000)
variable declaration of a struct declared type.
// rdar://8918702

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

lib/Rewrite/RewriteObjC.cpp
test/Rewriter/blockstruct.m [new file with mode: 0644]

index 488ee6044ea8b543e234d5cba36634de0bf4f536..659fe741544a97268d0ab3093672ffc6ed6ddf6f 100644 (file)
@@ -252,7 +252,7 @@ namespace {
     void RewriteTypeIntoString(QualType T, std::string &ResultStr,
                                const FunctionType *&FPRetType);
     void RewriteByRefString(std::string &ResultStr, const std::string &Name,
-                            ValueDecl *VD);
+                            ValueDecl *VD, bool def=false);
     void RewriteCategoryDecl(ObjCCategoryDecl *Dcl);
     void RewriteProtocolDecl(ObjCProtocolDecl *Dcl);
     void RewriteForwardProtocolDecl(ObjCForwardProtocolDecl *Dcl);
@@ -4118,10 +4118,12 @@ void RewriteObjC::SynthesizeMetaDataIntoBuffer(std::string &Result) {
 
 void RewriteObjC::RewriteByRefString(std::string &ResultStr, 
                                      const std::string &Name,
-                                     ValueDecl *VD) {
+                                     ValueDecl *VD, bool def) {
   assert(BlockByRefDeclNo.count(VD) && 
          "RewriteByRefString: ByRef decl missing");
-  ResultStr += "struct __Block_byref_" + Name + 
+  if (def)
+    ResultStr += "struct ";
+  ResultStr += "__Block_byref_" + Name + 
     "_" + utostr(BlockByRefDeclNo[VD]) ;
 }
 
@@ -5112,7 +5114,7 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) {
   const char *endBuf = SM->getCharacterData(X);
   std::string Name(ND->getNameAsString());
   std::string ByrefType;
-  RewriteByRefString(ByrefType, Name, ND);
+  RewriteByRefString(ByrefType, Name, ND, true);
   ByrefType += " {\n";
   ByrefType += "  void *__isa;\n";
   RewriteByRefString(ByrefType, Name, ND);
@@ -5405,7 +5407,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
       ValueDecl *ND = (*I);
       std::string Name(ND->getNameAsString());
       std::string RecName;
-      RewriteByRefString(RecName, Name, ND);
+      RewriteByRefString(RecName, Name, ND, true);
       IdentifierInfo *II = &Context->Idents.get(RecName.c_str() 
                                                 + sizeof("struct"));
       RecordDecl *RD = RecordDecl::Create(*Context, TTK_Struct, TUDecl,
diff --git a/test/Rewriter/blockstruct.m b/test/Rewriter/blockstruct.m
new file mode 100644 (file)
index 0000000..977e0d6
--- /dev/null
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// rdar://8918702
+
+typedef void (^b_t)(void);
+void a(b_t work) { }
+struct _s {
+    int a;
+};
+struct _s *r();
+
+void f() {
+    __block struct _s *s = 0;
+    a(^{
+        s = (struct _s *)r();
+    });
+}