]> granicus.if.org Git - clang/commitdiff
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231625 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 9879ed96110209d651c0f3dc17cf27a4a362e04a..aa7107a259d1bcf8b6ac794a895a03070b51a83c 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 9028e4ac2dd8957b69ab21eb4793cd375121a702..27c757b5081bff76201f2ecef2d2e221fb4c81ff 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 11ec4f5321e968d1c297ec8ecf8b1f9a8d61630c..1710c976afd18fb5a88fa815c2d7960b76756955 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();