From 0bf9e4ff0b534b8a9e310dd5debb33da82da22fb Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 9 Mar 2015 03:17:15 +0000 Subject: [PATCH] Fix a theoretical bug when ParseCompoundStatement() returns StmtError. ParseCompoundStatement() currently never returns StmtError, but if it did, Sema would keep the __finally scope on its stack indefinitely. Explicitly add an error callback that clears it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231625 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Sema.h | 1 + lib/Parse/ParseStmt.cpp | 4 +++- lib/Sema/SemaStmt.cpp | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 9879ed9611..aa7107a259 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -3297,6 +3297,7 @@ public: Expr *FilterExpr, Stmt *Block); void ActOnStartSEHFinallyBlock(); + void ActOnAbortSEHFinallyBlock(); StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block); StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope); diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 9028e4ac2d..27c757b508 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -519,8 +519,10 @@ StmtResult Parser::ParseSEHFinallyBlock(SourceLocation FinallyLoc) { Actions.ActOnStartSEHFinallyBlock(); StmtResult Block(ParseCompoundStatement()); - if(Block.isInvalid()) + if(Block.isInvalid()) { + Actions.ActOnAbortSEHFinallyBlock(); return Block; + } return Actions.ActOnFinishSEHFinallyBlock(FinallyLoc, Block.get()); } diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 11ec4f5321..1710c976af 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -3422,6 +3422,10 @@ void Sema::ActOnStartSEHFinallyBlock() { CurrentSEHFinally.push_back(CurScope); } +void Sema::ActOnAbortSEHFinallyBlock() { + CurrentSEHFinally.pop_back(); +} + StmtResult Sema::ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block) { assert(Block); CurrentSEHFinally.pop_back(); -- 2.40.0