[Sanitizer] Add methods back() and pop_back() to InternalVector. Patch by Sergey...
authorAlexey Samsonov <samsonov@google.com>
Tue, 5 Mar 2013 11:58:25 +0000 (11:58 +0000)
committerAlexey Samsonov <samsonov@google.com>
Tue, 5 Mar 2013 11:58:25 +0000 (11:58 +0000)
llvm-svn: 176478

compiler-rt/lib/sanitizer_common/sanitizer_common.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cc

index ce04919..021da70 100644 (file)
@@ -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_;
   }
index 1ffcde2..7b2232b 100644 (file)
@@ -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