@@ -13634,7 +13634,6 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
1363413634 struct type *type;
1363513635 struct attribute *attr;
1363613636 ULONGEST encoding = 0;
13637- int bits = 0;
1363813637 const char *name;
1363913638
1364013639 attr = dwarf2_attr (die, DW_AT_encoding, cu);
@@ -13644,9 +13643,33 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
1364413643 if (value.has_value ())
1364513644 encoding = *value;
1364613645 }
13646+
1364713647 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
13648+ std::optional<ULONGEST> byte_size;
13649+ if (attr != nullptr)
13650+ byte_size = attr->unsigned_constant ();
13651+ attr = dwarf2_attr (die, DW_AT_bit_size, cu);
13652+ std::optional<ULONGEST> bit_size;
1364813653 if (attr != nullptr)
13649- bits = attr->unsigned_constant ().value_or (0) * TARGET_CHAR_BIT;
13654+ bit_size = attr->unsigned_constant ();
13655+
13656+ attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
13657+ std::optional<ULONGEST> bit_offset;
13658+ if (attr != nullptr)
13659+ bit_offset = attr->unsigned_constant ();
13660+
13661+ int bits = 0;
13662+ if (byte_size.has_value ())
13663+ bits = TARGET_CHAR_BIT * *byte_size;
13664+ else if (bit_size.has_value ())
13665+ bits = align_up (*bit_size, 8);
13666+ else
13667+ {
13668+ /* No size, so arrange for an error type. */
13669+ complaint (_("DW_TAG_base_type has neither bit- nor byte-size"));
13670+ encoding = (ULONGEST) -1;
13671+ }
13672+
1365013673 name = dwarf2_full_name (nullptr, die, cu);
1365113674 if (!name)
1365213675 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
@@ -13792,35 +13815,21 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
1379213815
1379313816 type->set_endianity_is_not_default (not_default);
1379413817
13795- if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_INT)
13818+ /* If both a byte size and bit size were provided, then that means
13819+ that not every bit in the object contributes to the value. */
13820+ if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_INT
13821+ && byte_size.has_value ()
13822+ && bit_size.has_value ())
1379613823 {
13797- attr = dwarf2_attr (die, DW_AT_bit_size, cu);
13798- if (attr != nullptr && attr->form_is_constant ())
13824+ /* DWARF says: If this attribute is omitted a default data bit
13825+ offset of zero is assumed. */
13826+ ULONGEST offset = bit_offset.value_or (0);
13827+
13828+ /* Only use the attributes if they make sense together. */
13829+ if (*bit_size + offset <= 8 * type->length ())
1379913830 {
13800- unsigned real_bit_size = attr->unsigned_constant ().value_or (0);
13801- if (real_bit_size >= 0 && real_bit_size <= 8 * type->length ())
13802- {
13803- attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
13804- /* Only use the attributes if they make sense together. */
13805- std::optional<ULONGEST> bit_offset;
13806- if (attr == nullptr)
13807- bit_offset = 0;
13808- else if (attr->form_is_constant ())
13809- {
13810- bit_offset = attr->unsigned_constant ();
13811- if (bit_offset.has_value ()
13812- && *bit_offset + real_bit_size > 8 * type->length ())
13813- bit_offset.reset ();
13814- }
13815- if (bit_offset.has_value ())
13816- {
13817- TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size
13818- = real_bit_size;
13819- if (attr != nullptr)
13820- TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset
13821- = *bit_offset;
13822- }
13823- }
13831+ TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size = *bit_size;
13832+ TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset = offset;
1382413833 }
1382513834 }
1382613835
0 commit comments