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:
parent
b067bbd019
commit
ce2dca186b
|
@ -1323,22 +1323,22 @@ Stmt *RewriteObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) {
|
|||
startBuf = SM->getCharacterData(startLoc);
|
||||
|
||||
assert((*startBuf == '}') && "bogus @try block");
|
||||
|
||||
|
||||
SourceLocation lastCurlyLoc = startLoc;
|
||||
|
||||
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());
|
||||
|
||||
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 */";
|
||||
|
||||
InsertText(startLoc, buf.c_str(), buf.size());
|
||||
}
|
||||
bool sawIdTypedCatch = false;
|
||||
Stmt *lastCatchBody = 0;
|
||||
ObjCAtCatchStmt *catchList = S->getCatchStmts();
|
||||
while (catchList) {
|
||||
Stmt *catchStmt = catchList->getCatchParamStmt();
|
||||
|
||||
|
|
|
@ -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 { }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue