[compiler-rt] r330049 - [sanitizer] Fix __sanitizer::Vector::Resize vector

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 13 11:41:52 PDT 2018


Author: vitalybuka
Date: Fri Apr 13 11:41:52 2018
New Revision: 330049

URL: http://llvm.org/viewvc/llvm-project?rev=330049&view=rev
Log:
[sanitizer] Fix __sanitizer::Vector::Resize vector

Implemented downsizing

Patch by Oleg Doronin

Reviewers: kcc, vitalybuka

Reviewed By: kcc, vitalybuka

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D45605

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_vector.h
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_vector.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_vector.h?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_vector.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_vector.h Fri Apr 13 11:41:52 2018
@@ -82,6 +82,10 @@ class Vector {
       return;
     }
     uptr old_size = Size();
+    if (size <= old_size) {
+      end_ = begin_ + size;
+      return;
+    }
     EnsureSize(size);
     if (old_size < size) {
       for (uptr i = old_size; i < size; i++)

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc Fri Apr 13 11:41:52 2018
@@ -39,4 +39,13 @@ TEST(Vector, Stride) {
   }
 }
 
+TEST(Vector, ResizeReduction) {
+  Vector<int> v;
+  v.PushBack(0);
+  v.PushBack(0);
+  EXPECT_EQ(v.Size(), 2u);
+  v.Resize(1);
+  EXPECT_EQ(v.Size(), 1u);
+}
+
 }  // namespace __sanitizer




More information about the llvm-commits mailing list