[llvm-commits] [llvm] r156810 - in /llvm/trunk: include/llvm/ADT/FlatArrayMap.h unittests/ADT/SmallMapTest.cpp
Stepan Dyatkovskiy
stpworld at narod.ru
Tue May 15 02:21:40 PDT 2012
Author: dyatkovskiy
Date: Tue May 15 04:21:39 2012
New Revision: 156810
URL: http://llvm.org/viewvc/llvm-project?rev=156810&view=rev
Log:
Fixed one small stupid, but critical bug.
Modified:
llvm/trunk/include/llvm/ADT/FlatArrayMap.h
llvm/trunk/unittests/ADT/SmallMapTest.cpp
Modified: llvm/trunk/include/llvm/ADT/FlatArrayMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/FlatArrayMap.h?rev=156810&r1=156809&r2=156810&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/FlatArrayMap.h (original)
+++ llvm/trunk/include/llvm/ADT/FlatArrayMap.h Tue May 15 04:21:39 2012
@@ -162,10 +162,10 @@
}
iterator end() {
- return iterator(Array + MaxArraySize);
+ return iterator(Array + NumElements);
}
const_iterator end() const {
- return const_iterator(Array + MaxArraySize);
+ return const_iterator(Array + NumElements);
}
// Modifiers
Modified: llvm/trunk/unittests/ADT/SmallMapTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/SmallMapTest.cpp?rev=156810&r1=156809&r2=156810&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/SmallMapTest.cpp (original)
+++ llvm/trunk/unittests/ADT/SmallMapTest.cpp Tue May 15 04:21:39 2012
@@ -144,4 +144,19 @@
(i->first == &buf[1] && i->second == 1) ||
(i->first == &buf[2] && i->second == 2));
}
+
+ // Check that iteration only visits elements that actually exist.
+ SmallMap<int, int, 8> d;
+ d[0] = 2;
+ d[1] = 3;
+ unsigned counts[2] = { 0, 0 };
+ for (SmallMap<int, int, 8>::iterator I = d.begin(), E = d.end(); I != E;
+ ++I) {
+ EXPECT_TRUE(I->first == 0 || I->first == 1);
+ EXPECT_TRUE(I->second == 2 || I->second == 3);
+ EXPECT_EQ(I->second, I->first + 2);
+ ++counts[I->first];
+ }
+ EXPECT_EQ(counts[0], 1);
+ EXPECT_EQ(counts[1], 1);
}
More information about the llvm-commits
mailing list