aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2024-01-23 17:59:44 +0900
committerGitHub <noreply@github.com>2024-01-23 17:59:44 +0900
commitc193bb7e9eee02a435944506c732db9b480f0c84 (patch)
treed645c0dd4fe7c520ed3d3c8c5d484ffee651738a /llvm/lib/ProfileData
parentd8628a00fd92c6f9db631f817a63eada90707ad2 (diff)
downloadllvm-c193bb7e9eee02a435944506c732db9b480f0c84.zip
llvm-c193bb7e9eee02a435944506c732db9b480f0c84.tar.gz
llvm-c193bb7e9eee02a435944506c732db9b480f0c84.tar.bz2
[Coverage] getMaxBitmapSize: Scan `max(BitmapIdx)` instead of the last `Decision` (#78963)
In `CoverageMapping.cpp:getMaxBitmapSize()`, this assumed that the last `Decision` has the maxmum `BitmapIdx`. Let it scan `max(BitmapIdx)`. Note that `<=` is used insted of `<`, because `BitmapIdx == 0` is valid and `MaxBitmapID` is `unsigned`. `BitmapIdx` is unique in the record. Fixes #78922
Diffstat (limited to 'llvm/lib/ProfileData')
-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);