[cfe-commits] r155462 - in /cfe/trunk: lib/Rewrite/RewriteModernObjC.cpp test/Rewriter/rewrite-modern-block.mm

Fariborz Jahanian fjahanian at apple.com
Tue Apr 24 11:16:20 PDT 2012


Author: fjahanian
Date: Tue Apr 24 13:16:20 2012
New Revision: 155462

URL: http://llvm.org/viewvc/llvm-project?rev=155462&view=rev
Log:
objc modern rewriter: allow translation of
multiple declaration of block variables
(with no initializer) on the same line.

Modified:
    cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
    cfe/trunk/test/Rewriter/rewrite-modern-block.mm

Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=155462&r1=155461&r2=155462&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Tue Apr 24 13:16:20 2012
@@ -337,7 +337,7 @@
     
     // Block specific rewrite rules.
     void RewriteBlockPointerDecl(NamedDecl *VD);
-    void RewriteByRefVar(VarDecl *VD);
+    void RewriteByRefVar(VarDecl *VD, bool firstDecl);
     Stmt *RewriteBlockDeclRefExpr(DeclRefExpr *VD);
     Stmt *RewriteLocalVariableExternalStorage(DeclRefExpr *DRE);
     void RewriteBlockPointerFunctionArgs(FunctionDecl *FD);
@@ -4742,7 +4742,7 @@
 ///                               ND=initializer-if-any};
 ///
 ///
-void RewriteModernObjC::RewriteByRefVar(VarDecl *ND) {
+void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl) {
   int flag = 0;
   int isa = 0;
   SourceLocation DeclLoc = ND->getTypeSpecStartLoc();
@@ -4843,6 +4843,19 @@
     // part of the declaration.
     if (Ty->isBlockPointerType() || Ty->isFunctionPointerType())
       nameSize = 1;
+    if (!firstDecl) {
+      // In multiple __block declarations, and for all but 1st declaration,
+      // find location of the separating comma. This would be start location
+      // where new text is to be inserted.
+      DeclLoc = ND->getLocation();
+      const char *startDeclBuf = SM->getCharacterData(DeclLoc);
+      const char *commaBuf = startDeclBuf;
+      while (*commaBuf != ',')
+        commaBuf--;
+      assert((*commaBuf == ',') && "RewriteByRefVar: can't find ','");
+      DeclLoc = DeclLoc.getLocWithOffset(commaBuf - startDeclBuf);
+      startBuf = commaBuf;
+    }
     ReplaceText(DeclLoc, endBuf-startBuf+nameSize, ByrefType);
   }
   else {
@@ -5309,7 +5322,7 @@
             assert(!BlockByRefDeclNo.count(ND) &&
               "RewriteFunctionBodyOrGlobalInitializer: Duplicate byref decl");
             BlockByRefDeclNo[ND] = uniqueByrefDeclCount++;
-            RewriteByRefVar(VD);
+            RewriteByRefVar(VD, (DI == DS->decl_begin()));
           }
           else           
             RewriteTypeOfDecl(VD);

Modified: cfe/trunk/test/Rewriter/rewrite-modern-block.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-modern-block.mm?rev=155462&r1=155461&r2=155462&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-modern-block.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-modern-block.mm Tue Apr 24 13:16:20 2012
@@ -21,3 +21,15 @@
 int foo() {
     __block int hello;
 }
+
+// rdar://7547630
+// rewriting multiple __block decls on wintin same decl stmt.
+int radar7547630() {
+  __block int BI1, BI2;
+
+  __block float FLOAT1, FT2, FFFFFFFF3,
+   FFFXXX4;
+
+  __block void (^B)(), (^BB)();
+}
+





More information about the cfe-commits mailing list