]> granicus.if.org Git - clang/commitdiff
Fix two bugs with an @throw that doesn't have a statement.
authorSteve Naroff <snaroff@apple.com>
Sat, 19 Jan 2008 00:42:38 +0000 (00:42 +0000)
committerSteve Naroff <snaroff@apple.com>
Sat, 19 Jan 2008 00:42:38 +0000 (00:42 +0000)
- ObjCAtThrowStmt::getSourceRange() needs to check if it has a statement (and not go "boom":-)
- RewriteTest::RewriteObjCThrowStmt() needs to generate refer to the current exception.

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

Driver/RewriteTest.cpp
include/clang/AST/Stmt.h
test/Sema/rewrite-try-catch.m [new file with mode: 0644]

index d9af1f97438ae36ab11ce2b3cdb650594db188bf..20c684c0d0e88329ee89d03fc8bc333cb5a8fa87 100644 (file)
@@ -1207,7 +1207,10 @@ Stmt *RewriteTest::RewriteObjCThrowStmt(ObjCAtThrowStmt *S) {
 
   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 ';'");
index d321c9715c7f7307f96becfab713ff41233bb4eb..c34f5c5a113cbd9e46ffbe644b0b9db31986100d 100644 (file)
@@ -974,8 +974,11 @@ public:
   
   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) {
diff --git a/test/Sema/rewrite-try-catch.m b/test/Sema/rewrite-try-catch.m
new file mode 100644 (file)
index 0000000..b8ba45e
--- /dev/null
@@ -0,0 +1,18 @@
+// RUN: clang -rewrite-test %s | clang
+
+@interface foo @end
+@interface GARF @end
+
+int main()
+{
+
+@try  {
+   MYTRY();
+}
+
+@catch (foo* localException) {
+   MYCATCH();
+   @throw;
+}
+}
+