Sema: Don't crash when __try/__except/__finally appears in a template function

We wouldn't transform the compound statement in any of these forms,
causing crashes when it got time to act on them.  Additionally, we
wouldn't check to see if the handler was invalid before deciding whether
or not we should continue acting on the __try.

This fixes PR17584.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192682 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 977d013..831c8e8 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -6233,10 +6233,13 @@
 template<typename Derived>
 StmtResult
 TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
-  StmtResult TryBlock; //  = getDerived().TransformCompoundStmt(S->getTryBlock());
+  StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
   if(TryBlock.isInvalid()) return StmtError();
 
   StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
+  if (Handler.isInvalid())
+    return StmtError();
+
   if(!getDerived().AlwaysRebuild() &&
      TryBlock.get() == S->getTryBlock() &&
      Handler.get() == S->getHandler())
@@ -6251,7 +6254,7 @@
 template<typename Derived>
 StmtResult
 TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
-  StmtResult Block; //  = getDerived().TransformCompoundStatement(S->getBlock());
+  StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
   if(Block.isInvalid()) return StmtError();
 
   return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
@@ -6264,7 +6267,7 @@
   ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
   if(FilterExpr.isInvalid()) return StmtError();
 
-  StmtResult Block; //  = getDerived().TransformCompoundStatement(S->getBlock());
+  StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
   if(Block.isInvalid()) return StmtError();
 
   return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),