Skip to content

Commit 222a658

Browse files
tromeycuviper
authored andcommitted
Fix handling of variant parts
This fixes a couple of problems noticed while debugging the rust compiler change to use DW_TAG_variant_part: * IterableDIEChildren returned one extra DIE, because it did not preserve the CU in end() * The entire block dealing with DW_TAG_variant_part was erroneously inside the DW_TAG_member case.
1 parent 6bbaf6e commit 222a658

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserRust.cpp

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class IterableDIEChildren
175175

176176
iterator end() const
177177
{
178-
return iterator(DWARFDIE());
178+
return iterator(DWARFDIE(m_die.GetCU(), (DWARFDebugInfoEntry*) nullptr));
179179
}
180180

181181
private:
@@ -611,38 +611,42 @@ DWARFASTParserRust::ParseFields(const DWARFDIE &die, std::vector<size_t> &discri
611611
break;
612612
}
613613
}
614+
}
614615

615-
if (child_die == discriminant_die) {
616-
// This field is the discriminant, so don't push it, but instead
617-
// record this for the caller.
618-
saw_discr = true;
619-
discr_offset = new_field.byte_offset;
620-
discr_byte_size = m_ast.GetBitSize(new_field.compiler_type.GetOpaqueQualType(),
621-
nullptr) / 8;
622-
} else if (child_die.Tag() == DW_TAG_variant_part) {
623-
// New-style enum representation -- nothing useful is in the
624-
// enclosing struct, so we can just recurse here.
625-
return ParseFields(child_die, discriminant_path, is_tuple,
626-
discr_offset, discr_byte_size, saw_discr);
627-
} else {
628-
if (new_field.is_discriminant) {
629-
// Don't check this field name, and don't increment field_index.
630-
// When we see a tuple with fields like
631-
// RUST$ENUM$DISR
632-
// __0
633-
// __1
634-
// etc
635-
// ... it means the tuple is a member type of an enum.
636-
} else if (numeric_names) {
637-
char buf[32];
638-
snprintf (buf, sizeof (buf), "__%u", field_index);
639-
if (!new_field.name || strcmp(new_field.name, buf) != 0)
640-
numeric_names = false;
641-
++field_index;
642-
}
616+
if (child_die == discriminant_die) {
617+
// This field is the discriminant, so don't push it, but instead
618+
// record this for the caller.
619+
saw_discr = true;
620+
discr_offset = new_field.byte_offset;
643621

644-
fields.push_back(new_field);
622+
Type *type = die.ResolveTypeUID(DIERef(new_field.type));
623+
if (type) {
624+
lldb_private::CompilerType ctype = type->GetFullCompilerType();
625+
discr_byte_size = m_ast.GetBitSize(ctype.GetOpaqueQualType(), nullptr) / 8;
645626
}
627+
} else if (child_die.Tag() == DW_TAG_variant_part) {
628+
// New-style enum representation -- nothing useful is in the
629+
// enclosing struct, so we can just recurse here.
630+
return ParseFields(child_die, discriminant_path, is_tuple,
631+
discr_offset, discr_byte_size, saw_discr);
632+
} else {
633+
if (new_field.is_discriminant) {
634+
// Don't check this field name, and don't increment field_index.
635+
// When we see a tuple with fields like
636+
// RUST$ENUM$DISR
637+
// __0
638+
// __1
639+
// etc
640+
// ... it means the tuple is a member type of an enum.
641+
} else if (numeric_names) {
642+
char buf[32];
643+
snprintf (buf, sizeof (buf), "__%u", field_index);
644+
if (!new_field.name || strcmp(new_field.name, buf) != 0)
645+
numeric_names = false;
646+
++field_index;
647+
}
648+
649+
fields.push_back(new_field);
646650
}
647651
}
648652

0 commit comments

Comments
 (0)