summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2009-02-02 17:19:26 +0000
committerSteve Naroff <snaroff@apple.com>2009-02-02 17:19:26 +0000
commitf26a1d4ef7a29b06559c64f3a5e0d04c8386b5b8 (patch)
treed45291eb866dbce345060b5f08566931b201718f
parent50aeb12d806a4e1aca9a3bd903d71ee3c01660db (diff)
downloadbcm5719-llvm-f26a1d4ef7a29b06559c64f3a5e0d04c8386b5b8.tar.gz
bcm5719-llvm-f26a1d4ef7a29b06559c64f3a5e0d04c8386b5b8.zip
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. llvm-svn: 63522
-rw-r--r--clang/Driver/RewriteObjC.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/clang/Driver/RewriteObjC.cpp b/clang/Driver/RewriteObjC.cpp
index e2ddafe8d19..f18a0c53ce5 100644
--- a/clang/Driver/RewriteObjC.cpp
+++ b/clang/Driver/RewriteObjC.cpp
@@ -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) {
OpenPOWER on IntegriCloud