Reset the lifetime-managed flag between emission of the agg conditional
branches.  Fixes PR8623.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119408 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp
index 00cfb21..308520a 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -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);
diff --git a/lib/CodeGen/CGValue.h b/lib/CodeGen/CGValue.h
index a000b22..bb98c3c 100644
--- a/lib/CodeGen/CGValue.h
+++ b/lib/CodeGen/CGValue.h
@@ -379,8 +379,8 @@
   bool isLifetimeExternallyManaged() const {
     return LifetimeFlag;
   }
-  void setLifetimeExternallyManaged() {
-    LifetimeFlag = true;
+  void setLifetimeExternallyManaged(bool Managed = true) {
+    LifetimeFlag = Managed;
   }
 
   bool isVolatile() const {