diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h index d1230b0ba7c58..8e6180be25b51 100644 --- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h +++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h @@ -31,6 +31,7 @@ #include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" +#include #include #include #include @@ -494,6 +495,17 @@ struct MCDCRecord { return TV[TestVectorIndex].first[PosToID[Condition]]; } + /// Return the number of True and False decisions for all executed test + /// vectors. + std::pair getDecisions() const { + const unsigned TrueDecisions = + std::count_if(TV.begin(), TV.end(), [](const auto &TestVec) { + return TestVec.second == CondState::MCDC_True; + }); + + return {TrueDecisions, TV.size() - TrueDecisions}; + } + /// 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..024693a24cc23 100644 --- a/llvm/tools/llvm-cov/CoverageExporterJson.cpp +++ b/llvm/tools/llvm-cov/CoverageExporterJson.cpp @@ -62,7 +62,7 @@ #include /// 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" @@ -110,8 +110,10 @@ json::Array gatherConditions(const coverage::MCDCRecord &Record) { json::Array renderMCDCRecord(const coverage::MCDCRecord &Record) { const llvm::coverage::CounterMappingRegion &CMR = Record.getDecisionRegion(); + const auto [TrueDecisions, FalseDecisions] = Record.getDecisions(); return json::Array({CMR.LineStart, CMR.ColumnStart, CMR.LineEnd, - CMR.ColumnEnd, CMR.ExpandedFileID, int64_t(CMR.Kind), + CMR.ColumnEnd, TrueDecisions, FalseDecisions, + CMR.ExpandedFileID, int64_t(CMR.Kind), gatherConditions(Record)}); }