r231625 - Fix a theoretical bug when ParseCompoundStatement() returns StmtError.

Nico Weber nicolasweber at gmx.de
Sun Mar 8 20:17:15 PDT 2015


Author: nico
Date: Sun Mar  8 22:17:15 2015
New Revision: 231625

URL: http://llvm.org/viewvc/llvm-project?rev=231625&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Parse/ParseStmt.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=231625&r1=231624&r2=231625&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sun Mar  8 22:17:15 2015
@@ -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);
 

Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=231625&r1=231624&r2=231625&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Sun Mar  8 22:17:15 2015
@@ -519,8 +519,10 @@ StmtResult Parser::ParseSEHFinallyBlock(
   Actions.ActOnStartSEHFinallyBlock();
 
   StmtResult Block(ParseCompoundStatement());
-  if(Block.isInvalid())
+  if(Block.isInvalid()) {
+    Actions.ActOnAbortSEHFinallyBlock();
     return Block;
+  }
 
   return Actions.ActOnFinishSEHFinallyBlock(FinallyLoc, Block.get());
 }

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=231625&r1=231624&r2=231625&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Mar  8 22:17:15 2015
@@ -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();





More information about the cfe-commits mailing list