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) { |
Anders Carlsson | f4b8fea | 2009-06-03 19:05:16 +0000 | [diff] [blame] | 20 | llvm::BasicBlock *DtorBlock = createBasicBlock("temp.dtor"); |
| 21 | |
| 22 | LiveTemporaries.push_back(CXXLiveTemporaryInfo(Temporary, Ptr, DtorBlock, 0)); |
Anders Carlsson | 2ce6612 | 2009-06-03 18:40:21 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Anders Carlsson | f4b8fea | 2009-06-03 19:05:16 +0000 | [diff] [blame] | 25 | void CodeGenFunction::PopCXXTemporary() { |
| 26 | const CXXLiveTemporaryInfo& Info = LiveTemporaries.back(); |
| 27 | |
| 28 | CleanupBlockInfo CleanupInfo = PopCleanupBlock(); |
| 29 | assert(CleanupInfo.CleanupBlock == Info.DtorBlock && |
| 30 | "Cleanup block mismatch!"); |
| 31 | assert(!CleanupInfo.SwitchBlock && |
| 32 | "Should not have a switch block for temporary cleanup!"); |
| 33 | assert(!CleanupInfo.EndBlock && |
| 34 | "Should not have an end block for temporary cleanup!"); |
| 35 | |
| 36 | EmitBlock(Info.DtorBlock); |
| 37 | |
| 38 | EmitCXXDestructorCall(Info.Temporary->getDestructor(), |
| 39 | Dtor_Complete, Info.ThisPtr); |
| 40 | |
| 41 | LiveTemporaries.pop_back(); |
| 42 | } |
| 43 | |
| 44 | RValue |
Anders Carlsson | 2ce6612 | 2009-06-03 18:40:21 +0000 | [diff] [blame] | 45 | CodeGenFunction::EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, |
| 46 | llvm::Value *AggLoc, |
| 47 | bool isAggLocVolatile) { |
| 48 | // Keep track of the current cleanup stack depth. |
| 49 | size_t CleanupStackDepth = CleanupEntries.size(); |
| 50 | |
| 51 | unsigned OldNumLiveTemporaries = LiveTemporaries.size(); |
| 52 | |
| 53 | RValue RV = EmitAnyExpr(E->getSubExpr(), AggLoc, isAggLocVolatile); |
| 54 | |
| 55 | // Go through the temporaries backwards. |
| 56 | for (unsigned i = E->getNumTemporaries(); i != 0; --i) { |
Anders Carlsson | e8b5578 | 2009-06-03 18:54:26 +0000 | [diff] [blame] | 57 | assert(LiveTemporaries.back().Temporary == E->getTemporary(i - 1)); |
Anders Carlsson | 2ce6612 | 2009-06-03 18:40:21 +0000 | [diff] [blame] | 58 | LiveTemporaries.pop_back(); |
| 59 | } |
| 60 | |
| 61 | assert(OldNumLiveTemporaries == LiveTemporaries.size() && |
| 62 | "Live temporary stack mismatch!"); |
| 63 | |
| 64 | EmitCleanupBlocks(CleanupStackDepth); |
| 65 | |
| 66 | return RV; |
| 67 | } |