aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-cov/SourceCoverageView.cpp
diff options
context:
space:
mode:
authorAlan Phipps <a-phipps@ti.com>2020-12-28 11:20:48 -0600
committerAlan Phipps <a-phipps@ti.com>2021-01-05 09:51:51 -0600
commit9f2967bcfe2f7d1fc02281f0098306c90c2c10a5 (patch)
treea29793dac7b81d67601905911a389a2cf2cdde2e /llvm/tools/llvm-cov/SourceCoverageView.cpp
parent53c3acb89fcc25ba7ef1f1d76a79c241eeacb7f0 (diff)
downloadllvm-9f2967bcfe2f7d1fc02281f0098306c90c2c10a5.zip
llvm-9f2967bcfe2f7d1fc02281f0098306c90c2c10a5.tar.gz
llvm-9f2967bcfe2f7d1fc02281f0098306c90c2c10a5.tar.bz2
[Coverage] Add support for Branch Coverage in LLVM Source-Based Code Coverage
This is an enhancement to LLVM Source-Based Code Coverage in clang to track how many times individual branch-generating conditions are taken (evaluate to TRUE) and not taken (evaluate to FALSE). Individual conditions may comprise larger boolean expressions using boolean logical operators. This functionality is very similar to what is supported by GCOV except that it is very closely anchored to the ASTs. Differential Revision: https://reviews.llvm.org/D84467
Diffstat (limited to 'llvm/tools/llvm-cov/SourceCoverageView.cpp')
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageView.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp
index cd7395a..aca58a0 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp
@@ -132,7 +132,8 @@ bool SourceCoverageView::shouldRenderRegionMarkers(
}
bool SourceCoverageView::hasSubViews() const {
- return !ExpansionSubViews.empty() || !InstantiationSubViews.empty();
+ return !ExpansionSubViews.empty() || !InstantiationSubViews.empty() ||
+ !BranchSubViews.empty();
}
std::unique_ptr<SourceCoverageView>
@@ -167,6 +168,12 @@ void SourceCoverageView::addExpansion(
ExpansionSubViews.emplace_back(Region, std::move(View));
}
+void SourceCoverageView::addBranch(unsigned Line,
+ ArrayRef<CountedRegion> Regions,
+ std::unique_ptr<SourceCoverageView> View) {
+ BranchSubViews.emplace_back(Line, Regions, std::move(View));
+}
+
void SourceCoverageView::addInstantiation(
StringRef FunctionName, unsigned Line,
std::unique_ptr<SourceCoverageView> View) {
@@ -187,14 +194,17 @@ void SourceCoverageView::print(raw_ostream &OS, bool WholeFile,
renderTableHeader(OS, (ViewDepth > 0) ? 0 : getFirstUncoveredLineNo(),
ViewDepth);
- // We need the expansions and instantiations sorted so we can go through them
- // while we iterate lines.
+ // We need the expansions, instantiations, and branches sorted so we can go
+ // through them while we iterate lines.
llvm::stable_sort(ExpansionSubViews);
llvm::stable_sort(InstantiationSubViews);
+ llvm::stable_sort(BranchSubViews);
auto NextESV = ExpansionSubViews.begin();
auto EndESV = ExpansionSubViews.end();
auto NextISV = InstantiationSubViews.begin();
auto EndISV = InstantiationSubViews.end();
+ auto NextBRV = BranchSubViews.begin();
+ auto EndBRV = BranchSubViews.end();
// Get the coverage information for the file.
auto StartSegment = CoverageInfo.begin();
@@ -234,7 +244,7 @@ void SourceCoverageView::print(raw_ostream &OS, bool WholeFile,
if (shouldRenderRegionMarkers(*LCI))
renderRegionMarkers(OS, *LCI, ViewDepth);
- // Show the expansions and instantiations for this line.
+ // Show the expansions, instantiations, and branches for this line.
bool RenderedSubView = false;
for (; NextESV != EndESV && NextESV->getLine() == LI.line_number();
++NextESV) {
@@ -257,6 +267,11 @@ void SourceCoverageView::print(raw_ostream &OS, bool WholeFile,
renderInstantiationView(OS, *NextISV, ViewDepth + 1);
RenderedSubView = true;
}
+ for (; NextBRV != EndBRV && NextBRV->Line == LI.line_number(); ++NextBRV) {
+ renderViewDivider(OS, ViewDepth + 1);
+ renderBranchView(OS, *NextBRV, ViewDepth + 1);
+ RenderedSubView = true;
+ }
if (RenderedSubView)
renderViewDivider(OS, ViewDepth + 1);
renderLineSuffix(OS, ViewDepth);