aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2008-01-19 00:42:38 +0000
committerSteve Naroff <snaroff@apple.com>2008-01-19 00:42:38 +0000
commit20ebf8f15df48f27ce2bf7c1b3ae87565235600f (patch)
tree3d6a32dff795a3a07148e54ce8837a764ccb5d22
parent452b899c9f5fbcb8ddd130375b7982bed6b4d93f (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46184 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/RewriteTest.cpp5
-rw-r--r--include/clang/AST/Stmt.h7
-rw-r--r--test/Sema/rewrite-try-catch.m18
3 files changed, 27 insertions, 3 deletions
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
index d9af1f9743..20c684c0d0 100644
--- a/Driver/RewriteTest.cpp
+++ b/Driver/RewriteTest.cpp
@@ -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 ';'");
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index d321c9715c..c34f5c5a11 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -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
index 0000000000..b8ba45ee64
--- /dev/null
+++ b/test/Sema/rewrite-try-catch.m
@@ -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;
+}
+}
+