[compiler-rt] r331619 - [sanitizer] Add operator== and operator!= for InternalMmapVectorNoCtor
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sun May 6 23:14:12 PDT 2018
Author: vitalybuka
Date: Sun May 6 23:14:12 2018
New Revision: 331619
URL: http://llvm.org/viewvc/llvm-project?rev=331619&view=rev
Log:
[sanitizer] Add operator== and operator!= for InternalMmapVectorNoCtor
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=331619&r1=331618&r2=331619&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Sun May 6 23:14:12 2018
@@ -528,6 +528,19 @@ class InternalMmapVectorNoCtor {
uptr size_;
};
+template <typename T>
+bool operator==(const InternalMmapVectorNoCtor<T> &lhs,
+ const InternalMmapVectorNoCtor<T> &rhs) {
+ if (lhs.size() != rhs.size()) return false;
+ return internal_memcmp(lhs.data(), rhs.data(), lhs.size() * sizeof(T)) == 0;
+}
+
+template <typename T>
+bool operator!=(const InternalMmapVectorNoCtor<T> &lhs,
+ const InternalMmapVectorNoCtor<T> &rhs) {
+ return !(lhs == rhs);
+}
+
template<typename T>
class InternalMmapVector : public InternalMmapVectorNoCtor<T> {
public:
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=331619&r1=331618&r2=331619&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 Sun May 6 23:14:12 2018
@@ -107,6 +107,29 @@ TEST(SanitizerCommon, InternalMmapVector
CHECK_EQ(0U, empty_vector.size());
}
+TEST(SanitizerCommon, InternalMmapVectorEq) {
+ InternalMmapVector<uptr> vector1;
+ InternalMmapVector<uptr> vector2;
+ for (uptr i = 0; i < 100; i++) {
+ vector1.push_back(i);
+ vector2.push_back(i);
+ }
+ EXPECT_TRUE(vector1 == vector2);
+ EXPECT_FALSE(vector1 != vector2);
+
+ vector1.push_back(1);
+ EXPECT_FALSE(vector1 == vector2);
+ EXPECT_TRUE(vector1 != vector2);
+
+ vector2.push_back(1);
+ EXPECT_TRUE(vector1 == vector2);
+ EXPECT_FALSE(vector1 != vector2);
+
+ vector1[55] = 1;
+ EXPECT_FALSE(vector1 == vector2);
+ EXPECT_TRUE(vector1 != vector2);
+}
+
void TestThreadInfo(bool main) {
uptr stk_addr = 0;
uptr stk_size = 0;
More information about the llvm-commits
mailing list