ADT: Fix reference invalidation in SmallVector::push_back and single-element insert
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 19 Nov 2020 03:53:23 +0000 (19:53 -0800)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 14 Jan 2021 02:58:24 +0000 (18:58 -0800)
commit9abac60309006db00eca0af406c2e16bef26807c
tree9b1ed72fab13fb16ee4e2df2920b09b33d98fd6a
parenteec856848ccc481b2704ebf64d725e635a3d7dca
ADT: Fix reference invalidation in SmallVector::push_back and single-element insert

For small enough, trivially copyable `T`, take the argument by value in
`SmallVector::push_back` and copy it when forwarding to
`SmallVector::insert_one_impl`. Otherwise, when growing, update the
argument appropriately.

Differential Revision: https://reviews.llvm.org/D93779
llvm/include/llvm/ADT/SmallVector.h
llvm/unittests/ADT/SmallVectorTest.cpp