Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

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 committed Aug 28, 2018
1 parent 7f69ffc commit 3be47d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/Plugins/LanguageRuntime/Rust/RustLanguageRuntime.cpp
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 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 3be47d2

Please sign in to comment.