diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -349,29 +349,36 @@ } auto SkippedRanges = CVM.getSourceInfo().getSkippedRanges(); - for (auto &I : SkippedRanges) { - SourceRange Range = I.Range; - auto LocStart = Range.getBegin(); - auto LocEnd = Range.getEnd(); - assert(SM.isWrittenInSameFile(LocStart, LocEnd) && - "region spans multiple files"); - - auto CovFileID = getCoverageFileID(LocStart); - if (!CovFileID) - continue; - Optional SR = - adjustSkippedRange(SM, LocStart, LocEnd, I.PrevTokLoc, I.NextTokLoc); - if (!SR.hasValue()) - continue; - auto Region = CounterMappingRegion::makeSkipped( - *CovFileID, SR->LineStart, SR->ColumnStart, SR->LineEnd, - SR->ColumnEnd); - // Make sure that we only collect the regions that are inside - // the source code of this function. - if (Region.LineStart >= FileLineRanges[*CovFileID].first && - Region.LineEnd <= FileLineRanges[*CovFileID].second) - MappingRegions.push_back(Region); - } + SkippedRanges.erase( + std::remove_if( + SkippedRanges.begin(), SkippedRanges.end(), + [&](SkippedRange I) { + SourceRange Range = I.Range; + auto LocStart = Range.getBegin(); + auto LocEnd = Range.getEnd(); + assert(SM.isWrittenInSameFile(LocStart, LocEnd) && + "region spans multiple files"); + + auto CovFileID = getCoverageFileID(LocStart); + if (!CovFileID) + return false; + auto SR = adjustSkippedRange(SM, LocStart, LocEnd, I.PrevTokLoc, + I.NextTokLoc); + if (!SR) + return false; + auto Region = CounterMappingRegion::makeSkipped( + *CovFileID, SR->LineStart, SR->ColumnStart, SR->LineEnd, + SR->ColumnEnd); + // Make sure that we only collect the regions that are inside + // the source code of this function. + if (Region.LineStart >= FileLineRanges[*CovFileID].first && + Region.LineEnd <= FileLineRanges[*CovFileID].second) { + MappingRegions.push_back(Region); + return true; + } + return false; + }), + SkippedRanges.end()); } /// Generate the coverage counter mapping regions from collected