[compiler-rt] r176478 - [Sanitizer] Add methods back() and pop_back() to InternalVector. Patch by Sergey Matveev
Alexey Samsonov
samsonov at google.com
Tue Mar 5 03:58:25 PST 2013
Author: samsonov
Date: Tue Mar 5 05:58:25 2013
New Revision: 176478
URL: http://llvm.org/viewvc/llvm-project?rev=176478&view=rev
Log:
[Sanitizer] Add methods back() and pop_back() to InternalVector. Patch by Sergey Matveev
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=176478&r1=176477&r2=176478&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Tue Mar 5 05:58:25 2013
@@ -287,6 +287,14 @@ class InternalVector {
}
data_[size_++] = element;
}
+ T &back() {
+ CHECK_GT(size_, 0);
+ return data_[size_ - 1];
+ }
+ void pop_back() {
+ CHECK_GT(size_, 0);
+ size_--;
+ }
uptr size() {
return size_;
}
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc?rev=176478&r1=176477&r2=176478&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc Tue Mar 5 05:58:25 2013
@@ -105,6 +105,11 @@ TEST(SanitizerCommon, InternalVector) {
for (uptr i = 0; i < 100; i++) {
EXPECT_EQ(vector[i], i);
}
+ for (int i = 99; i >= 0; i--) {
+ EXPECT_EQ(vector.back(), i);
+ vector.pop_back();
+ EXPECT_EQ(vector.size(), i);
+ }
}
} // namespace __sanitizer
More information about the llvm-commits
mailing list