summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorWarren Hunt <whunt@google.com>2014-07-19 00:45:07 +0000
committerWarren Hunt <whunt@google.com>2014-07-19 00:45:07 +0000
commitb530bc0242901d1322d77ce24b64eda10554c35f (patch)
tree782cf0d367af07d228d51d6e278392ae571a023e /clang/lib
parent6971b861d7d33eb87b8cad86555a8e483499299f (diff)
downloadbcm5719-llvm-b530bc0242901d1322d77ce24b64eda10554c35f.tar.gz
bcm5719-llvm-b530bc0242901d1322d77ce24b64eda10554c35f.zip
[MS-ABI] Assign SEH handler indices to __try blocks
Assigns indices to try blocks. These indices will used in constructing tables that the mscrt function __except_handler3 reads during SEH. Testing will occur once we actually emit the tables, in a subsequent patch. llvm-svn: 213437
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/Stmt.cpp22
-rw-r--r--clang/lib/Parse/ParseStmt.cpp48
-rw-r--r--clang/lib/Sema/Scope.cpp9
-rw-r--r--clang/lib/Sema/SemaStmt.cpp11
-rw-r--r--clang/lib/Sema/TreeTransform.h11
5 files changed, 70 insertions, 31 deletions
diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp
index e46edd23ec0..a5ca49df204 100644
--- a/clang/lib/AST/Stmt.cpp
+++ b/clang/lib/AST/Stmt.cpp
@@ -956,22 +956,20 @@ Expr* ReturnStmt::getRetValue() {
return cast_or_null<Expr>(RetExpr);
}
-SEHTryStmt::SEHTryStmt(bool IsCXXTry,
- SourceLocation TryLoc,
- Stmt *TryBlock,
- Stmt *Handler)
- : Stmt(SEHTryStmtClass),
- IsCXXTry(IsCXXTry),
- TryLoc(TryLoc)
-{
- Children[TRY] = TryBlock;
+SEHTryStmt::SEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock,
+ Stmt *Handler, int HandlerIndex, int HandlerParentIndex)
+ : Stmt(SEHTryStmtClass), IsCXXTry(IsCXXTry), TryLoc(TryLoc),
+ HandlerIndex(HandlerIndex), HandlerParentIndex(HandlerParentIndex) {
+ Children[TRY] = TryBlock;
Children[HANDLER] = Handler;
}
-SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry,
+SEHTryStmt *SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry,
SourceLocation TryLoc, Stmt *TryBlock,
- Stmt *Handler) {
- return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
+ Stmt *Handler, int HandlerIndex,
+ int HandlerParentIndex) {
+ return new (C) SEHTryStmt(IsCXXTry, TryLoc, TryBlock, Handler, HandlerIndex,
+ HandlerParentIndex);
}
SEHExceptStmt* SEHTryStmt::getExceptHandler() const {
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 6f6c495dde3..1e8c4a69d86 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -424,11 +424,27 @@ StmtResult Parser::ParseSEHTryBlock() {
/// seh-finally-block
///
StmtResult Parser::ParseSEHTryBlockCommon(SourceLocation TryLoc) {
- if(Tok.isNot(tok::l_brace))
+ if (Tok.isNot(tok::l_brace))
return StmtError(Diag(Tok, diag::err_expected) << tok::l_brace);
- StmtResult TryBlock(ParseCompoundStatement(/*isStmtExpr=*/false,
- Scope::DeclScope | Scope::SEHTryScope));
+ int SEHTryIndex, SEHTryParentIndex;
+ StmtResult TryBlock;
+ {
+ assert(Tok.is(tok::l_brace) && "Not a compount stmt!");
+
+ // Enter a scope to hold everything within the compound stmt. Compound
+ // statements can always hold declarations.
+ ParseScope CompoundScope(this, Scope::DeclScope | Scope::SEHTryScope);
+ SEHTryIndex = getCurScope()->getSEHTryIndex();
+ SEHTryParentIndex = getCurScope()->getSEHTryParentIndex();
+
+ // Parse the statements in the body.
+ TryBlock = ParseCompoundStatementBody();
+ }
+
+ //StmtResult TryBlock(ParseCompoundStatement(/*isStmtExpr=*/false,
+ // Scope::DeclScope | Scope::SEHTryScope));
+
if(TryBlock.isInvalid())
return TryBlock;
@@ -450,7 +466,9 @@ StmtResult Parser::ParseSEHTryBlockCommon(SourceLocation TryLoc) {
return Actions.ActOnSEHTryBlock(false /* IsCXXTry */,
TryLoc,
TryBlock.get(),
- Handler.get());
+ Handler.get(),
+ SEHTryIndex,
+ SEHTryParentIndex);
}
/// ParseSEHExceptBlock - Handle __except
@@ -1961,9 +1979,21 @@ StmtResult Parser::ParseCXXTryBlockCommon(SourceLocation TryLoc, bool FnTry) {
return StmtError(Diag(Tok, diag::err_expected) << tok::l_brace);
// FIXME: Possible draft standard bug: attribute-specifier should be allowed?
- StmtResult TryBlock(ParseCompoundStatement(/*isStmtExpr=*/false,
- Scope::DeclScope | Scope::TryScope |
- (FnTry ? Scope::FnTryCatchScope : 0)));
+ int SEHTryIndex, SEHTryParentIndex;
+ StmtResult TryBlock;
+ {
+ assert(Tok.is(tok::l_brace) && "Not a compount stmt!");
+
+ // Enter a scope to hold everything within the compound stmt. Compound
+ // statements can always hold declarations.
+ ParseScope CompoundScope(this, Scope::DeclScope | Scope::TryScope |
+ (FnTry ? Scope::FnTryCatchScope : 0));
+ SEHTryIndex = getCurScope()->getSEHTryIndex();
+ SEHTryParentIndex = getCurScope()->getSEHTryParentIndex();
+
+ // Parse the statements in the body.
+ TryBlock = ParseCompoundStatementBody();
+ }
if (TryBlock.isInvalid())
return TryBlock;
@@ -1988,7 +2018,9 @@ StmtResult Parser::ParseCXXTryBlockCommon(SourceLocation TryLoc, bool FnTry) {
return Actions.ActOnSEHTryBlock(true /* IsCXXTry */,
TryLoc,
TryBlock.get(),
- Handler.get());
+ Handler.get(),
+ SEHTryIndex,
+ SEHTryParentIndex);
}
else {
StmtVector Handlers;
diff --git a/clang/lib/Sema/Scope.cpp b/clang/lib/Sema/Scope.cpp
index 6c797788238..35e2075b382 100644
--- a/clang/lib/Sema/Scope.cpp
+++ b/clang/lib/Sema/Scope.cpp
@@ -39,6 +39,9 @@ void Scope::Init(Scope *parent, unsigned flags) {
BlockParent = parent->BlockParent;
TemplateParamParent = parent->TemplateParamParent;
MSLocalManglingParent = parent->MSLocalManglingParent;
+ SEHTryParent = parent->SEHTryParent;
+ if (parent->Flags & SEHTryScope)
+ SEHTryParent = parent;
if ((Flags & (FnScope | ClassScope | BlockScope | TemplateParamScope |
FunctionPrototypeScope | AtCatchScope | ObjCMethodScope)) ==
0)
@@ -47,13 +50,17 @@ void Scope::Init(Scope *parent, unsigned flags) {
Depth = 0;
PrototypeDepth = 0;
PrototypeIndex = 0;
- MSLocalManglingParent = FnParent = BlockParent = nullptr;
+ SEHTryParent = MSLocalManglingParent = FnParent = BlockParent = nullptr;
TemplateParamParent = nullptr;
MSLocalManglingNumber = 1;
}
// If this scope is a function or contains breaks/continues, remember it.
if (flags & FnScope) FnParent = this;
+ SEHTryIndexPool = 0;
+ SEHTryIndex = -1;
+ if (flags & SEHTryScope)
+ SEHTryIndex = FnParent ? FnParent->SEHTryIndexPool++ : -1;
// The MS mangler uses the number of scopes that can hold declarations as
// part of an external name.
if (Flags & (ClassScope | FnScope)) {
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 1ddb3694cbe..278e6d66828 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3249,16 +3249,15 @@ StmtResult Sema::ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
return CXXTryStmt::Create(Context, TryLoc, TryBlock, Handlers);
}
-StmtResult
-Sema::ActOnSEHTryBlock(bool IsCXXTry,
- SourceLocation TryLoc,
- Stmt *TryBlock,
- Stmt *Handler) {
+StmtResult Sema::ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc,
+ Stmt *TryBlock, Stmt *Handler,
+ int HandlerIndex, int HandlerParentIndex) {
assert(TryBlock && Handler);
getCurFunction()->setHasBranchProtectedScope();
- return SEHTryStmt::Create(Context,IsCXXTry,TryLoc,TryBlock,Handler);
+ return SEHTryStmt::Create(Context, IsCXXTry, TryLoc, TryBlock, Handler,
+ HandlerIndex, HandlerParentIndex);
}
StmtResult
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 04a3909da35..1f648d4aca6 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -1653,8 +1653,10 @@ public:
}
StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
- Stmt *TryBlock, Stmt *Handler) {
- return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
+ Stmt *TryBlock, Stmt *Handler, int HandlerIndex,
+ int HandlerParentIndex) {
+ return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler,
+ HandlerIndex, HandlerParentIndex);
}
StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
@@ -6366,8 +6368,9 @@ StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
Handler.get() == S->getHandler())
return S;
- return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
- TryBlock.get(), Handler.get());
+ return getDerived().RebuildSEHTryStmt(
+ S->getIsCXXTry(), S->getTryLoc(), TryBlock.get(), Handler.get(),
+ S->getHandlerIndex(), S->getHandlerParentIndex());
}
template <typename Derived>
OpenPOWER on IntegriCloud