[cfe-commits] r46184 - in /cfe/trunk: Driver/RewriteTest.cpp include/clang/AST/Stmt.h test/Sema/rewrite-try-catch.m

Steve Naroff snaroff at apple.com
Fri Jan 18 16:42:41 PST 2008


Author: snaroff
Date: Fri Jan 18 18:42:38 2008
New Revision: 46184

URL: http://llvm.org/viewvc/llvm-project?rev=46184&view=rev
Log:

Fix two bugs with an @throw that doesn't have a statement.
- ObjCAtThrowStmt::getSourceRange() needs to check if it has a statement (and not go "boom":-)
- RewriteTest::RewriteObjCThrowStmt() needs to generate refer to the current exception. 


Added:
    cfe/trunk/test/Sema/rewrite-try-catch.m
Modified:
    cfe/trunk/Driver/RewriteTest.cpp
    cfe/trunk/include/clang/AST/Stmt.h

Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=46184&r1=46183&r2=46184&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Fri Jan 18 18:42:38 2008
@@ -1207,7 +1207,10 @@
 
   std::string buf;
   /* void objc_exception_throw(id) __attribute__((noreturn)); */
-  buf = "objc_exception_throw(";
+  if (S->getThrowExpr())
+    buf = "objc_exception_throw(";
+  else // add an implicit argument
+    buf = "objc_exception_throw(_caught";
   Rewrite.ReplaceText(startLoc, 6, buf.c_str(), buf.size());
   const char *semiBuf = strchr(startBuf, ';');
   assert((*semiBuf == ';') && "@throw: can't find ';'");

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=46184&r1=46183&r2=46184&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Fri Jan 18 18:42:38 2008
@@ -974,8 +974,11 @@
   
   Expr *const getThrowExpr() const { return reinterpret_cast<Expr*>(Throw); }
   
-  virtual SourceRange getSourceRange() const { 
-    return SourceRange(AtThrowLoc, Throw->getLocEnd()); 
+  virtual SourceRange getSourceRange() const {
+    if (Throw)
+      return SourceRange(AtThrowLoc, Throw->getLocEnd()); 
+	else 
+	  return SourceRange(AtThrowLoc);
   }
   
   static bool classof(const Stmt *T) {

Added: cfe/trunk/test/Sema/rewrite-try-catch.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/rewrite-try-catch.m?rev=46184&view=auto

==============================================================================
--- cfe/trunk/test/Sema/rewrite-try-catch.m (added)
+++ cfe/trunk/test/Sema/rewrite-try-catch.m Fri Jan 18 18:42:38 2008
@@ -0,0 +1,18 @@
+// RUN: clang -rewrite-test %s | clang
+
+ at interface foo @end
+ at interface GARF @end
+
+int main()
+{
+
+ at try  {
+   MYTRY();
+}
+
+ at catch (foo* localException) {
+   MYCATCH();
+   @throw;
+}
+}
+





More information about the cfe-commits mailing list