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 #16
  • Loading branch information
tromey authored and cuviper committed Mar 18, 2019
1 parent f65a0c0 commit 5acac0d
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 5acac0d

Please sign in to comment.