Skip to content

Commit afb75e6

Browse files
committed
Fix off-by-one error in maskForCount, comment more carefully
1 parent 35a98aa commit afb75e6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stdlib/public/RemoteInspection/TypeLowering.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,13 @@ class TrivialEnumTypeInfo: public EnumTypeInfo {
450450
}
451451
};
452452

453-
// Old bit hack for setting all the bits lower than
454-
// the highest set bit.
453+
// Given a count, return a mask that is just
454+
// big enough to preserve values less than that count.
455+
// E.g., given a count of 6, max value is 5 (binary 0101),
456+
// so we want to return binary 0111.
455457
static uint32_t maskForCount(uint32_t t) {
458+
t -= 1; // Convert count => max value
459+
// Set all bits below highest bit...
456460
t |= t >> 16;
457461
t |= t >> 8;
458462
t |= t >> 4;

0 commit comments

Comments
 (0)