llvm-project/clang/lib/ARCMigrate
Vassil Vassilev 0cb7e7ca0c Make iteration over the DeclContext::lookup_result safe.
The idiom:
```
DeclContext::lookup_result R = DeclContext::lookup(Name);
for (auto *D : R) {...}
```

is not safe when in the loop body we trigger deserialization from an AST file.
The deserialization can insert new declarations in the StoredDeclsList whose
underlying type is a vector. When the vector decides to reallocate its storage
the pointer we hold becomes invalid.

This patch replaces a SmallVector with an singly-linked list. The current
approach stores a SmallVector<NamedDecl*, 4> which is around 8 pointers.
The linked list is 3, 5, or 7. We do better in terms of memory usage for small
cases (and worse in terms of locality -- the linked list entries won't be near
each other, but will be near their corresponding declarations, and we were going
to fetch those memory pages anyway). For larger cases: the vector uses a
doubling strategy for reallocation, so will generally be between half-full and
full. Let's say it's 75% full on average, so there's N * 4/3 + 4 pointers' worth
of space allocated currently and will be 2N pointers with the linked list. So we
break even when there are N=6 entries and slightly lose in terms of memory usage
after that. We suspect that's still a win on average.

Thanks to @rsmith!

Differential revision: https://reviews.llvm.org/D91524
2021-03-17 08:59:04 +00:00
..
ARCMT.cpp ARCMigrate: Stop abusing PreprocessorOptions for passing back file remappings, NFC 2020-12-02 16:28:33 -08:00
ARCMTActions.cpp
CMakeLists.txt With MSVC, file needs to be compiled with /BIGOBJ 2020-07-17 09:43:06 -07:00
FileRemapper.cpp ARCMigrate: Stop abusing PreprocessorOptions for passing back file remappings, NFC 2020-12-02 16:28:33 -08:00
Internals.h
ObjCMT.cpp Make iteration over the DeclContext::lookup_result safe. 2021-03-17 08:59:04 +00:00
PlistReporter.cpp
TransAPIUses.cpp
TransARCAssign.cpp
TransAutoreleasePool.cpp
TransBlockObjCVariable.cpp
TransEmptyStatementsAndDealloc.cpp
TransGCAttrs.cpp [clang] Use SourceLocation as key in hash maps, NFCI 2020-10-20 16:24:09 +01:00
TransGCCalls.cpp
TransProperties.cpp [clang] Use SourceLocation as key in hash maps, NFCI 2020-10-20 16:24:09 +01:00
TransProtectedScope.cpp
TransRetainReleaseDealloc.cpp
TransUnbridgedCasts.cpp
TransUnusedInitDelegate.cpp
TransZeroOutPropsInDealloc.cpp [NFC] Refactoring PropertyAttributeKind for ObjCPropertyDecl and ObjCDeclSpec. 2020-04-23 17:21:25 -04:00
TransformActions.cpp
Transforms.cpp
Transforms.h [clang] Use SourceLocation as key in hash maps, NFCI 2020-10-20 16:24:09 +01:00