aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/ProfileData/Coverage/CoverageMapping.cpp')
-rw-r--r--llvm/lib/ProfileData/Coverage/CoverageMapping.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 9c95cd5..da8e1d8 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -229,6 +229,7 @@ Expected<BitVector> CounterMappingContext::evaluateBitmap(
unsigned SizeInBits = llvm::alignTo(uint64_t(1) << NC, CHAR_BIT);
unsigned SizeInBytes = SizeInBits / CHAR_BIT;
+ assert(ID + SizeInBytes <= BitmapBytes.size() && "BitmapBytes overrun");
ArrayRef<uint8_t> Bytes(&BitmapBytes[ID], SizeInBytes);
// Mask each bitmap byte into the BitVector. Go in reverse so that the
@@ -568,14 +569,14 @@ static unsigned getMaxBitmapSize(const CounterMappingContext &Ctx,
const CoverageMappingRecord &Record) {
unsigned MaxBitmapID = 0;
unsigned NumConditions = 0;
- // The last DecisionRegion has the highest bitmap byte index used in the
- // function, which when combined with its number of conditions, yields the
- // full bitmap size.
+ // Scan max(BitmapIdx).
+ // Note that `<=` is used insted of `<`, because `BitmapIdx == 0` is valid
+ // and `MaxBitmapID is `unsigned`. `BitmapIdx` is unique in the record.
for (const auto &Region : reverse(Record.MappingRegions)) {
- if (Region.Kind == CounterMappingRegion::MCDCDecisionRegion) {
+ if (Region.Kind == CounterMappingRegion::MCDCDecisionRegion &&
+ MaxBitmapID <= Region.MCDCParams.BitmapIdx) {
MaxBitmapID = Region.MCDCParams.BitmapIdx;
NumConditions = Region.MCDCParams.NumConditions;
- break;
}
}
unsigned SizeInBits = llvm::alignTo(uint64_t(1) << NumConditions, CHAR_BIT);