diff options
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 10 | ||||
-rw-r--r-- | test/CodeGenCXX/temporaries.cpp | 21 |
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 563db0b2be..8880701455 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -113,8 +113,16 @@ RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E, if (E->isLvalue(getContext()) == Expr::LV_Valid) { // Emit the expr as an lvalue. LValue LV = EmitLValue(E); - if (LV.isSimple()) + if (LV.isSimple()) { + if (ShouldDestroyTemporaries) { + // Pop temporaries. + while (LiveTemporaries.size() > OldNumLiveTemporaries) + PopCXXTemporary(); + } + return RValue::get(LV.getAddress()); + } + Val = EmitLoadOfLValue(LV, E->getType()); if (ShouldDestroyTemporaries) { diff --git a/test/CodeGenCXX/temporaries.cpp b/test/CodeGenCXX/temporaries.cpp index c33ca4ebff..3b624afd0a 100644 --- a/test/CodeGenCXX/temporaries.cpp +++ b/test/CodeGenCXX/temporaries.cpp @@ -267,3 +267,24 @@ namespace PR6199 { template A f2<int>(int); } + +namespace T12 { + +struct A { + A(); + ~A(); + int f(); +}; + +int& f(int); + +// CHECK: define void @_ZN3T121gEv +void g() { + // CHECK: call void @_ZN3T121AC1Ev + // CHECK-NEXT: call i32 @_ZN3T121A1fEv( + // CHECK-NEXT: call i32* @_ZN3T121fEi( + // CHECK-NEXT: call void @_ZN3T121AD1Ev( + int& i = f(A().f()); +} + +} |