From: David Majnemer Date: Tue, 15 Oct 2013 09:30:14 +0000 (+0000) Subject: Sema: Don't crash when __try/__except/__finally appears in a template function X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7752a741093888ea62e88777929fdaa4c23d0264;p=clang 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 977d0132b7..831c8e89d3 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -6233,10 +6233,13 @@ TreeTransform::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { template StmtResult TreeTransform::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 @@ TreeTransform::TransformSEHTryStmt(SEHTryStmt *S) { template StmtResult TreeTransform::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 @@ TreeTransform::TransformSEHExceptStmt(SEHExceptStmt *S) { 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(), diff --git a/test/SemaCXX/__try.cpp b/test/SemaCXX/__try.cpp index a0f503abe6..1c45581b32 100644 --- a/test/SemaCXX/__try.cpp +++ b/test/SemaCXX/__try.cpp @@ -57,3 +57,23 @@ int main() } return e; } + +namespace PR17584 { +template +void Except() { + __try { + } __except(true) { + } +} + +template +void Finally() { + __try { + } __finally { + } +} + +template void Except(); +template void Finally(); + +}