Skip to content

Commit 75cef15

Browse files
committed
Move getDecisions to MCDCRecord
1 parent cb87084 commit 75cef15

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/Support/Endian.h"
3232
#include "llvm/Support/Error.h"
3333
#include "llvm/Support/raw_ostream.h"
34+
#include <algorithm>
3435
#include <cassert>
3536
#include <cstdint>
3637
#include <iterator>
@@ -494,8 +495,16 @@ struct MCDCRecord {
494495
return TV[TestVectorIndex].first[PosToID[Condition]];
495496
}
496497

497-
/// Return the executed test vectors.
498-
const TestVectors &getTV() const { return TV; }
498+
/// Return the number of True and False decisions for all executed test
499+
/// vectors.
500+
std::pair<unsigned, unsigned> getDecisions() const {
501+
const unsigned TrueDecisions =
502+
std::count_if(TV.begin(), TV.end(), [](const auto &TestVec) {
503+
return TestVec.second == CondState::MCDC_True;
504+
});
505+
506+
return {TrueDecisions, TV.size() - TrueDecisions};
507+
}
499508

500509
/// Return the Result evaluation for an executed test vector.
501510
/// See MCDCRecordProcessor::RecordTestVector().

llvm/tools/llvm-cov/CoverageExporterJson.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,11 @@ json::Array gatherConditions(const coverage::MCDCRecord &Record) {
108108
return Conditions;
109109
}
110110

111-
std::pair<unsigned, unsigned> getDecisions(const coverage::MCDCRecord &Record) {
112-
const coverage::MCDCRecord::TestVectors &TestVectors = Record.getTV();
113-
const unsigned TrueConditions =
114-
std::count_if(TestVectors.begin(), TestVectors.end(), [](const auto &TV) {
115-
return TV.second == coverage::MCDCRecord::CondState::MCDC_True;
116-
});
117-
118-
return {TrueConditions, TestVectors.size() - TrueConditions};
119-
}
120-
121111
json::Array renderMCDCRecord(const coverage::MCDCRecord &Record) {
122112
const llvm::coverage::CounterMappingRegion &CMR = Record.getDecisionRegion();
123-
const auto [TrueConditions, FalseConditions] = getDecisions(Record);
113+
const auto [TrueDecisions, FalseDecisions] = Record.getDecisions();
124114
return json::Array({CMR.LineStart, CMR.ColumnStart, CMR.LineEnd,
125-
CMR.ColumnEnd, TrueConditions, FalseConditions,
115+
CMR.ColumnEnd, TrueDecisions, FalseDecisions,
126116
CMR.ExpandedFileID, int64_t(CMR.Kind),
127117
gatherConditions(Record)});
128118
}

0 commit comments

Comments
 (0)