[PATCH] D91832: ADT: Weaken SmallVector::resize assertion from 5abf76fbe37380874a88cc9aa02164800e4e10f3
Duncan P. N. Exon Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 19 17:27:50 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG40e877264dc5: ADT: Weaken SmallVector::resize assertion from… (authored by dexonsmith).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91832/new/
https://reviews.llvm.org/D91832
Files:
llvm/include/llvm/ADT/SmallVector.h
llvm/unittests/ADT/SmallVectorTest.cpp
Index: llvm/unittests/ADT/SmallVectorTest.cpp
===================================================================
--- llvm/unittests/ADT/SmallVectorTest.cpp
+++ llvm/unittests/ADT/SmallVectorTest.cpp
@@ -1051,9 +1051,13 @@
TYPED_TEST(SmallVectorReferenceInvalidationTest, Resize) {
auto &V = this->V;
(void)V;
+ int N = this->NumBuiltinElts(V);
#if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST
- EXPECT_DEATH(V.resize(2, V.back()), this->AssertionMessage);
+ EXPECT_DEATH(V.resize(N + 1, V.back()), this->AssertionMessage);
#endif
+
+ // No assertion when shrinking, since the parameter isn't accessed.
+ V.resize(N - 1, V.back());
}
TYPED_TEST(SmallVectorReferenceInvalidationTest, Append) {
Index: llvm/include/llvm/ADT/SmallVector.h
===================================================================
--- llvm/include/llvm/ADT/SmallVector.h
+++ llvm/include/llvm/ADT/SmallVector.h
@@ -462,11 +462,11 @@
}
void resize(size_type N, const T &NV) {
- this->assertSafeToReferenceAfterResize(&NV, N);
if (N < this->size()) {
this->destroy_range(this->begin()+N, this->end());
this->set_size(N);
} else if (N > this->size()) {
+ this->assertSafeToReferenceAfterResize(&NV, N);
if (this->capacity() < N)
this->grow(N);
std::uninitialized_fill(this->end(), this->begin()+N, NV);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91832.306567.patch
Type: text/x-patch
Size: 1350 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201120/93655568/attachment.bin>
More information about the llvm-commits
mailing list