})
DEF_TRAVERSE_STMT(SEHTryStmt, {})
+DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
DEF_TRAVERSE_STMT(SEHExceptStmt, {})
DEF_TRAVERSE_STMT(SEHFinallyStmt,{})
static bool classof(SEHTryStmt *) { return true; }
};
+class SEHLeaveStmt : public Stmt {
+ SourceLocation LeaveLoc;
+
+ SEHLeaveStmt(SourceLocation LeaveLoc);
+
+ friend class ASTReader;
+ friend class ASTStmtReader;
+ explicit SEHLeaveStmt(EmptyShell E) : Stmt(SEHLeaveStmtClass, E) { }
+
+public:
+ static SEHLeaveStmt* Create(ASTContext &C,
+ SourceLocation LeaveLoc);
+
+ SourceRange getSourceRange() const LLVM_READONLY {
+ return SourceRange(getLeaveLoc());
+ }
+
+ SourceLocation getLeaveLoc() const { return LeaveLoc; }
+
+ child_range children() { return child_range(); }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == SEHLeaveStmtClass;
+ }
+
+ static bool classof(SEHLeaveStmt *) { return true; }
+};
+
} // end namespace clang
#endif
def err_seh___finally_block : Error<
"%0 only allowed in __finally block">;
+
+def err_seh___try_block : Error<
+ "%0 only allowed in __try block">;
} // end of Parse Issue category.
// Microsoft Extensions.
def CXXUuidofExpr : DStmt<Expr>;
def SEHTryStmt : Stmt;
+def SEHLeaveStmt : Stmt;
def SEHExceptStmt : Stmt;
def SEHFinallyStmt : Stmt;
def MSDependentExistsStmt : Stmt;
SwitchScope = 0x800,
/// TryScope - This is the scope of a C++ try statement.
- TryScope = 0x1000
+ TryScope = 0x1000,
+
+ /// SEHTryScope - This is scope of a Microsoft SEH try statement.
+ SEHTryScope = 0x2000
};
private:
/// The parent scope for this scope. This is null for the translation-unit
/// \brief Determine whether this scope is a C++ 'try' block.
bool isTryScope() const { return getFlags() & Scope::TryScope; }
+ /// \brief Determine whether this scope is a MS SEH 'try' block.
+ bool isSEHTryScope() const { return getFlags() & Scope::SEHTryScope; }
+
/// containedInPrototypeScope - Return true if this or a parent scope
/// is a FunctionPrototypeScope.
bool containedInPrototypeScope() const;
Stmt *TryBlock,
Stmt *Handler);
+ StmtResult ActOnSEHLeaveStmt(SourceLocation LeaveLoc);
+
StmtResult ActOnSEHExceptBlock(SourceLocation Loc,
Expr *FilterExpr,
Stmt *Block);
STMT_SEH_EXCEPT, // SEHExceptStmt
STMT_SEH_FINALLY, // SEHFinallyStmt
STMT_SEH_TRY, // SEHTryStmt
+ STMT_SEH_LEAVE, // SEHLeaveStmt
// ARC
EXPR_OBJC_BRIDGED_CAST, // ObjCBridgedCastExpr
return dyn_cast<SEHFinallyStmt>(getHandler());
}
+SEHLeaveStmt::SEHLeaveStmt(SourceLocation LeaveLoc)
+ : Stmt(SEHLeaveStmtClass),
+ LeaveLoc(LeaveLoc)
+{
+}
+
+SEHLeaveStmt* SEHLeaveStmt::Create(ASTContext &C,
+ SourceLocation LeaveLoc) {
+ return new(C) SEHLeaveStmt(LeaveLoc);
+}
+
SEHExceptStmt::SEHExceptStmt(SourceLocation Loc,
Expr *FilterExpr,
Stmt *Block)
OS << "\n";
}
+void StmtPrinter::VisitSEHLeaveStmt(SEHLeaveStmt *Node) {
+ Indent() << "__leave;";
+ OS << "\n";
+}
+
void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
OS << "__finally ";
PrintRawCompoundStmt(Node->getBlock());
void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
OS << "__except (";
VisitExpr(Node->getFilterExpr());
- OS << ")\n";
+ OS << ") ";
PrintRawCompoundStmt(Node->getBlock());
OS << "\n";
}
VisitStmt(S);
}
+void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
+ VisitStmt(S);
+}
+
void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
VisitStmt(S);
}
case Stmt::CXXForRangeStmtClass:
EmitCXXForRangeStmt(cast<CXXForRangeStmt>(*S));
case Stmt::SEHTryStmtClass:
+ case Stmt::SEHLeaveStmtClass:
// FIXME Not yet implemented
break;
}
return ParseExprStatement();
}
+
+ case tok::kw___leave: {
+ Token LeaveTok = Tok;
+ ConsumeToken();
+ if (getCurScope()->isSEHTryScope()) {
+ Res = Actions.ActOnSEHLeaveStmt(LeaveTok.getLocation());
+ } else {
+ Diag(LeaveTok, diag::err_seh___try_block)
+ << LeaveTok.getIdentifierInfo()->getName();
+ Res = StmtError();
+ }
+ break;
+ }
case tok::kw_case: // C99 6.8.1: labeled-statement
return ParseCaseStatement();
if(Tok.isNot(tok::l_brace))
return StmtError(Diag(Tok,diag::err_expected_lbrace));
- StmtResult TryBlock(ParseCompoundStatement());
+ // Use the SEHTryScope to handle __leave as a statement.
+ unsigned ScopeFlags = Scope::DeclScope | Scope::SEHTryScope;
+ StmtResult TryBlock(ParseCompoundStatement(false /*isStmtExpr*/, ScopeFlags));
if(TryBlock.isInvalid())
return TryBlock;
return Owned(SEHTryStmt::Create(Context,IsCXXTry,TryLoc,TryBlock,Handler));
}
+StmtResult
+Sema::ActOnSEHLeaveStmt(SourceLocation LeaveLoc)
+{
+ return Owned(SEHLeaveStmt::Create(Context, LeaveLoc));
+}
+
StmtResult
Sema::ActOnSEHExceptBlock(SourceLocation Loc,
Expr *FilterExpr,
return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
}
+ StmtResult RebuildSEHLeaveStmt(SourceLocation LeaveLoc) {
+ return getSema().ActOnSEHLeaveStmt(LeaveLoc);
+ }
+
StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
Expr *FilterExpr,
Stmt *Block) {
Handler.take());
}
+template<typename Derived>
+StmtResult
+TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
+ return getDerived().RebuildSEHLeaveStmt(S->getLeaveLoc());
+}
+
template<typename Derived>
StmtResult
TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt();
}
+void ASTStmtReader::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
+ VisitStmt(S);
+ S->LeaveLoc = ReadSourceLocation(Record, Idx);
+}
+
//===----------------------------------------------------------------------===//
// CUDA Expressions and Statements
//===----------------------------------------------------------------------===//
case STMT_SEH_TRY:
S = new (Context) SEHTryStmt(Empty);
break;
+ case STMT_SEH_LEAVE:
+ S = new (Context) SEHLeaveStmt(Empty);
+ break;
case STMT_CXX_CATCH:
S = new (Context) CXXCatchStmt(Empty);
break;
Code = serialization::STMT_SEH_TRY;
}
+void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
+ VisitStmt(S);
+ Writer.AddSourceLocation(S->getLeaveLoc(), Record);
+ Code = serialization::STMT_SEH_LEAVE;
+}
+
//===----------------------------------------------------------------------===//
// ASTWriter Implementation
//===----------------------------------------------------------------------===//
case Stmt::PackExpansionExprClass:
case Stmt::SubstNonTypeTemplateParmPackExprClass:
case Stmt::SEHTryStmtClass:
+ case Stmt::SEHLeaveStmtClass:
case Stmt::SEHExceptStmtClass:
case Stmt::LambdaExprClass:
case Stmt::SEHFinallyStmtClass: {
struct S7 s;
int i = s.t; /* expected-warning {{'t' is deprecated}} */
}
+
+void SEH() {
+ __try { __leave; } __except (0) {}
+ __try { } __except (0) { __leave; } // expected-error {{__leave only allowed in __try block}}
+ __try { } __finally { __leave; } // expected-error {{__leave only allowed in __try block}}
+}
\ No newline at end of file
})
DEF_TRAVERSE_STMT(SEHTryStmt, {})
+DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
DEF_TRAVERSE_STMT(SEHExceptStmt, {})
DEF_TRAVERSE_STMT(SEHFinallyStmt,{})