1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00
llvm-mirror/unittests
Duncan P. N. Exon Smith 66bedcb549 ADT: Fix reference invalidation in SmallVector::emplace_back and assign(N,V)
This fixes the final (I think?) reference invalidation in `SmallVector`
that we need to fix to align with `std::vector`. (There is still some
left in the range insert / append / assign, but the standard calls that
UB for `std::vector` so I think we don't care?)

For POD-like types, reimplement `emplace_back()` in terms of
`push_back()`, taking a copy even for large `T` rather than lose the
realloc optimization in `grow_pod()`.

For other types, split the grow operation in three and construct the new
element in the middle.

- `mallocForGrow()` calculates the new capacity and returns the result
  of `safe_malloc()`. We only need a single definition per
  `SmallVectorBase` so this is defined in SmallVector.cpp to avoid code
  size bloat. Moving this part of non-POD grow to the source file also
  allows the logic to be easily shared with `grow_pod`, and
  `report_size_overflow()` and `report_at_maximum_capacity()` can move
  there too.
- `moveElementsForGrow()` moves elements from the old to the new
  allocation.
- `takeAllocationForGrow()` frees the old allocation and saves the
  new allocation and capacity .

`SmallVector:assign(size_type, const T&)` also uses the split-grow
operations for non-POD, but it also has a semantic change when not
growing. Previously, assign would start with `clear()`, and so the old
elements were destructed and all elements of the new vector were
copy-constructed (potentially invalidating references). The new
implementation skips destruction and uses copy-assignment for the prefix
of the new vector that fits. The new semantics match what libc++ does
for `std::vector::assign()`.

Note that the following is another possible implementation:
```
  void assign(size_type NumElts, ValueParamT Elt) {
    std::fill_n(this->begin(), std::min(NumElts, this->size()), Elt);
    this->resize(NumElts, Elt);
  }
```
The downside of this simpler implementation is that if the vector has to
grow there will be `size()` redundant copy operations.

(I had planned on splitting this patch up into three for committing
(after getting performance numbers / initial review), but I've realized
that if this does for some reason need to be reverted we'll probably
want to revert the whole package...)

Differential Revision: https://reviews.llvm.org/D94739
2021-01-21 12:11:41 -08:00
..
ADT ADT: Fix reference invalidation in SmallVector::emplace_back and assign(N,V) 2021-01-21 12:11:41 -08:00
Analysis [ValueTracking] Strengthen impliesPoison reasoning 2021-01-19 18:04:23 +01:00
AsmParser
BinaryFormat
Bitcode [AMDGPU] Set the default globals address space to 1 2020-11-20 15:46:53 +00:00
Bitstream Switch from llvm::is_trivially_copyable to std::is_trivially_copyable 2020-12-02 22:02:48 -08:00
CodeGen [MIPatternMatch] Add m_OneNonDBGUse 2021-01-15 10:18:46 -08:00
DebugInfo llvm-dwarfdump: Support verbose printing DW_OP_convert to print the CU local offset before the resolved absolute offset 2020-10-23 18:50:15 -07:00
Demangle
ExecutionEngine [ORC] Move OrcError.h to include/llvm/ExecutionEngine/Orc/Shared. 2021-01-19 16:18:00 +11:00
FileCheck
Frontend [docs][unittest][Go][StackProtector] Migrate deprecated DebugInfo::get to DILocation::get 2020-12-15 14:17:04 -08:00
FuzzMutate
InterfaceStub [llvm] Fix ODRViolations for VersionTuple YAML specializations NFC 2020-10-20 18:29:15 -07:00
IR Fixup Asserts+!AbiBreakingChecks fallout from db33f85c7124 2021-01-07 14:18:19 -08:00
LineEditor
Linker
MC [MC] Adjust StringTableBuilder for linked Mach-O binaries 2020-10-22 19:19:41 -07:00
MI [AMDGPU] Add _e64 suffix to VOP3 Insts 2021-01-12 18:33:18 -05:00
Object [llvm-readelf/obj] - Add support of multiple SHT_SYMTAB_SHNDX sections. 2021-01-13 11:36:43 +03:00
ObjectYAML
Option [clang][cli] Specify KeyPath prefixes via TableGen classes 2021-01-15 08:42:59 +01:00
Passes
ProfileData
Remarks
Support D94954: Fixes Snapdragon Kryo CPU core detection 2021-01-20 22:23:43 +00:00
TableGen [TableGen] Eliminte source location from CodeInit 2020-11-23 11:30:13 -05:00
Target [NFC][AMDGPU] Split AMDGPUSubtarget.h to R600 and GCN subtargets 2021-01-20 22:22:45 +03:00
TextAPI [YAML] Use correct source location for unknown key errors. 2020-12-11 16:34:06 +00:00
tools [llvm-exegesis][PowerPC] Add more register classes 2020-12-04 15:02:12 +00:00
Transforms [VPlan] Unify value/recipe printing after VPDef transition. 2021-01-11 14:42:46 +00:00
XRay
CMakeLists.txt
unittest.cfg.in