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. 

llvm-svn: 46184
diff --git a/clang/Driver/RewriteTest.cpp b/clang/Driver/RewriteTest.cpp
index d9af1f9..20c684c 100644
--- a/clang/Driver/RewriteTest.cpp
+++ b/clang/Driver/RewriteTest.cpp
@@ -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 ';'");
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index d321c97..c34f5c5 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -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) {
diff --git a/clang/test/Sema/rewrite-try-catch.m b/clang/test/Sema/rewrite-try-catch.m
new file mode 100644
index 0000000..b8ba45e
--- /dev/null
+++ b/clang/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;
+}
+}
+