[Reflection] Prevent symbolic reference mangling induced crash #37732
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on lldb crash logs,
TypeRefBuilder
is crashing on instances of symbolic references in mangled names.The crash happens when a symbolic reference is attempted to be mangled (via
mangleNode()
), which leads to a call tounreachable
which aborts. For library usage, such as from lldb, these cases need to be handled without an abort.The improvements to gracefully handle symbolic references are:
normalizeReflectionName
fromstd::string
tollvm::Optional<std::string>
useOpaqueTypeSymbolicReferences
Both of these start in
normalizeReflectionName
.First, the call to
demangleTypeRef()
now setsuseOpaqueTypeSymbolicReferences
to false. Without this,demangleTypeRef()
can return a node of kindOpaqueTypeDescriptorSymbolicReference
, which is guaranteed to fail in this code path when in subsequent call tomangleNode()
.Second, if the result of
demangleTypeRef()
is one of the symbolic reference kinds, then the function exits early with a value ofNone
. Callers ofnormalizeReflectionName()
are now forced to handle such cases, where the mangled name could not be normalized.In
TypeRefBuilder::getFieldTypeInfo()
, ifnormalizeReflectionName()
fails, then the corresponding field is not supported, or in other words, dropped.rdar://77613304
(cherry picked from #37514)