forked from OSchip/llvm-project
[llvm-cov] Remove workaround in line execution count calculation (PR34962)
Gap areas make it possible to correctly determine when to use counts from deferred regions. Before gap areas were introduced, llvm-cov needed to use a heuristic to do this: it ignored counts from segments that start, but do not end, on a line. This heuristic breaks down on a simple example (see PR34962). This patch removes the heuristic and picks counts from any region entry segment which isn't a gap area. llvm-svn: 315960
This commit is contained in:
parent
1fada3b90a
commit
58548c30da
Binary file not shown.
Binary file not shown.
|
@ -68,6 +68,14 @@ out: // CHECK: [[@LINE]]|{{ +}}0|
|
|||
return;
|
||||
}
|
||||
|
||||
void if_else(bool flag) {
|
||||
if (flag) { // CHECK: [[@LINE]]|{{ +}}2|
|
||||
return; // CHECK: [[@LINE]]|{{ +}}1|
|
||||
} else { // CHECK: [[@LINE]]|{{ +}}2|
|
||||
return; // CHECK: [[@LINE]]|{{ +}}1|
|
||||
} // CHECK: [[@LINE]]|{{ +}}1|
|
||||
}
|
||||
|
||||
int main() {
|
||||
foo(0);
|
||||
foo(1);
|
||||
|
@ -75,6 +83,8 @@ int main() {
|
|||
for_loop();
|
||||
while_loop();
|
||||
gotos();
|
||||
if_else(true);
|
||||
if_else(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -107,3 +117,5 @@ int main() {
|
|||
// MARKER-NEXT: Highlighted line 67, 1 -> ?
|
||||
// MARKER-NEXT: Highlighted line 68, 1 -> 8
|
||||
// MARKER-NEXT: Highlighted line 69, 1 -> 2
|
||||
// MARKER-NEXT: Marker at 72:7 = 2
|
||||
// MARKER-NEXT: Highlighted line 77, 1 -> 2
|
||||
|
|
|
@ -43,23 +43,16 @@ LineCoverageStats::LineCoverageStats(
|
|||
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) {
|
||||
if (!LineSegments[I]->IsGapRegion)
|
||||
ExecutionCount = std::max(ExecutionCount, LineSegments[I]->Count);
|
||||
}
|
||||
// Pick the max count from the non-gap, region entry segments. If there
|
||||
// aren't any, use the wrapepd count.
|
||||
if (HasMultipleRegions) {
|
||||
for (const auto *LS : LineSegments)
|
||||
if (isStartOfRegion(LS))
|
||||
ExecutionCount = std::max(ExecutionCount, LS->Count);
|
||||
return;
|
||||
}
|
||||
|
||||
// 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;
|
||||
ExecutionCount =
|
||||
(MinRegionCount == 1) ? LineSegments[0]->Count : WrappedSegment->Count;
|
||||
}
|
||||
|
||||
LineCoverageIterator &LineCoverageIterator::operator++() {
|
||||
|
|
Loading…
Reference in New Issue