summaryrefslogtreecommitdiffstats
path: root/clang/lib
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
commitb80760bd78be450731a39a1c14c1d71918b97e3d (patch)
tree870fec1251653f429950cca2c4575589987833d5 /clang/lib
parent84b4d2241f4323a5d4e8752615b2336ac57ea089 (diff)
downloadbcm5719-llvm-b80760bd78be450731a39a1c14c1d71918b97e3d.tar.gz
bcm5719-llvm-b80760bd78be450731a39a1c14c1d71918b97e3d.zip
Destroy bound temporaries.
llvm-svn: 79196
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 3818f56df94..ea534d3b2bd 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/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()) {
OpenPOWER on IntegriCloud