Skip to content

Commit c638c61

Browse files
tromeyartemmukhin
authored andcommitted
Do not crash when enum discriminant is not recognized
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
1 parent 71a2a43 commit c638c61

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lldb/source/Plugins/LanguageRuntime/Rust/RustLanguageRuntime.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ bool RustLanguageRuntime::GetDynamicTypeAndAddress(
9898
}
9999

100100
CompilerType variant_type = ast->FindEnumVariant(type, discriminant);
101+
if (!variant_type) {
102+
return false;
103+
}
101104
class_type_or_name = TypeAndOrName(variant_type);
102105
// The address doesn't change.
103106
dynamic_address.SetLoadAddress(original_ptr, exe_ctx.GetTargetPtr());

lldb/source/Symbol/RustASTContext.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,10 @@ class RustEnum : public RustAggregateBase {
625625
int idx = m_default;
626626
if (iter != m_discriminants.end()) {
627627
idx = iter->second;
628+
} else if (idx == -1) {
629+
// If the DWARF was bad somehow, we could end up not finding the
630+
// discriminant and not having a default.
631+
return CompilerType();
628632
}
629633
return FieldAt(idx)->m_type;
630634
}

0 commit comments

Comments
 (0)