]> granicus.if.org Git - clang/commitdiff
RewriteObjC::RewriteBlockDeclRefExpr(): Add parens to enforce precedence. This fixes...
authorSteve Naroff <snaroff@apple.com>
Mon, 2 Feb 2009 17:19:26 +0000 (17:19 +0000)
committerSteve Naroff <snaroff@apple.com>
Mon, 2 Feb 2009 17:19:26 +0000 (17:19 +0000)
Also changed RewriteObjC::SynthesizeBlockFunc() to declare a pointer to the block argument even when there are no user-supplied arguments to the block.

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

Driver/RewriteObjC.cpp

index e2ddafe8d1925d12dea11e888705393a2e0a0a8a..f18a0c53ce54262f300049b90c03d7cdc24f0fc9 100644 (file)
@@ -3458,7 +3458,9 @@ std::string RewriteObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
   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::RewriteBlockCall(CallExpr *Exp) {
 
 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) {