Make Type::GetByteSize optional (NFC)

This is a continuation of my quest to make the size 0 a supported value.

This reapplies r352394 with additional PDB parser fixes prepared by
Pavel Labath!

Differential Revision: https://reviews.llvm.org/D57273

llvm-svn: 352521
This commit is contained in:
Adrian Prantl 2019-01-29 17:52:34 +00:00
parent cd6b240303
commit d13777aa18
7 changed files with 92 additions and 68 deletions

View File

@ -95,7 +95,7 @@ public:
} ResolveState; } ResolveState;
Type(lldb::user_id_t uid, SymbolFile *symbol_file, const ConstString &name, Type(lldb::user_id_t uid, SymbolFile *symbol_file, const ConstString &name,
uint64_t byte_size, SymbolContextScope *context, llvm::Optional<uint64_t> byte_size, SymbolContextScope *context,
lldb::user_id_t encoding_uid, EncodingDataType encoding_uid_type, lldb::user_id_t encoding_uid, EncodingDataType encoding_uid_type,
const Declaration &decl, const CompilerType &compiler_qual_type, const Declaration &decl, const CompilerType &compiler_qual_type,
ResolveState compiler_type_resolve_state); ResolveState compiler_type_resolve_state);
@ -127,7 +127,7 @@ public:
const ConstString &GetName(); const ConstString &GetName();
uint64_t GetByteSize(); llvm::Optional<uint64_t> GetByteSize();
uint32_t GetNumChildren(bool omit_empty_base_classes); uint32_t GetNumChildren(bool omit_empty_base_classes);
@ -217,7 +217,8 @@ protected:
Type *m_encoding_type; Type *m_encoding_type;
lldb::user_id_t m_encoding_uid; lldb::user_id_t m_encoding_uid;
EncodingDataType m_encoding_uid_type; EncodingDataType m_encoding_uid_type;
uint64_t m_byte_size; uint64_t m_byte_size : 63;
uint64_t m_byte_size_has_value : 1;
Declaration m_decl; Declaration m_decl;
CompilerType m_compiler_type; CompilerType m_compiler_type;

View File

@ -136,10 +136,8 @@ size_t ValueObjectMemory::CalculateNumChildren(uint32_t max) {
uint64_t ValueObjectMemory::GetByteSize() { uint64_t ValueObjectMemory::GetByteSize() {
if (m_type_sp) if (m_type_sp)
return m_type_sp->GetByteSize(); return m_type_sp->GetByteSize().getValueOr(0);
if (llvm::Optional<uint64_t> size = m_compiler_type.GetByteSize(nullptr)) return m_compiler_type.GetByteSize(nullptr).getValueOr(0);
return *size;
return 0;
} }
lldb::ValueType ValueObjectMemory::GetValueType() const { lldb::ValueType ValueObjectMemory::GetValueType() const {

View File

@ -537,7 +537,8 @@ public:
"size of variable %s (%" PRIu64 "size of variable %s (%" PRIu64
") is larger than the ValueObject's size (%" PRIu64 ")", ") is larger than the ValueObject's size (%" PRIu64 ")",
m_variable_sp->GetName().AsCString(), m_variable_sp->GetName().AsCString(),
m_variable_sp->GetType()->GetByteSize(), data.GetByteSize()); m_variable_sp->GetType()->GetByteSize().getValueOr(0),
data.GetByteSize());
} }
return; return;
} }

View File

