diff options
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGExprAgg.cpp | 10 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGValue.h | 4 |
2 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 00cfb214472..308520aadd4 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -394,8 +394,8 @@ void AggExprEmitter::VisitConditionalOperator(const ConditionalOperator *E) { 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 @@ void AggExprEmitter::VisitConditionalOperator(const ConditionalOperator *E) { 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/clang/lib/CodeGen/CGValue.h b/clang/lib/CodeGen/CGValue.h index a000b223311..bb98c3cb237 100644 --- a/clang/lib/CodeGen/CGValue.h +++ b/clang/lib/CodeGen/CGValue.h @@ -379,8 +379,8 @@ public: bool isLifetimeExternallyManaged() const { return LifetimeFlag; } - void setLifetimeExternallyManaged() { - LifetimeFlag = true; + void setLifetimeExternallyManaged(bool Managed = true) { + LifetimeFlag = Managed; } bool isVolatile() const { |