[cfe-commits] r53679 - in /cfe/trunk: Driver/RewriteObjC.cpp test/Rewriter/rewrite-try-catch.m
Steve Naroff
snaroff at apple.com
Wed Jul 16 08:31:38 PDT 2008
Author: snaroff
Date: Wed Jul 16 10:31:30 2008
New Revision: 53679
URL: http://llvm.org/viewvc/llvm-project?rev=53679&view=rev
Log:
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.
Modified:
cfe/trunk/Driver/RewriteObjC.cpp
cfe/trunk/test/Rewriter/rewrite-try-catch.m
Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=53679&r1=53678&r2=53679&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Wed Jul 16 10:31:30 2008
@@ -1323,22 +1323,22 @@
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());
+ 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 */";
+
+ InsertText(startLoc, buf.c_str(), buf.size());
+ }
bool sawIdTypedCatch = false;
Stmt *lastCatchBody = 0;
- ObjCAtCatchStmt *catchList = S->getCatchStmts();
while (catchList) {
Stmt *catchStmt = catchList->getCatchParamStmt();
Modified: cfe/trunk/test/Rewriter/rewrite-try-catch.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-try-catch.m?rev=53679&r1=53678&r2=53679&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-try-catch.m (original)
+++ cfe/trunk/test/Rewriter/rewrite-try-catch.m Wed Jul 16 10:31:30 2008
@@ -11,13 +11,17 @@
int main()
{
- at try {
- MYTRY();
-}
+ @try {
+ MYTRY();
+ }
- at catch (Foo* localException) {
- MYCATCH();
- @throw;
-}
+ @catch (Foo* localException) {
+ MYCATCH();
+ @throw;
+ }
+
+ // no catch clause
+ @try { }
+ @finally { }
}
More information about the cfe-commits
mailing list