Skip to content

Commit

Permalink
Do not crash when enum discriminant is not recognized
Browse files Browse the repository at this point in the history
Sometimes the DWARF can omit information about a discriminant, for
example when an Option shares a discriminant slot with an enum that it
wraps.  In this case, lldb could crash, because the discriminant was
not found and because there was no default variant.

No test case because this relies on a compiler bug that will soon be
fixed.

Fixes llvm#16

Signed-off-by: Gabor Greif <gabor@dfinity.org>
  • Loading branch information
tromey authored and ggreif committed Oct 9, 2020
1 parent c5b4cb6 commit 27401d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ bool RustLanguageRuntime::GetDynamicTypeAndAddress(
}

CompilerType variant_type = ast->FindEnumVariant(type, discriminant);
if (!variant_type) {
return false;
}
class_type_or_name = TypeAndOrName(variant_type);
// The address doesn't change.
dynamic_address.SetLoadAddress(original_ptr, exe_ctx.GetTargetPtr());
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Symbol/RustASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ class RustEnum : public RustAggregateBase {
int idx = m_default;
if (iter != m_discriminants.end()) {
idx = iter->second;
} else if (idx == -1) {
// If the DWARF was bad somehow, we could end up not finding the
// discriminant and not having a default.
return CompilerType();
}
return FieldAt(idx)->m_type;
}
Expand Down

0 comments on commit 27401d6

Please sign in to comment.