diff options
author | John McCall <rjmccall@apple.com> | 2011-08-17 21:34:14 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-08-17 21:34:14 +0000 |
commit | 75f92b519c5d7fdbdf5c8e9db9a5cd3ce239c769 (patch) | |
tree | b1d074552a49d4a199cab1693e1edc09e0e7cd3a /clang/lib/Sema/SemaStmt.cpp | |
parent | 8bbcbedeaf8a9cf5c396ce3e77806bf64b858adf (diff) | |
download | bcm5719-llvm-75f92b519c5d7fdbdf5c8e9db9a5cd3ce239c769.tar.gz bcm5719-llvm-75f92b519c5d7fdbdf5c8e9db9a5cd3ce239c769.zip |
Gather cleanups correctly in block return statements.
Thanks to Ted for finding this with magic tools.
llvm-svn: 137877
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 7219718ba49..8303616db4c 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1741,21 +1741,17 @@ Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { // pickier with blocks than for normal functions because we don't have GCC // compatibility to worry about here. ReturnStmt *Result = 0; + const VarDecl *NRVOCandidate = 0; if (CurBlock->ReturnType->isVoidType()) { if (RetValExp && !RetValExp->isTypeDependent() && (!getLangOptions().CPlusPlus || !RetValExp->getType()->isVoidType())) { Diag(ReturnLoc, diag::err_return_block_has_expr); RetValExp = 0; } - Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, 0); } else if (!RetValExp) { if (!CurBlock->ReturnType->isDependentType()) return StmtError(Diag(ReturnLoc, diag::err_block_return_missing_expr)); - - Result = new (Context) ReturnStmt(ReturnLoc, 0, 0); } else { - const VarDecl *NRVOCandidate = 0; - if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) { // we have a non-void block with an expression, continue checking @@ -1775,19 +1771,18 @@ Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { // FIXME: Cleanup temporaries here, anyway? return StmtError(); } + RetValExp = Res.take(); - if (RetValExp) { - CheckImplicitConversions(RetValExp, ReturnLoc); - RetValExp = MaybeCreateExprWithCleanups(RetValExp); - } - - RetValExp = Res.takeAs<Expr>(); if (RetValExp) CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc); } + } - Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, NRVOCandidate); + if (RetValExp) { + CheckImplicitConversions(RetValExp, ReturnLoc); + RetValExp = MaybeCreateExprWithCleanups(RetValExp); } + Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, NRVOCandidate); // If we need to check for the named return value optimization, save the // return statement in our scope for later processing. |