blob: 3b4c50910bf865669e1c69cc9c13dd9515cb07d6 [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 McCall4bbcbda2011-01-26 19:15:39 +000019 struct DestroyTemporary {
20 static void Emit(CodeGenFunction &CGF, bool forEH,
21 const CXXDestructorDecl *dtor, llvm::Value *addr) {
22 CGF.EmitCXXDestructorCall(dtor, Dtor_Complete, /*ForVirtualBase=*/false,
23 addr);
John McCall45483b42010-07-21 06:44:28 +000024 }
25 };
26}
John McCallf1549f62010-07-06 01:34:17 +000027
28/// Emits all the code to cause the given temporary to be cleaned up.
29void CodeGenFunction::EmitCXXTemporary(const CXXTemporary *Temporary,
30 llvm::Value *Ptr) {
John McCall4bbcbda2011-01-26 19:15:39 +000031 pushFullExprCleanup<DestroyTemporary>(NormalAndEHCleanup,
32 Temporary->getDestructor(),
33 Ptr);
Anders Carlsson2ce66122009-06-03 18:40:21 +000034}
35
Anders Carlssonf4b8fea2009-06-03 19:05:16 +000036RValue
John McCall4765fa02010-12-06 08:20:24 +000037CodeGenFunction::EmitExprWithCleanups(const ExprWithCleanups *E,
38 AggValueSlot Slot) {
John McCalldf054db2010-07-21 06:45:54 +000039 RunCleanupsScope Scope(*this);
John McCall558d2ab2010-09-15 10:14:12 +000040 return EmitAnyExpr(E->getSubExpr(), Slot);
Anders Carlsson2ce66122009-06-03 18:40:21 +000041}
Anders Carlsson1d847502009-06-04 02:22:12 +000042
John McCall4765fa02010-12-06 08:20:24 +000043LValue CodeGenFunction::EmitExprWithCleanupsLValue(const ExprWithCleanups *E) {
John McCalldf054db2010-07-21 06:45:54 +000044 RunCleanupsScope Scope(*this);
45 return EmitLValue(E->getSubExpr());
Anders Carlssonb9ea0b52009-09-14 01:10:45 +000046}