Index: lib/ProfileData/CoverageMappingReader.cpp =================================================================== --- lib/ProfileData/CoverageMappingReader.cpp +++ lib/ProfileData/CoverageMappingReader.cpp @@ -251,15 +251,20 @@ // from the expanded file. // Perform multiple passes to correctly propagate the counters through // all the nested expansion regions. + SmallVector ExpansionRegions; for (unsigned Pass = 1, S = VirtualFileMapping.size(); Pass < S; ++Pass) { - for (auto &I : MappingRegions) { - if (I.Kind == CounterMappingRegion::ExpansionRegion) { - for (const auto &J : MappingRegions) { - if (J.FileID == I.ExpandedFileID) { - I.Count = J.Count; - break; - } - } + ExpansionRegions.clear(); + ExpansionRegions.resize(VirtualFileMapping.size(), nullptr); + for (auto &R : MappingRegions) { + if (R.Kind != CounterMappingRegion::ExpansionRegion) + continue; + assert(!ExpansionRegions[R.ExpandedFileID]); + ExpansionRegions[R.ExpandedFileID] = &R; + } + for (auto &R : MappingRegions) { + if (ExpansionRegions[R.FileID]) { + ExpansionRegions[R.FileID]->Count = R.Count; + ExpansionRegions[R.FileID] = nullptr; } } }