aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-cov/SourceCoverageView.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-08-04 00:36:24 +0000
committerVedant Kumar <vsk@apple.com>2017-08-04 00:36:24 +0000
commit846b985a92cb816dbf22637e98b7d6e726cf4acf (patch)
treeffd2a1ab8840b7595f4dce0ff7abc34b4a25fc74 /llvm/tools/llvm-cov/SourceCoverageView.cpp
parent8a6223887c843b5fe72c1ed3d82d478a6cc94f3f (diff)
downloadllvm-846b985a92cb816dbf22637e98b7d6e726cf4acf.zip
llvm-846b985a92cb816dbf22637e98b7d6e726cf4acf.tar.gz
llvm-846b985a92cb816dbf22637e98b7d6e726cf4acf.tar.bz2
[llvm-cov] Ignore unclosed line segments when setting line counts
This patch makes a slight change to the way llvm-cov determines line execution counts. If there are multiple line segments on a line, the line count is the max count among the regions which start *and* end on the line. This avoids an issue posed by deferred regions which start on the same line as a terminated region, e.g: if (false) return; //< The line count should be 0, even though a new region //< starts at the semi-colon. foo(); Another change is that counts from line segments which don't correspond to region entries are considered. This enables the first change, and corrects an outstanding issue (see the showLineExecutionCounts.cpp test change). This is related to D35925. Testing: check-profile, llvm-cov lit tests Differential Revision: https://reviews.llvm.org/D36014 llvm-svn: 310012
Diffstat (limited to 'llvm/tools/llvm-cov/SourceCoverageView.cpp')
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageView.cpp45
1 files changed, 37 insertions, 8 deletions
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp
index 52b8ff1..6630f33 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp
@@ -83,6 +83,41 @@ CoveragePrinter::create(const CoverageViewOptions &Opts) {
llvm_unreachable("Unknown coverage output format!");
}
+LineCoverageStats::LineCoverageStats(
+ ArrayRef<const coverage::CoverageSegment *> LineSegments,
+ const coverage::CoverageSegment *WrappedSegment) {
+ // 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;
+ };
+ for (unsigned I = 0; I < LineSegments.size() && MinRegionCount < 2; ++I)
+ if (isStartOfRegion(LineSegments[I]))
+ ++MinRegionCount;
+
+ ExecutionCount = 0;
+ HasMultipleRegions = MinRegionCount > 1;
+ Mapped = (WrappedSegment && WrappedSegment->HasCount) || (MinRegionCount > 0);
+
+ if (!Mapped)
+ return;
+
+ // Pick the max count among regions which start and end on this line, to
+ // 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);
+ return;
+ }
+
+ // Just pick the maximum count.
+ if (WrappedSegment && WrappedSegment->HasCount)
+ ExecutionCount = WrappedSegment->Count;
+ if (!LineSegments.empty())
+ ExecutionCount = std::max(ExecutionCount, LineSegments[0]->Count);
+}
+
unsigned SourceCoverageView::getFirstUncoveredLineNo() {
auto CheckIfUncovered = [](const coverage::CoverageSegment &S) {
return S.HasCount && S.Count == 0;
@@ -207,17 +242,11 @@ void SourceCoverageView::print(raw_ostream &OS, bool WholeFile,
while (NextSegment != EndSegment && NextSegment->Line == LI.line_number())
LineSegments.push_back(&*NextSegment++);
- // Calculate a count to be for the line as a whole.
- LineCoverageStats LineCount;
- if (WrappedSegment && WrappedSegment->HasCount)
- LineCount.addRegionCount(WrappedSegment->Count);
- for (const auto *S : LineSegments)
- if (S->HasCount && S->IsRegionEntry)
- LineCount.addRegionStartCount(S->Count);
-
renderLinePrefix(OS, ViewDepth);
if (getOptions().ShowLineNumbers)
renderLineNumberColumn(OS, LI.line_number());
+
+ LineCoverageStats LineCount{LineSegments, WrappedSegment};
if (getOptions().ShowLineStats)
renderLineCoverageColumn(OS, LineCount);