[PATCH] D45605: Resize vector have does not work correctly
Oleg Doronin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 13 01:22:38 PDT 2018
dorooleg updated this revision to Diff 142347.
dorooleg added a comment.
@vitalybuka, @kcc thanks for the comments. ResizeReduction test was added into compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc
As recommended by @kcc the changes are transferred to the method Resize
An error was found while attempting to use Vector in my own changes. How I see this error does not affect the current logic, so as to Resize is used to increase the size of the Vector
https://reviews.llvm.org/D45605
Files:
sanitizer_common/sanitizer_vector.h
sanitizer_common/tests/sanitizer_vector_test.cc
Index: sanitizer_common/tests/sanitizer_vector_test.cc
===================================================================
--- sanitizer_common/tests/sanitizer_vector_test.cc
+++ sanitizer_common/tests/sanitizer_vector_test.cc
@@ -39,4 +39,13 @@
}
}
+TEST(Vector, ResizeReduction) {
+ Vector<int> v;
+ v.PushBack(0);
+ v.PushBack(0);
+ EXPECT_EQ(v.Size(), 2);
+ v.Resize(1);
+ EXPECT_EQ(v.Size(), 1);
+}
+
} // namespace __sanitizer
Index: sanitizer_common/sanitizer_vector.h
===================================================================
--- sanitizer_common/sanitizer_vector.h
+++ sanitizer_common/sanitizer_vector.h
@@ -82,6 +82,10 @@
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++)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45605.142347.patch
Type: text/x-patch
Size: 884 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180413/526a9ce8/attachment.bin>
More information about the llvm-commits
mailing list