[PATCH] D87648: [Coverage][NFC] Remove skipped region after added into MappingRegions
Zequan Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 14 16:01:30 PDT 2020
zequanwu created this revision.
zequanwu added a reviewer: vsk.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
zequanwu requested review of this revision.
There is no need to scan through all SkippedRegions when some of them are already added into MappingRegions.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D87648
Files:
clang/lib/CodeGen/CoverageMappingGen.cpp
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===================================================================
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ 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<SpellingRegion> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87648.291720.patch
Type: text/x-patch
Size: 2687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200914/1696d2fd/attachment.bin>
More information about the cfe-commits
mailing list