diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/CGStmt.cpp | 12 | ||||
-rw-r--r-- | lib/Sema/JumpDiagnostics.cpp | 11 |
2 files changed, 20 insertions, 3 deletions
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 4fdbfd0390..77414bf8a4 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -743,6 +743,17 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { // Emit the result value, even if unused, to evalute the side effects. const Expr *RV = S.getRetValue(); + // Treat block literals in a return expression as if they appeared + // in their own scope. This permits a small, easily-implemented + // exception to our over-conservative rules about not jumping to + // statements following block literals with non-trivial cleanups. + RunCleanupsScope cleanupScope(*this); + if (const ExprWithCleanups *cleanups = + dyn_cast_or_null<ExprWithCleanups>(RV)) { + enterFullExpression(cleanups); + RV = cleanups->getSubExpr(); + } + // FIXME: Clean this up by using an LValue for ReturnTemp, // EmitStoreThroughLValue, and EmitAnyExpr. if (S.getNRVOCandidate() && S.getNRVOCandidate()->isNRVOVariable() && @@ -779,6 +790,7 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { AggValueSlot::IsNotAliased)); } + cleanupScope.ForceCleanup(); EmitBranchThroughCleanup(ReturnBlock); } diff --git a/lib/Sema/JumpDiagnostics.cpp b/lib/Sema/JumpDiagnostics.cpp index ab786c65aa..a48779a1c3 100644 --- a/lib/Sema/JumpDiagnostics.cpp +++ b/lib/Sema/JumpDiagnostics.cpp @@ -453,14 +453,19 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned &origParentScope) BuildScopeInformation(AS->getSubStmt(), (newParentScope = Scopes.size()-1)); continue; } - - if (const BlockExpr *BE = dyn_cast<BlockExpr>(SubStmt)) { - const BlockDecl *BDecl = BE->getBlockDecl(); + + // Disallow jumps past full-expressions that use blocks with + // non-trivial cleanups of their captures. This is theoretically + // implementable but a lot of work which we haven't felt up to doing. + if (ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(SubStmt)) { + for (unsigned i = 0, e = EWC->getNumObjects(); i != e; ++i) { + const BlockDecl *BDecl = EWC->getObject(i); for (BlockDecl::capture_const_iterator ci = BDecl->capture_begin(), ce = BDecl->capture_end(); ci != ce; ++ci) { VarDecl *variable = ci->getVariable(); BuildScopeInformation(variable, BDecl, ParentScope); } + } } // Recursively walk the AST. |