Index: llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h =================================================================== --- llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h +++ llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h @@ -245,12 +245,6 @@ return std::pair(LineEnd, ColumnEnd); } - bool operator<(const CounterMappingRegion &Other) const { - if (FileID != Other.FileID) - return FileID < Other.FileID; - return startLoc() < Other.startLoc(); - } - bool contains(const CounterMappingRegion &Other) const { if (FileID != Other.FileID) return false; Index: llvm/trunk/lib/ProfileData/Coverage/CoverageMappingWriter.cpp =================================================================== --- llvm/trunk/lib/ProfileData/Coverage/CoverageMappingWriter.cpp +++ llvm/trunk/lib/ProfileData/Coverage/CoverageMappingWriter.cpp @@ -108,8 +108,16 @@ void CoverageMappingWriter::write(raw_ostream &OS) { // Sort the regions in an ascending order by the file id and the starting - // location. - std::stable_sort(MappingRegions.begin(), MappingRegions.end()); + // location. Sort by region kinds to ensure stable order for tests. + std::stable_sort( + MappingRegions.begin(), MappingRegions.end(), + [](const CounterMappingRegion &LHS, const CounterMappingRegion &RHS) { + if (LHS.FileID != RHS.FileID) + return LHS.FileID < RHS.FileID; + if (LHS.startLoc() != RHS.startLoc()) + return LHS.startLoc() < RHS.startLoc(); + return LHS.Kind < RHS.Kind; + }); // Write out the fileid -> filename mapping. encodeULEB128(VirtualFileMapping.size(), OS);