diff --git a/llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h b/llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h --- a/llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h +++ b/llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h @@ -178,8 +178,11 @@ /// Compare two fragments based on their offset. inline bool operator<(const DebugLocEntry::Value &A, const DebugLocEntry::Value &B) { - return A.getExpression()->getFragmentInfo()->OffsetInBits < - B.getExpression()->getFragmentInfo()->OffsetInBits; + const auto AFI = A.getExpression()->getFragmentInfo(); + const auto BFI = A.getExpression()->getFragmentInfo(); + if (AFI.hasValue() && BFI.hasValue()) + return AFI->OffsetInBits < BFI->OffsetInBits; + return AFI.hasValue() < BFI.hasValue(); } }