@ -264,7 +264,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
const char *mangled_name_cstr = NULL; const char *mangled_name_cstr = NULL;
ConstString type_name_const_str; ConstString type_name_const_str;
Type::ResolveState resolve_state = Type::eResolveStateUnresolved; Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
uint64_t byte_size = 0; llvm::Optional<uint64_t> byte_size;
Declaration decl; Declaration decl;
Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
@ -386,7 +386,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
case DW_TAG_base_type: case DW_TAG_base_type:
resolve_state = Type::eResolveStateFull; resolve_state = Type::eResolveStateFull;
clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize( clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize(
type_name_cstr, encoding, byte_size * 8); type_name_cstr, encoding, byte_size.getValueOr(0) * 8);
break; break;
case DW_TAG_pointer_type: case DW_TAG_pointer_type:
@ -535,7 +535,6 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
case DW_TAG_class_type: { case DW_TAG_class_type: {
// Set a bit that lets us know that we are currently parsing this // Set a bit that lets us know that we are currently parsing this
dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED;
bool byte_size_valid = false;
LanguageType class_language = eLanguageTypeUnknown; LanguageType class_language = eLanguageTypeUnknown;
bool is_complete_objc_class = false; bool is_complete_objc_class = false;
@ -569,7 +568,6 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
case DW_AT_byte_size: case DW_AT_byte_size:
byte_size = form_value.Unsigned(); byte_size = form_value.Unsigned();
byte_size_valid = true;
break; break;
case DW_AT_accessibility: case DW_AT_accessibility:
@ -629,7 +627,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
if (dwarf->GetUniqueDWARFASTTypeMap().Find( if (dwarf->GetUniqueDWARFASTTypeMap().Find(
unique_typename, die, unique_decl, unique_typename, die, unique_decl,
byte_size_valid ? byte_size : -1, *unique_ast_entry_ap)) { byte_size ? *byte_size : -1, *unique_ast_entry_ap)) {
type_sp = unique_ast_entry_ap->m_type_sp; type_sp = unique_ast_entry_ap->m_type_sp;
if (type_sp) { if (type_sp) {
dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
@ -654,7 +652,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
default_accessibility = eAccessPrivate; default_accessibility = eAccessPrivate;
} }
if (byte_size_valid && byte_size == 0 && type_name_cstr && if (byte_size && *byte_size == 0 && type_name_cstr &&
!die.HasChildren() && !die.HasChildren() &&
sc.comp_unit->GetLanguage() == eLanguageTypeObjC) { sc.comp_unit->GetLanguage() == eLanguageTypeObjC) {
// Work around an issue with clang at the moment where forward // Work around an issue with clang at the moment where forward
@ -857,7 +855,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
unique_ast_entry_ap->m_type_sp = type_sp; unique_ast_entry_ap->m_type_sp = type_sp;
unique_ast_entry_ap->m_die = die; unique_ast_entry_ap->m_die = die;
unique_ast_entry_ap->m_declaration = unique_decl; unique_ast_entry_ap->m_declaration = unique_decl;
unique_ast_entry_ap->m_byte_size = byte_size; unique_ast_entry_ap->m_byte_size = byte_size.getValueOr(0);
dwarf->GetUniqueDWARFASTTypeMap().Insert(unique_typename, dwarf->GetUniqueDWARFASTTypeMap().Insert(unique_typename,
*unique_ast_entry_ap); *unique_ast_entry_ap);
@ -1084,10 +1082,10 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
} }
if (!enumerator_clang_type) { if (!enumerator_clang_type) {
if (byte_size > 0) { if (byte_size) {
enumerator_clang_type = enumerator_clang_type =
m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize( m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize(
NULL, DW_ATE_signed, byte_size * 8); NULL, DW_ATE_signed, *byte_size * 8);
} else { } else {
enumerator_clang_type = m_ast.GetBasicType(eBasicTypeInt); enumerator_clang_type = m_ast.GetBasicType(eBasicTypeInt);
} }
@ -1115,7 +1113,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
bool is_signed = false; bool is_signed = false;
enumerator_clang_type.IsIntegerType(is_signed); enumerator_clang_type.IsIntegerType(is_signed);
ParseChildEnumerators(cu_sc, clang_type, is_signed, ParseChildEnumerators(cu_sc, clang_type, is_signed,
type_sp->GetByteSize(), die); type_sp->GetByteSize().getValueOr(0), die);
} }
ClangASTContext::CompleteTagDeclarationDefinition(clang_type); ClangASTContext::CompleteTagDeclarationDefinition(clang_type);
} else { } else {
@ -1653,9 +1651,10 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
} }
} }
} }
type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, 0, NULL, type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str,
LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, llvm::None, NULL, LLDB_INVALID_UID,
clang_type, Type::eResolveStateFull)); Type::eEncodingIsUID, &decl, clang_type,
Type::eResolveStateFull));
assert(type_sp.get()); assert(type_sp.get());
} break; } break;
@ -1739,7 +1738,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
bit_stride = array_info->bit_stride; bit_stride = array_info->bit_stride;
} }
if (byte_stride == 0 && bit_stride == 0) if (byte_stride == 0 && bit_stride == 0)
byte_stride = element_type->GetByteSize(); byte_stride = element_type->GetByteSize().getValueOr(0);
CompilerType array_element_type = CompilerType array_element_type =
element_type->GetForwardCompilerType(); element_type->GetForwardCompilerType();
@ -2312,7 +2311,7 @@ bool DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die,
!layout_info.base_offsets.empty() || !layout_info.base_offsets.empty() ||
!layout_info.vbase_offsets.empty()) { !layout_info.vbase_offsets.empty()) {
if (type) if (type)
layout_info.bit_size = type->GetByteSize() * 8; layout_info.bit_size = type->GetByteSize().getValueOr(0) * 8;
if (layout_info.bit_size == 0) if (layout_info.bit_size == 0)
layout_info.bit_size = layout_info.bit_size =
die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8; die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
@ -2396,8 +2395,8 @@ bool DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die,
SymbolContext sc(die.GetLLDBCompileUnit()); SymbolContext sc(die.GetLLDBCompileUnit());
bool is_signed = false; bool is_signed = false;
clang_type.IsIntegerType(is_signed); clang_type.IsIntegerType(is_signed);
ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), ParseChildEnumerators(sc, clang_type, is_signed,
die); type->GetByteSize().getValueOr(0), die);
} }
ClangASTContext::CompleteTagDeclarationDefinition(clang_type); ClangASTContext::CompleteTagDeclarationDefinition(clang_type);
} }
@ -2721,7 +2720,7 @@ bool DWARFASTParserClang::ParseChildMembers(
AccessType accessibility = eAccessNone; AccessType accessibility = eAccessNone;
uint32_t member_byte_offset = uint32_t member_byte_offset =
(parent_die.Tag() == DW_TAG_union_type) ? 0 : UINT32_MAX; (parent_die.Tag() == DW_TAG_union_type) ? 0 : UINT32_MAX;
size_t byte_size = 0; llvm::Optional<uint64_t> byte_size;
int64_t bit_offset = 0; int64_t bit_offset = 0;
uint64_t data_bit_offset = UINT64_MAX; uint64_t data_bit_offset = UINT64_MAX;
size_t bit_size = 0; size_t bit_size = 0;
@ -2864,7 +2863,7 @@ bool DWARFASTParserClang::ParseChildMembers(
// with a crash if we try to use this type in an expression when clang // with a crash if we try to use this type in an expression when clang
// becomes unhappy with its recycled debug info. // becomes unhappy with its recycled debug info.
if (byte_size == 0 && bit_offset < 0) { if (byte_size.getValueOr(0) == 0 && bit_offset < 0) {
bit_size = 0; bit_size = 0;
bit_offset = 0; bit_offset = 0;
} }
@ -2926,12 +2925,12 @@ bool DWARFASTParserClang::ParseChildMembers(
if (data_bit_offset != UINT64_MAX) { if (data_bit_offset != UINT64_MAX) {
this_field_info.bit_offset = data_bit_offset; this_field_info.bit_offset = data_bit_offset;
} else { } else {
if (byte_size == 0) if (!byte_size)
byte_size = member_type->GetByteSize(); byte_size = member_type->GetByteSize();
ObjectFile *objfile = die.GetDWARF()->GetObjectFile(); ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
if (objfile->GetByteOrder() == eByteOrderLittle) { if (objfile->GetByteOrder() == eByteOrderLittle) {
this_field_info.bit_offset += byte_size * 8; this_field_info.bit_offset += byte_size.getValueOr(0) * 8;
this_field_info.bit_offset -= (bit_offset + bit_size); this_field_info.bit_offset -= (bit_offset + bit_size);
} else { } else {
this_field_info.bit_offset += bit_offset; this_field_info.bit_offset += bit_offset;

View File

@ -1699,7 +1699,8 @@ SymbolFileDWARF::GlobalVariableMap &SymbolFileDWARF::GetGlobalAranges() {
location_result.GetScalar().ULongLong(); location_result.GetScalar().ULongLong();
lldb::addr_t byte_size = 1; lldb::addr_t byte_size = 1;
if (var_sp->GetType()) if (var_sp->GetType())
byte_size = var_sp->GetType()->GetByteSize(); byte_size =
var_sp->GetType()->GetByteSize().getValueOr(0);
m_global_aranges_ap->Append(GlobalVariableMap::Entry( m_global_aranges_ap->Append(GlobalVariableMap::Entry(
file_addr, byte_size, var_sp.get())); file_addr, byte_size, var_sp.get()));
} }
@ -3534,9 +3535,10 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
new SymbolFileType(*this, DIERef(type_die_form).GetUID(this))); new SymbolFileType(*this, DIERef(type_die_form).GetUID(this)));
if (const_value.Form() && type_sp && type_sp->GetType()) if (const_value.Form() && type_sp && type_sp->GetType())
location.CopyOpcodeData(const_value.Unsigned(), location.CopyOpcodeData(
type_sp->GetType()->GetByteSize(), const_value.Unsigned(),
die.GetCU()->GetAddressByteSize()); type_sp->GetType()->GetByteSize().getValueOr(0),
die.GetCU()->GetAddressByteSize());
var_sp.reset(new Variable(die.GetID(), name, mangled, type_sp, scope, var_sp.reset(new Variable(die.GetID(), name, mangled, type_sp, scope,
symbol_context_scope, scope_ranges, &decl, symbol_context_scope, scope_ranges, &decl,

View File

@ -567,9 +567,12 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
ast_typedef = ast_typedef.AddVolatileModifier(); ast_typedef = ast_typedef.AddVolatileModifier();
GetDeclarationForSymbol(type, decl); GetDeclarationForSymbol(type, decl);
llvm::Optional<uint64_t> size;
if (type_def->getLength())
size = type_def->getLength();
return std::make_shared<lldb_private::Type>( return std::make_shared<lldb_private::Type>(
type_def->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), type_def->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name),
type_def->getLength(), nullptr, target_type->GetID(), size, nullptr, target_type->GetID(),
lldb_private::Type::eEncodingIsTypedefUID, decl, ast_typedef, lldb_private::Type::eEncodingIsTypedefUID, decl, ast_typedef,
lldb_private::Type::eResolveStateFull); lldb_private::Type::eResolveStateFull);
} break; } break;
@ -636,9 +639,10 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
GetDeclarationForSymbol(type, decl); GetDeclarationForSymbol(type, decl);
return std::make_shared<lldb_private::Type>( return std::make_shared<lldb_private::Type>(
type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), 0, type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name),
nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, llvm::None, nullptr, LLDB_INVALID_UID,
func_sig_ast_type, lldb_private::Type::eResolveStateFull); lldb_private::Type::eEncodingIsUID, decl, func_sig_ast_type,
lldb_private::Type::eResolveStateFull);
} break; } break;
case PDB_SymType::ArrayType: { case PDB_SymType::ArrayType: {
auto array_type = llvm::dyn_cast<PDBSymbolTypeArray>(&type); auto array_type = llvm::dyn_cast<PDBSymbolTypeArray>(&type);
@ -681,10 +685,10 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
if (builtin_kind == PDB_BuiltinType::None) if (builtin_kind == PDB_BuiltinType::None)
return nullptr; return nullptr;
uint64_t bytes = builtin_type->getLength(); llvm::Optional<uint64_t> bytes = builtin_type->getLength();
Encoding encoding = TranslateBuiltinEncoding(builtin_kind); Encoding encoding = TranslateBuiltinEncoding(builtin_kind);
CompilerType builtin_ast_type = GetBuiltinTypeForPDBEncodingAndBitSize( CompilerType builtin_ast_type = GetBuiltinTypeForPDBEncodingAndBitSize(
m_ast, *builtin_type, encoding, bytes * 8); m_ast, *builtin_type, encoding, bytes.getValueOr(0) * 8);
if (builtin_type->isConstType()) if (builtin_type->isConstType())
builtin_ast_type = builtin_ast_type.AddConstModifier(); builtin_ast_type = builtin_ast_type.AddConstModifier();

View File

@ -107,7 +107,7 @@ Type *SymbolFileType::GetType() {
} }
Type::Type(lldb::user_id_t uid, SymbolFile *symbol_file, Type::Type(lldb::user_id_t uid, SymbolFile *symbol_file,
const ConstString &name, uint64_t byte_size, const ConstString &name, llvm::Optional<uint64_t> byte_size,
SymbolContextScope *context, user_id_t encoding_uid, SymbolContextScope *context, user_id_t encoding_uid,
EncodingDataType encoding_uid_type, const Declaration &decl, EncodingDataType encoding_uid_type, const Declaration &decl,
const CompilerType &compiler_type, const CompilerType &compiler_type,
@ -115,7 +115,14 @@ Type::Type(lldb::user_id_t uid, SymbolFile *symbol_file,
: std::enable_shared_from_this<Type>(), UserID(uid), m_name(name), : std::enable_shared_from_this<Type>(), UserID(uid), m_name(name),
m_symbol_file(symbol_file), m_context(context), m_encoding_type(nullptr), m_symbol_file(symbol_file), m_context(context), m_encoding_type(nullptr),
m_encoding_uid(encoding_uid), m_encoding_uid_type(encoding_uid_type), m_encoding_uid(encoding_uid), m_encoding_uid_type(encoding_uid_type),
m_byte_size(byte_size), m_decl(decl), m_compiler_type(compiler_type) { m_decl(decl), m_compiler_type(compiler_type) {
if (byte_size) {
m_byte_size = *byte_size;
m_byte_size_has_value = true;
} else {
m_byte_size = 0;
m_byte_size_has_value = false;
}
m_flags.compiler_type_resolve_state = m_flags.compiler_type_resolve_state =
(compiler_type ? compiler_type_resolve_state : eResolveStateUnresolved); (compiler_type ? compiler_type_resolve_state : eResolveStateUnresolved);
m_flags.is_complete_objc_class = false; m_flags.is_complete_objc_class = false;
@ -125,7 +132,8 @@ Type::Type()
: std::enable_shared_from_this<Type>(), UserID(0), m_name("<INVALID TYPE>"), : std::enable_shared_from_this<Type>(), UserID(0), m_name("<INVALID TYPE>"),
m_symbol_file(nullptr), m_context(nullptr), m_encoding_type(nullptr), m_symbol_file(nullptr), m_context(nullptr), m_encoding_type(nullptr),
m_encoding_uid(LLDB_INVALID_UID), m_encoding_uid_type(eEncodingInvalid), m_encoding_uid(LLDB_INVALID_UID), m_encoding_uid_type(eEncodingInvalid),
m_byte_size(0), m_decl(), m_compiler_type() { m_byte_size(0), m_byte_size_has_value(false), m_decl(),
m_compiler_type() {
m_flags.compiler_type_resolve_state = eResolveStateUnresolved; m_flags.compiler_type_resolve_state = eResolveStateUnresolved;
m_flags.is_complete_objc_class = false; m_flags.is_complete_objc_class = false;
} }
@ -135,7 +143,8 @@ Type::Type(const Type &rhs)
m_symbol_file(rhs.m_symbol_file), m_context(rhs.m_context), m_symbol_file(rhs.m_symbol_file), m_context(rhs.m_context),
m_encoding_type(rhs.m_encoding_type), m_encoding_uid(rhs.m_encoding_uid), m_encoding_type(rhs.m_encoding_type), m_encoding_uid(rhs.m_encoding_uid),
m_encoding_uid_type(rhs.m_encoding_uid_type), m_encoding_uid_type(rhs.m_encoding_uid_type),
m_byte_size(rhs.m_byte_size), m_decl(rhs.m_decl), m_byte_size(rhs.m_byte_size),
m_byte_size_has_value(rhs.m_byte_size_has_value), m_decl(rhs.m_decl),
m_compiler_type(rhs.m_compiler_type), m_flags(rhs.m_flags) {} m_compiler_type(rhs.m_compiler_type), m_flags(rhs.m_flags) {}
void Type::GetDescription(Stream *s, lldb::DescriptionLevel level, void Type::GetDescription(Stream *s, lldb::DescriptionLevel level,
@ -207,7 +216,7 @@ void Type::Dump(Stream *s, bool show_context) {
if (m_name) if (m_name)
*s << ", name = \"" << m_name << "\""; *s << ", name = \"" << m_name << "\"";
if (m_byte_size != 0) if (m_byte_size_has_value)
s->Printf(", size = %" PRIu64, m_byte_size); s->Printf(", size = %" PRIu64, m_byte_size);
if (show_context && m_context != nullptr) { if (show_context && m_context != nullptr) {
@ -286,7 +295,7 @@ void Type::DumpValue(ExecutionContext *exe_ctx, Stream *s,
GetForwardCompilerType().DumpValue( GetForwardCompilerType().DumpValue(
exe_ctx, s, format == lldb::eFormatDefault ? GetFormat() : format, data, exe_ctx, s, format == lldb::eFormatDefault ? GetFormat() : format, data,
data_byte_offset, GetByteSize(), data_byte_offset, GetByteSize().getValueOr(0),
0, // Bitfield bit size 0, // Bitfield bit size
0, // Bitfield bit offset 0, // Bitfield bit offset
show_types, show_summary, verbose, 0); show_types, show_summary, verbose, 0);
@ -299,36 +308,46 @@ Type *Type::GetEncodingType() {
return m_encoding_type; return m_encoding_type;
} }
uint64_t Type::GetByteSize() { llvm::Optional<uint64_t> Type::GetByteSize() {
if (m_byte_size == 0) { if (m_byte_size_has_value)
switch (m_encoding_uid_type) { return m_byte_size;
case eEncodingInvalid:
case eEncodingIsSyntheticUID: switch (m_encoding_uid_type) {
break; case eEncodingInvalid:
case eEncodingIsUID: case eEncodingIsSyntheticUID:
case eEncodingIsConstUID: break;
case eEncodingIsRestrictUID: case eEncodingIsUID:
case eEncodingIsVolatileUID: case eEncodingIsConstUID:
case eEncodingIsTypedefUID: { case eEncodingIsRestrictUID:
Type *encoding_type = GetEncodingType(); case eEncodingIsVolatileUID:
if (encoding_type) case eEncodingIsTypedefUID: {
m_byte_size = encoding_type->GetByteSize(); Type *encoding_type = GetEncodingType();
if (m_byte_size == 0) if (encoding_type)
if (llvm::Optional<uint64_t> size = if (llvm::Optional<uint64_t> size = encoding_type->GetByteSize()) {
GetLayoutCompilerType().GetByteSize(nullptr)) m_byte_size = *size;
m_byte_size = *size; m_byte_size_has_value = true;
} break; return m_byte_size;
}
if (llvm::Optional<uint64_t> size =
GetLayoutCompilerType().GetByteSize(nullptr)) {
m_byte_size = *size;
m_byte_size_has_value = true;
return m_byte_size;
}
} break;
// If we are a pointer or reference, then this is just a pointer size; // If we are a pointer or reference, then this is just a pointer size;
case eEncodingIsPointerUID: case eEncodingIsPointerUID:
case eEncodingIsLValueReferenceUID: case eEncodingIsLValueReferenceUID:
case eEncodingIsRValueReferenceUID: { case eEncodingIsRValueReferenceUID: {
if (ArchSpec arch = m_symbol_file->GetObjectFile()->GetArchitecture()) if (ArchSpec arch = m_symbol_file->GetObjectFile()->GetArchitecture()) {
m_byte_size = arch.GetAddressByteSize(); m_byte_size = arch.GetAddressByteSize();
m_byte_size_has_value = true;
}
} break; } break;
}
} }
return m_byte_size; return {};
} }
uint32_t Type::GetNumChildren(bool omit_empty_base_classes) { uint32_t Type::GetNumChildren(bool omit_empty_base_classes) {
@ -382,7 +401,7 @@ bool Type::ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t addr,
return false; return false;
} }
const uint64_t byte_size = GetByteSize(); const uint64_t byte_size = GetByteSize().getValueOr(0);
if (data.GetByteSize() < byte_size) { if (data.GetByteSize() < byte_size) {
lldb::DataBufferSP data_sp(new DataBufferHeap(byte_size, '\0')); lldb::DataBufferSP data_sp(new DataBufferHeap(byte_size, '\0'));
data.SetData(data_sp); data.SetData(data_sp);