summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-06-19 17:40:35 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-06-19 17:40:35 +0000
commit198422a4758d1ad9ba9bcfc199e2a2c1ad4ba162 (patch)
treee094ba212d80b5834ed988ed7dbf1ee0146ffd58 /llvm/lib/Support
parentfc3856d9fb36459b6f44e97bdf4759d8c04fb228 (diff)
downloadbcm5719-llvm-198422a4758d1ad9ba9bcfc199e2a2c1ad4ba162.tar.gz
bcm5719-llvm-198422a4758d1ad9ba9bcfc199e2a2c1ad4ba162.zip
Fix PR13148, an inf-loop in StringMap.
StringMap suffered from the same bug as DenseMap: when you explicitly construct it with a small number of buckets, you can arrange for the tombstone-based growth path to be followed when the number of buckets was less than '8'. In that case, even with a full map, it would compare '0' as not less than '0', and refuse to grow the table, leading to inf-loops trying to find an empty bucket on the next insertion. The fix is very simple: use '<=' as the comparison. The same fix was applied to DenseMap as well during its recent refactoring. Thanks to Alex Bolz for the great report and test case. =] llvm-svn: 158725
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/StringMap.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp
index c131fe07f48..c2fc261df3a 100644
--- a/llvm/lib/Support/StringMap.cpp
+++ b/llvm/lib/Support/StringMap.cpp
@@ -189,7 +189,7 @@ void StringMapImpl::RehashTable() {
// grow/rehash the table.
if (NumItems*4 > NumBuckets*3) {
NewSize = NumBuckets*2;
- } else if (NumBuckets-(NumItems+NumTombstones) < NumBuckets/8) {
+ } else if (NumBuckets-(NumItems+NumTombstones) <= NumBuckets/8) {
NewSize = NumBuckets;
} else {
return;
OpenPOWER on IntegriCloud