summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-09-18 23:37:28 +0000
committerVedant Kumar <vsk@apple.com>2017-09-18 23:37:28 +0000
commitad8f637bd83aeeca7321d6c74b3d7787587c0d55 (patch)
treee771084274c8fde30518a8c9f08c7ffb4e2cd3dd /llvm/tools/llvm-cov
parent27d1b14ab056a3de64cf93c80a10886e2dc904f7 (diff)
downloadbcm5719-llvm-ad8f637bd83aeeca7321d6c74b3d7787587c0d55.tar.gz
bcm5719-llvm-ad8f637bd83aeeca7321d6c74b3d7787587c0d55.zip
[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. llvm-svn: 313597
Diffstat (limited to 'llvm/tools/llvm-cov')
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageView.cpp17
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp2
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageViewText.cpp2
3 files changed, 12 insertions, 9 deletions
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp
index 79c2c69571c..1965595cdb7 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.cpp
+++ b/llvm/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() {
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
index 1a21b72b14e..300a0162bd1 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
@@ -527,7 +527,7 @@ void SourceCoverageViewHTML::renderLine(
const auto *CurSeg = Segments[I];
if (CurSeg->Col == ExpansionCol)
Color = "cyan";
- else if (CheckIfUncovered(CurSeg))
+ else if (!CurSeg->IsGapRegion && CheckIfUncovered(CurSeg))
Color = "red";
else
Color = None;
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
index a88558fceca..a78c0575cdc 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
@@ -120,7 +120,7 @@ void SourceCoverageViewText::renderLine(
Col = End;
if (Col == ExpansionCol)
Highlight = raw_ostream::CYAN;
- else if (S->HasCount && S->Count == 0)
+ else if (!S->IsGapRegion && S->HasCount && S->Count == 0)
Highlight = raw_ostream::RED;
else
Highlight = None;
OpenPOWER on IntegriCloud