[cfe-commits] r119408 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CGValue.h test/CodeGenCXX/temporaries.cpp

John McCall rjmccall at apple.com
Tue Nov 16 16:07:33 PST 2010


Author: rjmccall
Date: Tue Nov 16 18:07:33 2010
New Revision: 119408

URL: http://llvm.org/viewvc/llvm-project?rev=119408&view=rev
Log:
Reset the lifetime-managed flag between emission of the agg conditional
branches.  Fixes PR8623.


Modified:
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/CodeGen/CGValue.h
    cfe/trunk/test/CodeGenCXX/temporaries.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=119408&r1=119407&r2=119408&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Tue Nov 16 18:07:33 2010
@@ -394,8 +394,8 @@
   CGF.BeginConditionalBranch();
   CGF.EmitBlock(LHSBlock);
 
-  // Handle the GNU extension for missing LHS.
-  assert(E->getLHS() && "Must have LHS for aggregate value");
+  // Save whether the destination's lifetime is externally managed.
+  bool DestLifetimeManaged = Dest.isLifetimeExternallyManaged();
 
   Visit(E->getLHS());
   CGF.EndConditionalBranch();
@@ -404,6 +404,12 @@
   CGF.BeginConditionalBranch();
   CGF.EmitBlock(RHSBlock);
 
+  // If the result of an agg expression is unused, then the emission
+  // of the LHS might need to create a destination slot.  That's fine
+  // with us, and we can safely emit the RHS into the same slot, but
+  // we shouldn't claim that its lifetime is externally managed.
+  Dest.setLifetimeExternallyManaged(DestLifetimeManaged);
+
   Visit(E->getRHS());
   CGF.EndConditionalBranch();
   CGF.EmitBranch(ContBlock);

Modified: cfe/trunk/lib/CodeGen/CGValue.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGValue.h?rev=119408&r1=119407&r2=119408&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGValue.h (original)
+++ cfe/trunk/lib/CodeGen/CGValue.h Tue Nov 16 18:07:33 2010
@@ -379,8 +379,8 @@
   bool isLifetimeExternallyManaged() const {
     return LifetimeFlag;
   }
-  void setLifetimeExternallyManaged() {
-    LifetimeFlag = true;
+  void setLifetimeExternallyManaged(bool Managed = true) {
+    LifetimeFlag = Managed;
   }
 
   bool isVolatile() const {

Modified: cfe/trunk/test/CodeGenCXX/temporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/temporaries.cpp?rev=119408&r1=119407&r2=119408&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/temporaries.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/temporaries.cpp Tue Nov 16 18:07:33 2010
@@ -493,3 +493,35 @@
     A(*x).foo();
   }
 }
+
+namespace PR8623 {
+  struct A { A(int); ~A(); };
+
+  // CHECK: define void @_ZN6PR86233fooEb(
+  void foo(bool b) {
+    // CHECK:      [[TMP:%.*]] = alloca [[A:%.*]], align 1
+    // CHECK-NEXT: [[LCONS:%.*]] = alloca i1
+    // CHECK-NEXT: [[RCONS:%.*]] = alloca i1
+    // CHECK-NEXT: store i1 false, i1* [[RCONS]]
+    // CHECK-NEXT: store i1 false, i1* [[LCONS]]
+    // CHECK:      br i1
+    // CHECK:      call void @_ZN6PR86231AC1Ei([[A]]* [[TMP]], i32 2)
+    // CHECK-NEXT: store i1 true, i1* [[LCONS]]
+    // CHECK-NEXT: br label
+    // CHECK:      call void @_ZN6PR86231AC1Ei([[A]]* [[TMP]], i32 3)
+    // CHECK-NEXT: store i1 true, i1* [[RCONS]]
+    // CHECK-NEXT: br label
+    // CHECK:      load i1* [[RCONS]]
+    // CHECK-NEXT: br i1
+    // CHECK:      call void @_ZN6PR86231AD1Ev([[A]]* [[TMP]])
+    // CHECK-NEXT: store i1 false, i1* [[RCONS]]
+    // CHECK-NEXT: br label
+    // CHECK:      load i1* [[LCONS]]
+    // CHECK-NEXT: br i1
+    // CHECK:      call void @_ZN6PR86231AD1Ev([[A]]* [[TMP]])
+    // CHECK-NEXT: store i1 false, i1* [[LCONS]]
+    // CHECK-NEXT: br label
+    // CHECK:      ret void
+    b ? A(2) : A(3);
+  }
+}





More information about the cfe-commits mailing list