]> granicus.if.org Git - clang/commitdiff
When binding an lvalue to a reference, we always need to pop temporaries.
authorAnders Carlsson <andersca@mac.com>
Thu, 4 Feb 2010 17:32:58 +0000 (17:32 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 4 Feb 2010 17:32:58 +0000 (17:32 +0000)
With this fix, and the other fixes committed today a make check-all with a clang-built LLVM now gives:

Expected Passes    : 6933
Expected Failures  : 46
Unsupported Tests  : 40
Unexpected Failures: 27

which means that we pass 99.96% of all tests :) The resulting 27 tests are all LLVMC tests and seem to be because of differences in the clang and gcc drivers.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95313 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
test/CodeGenCXX/temporaries.cpp

index 563db0b2be1faf7832f14f39ca75b4977ec79c7a..888070145572e615487b9e435a5138d8f1ff7deb 100644 (file)
@@ -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) {
index c33ca4ebff2446d5d3bbeb19733712ce10af4428..3b624afd0ad1b47cbf508dc3219816229eeca174 100644 (file)
@@ -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());
+}
+
+}