r192682 - Sema: Don't crash when __try/__except/__finally appears in a template function
David Majnemer
david.majnemer at gmail.com
Tue Oct 15 02:30:14 PDT 2013
Author: majnemer
Date: Tue Oct 15 04:30:14 2013
New Revision: 192682
URL: http://llvm.org/viewvc/llvm-project?rev=192682&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaCXX/__try.cpp
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=192682&r1=192681&r2=192682&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Tue Oct 15 04:30:14 2013
@@ -6233,10 +6233,13 @@ TreeTransform<Derived>::TransformMSPrope
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 @@ TreeTransform<Derived>::TransformSEHTryS
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 @@ TreeTransform<Derived>::TransformSEHExce
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(),
Modified: cfe/trunk/test/SemaCXX/__try.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/__try.cpp?rev=192682&r1=192681&r2=192682&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/__try.cpp (original)
+++ cfe/trunk/test/SemaCXX/__try.cpp Tue Oct 15 04:30:14 2013
@@ -57,3 +57,23 @@ int main()
}
return e;
}
+
+namespace PR17584 {
+template <typename>
+void Except() {
+ __try {
+ } __except(true) {
+ }
+}
+
+template <typename>
+void Finally() {
+ __try {
+ } __finally {
+ }
+}
+
+template void Except<void>();
+template void Finally<void>();
+
+}
More information about the cfe-commits
mailing list