Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp
Line
Count
Source
1
//===- CoverageSummaryInfo.cpp - Coverage summary for function/file -------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// These structures are used to represent code coverage metrics
10
// for functions/files.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "CoverageSummaryInfo.h"
15
16
using namespace llvm;
17
using namespace coverage;
18
19
FunctionCoverageSummary
20
FunctionCoverageSummary::get(const CoverageMapping &CM,
21
212
                             const coverage::FunctionRecord &Function) {
22
212
  // Compute the region coverage.
23
212
  size_t NumCodeRegions = 0, CoveredRegions = 0;
24
991
  for (auto &CR : Function.CountedRegions) {
25
991
    if (CR.Kind != CounterMappingRegion::CodeRegion)
26
249
      continue;
27
742
    ++NumCodeRegions;
28
742
    if (CR.ExecutionCount != 0)
29
571
      ++CoveredRegions;
30
742
  }
31
212
32
212
  // Compute the line coverage
33
212
  size_t NumLines = 0, CoveredLines = 0;
34
212
  CoverageData CD = CM.getCoverageForFunction(Function);
35
1.35k
  for (const auto &LCS : getLineCoverageStats(CD)) {
36
1.35k
    if (!LCS.isMapped())
37
33
      continue;
38
1.31k
    ++NumLines;
39
1.31k
    if (LCS.getExecutionCount())
40
1.10k
      ++CoveredLines;
41
1.31k
  }
42
212
43
212
  return FunctionCoverageSummary(
44
212
      Function.Name, Function.ExecutionCount,
45
212
      RegionCoverageInfo(CoveredRegions, NumCodeRegions),
46
212
      LineCoverageInfo(CoveredLines, NumLines));
47
212
}
48
49
FunctionCoverageSummary
50
FunctionCoverageSummary::get(const InstantiationGroup &Group,
51
168
                             ArrayRef<FunctionCoverageSummary> Summaries) {
52
168
  std::string Name;
53
168
  if (Group.hasName()) {
54
142
    Name = Group.getName();
55
142
  } else {
56
26
    llvm::raw_string_ostream OS(Name);
57
26
    OS << "Definition at line " << Group.getLine() << ", column "
58
26
       << Group.getColumn();
59
26
  }
60
168
61
168
  FunctionCoverageSummary Summary(Name);
62
168
  Summary.ExecutionCount = Group.getTotalExecutionCount();
63
168
  Summary.RegionCoverage = Summaries[0].RegionCoverage;
64
168
  Summary.LineCoverage = Summaries[0].LineCoverage;
65
168
  for (const auto &FCS : Summaries.drop_front()) {
66
34
    Summary.RegionCoverage.merge(FCS.RegionCoverage);
67
34
    Summary.LineCoverage.merge(FCS.LineCoverage);
68
34
  }
69
168
  return Summary;
70
168
}