Fix a theoretical bug when ParseCompoundStatement() returns StmtError.
authorNico Weber <nicolasweber@gmx.de>
Mon, 9 Mar 2015 03:17:15 +0000 (03:17 +0000)
committerNico Weber <nicolasweber@gmx.de>
Mon, 9 Mar 2015 03:17:15 +0000 (03:17 +0000)
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.

llvm-svn: 231625

clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseStmt.cpp
clang/lib/Sema/SemaStmt.cpp

index 9879ed9..aa7107a 100644 (file)
@@ -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);
 
index 9028e4a..27c757b 100644 (file)
@@ -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());
 }
index 11ec4f5..1710c97 100644 (file)
@@ -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();