aprantl created this revision.
aprantl added reviewers: jingham, labath.

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


https://reviews.llvm.org/D57273

Files:
  include/lldb/Symbol/Type.h
  source/Core/ValueObjectMemory.cpp
  source/Expression/Materializer.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Symbol/Type.cpp

Index: source/Symbol/Type.cpp
===================================================================
--- source/Symbol/Type.cpp
+++ source/Symbol/Type.cpp
@@ -107,7 +107,7 @@
 }
 
 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,
            EncodingDataType encoding_uid_type, const Declaration &decl,
            const CompilerType &compiler_type,
@@ -115,7 +115,14 @@
     : std::enable_shared_from_this<Type>(), UserID(uid), m_name(name),
       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_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 =
       (compiler_type ? compiler_type_resolve_state : eResolveStateUnresolved);
   m_flags.is_complete_objc_class = false;
@@ -125,7 +132,8 @@
     : std::enable_shared_from_this<Type>(), UserID(0), m_name("<INVALID TYPE>"),
       m_symbol_file(nullptr), m_context(nullptr), m_encoding_type(nullptr),
       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.is_complete_objc_class = false;
 }
@@ -135,7 +143,8 @@
       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_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) {}
 
 const Type &Type::operator=(const Type &rhs) {
@@ -213,7 +222,7 @@
   if (m_name)
     *s << ", name = \"" << m_name << "\"";
 
-  if (m_byte_size != 0)
+  if (m_byte_size_has_value)
     s->Printf(", size = %" PRIu64, m_byte_size);
 
   if (show_context && m_context != nullptr) {
@@ -292,7 +301,7 @@
 
     GetForwardCompilerType().DumpValue(
         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 offset
         show_types, show_summary, verbose, 0);
@@ -305,36 +314,45 @@
   return m_encoding_type;
 }
 
-uint64_t Type::GetByteSize() {
-  if (m_byte_size == 0) {
-    switch (m_encoding_uid_type) {
-    case eEncodingInvalid:
-    case eEncodingIsSyntheticUID:
-      break;
-    case eEncodingIsUID:
-    case eEncodingIsConstUID:
-    case eEncodingIsRestrictUID:
-    case eEncodingIsVolatileUID:
-    case eEncodingIsTypedefUID: {
-      Type *encoding_type = GetEncodingType();
-      if (encoding_type)
-        m_byte_size = encoding_type->GetByteSize();
-      if (m_byte_size == 0)
-        if (llvm::Optional<uint64_t> size =
-                GetLayoutCompilerType().GetByteSize(nullptr))
-          m_byte_size = *size;
+llvm::Optional<uint64_t> Type::GetByteSize() {
+  if (m_byte_size_has_value)
+    return m_byte_size;
+
+  switch (m_encoding_uid_type) {
+  case eEncodingInvalid:
+  case eEncodingIsSyntheticUID:
+    break;
+  case eEncodingIsUID:
+  case eEncodingIsConstUID:
+  case eEncodingIsRestrictUID:
+  case eEncodingIsVolatileUID:
+  case eEncodingIsTypedefUID: {
+    Type *encoding_type = GetEncodingType();
+    if (encoding_type)
+      if (llvm::Optional<uint64_t> size = encoding_type->GetByteSize()) {
+        m_byte_size = *size;
+        m_byte_size_has_value = true;
+      }
+    
+    if (!m_byte_size_has_value)
+      if (llvm::Optional<uint64_t> size =
+          GetLayoutCompilerType().GetByteSize(nullptr)) {
+        m_byte_size = *size;
+        m_byte_size_has_value = true;
+      }
     } break;
 
     // If we are a pointer or reference, then this is just a pointer size;
     case eEncodingIsPointerUID:
     case eEncodingIsLValueReferenceUID:
     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_has_value = true;
+      }
     } break;
-    }
   }
-  return m_byte_size;
+  return {};
 }
 
 uint32_t Type::GetNumChildren(bool omit_empty_base_classes) {
@@ -388,7 +406,7 @@
     return false;
   }
 
-  const uint64_t byte_size = GetByteSize();
+  const uint64_t byte_size = GetByteSize().getValueOr(0);
   if (data.GetByteSize() < byte_size) {
     lldb::DataBufferSP data_sp(new DataBufferHeap(byte_size, '\0'));
     data.SetData(data_sp);
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1699,7 +1699,8 @@
                         location_result.GetScalar().ULongLong();
                     lldb::addr_t byte_size = 1;
                     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(
                         file_addr, byte_size, var_sp.get()));
                   }
@@ -3534,9 +3535,10 @@
             new SymbolFileType(*this, DIERef(type_die_form).GetUID(this)));
 
         if (const_value.Form() && type_sp && type_sp->GetType())
