Coverage Report

Created: 2018-01-17 21:32

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp
Line
Count
Source (jump to first uncovered line)
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
FunctionCoverageSummary
21
FunctionCoverageSummary::get(const CoverageMapping &CM,
22
109
                             const coverage::FunctionRecord &Function) {
23
109
  // Compute the region coverage.
24
109
  size_t NumCodeRegions = 0, CoveredRegions = 0;
25
577
  for (auto &CR : Function.CountedRegions) {
26
577
    if (CR.Kind != CounterMappingRegion::CodeRegion)
27
159
      continue;
28
418
    ++NumCodeRegions;
29
418
    if (CR.ExecutionCount != 0)
30
336
      ++CoveredRegions;
31
418
  }
32
109
33
109
  // Compute the line coverage
34
109
  size_t NumLines = 0, CoveredLines = 0;
35
109
  CoverageData CD = CM.getCoverageForFunction(Function);
36
737
  for (const auto &LCS : getLineCoverageStats(CD)) {
37
737
    if (!LCS.isMapped())
38
0
      continue;
39
737
    ++NumLines;
40
737
    if (LCS.getExecutionCount())
41
624
      ++CoveredLines;
42
737
  }
43
109
44
109
  return FunctionCoverageSummary(
45
109
      Function.Name, Function.ExecutionCount,
46
109
      RegionCoverageInfo(CoveredRegions, NumCodeRegions),
47
109
      LineCoverageInfo(CoveredLines, NumLines));
48
109
}
49
50
FunctionCoverageSummary
51
FunctionCoverageSummary::get(const InstantiationGroup &Group,
52
82
                             ArrayRef<FunctionCoverageSummary> Summaries) {
53
82
  std::string Name;
54
82
  if (Group.hasName()) {
55
68
    Name = Group.getName();
56
68
  } else {
57
14
    llvm::raw_string_ostream OS(Name);
58
14
    OS << "Definition at line " << Group.getLine() << ", column "
59
14
       << Group.getColumn();
60
14
  }
61
82
62
82
  FunctionCoverageSummary Summary(Name);
63
82
  Summary.ExecutionCount = Group.getTotalExecutionCount();
64
82
  Summary.RegionCoverage = Summaries[0].RegionCoverage;
65
82
  Summary.LineCoverage = Summaries[0].LineCoverage;
66
82
  for (const auto &FCS : Summaries.drop_front()) {
67
19
    Summary.RegionCoverage.merge(FCS.RegionCoverage);
68
19
    Summary.LineCoverage.merge(FCS.LineCoverage);
69
19
  }
70
82
  return Summary;
71
82
}