mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
Prevent looping when DenseSet is abused.
llvm-svn: 70572
This commit is contained in:
parent
064820037b
commit
b3c08d427a
@ -346,12 +346,12 @@ private:
|
|||||||
// probe almost the entire table until it found the empty bucket. If the
|
// probe almost the entire table until it found the empty bucket. If the
|
||||||
// table completely filled with tombstones, no lookup would ever succeed,
|
// table completely filled with tombstones, no lookup would ever succeed,
|
||||||
// causing infinite loops in lookup.
|
// causing infinite loops in lookup.
|
||||||
|
++NumEntries;
|
||||||
if (NumEntries*4 >= NumBuckets*3 ||
|
if (NumEntries*4 >= NumBuckets*3 ||
|
||||||
NumBuckets-(NumEntries+NumTombstones) < NumBuckets/8) {
|
NumBuckets-(NumEntries+NumTombstones) < NumBuckets/8) {
|
||||||
this->grow(NumBuckets * 2);
|
this->grow(NumBuckets * 2);
|
||||||
LookupBucketFor(Key, TheBucket);
|
LookupBucketFor(Key, TheBucket);
|
||||||
}
|
}
|
||||||
++NumEntries;
|
|
||||||
|
|
||||||
// If we are writing over a tombstone, remember this.
|
// If we are writing over a tombstone, remember this.
|
||||||
if (!KeyInfoT::isEqual(TheBucket->first, getEmptyKey()))
|
if (!KeyInfoT::isEqual(TheBucket->first, getEmptyKey()))
|
||||||
|
30
unittests/ADT/DenseSetTest.cpp
Normal file
30
unittests/ADT/DenseSetTest.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//===- llvm/unittest/ADT/DenseSetTest.cpp - DenseSet unit tests --*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include <llvm/ADT/DenseSet.h>
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Test fixture
|
||||||
|
class DenseSetTest : public testing::Test {
|
||||||
|
};
|
||||||
|
|
||||||
|
// Test hashing with a set of only two entries.
|
||||||
|
TEST_F(DenseSetTest, DoubleEntrySetTest) {
|
||||||
|
llvm::DenseSet<unsigned> set(2);
|
||||||
|
set.insert(0);
|
||||||
|
set.insert(1);
|
||||||
|
// Original failure was an infinite loop in this call:
|
||||||
|
EXPECT_EQ(0, set.count(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user