[cfe-commits] r63522 - /cfe/trunk/Driver/RewriteObjC.cpp

Steve Naroff snaroff at apple.com
Mon Feb 2 09:19:27 PST 2009


Author: snaroff
Date: Mon Feb  2 11:19:26 2009
New Revision: 63522

URL: http://llvm.org/viewvc/llvm-project?rev=63522&view=rev
Log:
RewriteObjC::RewriteBlockDeclRefExpr(): Add parens to enforce precedence. This fixes <rdar://problem/6529468> clang ObjC rewriter: Need parenthesis around dereferences in rewritten Blocks.

Also changed RewriteObjC::SynthesizeBlockFunc() to declare a pointer to the block argument even when there are no user-supplied arguments to the block.

Modified:
    cfe/trunk/Driver/RewriteObjC.cpp

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=63522&r1=63521&r2=63522&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Mon Feb  2 11:19:26 2009
@@ -3458,7 +3458,9 @@
   BlockDecl *BD = CE->getBlockDecl();
   
   if (isa<FunctionTypeNoProto>(AFT)) {
-    S += "()";
+    // No user-supplied arguments. Still need to pass in a pointer to the 
+    // block (to reference imported block decl refs).
+    S += "(" + StructRef + " *__cself)";
   } else if (BD->param_empty()) {
     S += "(" + StructRef + " *__cself)";
   } else {
@@ -3842,7 +3844,12 @@
 
 void RewriteObjC::RewriteBlockDeclRefExpr(BlockDeclRefExpr *BDRE) {
   // FIXME: Add more elaborate code generation required by the ABI.
-  InsertText(BDRE->getLocStart(), "*", 1);
+  Expr *DerefExpr = new UnaryOperator(BDRE, UnaryOperator::Deref,
+                             Context->getPointerType(BDRE->getType()),
+                             SourceLocation());
+  // Need parens to enforce precedence.
+  ParenExpr *PE = new ParenExpr(SourceLocation(), SourceLocation(), DerefExpr);
+  ReplaceStmt(BDRE, PE);
 }
 
 void RewriteObjC::RewriteCastExpr(CStyleCastExpr *CE) {





More information about the cfe-commits mailing list