diff options
author | Anders Carlsson <andersca@mac.com> | 2009-06-03 18:40:21 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-06-03 18:40:21 +0000 |
commit | 2ce66125025536e6a06dc5cbc809d621a7c71a74 (patch) | |
tree | 3a47d046516dd2b62a92a9f78297afa792562ac8 /lib/CodeGen/CGCXXTemp.cpp | |
parent | 923cb23eabaf800a647dd9466ed68fe5b83c3250 (diff) |
Move code generation of C++ temporaries into a new file.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72792 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXXTemp.cpp')
-rw-r--r-- | lib/CodeGen/CGCXXTemp.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/CodeGen/CGCXXTemp.cpp b/lib/CodeGen/CGCXXTemp.cpp new file mode 100644 index 0000000000..4511078e1d --- /dev/null +++ b/lib/CodeGen/CGCXXTemp.cpp @@ -0,0 +1,53 @@ +//===--- CGCXXTemp.cpp - Emit LLVM Code for C++ temporaries ---------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This contains code dealing with C++ code generation of temporaries +// +//===----------------------------------------------------------------------===// + +#include "CodeGenFunction.h" +using namespace clang; +using namespace CodeGen; + +void CodeGenFunction::PushCXXTemporary(const CXXTemporary *Temporary, + llvm::Value *Ptr) { + LiveTemporaries.push_back(Temporary); + + // Make a cleanup scope and emit the destructor. + { + CleanupScope Scope(*this); + + EmitCXXDestructorCall(Temporary->getDestructor(), Dtor_Complete, Ptr); + } +} + +RValue +CodeGenFunction::EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, + llvm::Value *AggLoc, + bool isAggLocVolatile) { + // Keep track of the current cleanup stack depth. + size_t CleanupStackDepth = CleanupEntries.size(); + + unsigned OldNumLiveTemporaries = LiveTemporaries.size(); + + RValue RV = EmitAnyExpr(E->getSubExpr(), AggLoc, isAggLocVolatile); + + // Go through the temporaries backwards. + for (unsigned i = E->getNumTemporaries(); i != 0; --i) { + assert(LiveTemporaries.back() == E->getTemporary(i - 1)); + LiveTemporaries.pop_back(); + } + + assert(OldNumLiveTemporaries == LiveTemporaries.size() && + "Live temporary stack mismatch!"); + + EmitCleanupBlocks(CleanupStackDepth); + + return RV; +} |