-          location.CopyOpcodeData(const_value.Unsigned(),
-                                  type_sp->GetType()->GetByteSize(),
-                                  die.GetCU()->GetAddressByteSize());
+          location.CopyOpcodeData(
+              const_value.Unsigned(),
+              type_sp->GetType()->GetByteSize().getValueOr(0),
+              die.GetCU()->GetAddressByteSize());
 
         var_sp.reset(new Variable(die.GetID(), name, mangled, type_sp, scope,
                                   symbol_context_scope, scope_ranges, &decl,
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1115,7 +1115,7 @@
               bool is_signed = false;
               enumerator_clang_type.IsIntegerType(is_signed);
               ParseChildEnumerators(cu_sc, clang_type, is_signed,
-                                    type_sp->GetByteSize(), die);
+                                    type_sp->GetByteSize().getValueOr(0), die);
             }
             ClangASTContext::CompleteTagDeclarationDefinition(clang_type);
           } else {
@@ -1739,7 +1739,7 @@
               bit_stride = array_info->bit_stride;
             }
             if (byte_stride == 0 && bit_stride == 0)
-              byte_stride = element_type->GetByteSize();
+              byte_stride = element_type->GetByteSize().getValueOr(0);
             CompilerType array_element_type =
                 element_type->GetForwardCompilerType();
 
@@ -2312,7 +2312,7 @@
         !layout_info.base_offsets.empty() ||
         !layout_info.vbase_offsets.empty()) {
       if (type)
-        layout_info.bit_size = type->GetByteSize() * 8;
+        layout_info.bit_size = type->GetByteSize().getValueOr(0) * 8;
       if (layout_info.bit_size == 0)
         layout_info.bit_size =
             die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
@@ -2396,8 +2396,8 @@
         SymbolContext sc(die.GetLLDBCompileUnit());
         bool is_signed = false;
         clang_type.IsIntegerType(is_signed);
-        ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(),
-                              die);
+        ParseChildEnumerators(sc, clang_type, is_signed,
+                              type->GetByteSize().getValueOr(0), die);
       }
       ClangASTContext::CompleteTagDeclarationDefinition(clang_type);
     }
@@ -2927,7 +2927,7 @@
                   this_field_info.bit_offset = data_bit_offset;
                 } else {
                   if (byte_size == 0)
-                    byte_size = member_type->GetByteSize();
+                    byte_size = member_type->GetByteSize().getValueOr(0);
 
                   ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
                   if (objfile->GetByteOrder() == eByteOrderLittle) {
Index: source/Expression/Materializer.cpp
===================================================================
--- source/Expression/Materializer.cpp
+++ source/Expression/Materializer.cpp
@@ -537,7 +537,8 @@
                 "size of variable %s (%" PRIu64
                 ") is larger than the ValueObject's size (%" PRIu64 ")",
                 m_variable_sp->GetName().AsCString(),
-                m_variable_sp->GetType()->GetByteSize(), data.GetByteSize());
+                m_variable_sp->GetType()->GetByteSize().getValueOr(0),
+                data.GetByteSize());
           }
           return;
         }
Index: source/Core/ValueObjectMemory.cpp
===================================================================
--- source/Core/ValueObjectMemory.cpp
+++ source/Core/ValueObjectMemory.cpp
@@ -136,7 +136,8 @@
 
 uint64_t ValueObjectMemory::GetByteSize() {
   if (m_type_sp)
-    return m_type_sp->GetByteSize();
+    if (llvm::Optional<uint64_t> size = m_type_sp->GetByteSize())
+      return *size;
   if (llvm::Optional<uint64_t> size = m_compiler_type.GetByteSize(nullptr))
     return *size;
   return 0;
Index: include/lldb/Symbol/Type.h
===================================================================
--- include/lldb/Symbol/Type.h
+++ include/lldb/Symbol/Type.h
@@ -95,7 +95,7 @@
   } ResolveState;
 
   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,
        const Declaration &decl, const CompilerType &compiler_qual_type,
        ResolveState compiler_type_resolve_state);
@@ -127,7 +127,7 @@
 
   const ConstString &GetName();
 
-  uint64_t GetByteSize();
+  llvm::Optional<uint64_t> GetByteSize();
 
   uint32_t GetNumChildren(bool omit_empty_base_classes);
 
@@ -217,7 +217,8 @@
   Type *m_encoding_type;
   lldb::user_id_t m_encoding_uid;
   EncodingDataType m_encoding_uid_type;
-  uint64_t m_byte_size;
+  uint64_t m_byte_size : 63;
+  unsigned m_byte_size_has_value : 1;
   Declaration m_decl;
   CompilerType m_compiler_type;
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to