[cfe-commits] r56104 - /cfe/trunk/Driver/RewriteObjC.cpp

Steve Naroff snaroff at apple.com
Thu Sep 11 08:29:06 PDT 2008


Author: snaroff
Date: Thu Sep 11 10:29:03 2008
New Revision: 56104

URL: http://llvm.org/viewvc/llvm-project?rev=56104&view=rev
Log:
Fix <rdar://problem/6210791> clang ObjC rewriter: @try / @catch block with no @finally does not call objc_exception_try_exit.

Need a couple tweaks to RewriteObjCTryStmt(). Need to deal with implicit finally clauses (to make sure objc_exception_try_exit is called). Also fixed a related bug where we need to generate an implicit @catch else clause (to again make sure objc_exception_try_exit is called).

Modified:
    cfe/trunk/Driver/RewriteObjC.cpp

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=56104&r1=56103&r2=56104&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Thu Sep 11 10:29:03 2008
@@ -1455,9 +1455,16 @@
     SourceLocation bodyLoc = lastCatchBody->getLocEnd();
     assert(*SM->getCharacterData(bodyLoc) == '}' &&
            "bogus @catch body location");
-    bodyLoc = bodyLoc.getFileLocWithOffset(1);
-    buf = " } } /* @catch end */\n";
   
+    // Insert the last (implicit) else clause *before* the right curly brace.
+    bodyLoc = bodyLoc.getFileLocWithOffset(-1);
+    buf = "} /* last catch end */\n";
+    buf += "else {\n";
+    buf += " _rethrow = _caught;\n";
+    buf += " objc_exception_try_exit(&_stack);\n";
+    buf += "} } /* @catch end */\n";
+    if (!S->getFinallyStmt())
+      buf += "}\n";
     InsertText(bodyLoc, buf.c_str(), buf.size());
     
     // Set lastCurlyLoc
@@ -1488,6 +1495,12 @@
     
     // Set lastCurlyLoc
     lastCurlyLoc = body->getLocEnd();
+  } else { /* no finally clause - make sure we synthesize an implicit one */
+    buf = "{ /* implicit finally clause */\n";
+    buf += " if (!_rethrow) objc_exception_try_exit(&_stack);\n";
+    buf += " if (_rethrow) objc_exception_throw(_rethrow);\n";
+    buf += "}";
+    ReplaceText(lastCurlyLoc, 1, buf.c_str(), buf.size());
   }
   // Now emit the final closing curly brace...
   lastCurlyLoc = lastCurlyLoc.getFileLocWithOffset(1);





More information about the cfe-commits mailing list