1 //===--- CGTemporaries.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 namespace { 19 struct DestroyTemporary : EHScopeStack::Cleanup { 20 const CXXDestructorDecl *dtor; 21 llvm::Value *addr; 22 DestroyTemporary(const CXXDestructorDecl *dtor, llvm::Value *addr) 23 : dtor(dtor), addr(addr) {} 24 void Emit(CodeGenFunction &CGF, Flags flags) { 25 CGF.EmitCXXDestructorCall(dtor, Dtor_Complete, /*ForVirtualBase=*/false, 26 addr); 27 } 28 }; 29 } 30 31 /// Emits all the code to cause the given temporary to be cleaned up. 32 void CodeGenFunction::EmitCXXTemporary(const CXXTemporary *Temporary, 33 llvm::Value *Ptr) { 34 pushFullExprCleanup<DestroyTemporary>(NormalAndEHCleanup, 35 Temporary->getDestructor(), 36 Ptr); 37 } 38 39 RValue 40 CodeGenFunction::EmitExprWithCleanups(const ExprWithCleanups *E, 41 AggValueSlot Slot) { 42 RunCleanupsScope Scope(*this); 43 return EmitAnyExpr(E->getSubExpr(), Slot); 44 } 45 46 LValue CodeGenFunction::EmitExprWithCleanupsLValue(const ExprWithCleanups *E) { 47 RunCleanupsScope Scope(*this); 48 return EmitLValue(E->getSubExpr()); 49 } 50