E->arg_begin(), E->arg_end());
}
+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);
- // FIXME: Handle the temporaries.
+ // 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;
}
CodeGenFunction::EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E) {
LValue LV = EmitLValue(E->getSubExpr());
- // FIXME: Record the value and dest ptr.
+ PushCXXTemporary(E->getTemporary(), LV.getAddress());
return LV;
}
/// 'this' declaration.
ImplicitParamDecl *CXXThisDecl;
+ llvm::SmallVector<const CXXTemporary*, 4> LiveTemporaries;
+
public:
CodeGenFunction(CodeGenModule &cgm);
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type,
llvm::Value *This);
+ void PushCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr);
+
//===--------------------------------------------------------------------===//
// Declaration Emission
//===--------------------------------------------------------------------===//