RewriteObjC::RewriteObjCTryStmt():Don't synthesize a catch begin if there are 0 catch clauses.

This fixes <rdar://problem/5987211> clang ObjC rewriter: @try / @finally block produces unbalanced output.

llvm-svn: 53679
This commit is contained in:
Steve Naroff 2008-07-16 15:31:30 +00:00
parent b067bbd019
commit ce2dca186b
2 changed files with 25 additions and 21 deletions

View File

@ -1325,20 +1325,20 @@ Stmt *RewriteObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) {
assert((*startBuf == '}') && "bogus @try block");
SourceLocation lastCurlyLoc = startLoc;
ObjCAtCatchStmt *catchList = S->getCatchStmts();
if (catchList) {
startLoc = startLoc.getFileLocWithOffset(1);
buf = " /* @catch begin */ else {\n";
buf += " id _caught = objc_exception_extract(&_stack);\n";
buf += " objc_exception_try_enter (&_stack);\n";
buf += " if (_setjmp(_stack.buf))\n";
buf += " _rethrow = objc_exception_extract(&_stack);\n";
buf += " else { /* @catch continue */";
startLoc = startLoc.getFileLocWithOffset(1);
buf = " /* @catch begin */ else {\n";
buf += " id _caught = objc_exception_extract(&_stack);\n";
buf += " objc_exception_try_enter (&_stack);\n";
buf += " if (_setjmp(_stack.buf))\n";
buf += " _rethrow = objc_exception_extract(&_stack);\n";
buf += " else { /* @catch continue */";
InsertText(startLoc, buf.c_str(), buf.size());
InsertText(startLoc, buf.c_str(), buf.size());
}
bool sawIdTypedCatch = false;
Stmt *lastCatchBody = 0;
ObjCAtCatchStmt *catchList = S->getCatchStmts();
while (catchList) {
Stmt *catchStmt = catchList->getCatchParamStmt();

View File

@ -11,13 +11,17 @@ void foo() {
int main()
{
@try {
MYTRY();
}
@catch (Foo* localException) {
MYCATCH();
@throw;
}
@try {
MYTRY();
}
@catch (Foo* localException) {
MYCATCH();
@throw;
}
// no catch clause
@try { }
@finally { }
}