2014-08-23 00:56:03 +02:00
|
|
|
//===- CoverageSummaryInfo.cpp - Coverage summary for function/file -------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-08-23 00:56:03 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// These structures are used to represent code coverage metrics
|
|
|
|
// for functions/files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CoverageSummaryInfo.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace coverage;
|
|
|
|
|
2020-12-28 18:20:48 +01:00
|
|
|
static void sumBranches(size_t &NumBranches, size_t &CoveredBranches,
|
|
|
|
const ArrayRef<CountedRegion> &Branches) {
|
|
|
|
for (const auto &BR : Branches) {
|
|
|
|
// Skip folded branches.
|
|
|
|
if (BR.Folded)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// "True" Condition Branches.
|
|
|
|
++NumBranches;
|
|
|
|
if (BR.ExecutionCount > 0)
|
|
|
|
++CoveredBranches;
|
|
|
|
// "False" Condition Branches.
|
|
|
|
++NumBranches;
|
|
|
|
if (BR.FalseExecutionCount > 0)
|
|
|
|
++CoveredBranches;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sumBranchExpansions(size_t &NumBranches, size_t &CoveredBranches,
|
|
|
|
const CoverageMapping &CM,
|
|
|
|
ArrayRef<ExpansionRecord> Expansions) {
|
|
|
|
for (const auto &Expansion : Expansions) {
|
|
|
|
auto CE = CM.getCoverageForExpansion(Expansion);
|
|
|
|
sumBranches(NumBranches, CoveredBranches, CE.getBranches());
|
|
|
|
sumBranchExpansions(NumBranches, CoveredBranches, CM, CE.getExpansions());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
FunctionCoverageSummary
|
2017-09-19 04:00:12 +02:00
|
|
|
FunctionCoverageSummary::get(const CoverageMapping &CM,
|
|
|
|
const coverage::FunctionRecord &Function) {
|
2016-07-22 11:20:21 +02:00
|
|
|
// Compute the region coverage.
|
2014-08-23 00:56:03 +02:00
|
|
|
size_t NumCodeRegions = 0, CoveredRegions = 0;
|
2014-09-09 07:32:14 +02:00
|
|
|
for (auto &CR : Function.CountedRegions) {
|
|
|
|
if (CR.Kind != CounterMappingRegion::CodeRegion)
|
2014-08-23 00:56:03 +02:00
|
|
|
continue;
|
|
|
|
++NumCodeRegions;
|
2014-09-09 07:32:14 +02:00
|
|
|
if (CR.ExecutionCount != 0)
|
2014-08-23 00:56:03 +02:00
|
|
|
++CoveredRegions;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the line coverage
|
|
|
|
size_t NumLines = 0, CoveredLines = 0;
|
2017-09-19 04:00:12 +02:00
|
|
|
CoverageData CD = CM.getCoverageForFunction(Function);
|
2017-10-14 04:27:29 +02:00
|
|
|
for (const auto &LCS : getLineCoverageStats(CD)) {
|
|
|
|
if (!LCS.isMapped())
|
|
|
|
continue;
|
|
|
|
++NumLines;
|
|
|
|
if (LCS.getExecutionCount())
|
|
|
|
++CoveredLines;
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
2017-09-19 04:00:12 +02:00
|
|
|
|
2020-12-28 18:20:48 +01:00
|
|
|
// Compute the branch coverage, including branches from expansions.
|
|
|
|
size_t NumBranches = 0, CoveredBranches = 0;
|
|
|
|
sumBranches(NumBranches, CoveredBranches, CD.getBranches());
|
|
|
|
sumBranchExpansions(NumBranches, CoveredBranches, CM, CD.getExpansions());
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
return FunctionCoverageSummary(
|
2014-09-30 14:45:13 +02:00
|
|
|
Function.Name, Function.ExecutionCount,
|
|
|
|
RegionCoverageInfo(CoveredRegions, NumCodeRegions),
|
2020-12-28 18:20:48 +01:00
|
|
|
LineCoverageInfo(CoveredLines, NumLines),
|
|
|
|
BranchCoverageInfo(CoveredBranches, NumBranches));
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
2016-09-19 02:38:23 +02:00
|
|
|
|
2017-08-03 01:35:25 +02:00
|
|
|
FunctionCoverageSummary
|
|
|
|
FunctionCoverageSummary::get(const InstantiationGroup &Group,
|
|
|
|
ArrayRef<FunctionCoverageSummary> Summaries) {
|
|
|
|
std::string Name;
|
|
|
|
if (Group.hasName()) {
|
2020-01-28 20:23:46 +01:00
|
|
|
Name = std::string(Group.getName());
|
2017-08-03 01:35:25 +02:00
|
|
|
} else {
|
|
|
|
llvm::raw_string_ostream OS(Name);
|
|
|
|
OS << "Definition at line " << Group.getLine() << ", column "
|
|
|
|
<< Group.getColumn();
|
|
|
|
}
|
|
|
|
|
2017-09-08 20:44:49 +02:00
|
|
|
FunctionCoverageSummary Summary(Name);
|
2017-08-03 01:35:25 +02:00
|
|
|
Summary.ExecutionCount = Group.getTotalExecutionCount();
|
|
|
|
Summary.RegionCoverage = Summaries[0].RegionCoverage;
|
|
|
|
Summary.LineCoverage = Summaries[0].LineCoverage;
|
2020-12-28 18:20:48 +01:00
|
|
|
Summary.BranchCoverage = Summaries[0].BranchCoverage;
|
2017-08-03 01:35:25 +02:00
|
|
|
for (const auto &FCS : Summaries.drop_front()) {
|
2017-09-16 01:00:01 +02:00
|
|
|
Summary.RegionCoverage.merge(FCS.RegionCoverage);
|
|
|
|
Summary.LineCoverage.merge(FCS.LineCoverage);
|
2020-12-28 18:20:48 +01:00
|
|
|
|
|
|
|
// Sum branch coverage across instantiation groups for the summary rather
|
|
|
|
// than "merge" the maximum count. This is a clearer view into whether all
|
|
|
|
// created branches are covered.
|
|
|
|
Summary.BranchCoverage += FCS.BranchCoverage;
|
2017-08-03 01:35:25 +02:00
|
|
|
}
|
|
|
|
return Summary;
|
2016-09-19 02:38:23 +02:00
|
|
|
}
|