Skip to content

Commit 93d8d6c

Browse files
authored
Fix memory error in the implementation of IndexSubset. (#27850)
1 parent 4ffc714 commit 93d8d6c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

include/swift/AST/IndexSubset.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class IndexSubset : public llvm::FoldingSetNode {
5757
/// The number of bit words in the index subset.
5858
unsigned numBitWords;
5959

60+
static unsigned getNumBytesNeededForCapacity(unsigned capacity) {
61+
return getNumBitWordsNeededForCapacity(capacity) * bitWordSize;
62+
}
63+
6064
BitWord *getBitWordsData() {
6165
return reinterpret_cast<BitWord *>(this + 1);
6266
}

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4822,7 +4822,7 @@ IndexSubset::get(ASTContext &ctx, const SmallBitVector &indices) {
48224822
if (existing)
48234823
return existing;
48244824
auto sizeToAlloc = sizeof(IndexSubset) +
4825-
getNumBitWordsNeededForCapacity(capacity);
4825+
getNumBytesNeededForCapacity(capacity);
48264826
auto *buf = reinterpret_cast<IndexSubset *>(
48274827
ctx.Allocate(sizeToAlloc, alignof(IndexSubset)));
48284828
auto *newNode = new (buf) IndexSubset(indices);

0 commit comments

Comments
 (0)