@@ -161,22 +161,25 @@ void CoverageMappingWriter::write(raw_ostream &OS) {
161161
162162 // Sort the regions in an ascending order by the file id and the starting
163163 // location. Sort by region kinds to ensure stable order for tests.
164- llvm::stable_sort (MappingRegions, [](const CounterMappingRegion &LHS,
165- const CounterMappingRegion &RHS) {
166- if (LHS.FileID != RHS.FileID )
167- return LHS.FileID < RHS.FileID ;
168- if (LHS.startLoc () != RHS.startLoc ())
169- return LHS.startLoc () < RHS.startLoc ();
170-
171- // Put `Decision` before `Expansion`.
172- auto getKindKey = [](CounterMappingRegion::RegionKind Kind) {
173- return (Kind == CounterMappingRegion::MCDCDecisionRegion
174- ? 2 * CounterMappingRegion::ExpansionRegion - 1
175- : 2 * Kind);
176- };
177-
178- return getKindKey (LHS.Kind ) < getKindKey (RHS.Kind );
179- });
164+ if (!KeepMappingOrder) {
165+ llvm::stable_sort (MappingRegions, [](const CounterMappingRegion &LHS,
166+ const CounterMappingRegion &RHS) {
167+ if (LHS.FileID != RHS.FileID )
168+ return LHS.FileID < RHS.FileID ;
169+
170+ if (LHS.startLoc () != RHS.startLoc ())
171+ return LHS.startLoc () < RHS.startLoc ();
172+
173+ // Put `Decision` before `Expansion`.
174+ auto getKindKey = [](CounterMappingRegion::RegionKind Kind) {
175+ return (Kind == CounterMappingRegion::MCDCDecisionRegion
176+ ? 2 * CounterMappingRegion::ExpansionRegion - 1
177+ : 2 * Kind);
178+ };
179+
180+ return getKindKey (LHS.Kind ) < getKindKey (RHS.Kind );
181+ });
182+ }
180183
181184 // Write out the fileid -> filename mapping.
182185 encodeULEB128 (VirtualFileMapping.size (), OS);
0 commit comments