[llvm] [llvm-cov] Export decision coverage to output json (PR #144335)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 16 04:40:35 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-pgo
Author: None (uthmanna)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/144335.diff
2 Files Affected:
- (modified) llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h (+3)
- (modified) llvm/tools/llvm-cov/CoverageExporterJson.cpp (+14-2)
``````````diff
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)});
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/144335
More information about the llvm-commits
mailing list