[llvm] 6664e80 - Fix integer overflow in ConcurrentHashtTableByPtr
Andy Kaylor via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 16 15:43:27 PDT 2023
Author: Andy Kaylor
Date: 2023-08-16T15:42:49-07:00
New Revision: 6664e80ace0845d34eecebe0d5da0b576cde39ef
URL: https://github.com/llvm/llvm-project/commit/6664e80ace0845d34eecebe0d5da0b576cde39ef
DIFF: https://github.com/llvm/llvm-project/commit/6664e80ace0845d34eecebe0d5da0b576cde39ef.diff
LOG: Fix integer overflow in ConcurrentHashtTableByPtr
This change fixes a case where there was a potential integer overflow
when multiplying two 32-bit values and assigning the result to a 64-bit
value.
The potential overflow has been present since https://reviews.llvm.org/D132455
was re-landed. The initial version of the patch defined MaxBucketSize and
NumberOfBuckets as size_t (which I guess would still be a problem for some
targets). When the patch was re-landed they were defined as uint32_t, making
the calculation of ExtHashMask subject to overflow.
Differential Revision: https://reviews.llvm.org/D158117
Added:
Modified:
llvm/include/llvm/ADT/ConcurrentHashtable.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/ConcurrentHashtable.h b/llvm/include/llvm/ADT/ConcurrentHashtable.h
index 37c8af36bc73ec..a07688228da187 100644
--- a/llvm/include/llvm/ADT/ConcurrentHashtable.h
+++ b/llvm/include/llvm/ADT/ConcurrentHashtable.h
@@ -154,7 +154,7 @@ class ConcurrentHashTableByPtr {
MaxBucketSize = 1Ull << (std::min((size_t)31, LeadingZerosNumber));
// Calculate mask for extended hash bits.
- ExtHashMask = (NumberOfBuckets * MaxBucketSize) - 1;
+ ExtHashMask = (uint64_t)NumberOfBuckets * MaxBucketSize - 1;
}
virtual ~ConcurrentHashTableByPtr() {
More information about the llvm-commits
mailing list