@@ -1651,3 +1651,93 @@ TEST_F(DWARFASTParserClangTests, TestObjectPointer_IndexEncoding) {
16511651 EXPECT_EQ (param_die, ast_parser.GetObjectParameter (sub2, context_die));
16521652 }
16531653}
1654+
1655+ TEST_F (DWARFASTParserClangTests, TestTypeBitSize) {
1656+ // Tests that we correctly parse DW_AT_bit_size of a DW_AT_base_type.
1657+
1658+ const char *yamldata = R"(
1659+ --- !ELF
1660+ FileHeader:
1661+ Class: ELFCLASS64
1662+ Data: ELFDATA2LSB
1663+ Type: ET_EXEC
1664+ Machine: EM_AARCH64
1665+ DWARF:
1666+ debug_str:
1667+ - _BitInt(2)
1668+ debug_abbrev:
1669+ - ID: 0
1670+ Table:
1671+ - Code: 0x1
1672+ Tag: DW_TAG_compile_unit
1673+ Children: DW_CHILDREN_yes
1674+ Attributes:
1675+ - Attribute: DW_AT_language
1676+ Form: DW_FORM_data2
1677+ - Code: 0x2
1678+ Tag: DW_TAG_base_type
1679+ Children: DW_CHILDREN_no
1680+ Attributes:
1681+ - Attribute: DW_AT_name
1682+ Form: DW_FORM_strp
1683+ - Attribute: DW_AT_encoding
1684+ Form: DW_FORM_data1
1685+ - Attribute: DW_AT_byte_size
1686+ Form: DW_FORM_data1
1687+ - Attribute: DW_AT_bit_size
1688+ Form: DW_FORM_data1
1689+
1690+ debug_info:
1691+ - Version: 5
1692+ UnitType: DW_UT_compile
1693+ AddrSize: 8
1694+ Entries:
1695+
1696+ # DW_TAG_compile_unit
1697+ # DW_AT_language [DW_FORM_data2] (DW_LANG_C_plus_plus)
1698+
1699+ - AbbrCode: 0x1
1700+ Values:
1701+ - Value: 0x04
1702+
1703+ # DW_TAG_base_type
1704+ # DW_AT_name [DW_FORM_strp] ('_BitInt(2)')
1705+
1706+ - AbbrCode: 0x2
1707+ Values:
1708+ - Value: 0x0
1709+ - Value: 0x05
1710+ - Value: 0x01
1711+ - Value: 0x02
1712+ ...
1713+ )" ;
1714+
1715+ YAMLModuleTester t (yamldata);
1716+
1717+ DWARFUnit *unit = t.GetDwarfUnit ();
1718+ ASSERT_NE (unit, nullptr );
1719+ const DWARFDebugInfoEntry *cu_entry = unit->DIE ().GetDIE ();
1720+ ASSERT_EQ (cu_entry->Tag (), DW_TAG_compile_unit);
1721+ ASSERT_EQ (unit->GetDWARFLanguageType (), DW_LANG_C_plus_plus);
1722+ DWARFDIE cu_die (unit, cu_entry);
1723+
1724+ auto holder = std::make_unique<clang_utils::TypeSystemClangHolder>(" ast" );
1725+ auto &ast_ctx = *holder->GetAST ();
1726+ DWARFASTParserClangStub ast_parser (ast_ctx);
1727+
1728+ auto type_die = cu_die.GetFirstChild ();
1729+ ASSERT_TRUE (type_die.IsValid ());
1730+ ASSERT_EQ (type_die.Tag (), DW_TAG_base_type);
1731+
1732+ ParsedDWARFTypeAttributes attrs (type_die);
1733+ EXPECT_EQ (attrs.byte_size .value_or (0 ), 1U );
1734+ EXPECT_EQ (attrs.data_bit_size .value_or (0 ), 2U );
1735+
1736+ SymbolContext sc;
1737+ auto type_sp =
1738+ ast_parser.ParseTypeFromDWARF (sc, type_die, /* type_is_new_ptr=*/ nullptr );
1739+ ASSERT_NE (type_sp, nullptr );
1740+
1741+ EXPECT_EQ (llvm::expectedToOptional (type_sp->GetByteSize (nullptr )).value_or (0 ),
1742+ 1U );
1743+ }
0 commit comments