aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-08-14 02:56:51 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-08-14 02:56:51 +0000
commitb8ea08ca8c43016f5bc35e1a3b6557d414448fae (patch)
tree0956cdcbe69ac66867db5044658cb51b10160e01
parenta61d3a98c47b009274530830b2489d49ce215dbb (diff)
Avoid undefined behavior in DenseMap::shrink_and_clear(). Log2_32_Ceil(0)
returns 32. This change mirrors the corresponding code in SmallDenseMap::shrink_and_clear(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161829 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/ADT/DenseMap.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h
index d502be65a7..65a70fbfa6 100644
--- a/include/llvm/ADT/DenseMap.h
+++ b/include/llvm/ADT/DenseMap.h
@@ -617,8 +617,9 @@ public:
this->destroyAll();
// Reduce the number of buckets.
- unsigned NewNumBuckets
- = std::max(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1));
+ unsigned NewNumBuckets = 0;
+ if (OldNumEntries)
+ NewNumBuckets = std::max(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1));
if (NewNumBuckets == NumBuckets) {
this->BaseT::initEmpty();
return;