diff options
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 24 | ||||
-rw-r--r-- | clang/lib/Sema/TreeTransform.h | 2 |
2 files changed, 21 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index aaf29db702c..11ec4f5321e 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -2428,6 +2428,14 @@ Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, return new (Context) IndirectGotoStmt(GotoLoc, StarLoc, E); } +static void CheckJumpOutOfSEHFinally(Sema &S, SourceLocation Loc, + const Scope &DestScope) { + if (!S.CurrentSEHFinally.empty() && + DestScope.Contains(*S.CurrentSEHFinally.back())) { + S.Diag(Loc, diag::warn_jump_out_of_seh_finally); + } +} + StmtResult Sema::ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) { Scope *S = CurScope->getContinueParent(); @@ -2435,6 +2443,7 @@ Sema::ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) { // C99 6.8.6.2p1: A break shall appear only in or as a loop body. return StmtError(Diag(ContinueLoc, diag::err_continue_not_in_loop)); } + CheckJumpOutOfSEHFinally(*this, ContinueLoc, *S); return new (Context) ContinueStmt(ContinueLoc); } @@ -2449,6 +2458,7 @@ Sema::ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope) { if (S->isOpenMPLoopScope()) return StmtError(Diag(BreakLoc, diag::err_omp_loop_cannot_use_stmt) << "break"); + CheckJumpOutOfSEHFinally(*this, BreakLoc, *S); return new (Context) BreakStmt(BreakLoc); } @@ -2908,6 +2918,8 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, CurScope->setNoNRVO(); } + CheckJumpOutOfSEHFinally(*this, ReturnLoc, *CurScope->getFnParent()); + return R; } @@ -3406,11 +3418,14 @@ Sema::ActOnSEHExceptBlock(SourceLocation Loc, return SEHExceptStmt::Create(Context,Loc,FilterExpr,Block); } -StmtResult -Sema::ActOnSEHFinallyBlock(SourceLocation Loc, - Stmt *Block) { +void Sema::ActOnStartSEHFinallyBlock() { + CurrentSEHFinally.push_back(CurScope); +} + +StmtResult Sema::ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block) { assert(Block); - return SEHFinallyStmt::Create(Context,Loc,Block); + CurrentSEHFinally.pop_back(); + return SEHFinallyStmt::Create(Context, Loc, Block); } StmtResult @@ -3420,6 +3435,7 @@ Sema::ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope) { SEHTryParent = SEHTryParent->getParent(); if (!SEHTryParent) return StmtError(Diag(Loc, diag::err_ms___leave_not_in___try)); + CheckJumpOutOfSEHFinally(*this, Loc, *SEHTryParent); return new (Context) SEHLeaveStmt(Loc); } diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index e1d0d18dde4..351dacd256e 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1702,7 +1702,7 @@ public: } StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { - return getSema().ActOnSEHFinallyBlock(Loc, Block); + return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block); } /// \brief Build a new predefined expression. |