diff options
| author | John McCall <rjmccall@apple.com> | 2012-04-13 01:08:17 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2012-04-13 01:08:17 +0000 |
| commit | d239387098ff0ce0d13735e8f3df69e4efe46cea (patch) | |
| tree | 8b3cf96e6c80aace376c6c29618f794105c24eee /clang/lib/Sema | |
| parent | 585583c8dd13bebe6fe5851ba3b872cfea411cdf (diff) | |
| download | bcm5719-llvm-d239387098ff0ce0d13735e8f3df69e4efe46cea.tar.gz bcm5719-llvm-d239387098ff0ce0d13735e8f3df69e4efe46cea.zip | |
When we're flagging a protected scope to prevent jumps into the
shadow of a block expression with non-trivial destructed cleanups,
we should flag that in the enclosing function, not in the block
that we're about to pop.
llvm-svn: 154646
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 2333e32e85f..0d0f2f5b99a 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -9111,15 +9111,6 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, BSI->TheDecl->setBody(cast<CompoundStmt>(Body)); - for (BlockDecl::capture_const_iterator ci = BSI->TheDecl->capture_begin(), - ce = BSI->TheDecl->capture_end(); ci != ce; ++ci) { - const VarDecl *variable = ci->getVariable(); - QualType T = variable->getType(); - QualType::DestructionKind destructKind = T.isDestructedType(); - if (destructKind != QualType::DK_none) - getCurFunction()->setHasBranchProtectedScope(); - } - computeNRVO(Body, getCurBlock()); BlockExpr *Result = new (Context) BlockExpr(BSI->TheDecl, BlockTy); @@ -9127,10 +9118,23 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, PopFunctionScopeInfo(&WP, Result->getBlockDecl(), Result); // If the block isn't obviously global, i.e. it captures anything at - // all, mark this full-expression as needing a cleanup. + // all, then we need to do a few things in the surrounding context: if (Result->getBlockDecl()->hasCaptures()) { + // First, this expression has a new cleanup object. ExprCleanupObjects.push_back(Result->getBlockDecl()); ExprNeedsCleanups = true; + + // It also gets a branch-protected scope if any of the captured + // variables needs destruction. + for (BlockDecl::capture_const_iterator + ci = Result->getBlockDecl()->capture_begin(), + ce = Result->getBlockDecl()->capture_end(); ci != ce; ++ci) { + const VarDecl *var = ci->getVariable(); + if (var->getType().isDestructedType() != QualType::DK_none) { + getCurFunction()->setHasBranchProtectedScope(); + break; + } + } } return Owned(Result); |

