[llvm-branch-commits] [cfe-branch] r73414 - /cfe/branches/Apple/objective-rewrite/tools/clang/Driver/RewriteObjC.cpp
Steve Naroff
snaroff at apple.com
Mon Jun 15 13:57:22 PDT 2009
Author: snaroff
Date: Mon Jun 15 15:57:22 2009
New Revision: 73414
URL: http://llvm.org/viewvc/llvm-project?rev=73414&view=rev
Log:
Tweak fix for <rdar://problem/6849319> clang ObjC rewriter: No warning or error jumping out of @synchronized block
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=73414&r1=73413&r2=73414&view=diff
==============================================================================
--- cfe/branches/Apple/objective-rewrite/tools/clang/Driver/RewriteObjC.cpp (original)
+++ cfe/branches/Apple/objective-rewrite/tools/clang/Driver/RewriteObjC.cpp Mon Jun 15 15:57:22 2009
@@ -262,7 +262,8 @@
Stmt *RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp);
void WarnAboutReturnGotoStmts(Stmt *S);
void HasReturnStmts(Stmt *S, bool &hasReturns);
- void RewriteReturnStmts(Stmt *S);
+ void RewriteTryReturnStmts(Stmt *S);
+ void RewriteSyncReturnStmts(Stmt *S, std::string buf);
Stmt *RewriteObjCTryStmt(ObjCAtTryStmt *S);
Stmt *RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S);
Stmt *RewriteObjCCatchStmt(ObjCAtCatchStmt *S);
@@ -1512,7 +1513,9 @@
buf += "}\n";
buf += "{ /* implicit finally clause */\n";
buf += " if (!_rethrow) objc_exception_try_exit(&_stack);\n";
- buf += " objc_sync_exit(";
+
+ std::string syncBuf;
+ syncBuf += " objc_sync_exit(";
Expr *syncExpr = new CStyleCastExpr(Context->getObjCIdType(),
S->getSynchExpr(),
Context->getObjCIdType(),
@@ -1520,9 +1523,11 @@
std::string syncExprBufS;
llvm::raw_string_ostream syncExprBuf(syncExprBufS);
syncExpr->printPretty(syncExprBuf);
- buf += syncExprBuf.str();
- buf += ");\n";
- buf += " if (_rethrow) objc_exception_throw(_rethrow);\n";
+ syncBuf += syncExprBuf.str();
+ syncBuf += ");";
+
+ buf += syncBuf;
+ buf += "\n if (_rethrow) objc_exception_throw(_rethrow);\n";
buf += "}\n";
buf += "}";
@@ -1531,7 +1536,7 @@
bool hasReturns = false;
HasReturnStmts(S->getSynchBody(), hasReturns);
if (hasReturns)
- RewriteReturnStmts(S->getSynchBody());
+ RewriteSyncReturnStmts(S->getSynchBody(), syncBuf);
return 0;
}
@@ -1564,19 +1569,19 @@
return;
}
-void RewriteObjC::RewriteReturnStmts(Stmt *S) {
+void RewriteObjC::RewriteTryReturnStmts(Stmt *S) {
// Perform a bottom up traversal of all children.
for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end();
CI != E; ++CI)
if (*CI) {
- RewriteReturnStmts(*CI);
+ RewriteTryReturnStmts(*CI);
}
if (isa<ReturnStmt>(S)) {
SourceLocation startLoc = S->getLocStart();
const char *startBuf = SM->getCharacterData(startLoc);
const char *semiBuf = strchr(startBuf, ';');
- assert((*semiBuf == ';') && "RewriteReturnStmts: can't find ';'");
+ assert((*semiBuf == ';') && "RewriteTryReturnStmts: can't find ';'");
SourceLocation onePastSemiLoc = startLoc.getFileLocWithOffset(semiBuf-startBuf+1);
std::string buf;
@@ -1588,6 +1593,32 @@
return;
}
+void RewriteObjC::RewriteSyncReturnStmts(Stmt *S, std::string syncExitBuf) {
+ // Perform a bottom up traversal of all children.
+ for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end();
+ CI != E; ++CI)
+ if (*CI) {
+ RewriteSyncReturnStmts(*CI, syncExitBuf);
+ }
+ if (isa<ReturnStmt>(S)) {
+ SourceLocation startLoc = S->getLocStart();
+ const char *startBuf = SM->getCharacterData(startLoc);
+
+ const char *semiBuf = strchr(startBuf, ';');
+ assert((*semiBuf == ';') && "RewriteSyncReturnStmts: can't find ';'");
+ SourceLocation onePastSemiLoc = startLoc.getFileLocWithOffset(semiBuf-startBuf+1);
+
+ std::string buf;
+ buf = "{ objc_exception_try_exit(&_stack);";
+ buf += syncExitBuf;
+ buf += " return";
+
+ ReplaceText(startLoc, 6, buf.c_str(), buf.size());
+ InsertText(onePastSemiLoc, "}", 1);
+ }
+ return;
+}
+
Stmt *RewriteObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) {
// Get the start location and compute the semi location.
SourceLocation startLoc = S->getLocStart();
@@ -1754,7 +1785,7 @@
bool hasReturns = false;
HasReturnStmts(S->getTryBody(), hasReturns);
if (hasReturns)
- RewriteReturnStmts(S->getTryBody());
+ RewriteTryReturnStmts(S->getTryBody());
}
// Now emit the final closing curly brace...
lastCurlyLoc = lastCurlyLoc.getFileLocWithOffset(1);
More information about the llvm-branch-commits
mailing list