diff options
author | Vedant Kumar <vsk@apple.com> | 2017-09-18 23:37:28 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-09-18 23:37:28 +0000 |
commit | 7c57f171e2410142fea510be6135bb427dc86294 (patch) | |
tree | 680fa9b08b7c25459d1b2feb27244874e8d68093 /tools/llvm-cov/SourceCoverageView.cpp | |
parent | f71ef504eb54098b0ff6e7c709d5b8cdc75f8aae (diff) |
[Coverage] Use gap regions to select better line exec counts
After clang started emitting deferred regions (r312818), llvm-cov has
had a hard time picking reasonable line execuction counts. There have
been one or two generic improvements in this area (e.g r310012), but
line counts can still report coverage for whitespace instead of code
(llvm.org/PR34612).
To fix the problem:
* Introduce a new region kind so that frontends can explicitly label
gap areas.
This is done by changing the encoding of the columnEnd field of
MappingRegion. This doesn't substantially increase binary size, and
makes it easy to maintain backwards-compatibility.
* Don't set the line count to a count from a gap area, unless the count
comes from a wrapped segment.
* Don't highlight gap areas as uncovered.
Fixes llvm.org/PR34612.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313597 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-cov/SourceCoverageView.cpp')
-rw-r--r-- | tools/llvm-cov/SourceCoverageView.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/tools/llvm-cov/SourceCoverageView.cpp b/tools/llvm-cov/SourceCoverageView.cpp index 79c2c69571c..1965595cdb7 100644 --- a/tools/llvm-cov/SourceCoverageView.cpp +++ b/tools/llvm-cov/SourceCoverageView.cpp @@ -89,7 +89,7 @@ LineCoverageStats::LineCoverageStats( // Find the minimum number of regions which start in this line. unsigned MinRegionCount = 0; auto isStartOfRegion = [](const coverage::CoverageSegment *S) { - return S->HasCount && S->IsRegionEntry; + return !S->IsGapRegion && S->HasCount && S->IsRegionEntry; }; for (unsigned I = 0; I < LineSegments.size() && MinRegionCount < 2; ++I) if (isStartOfRegion(LineSegments[I])) @@ -112,16 +112,19 @@ LineCoverageStats::LineCoverageStats( // avoid erroneously using the wrapped count, and to avoid picking region // counts which come from deferred regions. if (LineSegments.size() > 1) { - for (unsigned I = 0; I < LineSegments.size() - 1; ++I) - ExecutionCount = std::max(ExecutionCount, LineSegments[I]->Count); + for (unsigned I = 0; I < LineSegments.size() - 1; ++I) { + if (!LineSegments[I]->IsGapRegion) + ExecutionCount = std::max(ExecutionCount, LineSegments[I]->Count); + } return; } - // Just pick the maximum count. - if (WrappedSegment && WrappedSegment->HasCount) + // If a non-gap region starts here, use its count. Otherwise use the wrapped + // count. + if (MinRegionCount == 1) + ExecutionCount = LineSegments[0]->Count; + else ExecutionCount = WrappedSegment->Count; - if (!LineSegments.empty()) - ExecutionCount = std::max(ExecutionCount, LineSegments[0]->Count); } unsigned SourceCoverageView::getFirstUncoveredLineNo() { |