diff options
author | Steve Naroff <snaroff@apple.com> | 2008-08-21 13:03:03 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2008-08-21 13:03:03 +0000 |
commit | 3498cc9793487a5ad51a5a050be85bd550775ecc (patch) | |
tree | 86be5f085ecd50b2a5befffde5ca0be9f930d5c3 | |
parent | 5323e2377719cf34951c0ab149d610be4a010391 (diff) |
RewriteObjC::RewriteObjCSynchronizedStmt(): Make sure the sync expr is cast to "id".
This fixes <rdar://problem/6163088> clang ObjC rewriter: @synchronized ([foo class]) {} does not cast properly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55118 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Driver/RewriteObjC.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp index 36e973d723..2f91ea9741 100644 --- a/Driver/RewriteObjC.cpp +++ b/Driver/RewriteObjC.cpp @@ -1302,8 +1302,10 @@ Stmt *RewriteObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) { assert((*startBuf == '@') && "bogus @synchronized location"); std::string buf; - buf = "objc_sync_enter"; - ReplaceText(startLoc, 13, buf.c_str(), buf.size()); + buf = "objc_sync_enter((id)"; + const char *lparenBuf = startBuf; + while (*lparenBuf != '(') lparenBuf++; + ReplaceText(startLoc, lparenBuf-startBuf+1, buf.c_str(), buf.size()); // We can't use S->getSynchExpr()->getLocEnd() to find the end location, since // the sync expression is typically a message expression that's already // been rewritten! (which implies the SourceLocation's are invalid). @@ -1329,8 +1331,10 @@ Stmt *RewriteObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) { buf += " _rethrow = objc_exception_extract(&_stack);\n"; buf += " if (!_rethrow) objc_exception_try_exit(&_stack);\n"; buf += " objc_sync_exit("; + Expr *syncExpr = new ExplicitCastExpr(Context->getObjCIdType(), + S->getSynchExpr(), SourceLocation()); std::ostringstream syncExprBuf; - S->getSynchExpr()->printPretty(syncExprBuf); + syncExpr->printPretty(syncExprBuf); buf += syncExprBuf.str(); buf += ");\n"; buf += " if (_rethrow) objc_exception_throw(_rethrow);\n"; |