Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp
Line
Count
Source
1
//===- CoverageSummaryInfo.cpp - Coverage summary for function/file -------===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// These structures are used to represent code coverage metrics
11
// for functions/files.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#include "CoverageSummaryInfo.h"
16
17
using namespace llvm;
18
using namespace coverage;
19
20
LineCoverageStats::LineCoverageStats(
21
    ArrayRef<const coverage::CoverageSegment *> LineSegments,
22
2.98k
    const coverage::CoverageSegment *WrappedSegment) {
23
2.98k
  // Find the minimum number of regions which start in this line.
24
2.98k
  unsigned MinRegionCount = 0;
25
1.40k
  auto isStartOfRegion = [](const coverage::CoverageSegment *S) {
26
1.40k
    return !S->IsGapRegion && 
S->HasCount1.39k
&&
S->IsRegionEntry1.18k
;
27
1.40k
  };
28
4.39k
  for (unsigned I = 0; 
I < LineSegments.size() && 4.39k
MinRegionCount < 21.48k
;
++I1.40k
)
29
1.40k
    
if (1.40k
isStartOfRegion(LineSegments[I])1.40k
)
30
739
      ++MinRegionCount;
31
2.98k
32
2.98k
  bool StartOfSkippedRegion = !LineSegments.empty() &&
33
886
                              !LineSegments.front()->HasCount &&
34
169
                              LineSegments.front()->IsRegionEntry;
35
2.98k
36
2.98k
  ExecutionCount = 0;
37
2.98k
  HasMultipleRegions = MinRegionCount > 1;
38
2.98k
  Mapped =
39
2.98k
      !StartOfSkippedRegion &&
40
2.98k
      
((WrappedSegment && 2.98k
WrappedSegment->HasCount2.62k
) ||
(MinRegionCount > 0)1.77k
);
41
2.98k
42
2.98k
  if (!Mapped)
43
1.56k
    return;
44
1.41k
45
1.41k
  // Pick the max count among regions which start and end on this line, to
46
1.41k
  // avoid erroneously using the wrapped count, and to avoid picking region
47
1.41k
  // counts which come from deferred regions.
48
1.41k
  
if (1.41k
LineSegments.size() > 11.41k
) {
49
1.05k
    for (unsigned I = 0; 
I < LineSegments.size() - 11.05k
;
++I634
) {
50
634
      if (!LineSegments[I]->IsGapRegion)
51
634
        ExecutionCount = std::max(ExecutionCount, LineSegments[I]->Count);
52
634
    }
53
421
    return;
54
421
  }
55
998
56
998
  // If a non-gap region starts here, use its count. Otherwise use the wrapped
57
998
  // count.
58
998
  
if (998
MinRegionCount == 1998
)
59
212
    ExecutionCount = LineSegments[0]->Count;
60
998
  else
61
786
    ExecutionCount = WrappedSegment->Count;
62
2.98k
}
63
64
FunctionCoverageSummary
65
FunctionCoverageSummary::get(const CoverageMapping &CM,
66
103
                             const coverage::FunctionRecord &Function) {
67
103
  // Compute the region coverage.
68
103
  size_t NumCodeRegions = 0, CoveredRegions = 0;
69
358
  for (auto &CR : Function.CountedRegions) {
70
358
    if (CR.Kind != CounterMappingRegion::CodeRegion)
71
10
      continue;
72
348
    ++NumCodeRegions;
73
348
    if (CR.ExecutionCount != 0)
74
228
      ++CoveredRegions;
75
358
  }
76
103
77
103
  // Compute the line coverage
78
103
  size_t NumLines = 0, CoveredLines = 0;
79
103
  CoverageData CD = CM.getCoverageForFunction(Function);
80
103
  auto NextSegment = CD.begin();
81
103
  auto EndSegment = CD.end();
82
103
  const coverage::CoverageSegment *WrappedSegment = nullptr;
83
103
  SmallVector<const coverage::CoverageSegment *, 4> LineSegments;
84
103
  unsigned Line = NextSegment->Line;
85
739
  while (
NextSegment != EndSegment739
) {
86
636
    // Gather the segments on this line and the wrapped segment.
87
636
    if (LineSegments.size())
88
284
      WrappedSegment = LineSegments.back();
89
636
    LineSegments.clear();
90
1.28k
    while (
NextSegment != EndSegment && 1.28k
NextSegment->Line == Line1.18k
)
91
651
      LineSegments.push_back(&*NextSegment++);
92
636
93
636
    LineCoverageStats LCS{LineSegments, WrappedSegment};
94
636
    if (
LCS.isMapped()636
) {
95
603
      ++NumLines;
96
603
      if (LCS.ExecutionCount)
97
472
        ++CoveredLines;
98
603
    }
99
636
100
636
    ++Line;
101
636
  }
102
103
103
103
  return FunctionCoverageSummary(
104
103
      Function.Name, Function.ExecutionCount,
105
103
      RegionCoverageInfo(CoveredRegions, NumCodeRegions),
106
103
      LineCoverageInfo(CoveredLines, NumLines));
107
103
}
108
109
FunctionCoverageSummary
110
FunctionCoverageSummary::get(const InstantiationGroup &Group,
111
82
                             ArrayRef<FunctionCoverageSummary> Summaries) {
112
82
  std::string Name;
113
82
  if (
Group.hasName()82
) {
114
72
    Name = Group.getName();
115
82
  } else {
116
10
    llvm::raw_string_ostream OS(Name);
117
10
    OS << "Definition at line " << Group.getLine() << ", column "
118
10
       << Group.getColumn();
119
10
  }
120
82
121
82
  FunctionCoverageSummary Summary(Name);
122
82
  Summary.ExecutionCount = Group.getTotalExecutionCount();
123
82
  Summary.RegionCoverage = Summaries[0].RegionCoverage;
124
82
  Summary.LineCoverage = Summaries[0].LineCoverage;
125
10
  for (const auto &FCS : Summaries.drop_front()) {
126
10
    Summary.RegionCoverage.merge(FCS.RegionCoverage);
127
10
    Summary.LineCoverage.merge(FCS.LineCoverage);
128
10
  }
129
82
  return Summary;
130
82
}