@@ -1617,3 +1617,93 @@ TEST_F(DWARFASTParserClangTests, TestObjectPointer_IndexEncoding) {
16171617 EXPECT_EQ (param_die, ast_parser.GetObjectParameter (sub2, context_die));
16181618 }
16191619}
1620+
1621+ TEST_F (DWARFASTParserClangTests, TestTypeBitSize) {
1622+ // Tests that we correctly parse DW_AT_bit_size of a DW_AT_base_type.
1623+
1624+ const char *yamldata = R"(
1625+ --- !ELF
1626+ FileHeader:
1627+ Class: ELFCLASS64
1628+ Data: ELFDATA2LSB
1629+ Type: ET_EXEC
1630+ Machine: EM_AARCH64
1631+ DWARF:
1632+ debug_str:
1633+ - _BitInt(2)
1634+ debug_abbrev:
1635+ - ID: 0
1636+ Table:
1637+ - Code: 0x1
1638+ Tag: DW_TAG_compile_unit
1639+ Children: DW_CHILDREN_yes
1640+ Attributes:
1641+ - Attribute: DW_AT_language
1642+ Form: DW_FORM_data2
1643+ - Code: 0x2
1644+ Tag: DW_TAG_base_type
1645+ Children: DW_CHILDREN_no
1646+ Attributes:
1647+ - Attribute: DW_AT_name
1648+ Form: DW_FORM_strp
1649+ - Attribute: DW_AT_encoding
1650+ Form: DW_FORM_data1
1651+ - Attribute: DW_AT_byte_size
1652+ Form: DW_FORM_data1
1653+ - Attribute: DW_AT_bit_size
1654+ Form: DW_FORM_data1
1655+
1656+ debug_info:
1657+ - Version: 5
1658+ UnitType: DW_UT_compile
1659+ AddrSize: 8
1660+ Entries:
1661+
1662+ # DW_TAG_compile_unit
1663+ # DW_AT_language [DW_FORM_data2] (DW_LANG_C_plus_plus)
1664+
1665+ - AbbrCode: 0x1
1666+ Values:
1667+ - Value: 0x04
1668+
1669+ # DW_TAG_base_type
1670+ # DW_AT_name [DW_FORM_strp] ('_BitInt(2)')
1671+
1672+ - AbbrCode: 0x2
1673+ Values:
1674+ - Value: 0x0
1675+ - Value: 0x3e
1676+ - Value: 0x01
1677+ - Value: 0x02
1678+ ...
1679+ )" ;
1680+
1681+ YAMLModuleTester t (yamldata);
1682+
1683+ DWARFUnit *unit = t.GetDwarfUnit ();
1684+ ASSERT_NE (unit, nullptr );
1685+ const DWARFDebugInfoEntry *cu_entry = unit->DIE ().GetDIE ();
1686+ ASSERT_EQ (cu_entry->Tag (), DW_TAG_compile_unit);
1687+ ASSERT_EQ (unit->GetDWARFLanguageType (), DW_LANG_C_plus_plus);
1688+ DWARFDIE cu_die (unit, cu_entry);
1689+
1690+ auto holder = std::make_unique<clang_utils::TypeSystemClangHolder>(" ast" );
1691+ auto &ast_ctx = *holder->GetAST ();
1692+ DWARFASTParserClangStub ast_parser (ast_ctx);
1693+
1694+ auto type_die = cu_die.GetFirstChild ();
1695+ ASSERT_TRUE (type_die.IsValid ());
1696+ ASSERT_EQ (type_die.Tag (), DW_TAG_base_type);
1697+
1698+ ParsedDWARFTypeAttributes attrs (type_die);
1699+ EXPECT_EQ (attrs.byte_size .value_or (0 ), 1U );
1700+ EXPECT_EQ (attrs.data_bit_size .value_or (0 ), 2U );
1701+
1702+ SymbolContext sc;
1703+ auto type_sp =
1704+ ast_parser.ParseTypeFromDWARF (sc, type_die, /* type_is_new_ptr=*/ nullptr );
1705+ ASSERT_NE (type_sp, nullptr );
1706+
1707+ EXPECT_EQ (llvm::expectedToOptional (type_sp->GetByteSize (nullptr )).value_or (0 ),
1708+ 1U );
1709+ }
0 commit comments