Index: include/llvm/Analysis/ValueLattice.h =================================================================== --- include/llvm/Analysis/ValueLattice.h +++ include/llvm/Analysis/ValueLattice.h @@ -114,21 +114,43 @@ *this = Other; } + ValueLatticeElement(ValueLatticeElement &&Other) : Tag(unknown) { + *this = std::move(Other); + } + /// Custom assignment operator, to ensure Range gets initialized when /// assigning a constant range lattice element. ValueLatticeElement &operator=(const ValueLatticeElement &Other) { - // If we change the state of this from constant range to non constant range, - // destroy Range. - if (isConstantRange() && !Other.isConstantRange()) + if (isConstantRange()) + Range.~ConstantRange(); + + switch (Other.Tag) { + case constantrange: + case constantrange_including_undef: + new (&Range) ConstantRange(Other.Range); + NumRangeExtensions = Other.NumRangeExtensions; + break; + case constant: + case notconstant: + ConstVal = Other.ConstVal; + break; + case overdefined: + case unknown: + case undef: + break; + } + Tag = Other.Tag; + return *this; + } + + ValueLatticeElement &operator=(ValueLatticeElement &&Other) { + if (isConstantRange()) Range.~ConstantRange(); switch (Other.Tag) { case constantrange: case constantrange_including_undef: - if (!isConstantRange()) - new (&Range) ConstantRange(Other.Range); - else - Range = Other.Range; + new (&Range) ConstantRange(std::move(Other.Range)); NumRangeExtensions = Other.NumRangeExtensions; break; case constant: @@ -141,6 +163,7 @@ break; } Tag = Other.Tag; + Other.Tag = unknown; return *this; }