blob: 0387daeb654f7926c132cc65a686348a625b091e [file] [log] [blame]
Anders Carlsson5b955922009-11-24 05:51:11 +00001//===--- CGTemporaries.cpp - Emit LLVM Code for C++ temporaries -----------===//
Anders Carlsson2ce66122009-06-03 18:40:21 +00002//
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"
15using namespace clang;
16using namespace CodeGen;
17
John McCall45483b42010-07-21 06:44:28 +000018namespace {
John McCallc4a1a842011-07-12 00:15:30 +000019 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 McCallad346f42011-07-12 20:27:29 +000024 void Emit(CodeGenFunction &CGF, Flags flags) {
John McCall4bbcbda2011-01-26 19:15:39 +000025 CGF.EmitCXXDestructorCall(dtor, Dtor_Complete, /*ForVirtualBase=*/false,
26 addr);
John McCall45483b42010-07-21 06:44:28 +000027 }
28 };
29}
John McCallf1549f62010-07-06 01:34:17 +000030
31/// Emits all the code to cause the given temporary to be cleaned up.
32void CodeGenFunction::EmitCXXTemporary(const CXXTemporary *Temporary,
33 llvm::Value *Ptr) {
John McCall4bbcbda2011-01-26 19:15:39 +000034 pushFullExprCleanup<DestroyTemporary>(NormalAndEHCleanup,
35 Temporary->getDestructor(),
36 Ptr);
Anders Carlsson2ce66122009-06-03 18:40:21 +000037}
38
Anders Carlssonf4b8fea2009-06-03 19:05:16 +000039RValue
John McCall4765fa02010-12-06 08:20:24 +000040CodeGenFunction::EmitExprWithCleanups(const ExprWithCleanups *E,
41 AggValueSlot Slot) {
John McCalldf054db2010-07-21 06:45:54 +000042 RunCleanupsScope Scope(*this);
John McCall558d2ab2010-09-15 10:14:12 +000043 return EmitAnyExpr(E->getSubExpr(), Slot);
Anders Carlsson2ce66122009-06-03 18:40:21 +000044}
Anders Carlsson1d847502009-06-04 02:22:12 +000045
John McCall4765fa02010-12-06 08:20:24 +000046LValue CodeGenFunction::EmitExprWithCleanupsLValue(const ExprWithCleanups *E) {
John McCalldf054db2010-07-21 06:45:54 +000047 RunCleanupsScope Scope(*this);
48 return EmitLValue(E->getSubExpr());
Anders Carlssonb9ea0b52009-09-14 01:10:45 +000049}