[cfe-commits] r124451 - in /cfe/trunk: lib/Rewrite/RewriteObjC.cpp test/Rewriter/blockstruct.m

Fariborz Jahanian fjahanian at apple.com
Thu Jan 27 15:18:16 PST 2011


Author: fjahanian
Date: Thu Jan 27 17:18:15 2011
New Revision: 124451

URL: http://llvm.org/viewvc/llvm-project?rev=124451&view=rev
Log:
Fix an objective-c rewriter bug rewriting a __block 
variable declaration of a struct declared type.
// rdar://8918702

Added:
    cfe/trunk/test/Rewriter/blockstruct.m
Modified:
    cfe/trunk/lib/Rewrite/RewriteObjC.cpp

Modified: cfe/trunk/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteObjC.cpp?rev=124451&r1=124450&r2=124451&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteObjC.cpp Thu Jan 27 17:18:15 2011
@@ -252,7 +252,7 @@
     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::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 @@
   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 @@
       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,

Added: cfe/trunk/test/Rewriter/blockstruct.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/blockstruct.m?rev=124451&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/blockstruct.m (added)
+++ cfe/trunk/test/Rewriter/blockstruct.m Thu Jan 27 17:18:15 2011
@@ -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();
+    });
+}





More information about the cfe-commits mailing list