diff options
author | Jean-Luc Duprat <jduprat@apple.com> | 2013-03-29 05:45:22 +0000 |
---|---|---|
committer | Jean-Luc Duprat <jduprat@apple.com> | 2013-03-29 05:45:22 +0000 |
commit | 67ce1472b43eedb8a2361d64e383e2d2e5a24da0 (patch) | |
tree | f75e203c49899b4095d254a1310f5c1cf29b4b26 /llvm/unittests/ADT/SmallPtrSetTest.cpp | |
parent | ffaae3511a3c4e9aa3d5624f98b569191c10b6c4 (diff) | |
download | bcm5719-llvm-67ce1472b43eedb8a2361d64e383e2d2e5a24da0.tar.gz bcm5719-llvm-67ce1472b43eedb8a2361d64e383e2d2e5a24da0.zip |
Fix allocations of SmallVector and SmallPtrSet so they are more prone to
being power-of-two sized.
llvm-svn: 178332
Diffstat (limited to 'llvm/unittests/ADT/SmallPtrSetTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/SmallPtrSetTest.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp index 9114875e003..f85d7c941eb 100644 --- a/llvm/unittests/ADT/SmallPtrSetTest.cpp +++ b/llvm/unittests/ADT/SmallPtrSetTest.cpp @@ -17,6 +17,61 @@ using namespace llvm; // SmallPtrSet swapping test. +TEST(SmallPtrSetTest, GrowthTest) { + int i; + int buf[8]; + for(i=0; i<8; ++i) buf[i]=0; + + + SmallPtrSet<int *, 4> s; + typedef SmallPtrSet<int *, 4>::iterator iter; + + s.insert(&buf[0]); + s.insert(&buf[1]); + s.insert(&buf[2]); + s.insert(&buf[3]); + EXPECT_EQ(4U, s.size()); + + i = 0; + for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i) + (**I)++; + EXPECT_EQ(4, i); + for(i=0; i<8; ++i) + EXPECT_EQ(i<4?1:0,buf[i]); + + s.insert(&buf[4]); + s.insert(&buf[5]); + s.insert(&buf[6]); + s.insert(&buf[7]); + + i = 0; + for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i) + (**I)++; + EXPECT_EQ(8, i); + s.erase(&buf[4]); + s.erase(&buf[5]); + s.erase(&buf[6]); + s.erase(&buf[7]); + EXPECT_EQ(4U, s.size()); + + i = 0; + for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i) + (**I)++; + EXPECT_EQ(4, i); + for(i=0; i<8; ++i) + EXPECT_EQ(i<4?3:1,buf[i]); + + s.clear(); + for(i=0; i<8; ++i) buf[i]=0; + for(i=0; i<128; ++i) s.insert(&buf[i%8]); // test repeated entires + EXPECT_EQ(8U, s.size()); + for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i) + (**I)++; + for(i=0; i<8; ++i) + EXPECT_EQ(1,buf[i]); +} + + TEST(SmallPtrSetTest, SwapTest) { int buf[10]; |