[compiler-rt] r331736 - [sanitizer] Add InternalMmapVector::swap
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon May 7 21:57:09 PDT 2018
Author: vitalybuka
Date: Mon May 7 21:57:08 2018
New Revision: 331736
URL: http://llvm.org/viewvc/llvm-project?rev=331736&view=rev
Log:
[sanitizer] Add InternalMmapVector::swap
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=331736&r1=331735&r2=331736&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Mon May 7 21:57:08 2018
@@ -510,6 +510,12 @@ class InternalMmapVectorNoCtor {
return data() + size();
}
+ void swap(InternalMmapVectorNoCtor &other) {
+ Swap(data_, other.data_);
+ Swap(capacity_, other.capacity_);
+ Swap(size_, other.size_);
+ }
+
private:
void Resize(uptr new_capacity) {
CHECK_GT(new_capacity, 0);
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=331736&r1=331735&r2=331736&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 Mon May 7 21:57:08 2018
@@ -130,6 +130,24 @@ TEST(SanitizerCommon, InternalMmapVector
EXPECT_TRUE(vector1 != vector2);
}
+TEST(SanitizerCommon, InternalMmapVectorSwap) {
+ InternalMmapVector<uptr> vector1;
+ InternalMmapVector<uptr> vector2;
+ InternalMmapVector<uptr> vector3;
+ InternalMmapVector<uptr> vector4;
+ for (uptr i = 0; i < 100; i++) {
+ vector1.push_back(i);
+ vector2.push_back(i);
+ vector3.push_back(-i);
+ vector4.push_back(-i);
+ }
+ EXPECT_NE(vector2, vector3);
+ EXPECT_NE(vector1, vector4);
+ vector1.swap(vector3);
+ EXPECT_EQ(vector2, vector3);
+ EXPECT_EQ(vector1, vector4);
+}
+
void TestThreadInfo(bool main) {
uptr stk_addr = 0;
uptr stk_size = 0;
More information about the llvm-commits
mailing list