Anders Carlsson | 2ce6612 | 2009-06-03 18:40:21 +0000 | [diff] [blame^] | 1 | //===--- CGCXXTemp.cpp - Emit LLVM Code for C++ temporaries ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This contains code dealing with C++ code generation of temporaries |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CodeGenFunction.h" |
| 15 | using namespace clang; |
| 16 | using namespace CodeGen; |
| 17 | |
| 18 | void CodeGenFunction::PushCXXTemporary(const CXXTemporary *Temporary, |
| 19 | llvm::Value *Ptr) { |
| 20 | LiveTemporaries.push_back(Temporary); |
| 21 | |
| 22 | // Make a cleanup scope and emit the destructor. |
| 23 | { |
| 24 | CleanupScope Scope(*this); |
| 25 | |
| 26 | EmitCXXDestructorCall(Temporary->getDestructor(), Dtor_Complete, Ptr); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | RValue |
| 31 | CodeGenFunction::EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, |
| 32 | llvm::Value *AggLoc, |
| 33 | bool isAggLocVolatile) { |
| 34 | // Keep track of the current cleanup stack depth. |
| 35 | size_t CleanupStackDepth = CleanupEntries.size(); |
| 36 | |
| 37 | unsigned OldNumLiveTemporaries = LiveTemporaries.size(); |
| 38 | |
| 39 | RValue RV = EmitAnyExpr(E->getSubExpr(), AggLoc, isAggLocVolatile); |
| 40 | |
| 41 | // Go through the temporaries backwards. |
| 42 | for (unsigned i = E->getNumTemporaries(); i != 0; --i) { |
| 43 | assert(LiveTemporaries.back() == E->getTemporary(i - 1)); |
| 44 | LiveTemporaries.pop_back(); |
| 45 | } |
| 46 | |
| 47 | assert(OldNumLiveTemporaries == LiveTemporaries.size() && |
| 48 | "Live temporary stack mismatch!"); |
| 49 | |
| 50 | EmitCleanupBlocks(CleanupStackDepth); |
| 51 | |
| 52 | return RV; |
| 53 | } |