diff options
author | Alan Phipps <a-phipps@ti.com> | 2020-12-28 11:20:48 -0600 |
---|---|---|
committer | Alan Phipps <a-phipps@ti.com> | 2021-01-05 09:51:51 -0600 |
commit | 9f2967bcfe2f7d1fc02281f0098306c90c2c10a5 (patch) | |
tree | a29793dac7b81d67601905911a389a2cf2cdde2e /llvm/tools/llvm-cov/SourceCoverageViewText.cpp | |
parent | 53c3acb89fcc25ba7ef1f1d76a79c241eeacb7f0 (diff) | |
download | llvm-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/SourceCoverageViewText.cpp')
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageViewText.cpp | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp index fcabee2..948414a 100644 --- a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp @@ -10,11 +10,12 @@ /// //===----------------------------------------------------------------------===// -#include "CoverageReport.h" #include "SourceCoverageViewText.h" +#include "CoverageReport.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/Format.h" using namespace llvm; @@ -222,6 +223,53 @@ void SourceCoverageViewText::renderExpansionView(raw_ostream &OS, /*ShowTitle=*/false, ViewDepth + 1); } +void SourceCoverageViewText::renderBranchView(raw_ostream &OS, BranchView &BRV, + unsigned ViewDepth) { + // Render the child subview. + if (getOptions().Debug) + errs() << "Branch at line " << BRV.getLine() << '\n'; + + for (const auto &R : BRV.Regions) { + double TruePercent = 0.0; + double FalsePercent = 0.0; + unsigned Total = R.ExecutionCount + R.FalseExecutionCount; + + if (!getOptions().ShowBranchCounts && Total != 0) { + TruePercent = ((double)(R.ExecutionCount) / (double)Total) * 100.0; + FalsePercent = ((double)(R.FalseExecutionCount) / (double)Total) * 100.0; + } + + renderLinePrefix(OS, ViewDepth); + OS << " Branch (" << R.LineStart << ":" << R.ColumnStart << "): ["; + + if (R.Folded) { + OS << "Folded - Ignored]\n"; + continue; + } + + colored_ostream(OS, raw_ostream::RED, + getOptions().Colors && !R.ExecutionCount, + /*Bold=*/false, /*BG=*/true) + << "True"; + + if (getOptions().ShowBranchCounts) + OS << ": " << formatCount(R.ExecutionCount) << ", "; + else + OS << ": " << format("%0.2f", TruePercent) << "%, "; + + colored_ostream(OS, raw_ostream::RED, + getOptions().Colors && !R.FalseExecutionCount, + /*Bold=*/false, /*BG=*/true) + << "False"; + + if (getOptions().ShowBranchCounts) + OS << ": " << formatCount(R.FalseExecutionCount); + else + OS << ": " << format("%0.2f", FalsePercent) << "%"; + OS << "]\n"; + } +} + void SourceCoverageViewText::renderInstantiationView(raw_ostream &OS, InstantiationView &ISV, unsigned ViewDepth) { |