llvm-project/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime
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
..
AppleObjCClassDescriptorV2.cpp [lldb/ObjC] Add support for direct selector references 2020-07-01 20:27:37 -07:00
AppleObjCClassDescriptorV2.h [lldb/ObjC] Add support for direct selector references 2020-07-01 20:27:37 -07:00
AppleObjCDeclVendor.cpp Make iteration over the DeclContext::lookup_result safe. 2021-03-17 08:59:04 +00:00
AppleObjCDeclVendor.h [lldb] Update header guards to be consistent and compliant with LLVM (NFC) 2020-02-17 23:15:40 -08:00
AppleObjCRuntime.cpp [lldb] Access the ModuleList through iterators where possible (NFC) 2021-01-07 21:06:36 -08:00
AppleObjCRuntime.h [lldb] Update header guards to be consistent and compliant with LLVM (NFC) 2020-02-17 23:15:40 -08:00
AppleObjCRuntimeV1.cpp Make the error condition in Value::ValueType explicit (NFC) 2021-02-12 16:12:31 -08:00
AppleObjCRuntimeV1.h [lldb] Redesign Target::GetUtilityFunctionForLanguage API 2020-10-23 10:00:23 -07:00
AppleObjCRuntimeV2.cpp [lldb] Inline objc_opt->version >= 14 to avoid dealing with bool type 2021-03-02 16:41:44 -08:00
AppleObjCRuntimeV2.h [lldb] Redesign Target::GetUtilityFunctionForLanguage API 2020-10-23 10:00:23 -07:00
AppleObjCTrampolineHandler.cpp Make the error condition in Value::ValueType explicit (NFC) 2021-02-12 16:12:31 -08:00
AppleObjCTrampolineHandler.h [lldb] Remove redundant access specifiers (NFC) 2020-06-15 21:34:13 -07:00
AppleObjCTypeEncodingParser.cpp [lldb] Use std::make_unique<> (NFC) 2020-06-24 17:48:40 -07:00
AppleObjCTypeEncodingParser.h [lldb] Update header guards to be consistent and compliant with LLVM (NFC) 2020-02-17 23:15:40 -08:00
AppleThreadPlanStepThroughObjCTrampoline.cpp [lldb] Inline invariant params to AppleThreadPlanStepThrough (NFC) 2021-02-09 08:03:51 -08:00
AppleThreadPlanStepThroughObjCTrampoline.h [lldb] Inline invariant params to AppleThreadPlanStepThrough (NFC) 2021-02-09 08:03:51 -08:00
CMakeLists.txt [lldb] Move clang-based files out of Symbol 2020-01-31 12:20:10 -08:00