[cfe-commits] r64645 - /cfe/branches/Apple/objective-rewrite/tools/clang/Driver/RewriteObjC.cpp

Steve Naroff snaroff at apple.com
Mon Feb 16 10:41:26 PST 2009


Author: snaroff
Date: Mon Feb 16 12:41:26 2009
New Revision: 64645

URL: http://llvm.org/viewvc/llvm-project?rev=64645&view=rev
Log:
Fix <rdar://problem/6563735> clang ObjC rewriter: Objects used in blocks not dereferenced properly.

Modified:
    cfe/branches/Apple/objective-rewrite/tools/clang/Driver/RewriteObjC.cpp

Modified: cfe/branches/Apple/objective-rewrite/tools/clang/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/objective-rewrite/tools/clang/Driver/RewriteObjC.cpp?rev=64645&r1=64644&r2=64645&view=diff

==============================================================================
--- cfe/branches/Apple/objective-rewrite/tools/clang/Driver/RewriteObjC.cpp (original)
+++ cfe/branches/Apple/objective-rewrite/tools/clang/Driver/RewriteObjC.cpp Mon Feb 16 12:41:26 2009
@@ -325,7 +325,7 @@
     // Block specific rewrite rules.    
     void RewriteBlockCall(CallExpr *Exp);
     void RewriteBlockPointerDecl(NamedDecl *VD);
-    void RewriteBlockDeclRefExpr(BlockDeclRefExpr *VD);
+    Stmt *RewriteBlockDeclRefExpr(BlockDeclRefExpr *VD);
     void RewriteBlockPointerFunctionArgs(FunctionDecl *FD);
     
     std::string SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, 
@@ -3859,7 +3859,20 @@
   ReplaceStmt(Exp, BlockCall);
 }
 
-void RewriteObjC::RewriteBlockDeclRefExpr(BlockDeclRefExpr *BDRE) {
+// We need to return the rewritten expression to handle cases where the
+// BlockDeclRefExpr is embedded in another expression being rewritten.
+// For example:
+//
+// int main() {
+//    __block Foo *f;
+//    __block int i;
+// 
+//    void (^myblock)() = ^() {
+//        [f test]; // f is a BlockDeclRefExpr embedded in a message (which is being rewritten).
+//        i = 77;
+//    };
+//}
+Stmt *RewriteObjC::RewriteBlockDeclRefExpr(BlockDeclRefExpr *BDRE) {
   // FIXME: Add more elaborate code generation required by the ABI.
   Expr *DerefExpr = new UnaryOperator(BDRE, UnaryOperator::Deref,
                              Context->getPointerType(BDRE->getType()),
@@ -3867,6 +3880,7 @@
   // Need parens to enforce precedence.
   ParenExpr *PE = new ParenExpr(SourceLocation(), SourceLocation(), DerefExpr);
   ReplaceStmt(BDRE, PE);
+  return PE;
 }
 
 void RewriteObjC::RewriteCastExpr(CStyleCastExpr *CE) {
@@ -4359,7 +4373,7 @@
   // Handle blocks rewriting.
   if (BlockDeclRefExpr *BDRE = dyn_cast<BlockDeclRefExpr>(S)) {
     if (BDRE->isByRef())
-      RewriteBlockDeclRefExpr(BDRE);
+      return RewriteBlockDeclRefExpr(BDRE);
   }
   if (CallExpr *CE = dyn_cast<CallExpr>(S)) {
     if (CE->getCallee()->getType()->isBlockPointerType()) {





More information about the cfe-commits mailing list