diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-11-19 17:12:27 -0800 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2021-01-13 20:48:08 -0800 |
commit | 260a856c2abcef49c7cb3bdcd999701db3e2af38 (patch) | |
tree | 691ae23214743865ca45e2e70c778e43735fe269 /llvm/unittests/ADT/SmallVectorTest.cpp | |
parent | 752fafda3dbf1f4885c64408a13ddb67c91ccb13 (diff) | |
download | llvm-260a856c2abcef49c7cb3bdcd999701db3e2af38.zip llvm-260a856c2abcef49c7cb3bdcd999701db3e2af38.tar.gz llvm-260a856c2abcef49c7cb3bdcd999701db3e2af38.tar.bz2 |
ADT: Fix reference invalidation in SmallVector::resize
For small enough, trivially copyable `T`, take the parameter by-value in
`SmallVector::resize`. Otherwise, when growing, update the arugment
appropriately.
Differential Revision: https://reviews.llvm.org/D93781
Diffstat (limited to 'llvm/unittests/ADT/SmallVectorTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/SmallVectorTest.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp index c236a68..1f6c7db 100644 --- a/llvm/unittests/ADT/SmallVectorTest.cpp +++ b/llvm/unittests/ADT/SmallVectorTest.cpp @@ -1135,12 +1135,14 @@ 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(N + 1, V.back()), this->AssertionMessage); -#endif + V.resize(N + 1, V.back()); + EXPECT_EQ(N, V.back()); - // No assertion when shrinking, since the parameter isn't accessed. - V.resize(N - 1, V.back()); + // Resize to add enough elements that V will grow again. If reference + // invalidation breaks in the future, sanitizers should be able to catch a + // use-after-free here. + V.resize(V.capacity() + 1, V.front()); + EXPECT_EQ(1, V.back()); } TYPED_TEST(SmallVectorReferenceInvalidationTest, Append) { |