Anders Carlsson | 5b95592 | 2009-11-24 05:51:11 +0000 | [diff] [blame] | 1 | //===--- CGTemporaries.cpp - Emit LLVM Code for C++ temporaries -----------===// |
Anders Carlsson | 2ce6612 | 2009-06-03 18:40:21 +0000 | [diff] [blame] | 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 | |
John McCall | 45483b4 | 2010-07-21 06:44:28 +0000 | [diff] [blame] | 18 | namespace { |
John McCall | c4a1a84 | 2011-07-12 00:15:30 +0000 | [diff] [blame] | 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) {} |
John McCall | ad346f4 | 2011-07-12 20:27:29 +0000 | [diff] [blame] | 24 | void Emit(CodeGenFunction &CGF, Flags flags) { |
John McCall | 4bbcbda | 2011-01-26 19:15:39 +0000 | [diff] [blame] | 25 | CGF.EmitCXXDestructorCall(dtor, Dtor_Complete, /*ForVirtualBase=*/false, |
| 26 | addr); |
John McCall | 45483b4 | 2010-07-21 06:44:28 +0000 | [diff] [blame] | 27 | } |
| 28 | }; |
| 29 | } |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 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) { |
John McCall | 4bbcbda | 2011-01-26 19:15:39 +0000 | [diff] [blame] | 34 | pushFullExprCleanup<DestroyTemporary>(NormalAndEHCleanup, |
| 35 | Temporary->getDestructor(), |
| 36 | Ptr); |
Anders Carlsson | 2ce6612 | 2009-06-03 18:40:21 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Anders Carlsson | f4b8fea | 2009-06-03 19:05:16 +0000 | [diff] [blame] | 39 | RValue |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 40 | CodeGenFunction::EmitExprWithCleanups(const ExprWithCleanups *E, |
| 41 | AggValueSlot Slot) { |
John McCall | df054db | 2010-07-21 06:45:54 +0000 | [diff] [blame] | 42 | RunCleanupsScope Scope(*this); |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 43 | return EmitAnyExpr(E->getSubExpr(), Slot); |
Anders Carlsson | 2ce6612 | 2009-06-03 18:40:21 +0000 | [diff] [blame] | 44 | } |
Anders Carlsson | 1d84750 | 2009-06-04 02:22:12 +0000 | [diff] [blame] | 45 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 46 | LValue CodeGenFunction::EmitExprWithCleanupsLValue(const ExprWithCleanups *E) { |
John McCall | df054db | 2010-07-21 06:45:54 +0000 | [diff] [blame] | 47 | RunCleanupsScope Scope(*this); |
| 48 | return EmitLValue(E->getSubExpr()); |
Anders Carlsson | b9ea0b5 | 2009-09-14 01:10:45 +0000 | [diff] [blame] | 49 | } |