summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-08-16 17:50:25 +0000
committerAnders Carlsson <andersca@mac.com>2009-08-16 17:50:25 +0000
commit8478ce6d3f2416a694e39f791655a473c3907d62 (patch)
treeff1c0f43d79750aa530f9968ba79eb185fd0fbed /lib/CodeGen/CGExpr.cpp
parent419cfb318cd69b6c717019288d5a3822be18d8f9 (diff)
downloadclang-8478ce6d3f2416a694e39f791655a473c3907d62.tar.gz
clang-8478ce6d3f2416a694e39f791655a473c3907d62.tar.bz2
clang-8478ce6d3f2416a694e39f791655a473c3907d62.tar.xz
Destroy bound temporaries.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79196 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 3818f56df9..ea534d3b2b 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -87,8 +87,24 @@ RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
return RValue::get(LV.getAddress());
Val = EmitLoadOfLValue(LV, E->getType());
} else {
+ // FIXME: Initializers don't work with casts yet. For example
+ // const A& a = B();
+ // if B inherits from A.
Val = EmitAnyExprToTemp(E, /*IsAggLocVolatile=*/false,
IsInitializer);
+
+ // We might have to destroy the temporary variable.
+ if (const RecordType *RT = E->getType()->getAs<RecordType>()) {
+ if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
+ if (!ClassDecl->hasTrivialDestructor()) {
+ const CXXDestructorDecl *Dtor =
+ ClassDecl->getDestructor(getContext());
+
+ CleanupScope scope(*this);
+ EmitCXXDestructorCall(Dtor, Dtor_Complete, Val.getAggregateAddr());
+ }
+ }
+ }
}
if (Val.isAggregate()) {