]> granicus.if.org Git - clang/commitdiff
RewriteObjC::RewriteObjCTryStmt():Don't synthesize a catch begin if there are 0 catch...
authorSteve Naroff <snaroff@apple.com>
Wed, 16 Jul 2008 15:31:30 +0000 (15:31 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 16 Jul 2008 15:31:30 +0000 (15:31 +0000)
This fixes <rdar://problem/5987211> clang ObjC rewriter: @try / @finally block produces unbalanced output.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53679 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteObjC.cpp
test/Rewriter/rewrite-try-catch.m

index 0154aaebd988d4c8b84df804dc2a7af1bed0d4ba..73277d163a652f285cad474a5c7dba66e2d04406 100644 (file)
@@ -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());
   
+  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();
 
index 14966dccb3642541a94d242c551193e951e486cf..be0bf0915890dc2116ed45a1f19ee7cb0d584287 100644 (file)
@@ -11,13 +11,17 @@ void foo() {
 int main()
 {
 
-@try  {
-   MYTRY();
-}
+  @try  {
+     MYTRY();
+  }
 
-@catch (Foo* localException) {
-   MYCATCH();
-   @throw;
-}
+  @catch (Foo* localException) {
+     MYCATCH();
+     @throw;
+  }
+  
+  // no catch clause
+  @try { } 
+  @finally { }
 }