Coverage Report

Created: 2017-09-21 03:39

/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.86k
    const coverage::CoverageSegment *WrappedSegment) {
23
2.86k
  // Find the minimum number of regions which start in this line.
24
2.86k
  unsigned MinRegionCount = 0;
25
1.30k
  auto isStartOfRegion = [](const coverage::CoverageSegment *S) {
26
1.30k
    return !S->IsGapRegion && 
S->HasCount1.29k
&&
S->IsRegionEntry1.10k
;
27
1.30k
  };
28
4.16k
  for (unsigned I = 0; 
I < LineSegments.size() && 4.16k
MinRegionCount < 21.37k
;
++I1.30k
)
29
1.30k
    
if (1.30k
isStartOfRegion(LineSegments[I])1.30k
)
30
687
      ++MinRegionCount;
31
2.86k
32
2.86k
  bool StartOfSkippedRegion = !LineSegments.empty() &&
33
815
                              !LineSegments.front()->HasCount &&
34
148
                              LineSegments.front()->IsRegionEntry;
35
2.86k
36
2.86k
  ExecutionCount = 0;
37
2.86k
  HasMultipleRegions = MinRegionCount > 1;
38
2.86k
  Mapped =
39
2.86k
      !StartOfSkippedRegion &&
40
2.85k
      
((WrappedSegment && 2.85k
WrappedSegment->HasCount2.52k
) ||
(MinRegionCount > 0)1.75k
);
41
2.86k
42
2.86k
  if (!Mapped)
43
1.56k
    return;
44
1.29k
45
1.29k
  // Pick the max count among regions which start and end on this line, to
46
1.29k
  // avoid erroneously using the wrapped count, and to avoid picking region
47
1.29k
  // counts which come from deferred regions.
48
1.29k
  
if (1.29k
LineSegments.size() > 11.29k
) {
49
995
    for (unsigned I = 0; 
I < LineSegments.size() - 1995
;
++I597
) {
50
597
      if (!LineSegments[I]->IsGapRegion)
51
597
        ExecutionCount = std::max(ExecutionCount, LineSegments[I]->Count);
52
597
    }
53
398
    return;
54
398
  }
55
900
56
900
  // If a non-gap region starts here, use its count. Otherwise use the wrapped
57
900
  // count.
58
900
  
if (900
MinRegionCount == 1900
)
59
190
    ExecutionCount = LineSegments[0]->Count;
60
900
  else
61
710
    ExecutionCount = WrappedSegment->Count;
62
2.86k
}
63
64
FunctionCoverageSummary
65
FunctionCoverageSummary::get(const CoverageMapping &CM,
66
88
                             const coverage::FunctionRecord &Function) {
67
88
  // Compute the region coverage.
68
88
  size_t NumCodeRegions = 0, CoveredRegions = 0;
69
310
  for (auto &CR : Function.CountedRegions) {
70
310
    if (CR.Kind != CounterMappingRegion::CodeRegion)
71
10
      continue;
72
300
    ++NumCodeRegions;
73
300
    if (CR.ExecutionCount != 0)
74
195
      ++CoveredRegions;
75
310
  }
76
88
77
88
  // Compute the line coverage
78
88
  size_t NumLines = 0, CoveredLines = 0;
79
88
  CoverageData CD = CM.getCoverageForFunction(Function);
80
88
  auto NextSegment = CD.begin();
81
88
  auto EndSegment = CD.end();
82
88
  const coverage::CoverageSegment *WrappedSegment = nullptr;
83
88
  SmallVector<const coverage::CoverageSegment *, 4> LineSegments;
84
88
  unsigned Line = NextSegment->Line;
85
625
  while (
NextSegment != EndSegment625
) {
86
537
    // Gather the segments on this line and the wrapped segment.
87
537
    if (LineSegments.size())
88
240
      WrappedSegment = LineSegments.back();
89
537
    LineSegments.clear();
90
1.09k
    while (
NextSegment != EndSegment && 1.09k
NextSegment->Line == Line1.00k
)
91
555
      LineSegments.push_back(&*NextSegment++);
92
537
93
537
    LineCoverageStats LCS{LineSegments, WrappedSegment};
94
537
    if (
LCS.isMapped()537
) {
95
504
      ++NumLines;
96
504
      if (LCS.ExecutionCount)
97
392
        ++CoveredLines;
98
504
    }
99
537
100
537
    ++Line;
101
537
  }
102
88
103
88
  return FunctionCoverageSummary(
104
88
      Function.Name, Function.ExecutionCount,
105
88
      RegionCoverageInfo(CoveredRegions, NumCodeRegions),
106
88
      LineCoverageInfo(CoveredLines, NumLines));
107
88
}
108
109
FunctionCoverageSummary
110
FunctionCoverageSummary::get(const InstantiationGroup &Group,
111
67
                             ArrayRef<FunctionCoverageSummary> Summaries) {
112
67
  std::string Name;
113
67
  if (
Group.hasName()67
) {
114
59
    Name = Group.getName();
115
67
  } else {
116
8
    llvm::raw_string_ostream OS(Name);
117
8
    OS << "Definition at line " << Group.getLine() << ", column "
118
8
       << Group.getColumn();
119
8
  }
120
67
121
67
  FunctionCoverageSummary Summary(Name);
122
67
  Summary.ExecutionCount = Group.getTotalExecutionCount();
123
67
  Summary.RegionCoverage = Summaries[0].RegionCoverage;
124
67
  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
67
  return Summary;
130
67
}