diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-05-17 15:52:46 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-05-17 15:52:46 +0000 |
commit | 9154b5dffe4ffa014c65f4629a8429c4b166e3b3 (patch) | |
tree | cc0771b6ec00b1cbd43cd1bfa89a434f0dbf89b6 /clang/lib/CodeGen/CGStmt.cpp | |
parent | f5e8c86424333a7ccbf71c2b25ef3b85749bf358 (diff) | |
download | bcm5719-llvm-9154b5dffe4ffa014c65f4629a8429c4b166e3b3.tar.gz bcm5719-llvm-9154b5dffe4ffa014c65f4629a8429c4b166e3b3.zip |
Ensure that destructors are called for NRVO'd objects when the
function does not return. Thanks to Eli for pointing out this corner
case.
llvm-svn: 103941
Diffstat (limited to 'clang/lib/CodeGen/CGStmt.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGStmt.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index f51a899e7ff..496fd2fe1fb 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -612,6 +612,14 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { // Apply the named return value optimization for this return statement, // which means doing nothing: the appropriate result has already been // constructed into the NRVO variable. + + // If there is an NRVO flag for this variable, set it to 1 into indicate + // that the cleanup code should not destroy the variable. + if (llvm::Value *NRVOFlag = NRVOFlags[S.getNRVOCandidate()]) { + const llvm::Type *BoolTy = llvm::Type::getInt1Ty(VMContext); + llvm::Value *One = llvm::ConstantInt::get(BoolTy, 1); + Builder.CreateStore(One, NRVOFlag); + } } else if (!ReturnValue) { // Make sure not to return anything, but evaluate the expression // for side effects. |