[llvm] [llvm-cov] Export decision coverage to output json (PR #144335)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 16 04:39:40 PDT 2025
https://github.com/uthmanna created https://github.com/llvm/llvm-project/pull/144335
This commit adds decision coverage to the JSON output of llvm-cov, as discussed here: [Missing Decision Coverage (DC) in output json](https://discourse.llvm.org/t/missing-decision-coverage-dc-in-output-json/86783) with @evodius96
>From cb87084d4cdd0cab86585226ed4ee4ebc964c8bf Mon Sep 17 00:00:00 2001
From: uthmanna <andre.uthmann at vector.com>
Date: Mon, 16 Jun 2025 13:18:55 +0200
Subject: [PATCH] [llvm-cov] Export decision coverage to output json
---
.../llvm/ProfileData/Coverage/CoverageMapping.h | 3 +++
llvm/tools/llvm-cov/CoverageExporterJson.cpp | 16 ++++++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index d1230b0ba7c58..c9854e08a38e8 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -494,6 +494,9 @@ struct MCDCRecord {
return TV[TestVectorIndex].first[PosToID[Condition]];
}
+ /// Return the executed test vectors.
+ const TestVectors &getTV() const { return TV; }
+
/// Return the Result evaluation for an executed test vector.
/// See MCDCRecordProcessor::RecordTestVector().
CondState getTVResult(unsigned TestVectorIndex) {
diff --git a/llvm/tools/llvm-cov/CoverageExporterJson.cpp b/llvm/tools/llvm-cov/CoverageExporterJson.cpp
index 4088c1b053aa8..cae7b86bc6b0c 100644
--- a/llvm/tools/llvm-cov/CoverageExporterJson.cpp
+++ b/llvm/tools/llvm-cov/CoverageExporterJson.cpp
@@ -62,7 +62,7 @@
#include <utility>
/// The semantic version combined as a string.
-#define LLVM_COVERAGE_EXPORT_JSON_STR "2.0.1"
+#define LLVM_COVERAGE_EXPORT_JSON_STR "3.0.0"
/// Unique type identifier for JSON coverage export.
#define LLVM_COVERAGE_EXPORT_JSON_TYPE_STR "llvm.coverage.json.export"
@@ -108,10 +108,22 @@ json::Array gatherConditions(const coverage::MCDCRecord &Record) {
return Conditions;
}
+std::pair<unsigned, unsigned> getDecisions(const coverage::MCDCRecord &Record) {
+ const coverage::MCDCRecord::TestVectors &TestVectors = Record.getTV();
+ const unsigned TrueConditions =
+ std::count_if(TestVectors.begin(), TestVectors.end(), [](const auto &TV) {
+ return TV.second == coverage::MCDCRecord::CondState::MCDC_True;
+ });
+
+ return {TrueConditions, TestVectors.size() - TrueConditions};
+}
+
json::Array renderMCDCRecord(const coverage::MCDCRecord &Record) {
const llvm::coverage::CounterMappingRegion &CMR = Record.getDecisionRegion();
+ const auto [TrueConditions, FalseConditions] = getDecisions(Record);
return json::Array({CMR.LineStart, CMR.ColumnStart, CMR.LineEnd,
- CMR.ColumnEnd, CMR.ExpandedFileID, int64_t(CMR.Kind),
+ CMR.ColumnEnd, TrueConditions, FalseConditions,
+ CMR.ExpandedFileID, int64_t(CMR.Kind),
gatherConditions(Record)});
}
More information about the llvm-commits
mailing list