1 //===- CoverageSummaryInfo.cpp - Coverage summary for function/file -------===//
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
7 //===----------------------------------------------------------------------===//
9 // These structures are used to represent code coverage metrics
10 // for functions/files.
12 //===----------------------------------------------------------------------===//
14 #include "CoverageSummaryInfo.h"
17 using namespace coverage;
19 FunctionCoverageSummary
20 FunctionCoverageSummary::get(const CoverageMapping &CM,
21 const coverage::FunctionRecord &Function) {
22 // Compute the region coverage.
23 size_t NumCodeRegions = 0, CoveredRegions = 0;
24 for (auto &CR : Function.CountedRegions) {
25 if (CR.Kind != CounterMappingRegion::CodeRegion)
28 if (CR.ExecutionCount != 0)
32 // Compute the line coverage
33 size_t NumLines = 0, CoveredLines = 0;
34 CoverageData CD = CM.getCoverageForFunction(Function);
35 for (const auto &LCS : getLineCoverageStats(CD)) {
39 if (LCS.getExecutionCount())
43 return FunctionCoverageSummary(
44 Function.Name, Function.ExecutionCount,
45 RegionCoverageInfo(CoveredRegions, NumCodeRegions),
46 LineCoverageInfo(CoveredLines, NumLines));
49 FunctionCoverageSummary
50 FunctionCoverageSummary::get(const InstantiationGroup &Group,
51 ArrayRef<FunctionCoverageSummary> Summaries) {
53 if (Group.hasName()) {
54 Name = Group.getName();
56 llvm::raw_string_ostream OS(Name);
57 OS << "Definition at line " << Group.getLine() << ", column "
61 FunctionCoverageSummary Summary(Name);
62 Summary.ExecutionCount = Group.getTotalExecutionCount();
63 Summary.RegionCoverage = Summaries[0].RegionCoverage;
64 Summary.LineCoverage = Summaries[0].LineCoverage;
65 for (const auto &FCS : Summaries.drop_front()) {
66 Summary.RegionCoverage.merge(FCS.RegionCoverage);
67 Summary.LineCoverage.merge(FCS.LineCoverage);