From 4e76d7fcb69d615096a55efbb1efb0cde6550c9f Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Tue, 8 May 2018 04:57:08 +0000 Subject: [PATCH] [sanitizer] Add InternalMmapVector::swap llvm-svn: 331736 --- .../lib/sanitizer_common/sanitizer_common.h | 6 ++++++ .../tests/sanitizer_common_test.cc | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index cd47028c949a..52958de6de0e 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -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); diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cc index ff5c63279dcb..da761bef689c 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cc @@ -130,6 +130,24 @@ TEST(SanitizerCommon, InternalMmapVectorEq) { EXPECT_TRUE(vector1 != vector2); } +TEST(SanitizerCommon, InternalMmapVectorSwap) { + InternalMmapVector vector1; + InternalMmapVector vector2; + InternalMmapVector vector3; + InternalMmapVector 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;