@@ -1741,3 +1741,220 @@ TEST_F(DWARFASTParserClangTests, TestTypeBitSize) {
17411741 EXPECT_EQ (llvm::expectedToOptional (type_sp->GetByteSize (nullptr )).value_or (0 ),
17421742 1U );
17431743}
1744+
1745+ TEST_F (DWARFASTParserClangTests, TestBitIntParsing) {
1746+ // Tests that we correctly parse the DW_AT_base_type for a _BitInt.
1747+ // Older versions of Clang only emit the `_BitInt` string into the
1748+ // DW_AT_name (not including the bitsize). Make sure we understand
1749+ // those too.
1750+
1751+ const char *yamldata = R"(
1752+ --- !ELF
1753+ FileHeader:
1754+ Class: ELFCLASS64
1755+ Data: ELFDATA2LSB
1756+ Type: ET_EXEC
1757+ Machine: EM_AARCH64
1758+ DWARF:
1759+ debug_str:
1760+ - _BitInt(2)
1761+ - _BitInt
1762+ - unsigned _BitInt(2)
1763+ - unsigned _BitInt
1764+ debug_abbrev:
1765+ - ID: 0
1766+ Table:
1767+ - Code: 0x1
1768+ Tag: DW_TAG_compile_unit
1769+ Children: DW_CHILDREN_yes
1770+ Attributes:
1771+ - Attribute: DW_AT_language
1772+ Form: DW_FORM_data2
1773+ - Code: 0x2
1774+ Tag: DW_TAG_base_type
1775+ Children: DW_CHILDREN_no
1776+ Attributes:
1777+ - Attribute: DW_AT_name
1778+ Form: DW_FORM_strp
1779+ - Attribute: DW_AT_encoding
1780+ Form: DW_FORM_data1
1781+ - Attribute: DW_AT_byte_size
1782+ Form: DW_FORM_data1
1783+ - Attribute: DW_AT_bit_size
1784+ Form: DW_FORM_data1
1785+ - Code: 0x3
1786+ Tag: DW_TAG_base_type
1787+ Children: DW_CHILDREN_no
1788+ Attributes:
1789+ - Attribute: DW_AT_name
1790+ Form: DW_FORM_strp
1791+ - Attribute: DW_AT_encoding
1792+ Form: DW_FORM_data1
1793+ - Attribute: DW_AT_byte_size
1794+ Form: DW_FORM_data1
1795+
1796+ debug_info:
1797+ - Version: 5
1798+ UnitType: DW_UT_compile
1799+ AddrSize: 8
1800+ Entries:
1801+
1802+ # DW_TAG_compile_unit
1803+ # DW_AT_language [DW_FORM_data2] (DW_LANG_C_plus_plus)
1804+
1805+ - AbbrCode: 0x1
1806+ Values:
1807+ - Value: 0x04
1808+
1809+ # DW_TAG_base_type
1810+ # DW_AT_name [DW_FORM_strp] ('_BitInt(2)')
1811+
1812+ - AbbrCode: 0x2
1813+ Values:
1814+ - Value: 0x0
1815+ - Value: 0x05
1816+ - Value: 0x01
1817+ - Value: 0x02
1818+
1819+ # DW_TAG_base_type
1820+ # DW_AT_name [DW_FORM_strp] ('_BitInt')
1821+
1822+ - AbbrCode: 0x2
1823+ Values:
1824+ - Value: 0x0b
1825+ - Value: 0x05
1826+ - Value: 0x08
1827+ - Value: 0x34
1828+
1829+ # DW_TAG_base_type
1830+ # DW_AT_name [DW_FORM_strp] ('unsigned _BitInt(2)')
1831+
1832+ - AbbrCode: 0x2
1833+ Values:
1834+ - Value: 0x13
1835+ - Value: 0x07
1836+ - Value: 0x01
1837+ - Value: 0x02
1838+
1839+ # DW_TAG_base_type
1840+ # DW_AT_name [DW_FORM_strp] ('unsigned _BitInt')
1841+
1842+ - AbbrCode: 0x2
1843+ Values:
1844+ - Value: 0x27
1845+ - Value: 0x07
1846+ - Value: 0x08
1847+ - Value: 0x34
1848+
1849+ # DW_TAG_base_type
1850+ # DW_AT_name [DW_FORM_strp] ('_BitInt')
1851+
1852+ - AbbrCode: 0x3
1853+ Values:
1854+ - Value: 0x0b
1855+ - Value: 0x05
1856+ - Value: 0x08
1857+ ...
1858+
1859+ )" ;
1860+
1861+ YAMLModuleTester t (yamldata);
1862+
1863+ DWARFUnit *unit = t.GetDwarfUnit ();
1864+ ASSERT_NE (unit, nullptr );
1865+ const DWARFDebugInfoEntry *cu_entry = unit->DIE ().GetDIE ();
1866+ ASSERT_EQ (cu_entry->Tag (), DW_TAG_compile_unit);
1867+ ASSERT_EQ (unit->GetDWARFLanguageType (), DW_LANG_C_plus_plus);
1868+ DWARFDIE cu_die (unit, cu_entry);
1869+
1870+ auto holder = std::make_unique<clang_utils::TypeSystemClangHolder>(" ast" );
1871+ auto &ast_ctx = *holder->GetAST ();
1872+ DWARFASTParserClangStub ast_parser (ast_ctx);
1873+
1874+ auto type_die = cu_die.GetFirstChild ();
1875+ ASSERT_TRUE (type_die.IsValid ());
1876+
1877+ {
1878+ SymbolContext sc;
1879+ auto type_sp = ast_parser.ParseTypeFromDWARF (sc, type_die,
1880+ /* type_is_new_ptr=*/ nullptr );
1881+ ASSERT_NE (type_sp, nullptr );
1882+
1883+ EXPECT_EQ (
1884+ llvm::expectedToOptional (type_sp->GetByteSize (nullptr )).value_or (0 ),
1885+ 1U );
1886+ uint64_t count;
1887+ EXPECT_EQ (type_sp->GetEncoding (count), lldb::eEncodingSint);
1888+ EXPECT_EQ (type_sp->GetName (), " _BitInt(2)" );
1889+ EXPECT_EQ (type_sp->GetForwardCompilerType ().GetTypeName (), " _BitInt(2)" );
1890+ }
1891+
1892+ {
1893+ type_die = type_die.GetSibling ();
1894+ SymbolContext sc;
1895+ auto type_sp = ast_parser.ParseTypeFromDWARF (sc, type_die,
1896+ /* type_is_new_ptr=*/ nullptr );
1897+ ASSERT_NE (type_sp, nullptr );
1898+
1899+ EXPECT_EQ (
1900+ llvm::expectedToOptional (type_sp->GetByteSize (nullptr )).value_or (0 ),
1901+ 8U );
1902+ uint64_t count;
1903+ EXPECT_EQ (type_sp->GetEncoding (count), lldb::eEncodingSint);
1904+ EXPECT_EQ (type_sp->GetName (), " _BitInt" );
1905+ EXPECT_EQ (type_sp->GetForwardCompilerType ().GetTypeName (), " _BitInt(52)" );
1906+ }
1907+
1908+ {
1909+ type_die = type_die.GetSibling ();
1910+ SymbolContext sc;
1911+ auto type_sp = ast_parser.ParseTypeFromDWARF (sc, type_die,
1912+ /* type_is_new_ptr=*/ nullptr );
1913+ ASSERT_NE (type_sp, nullptr );
1914+
1915+ EXPECT_EQ (
1916+ llvm::expectedToOptional (type_sp->GetByteSize (nullptr )).value_or (0 ),
1917+ 1U );
1918+ uint64_t count;
1919+ EXPECT_EQ (type_sp->GetEncoding (count), lldb::eEncodingUint);
1920+ EXPECT_EQ (type_sp->GetName (), " unsigned _BitInt(2)" );
1921+ EXPECT_EQ (type_sp->GetForwardCompilerType ().GetTypeName (),
1922+ " unsigned _BitInt(2)" );
1923+ }
1924+
1925+ {
1926+ type_die = type_die.GetSibling ();
1927+ SymbolContext sc;
1928+ auto type_sp = ast_parser.ParseTypeFromDWARF (sc, type_die,
1929+ /* type_is_new_ptr=*/ nullptr );
1930+ ASSERT_NE (type_sp, nullptr );
1931+
1932+ EXPECT_EQ (
1933+ llvm::expectedToOptional (type_sp->GetByteSize (nullptr )).value_or (0 ),
1934+ 8U );
1935+ uint64_t count;
1936+ EXPECT_EQ (type_sp->GetEncoding (count), lldb::eEncodingUint);
1937+ EXPECT_EQ (type_sp->GetName (), " unsigned _BitInt" );
1938+ EXPECT_EQ (type_sp->GetForwardCompilerType ().GetTypeName (),
1939+ " unsigned _BitInt(52)" );
1940+ }
1941+
1942+ {
1943+ type_die = type_die.GetSibling ();
1944+ SymbolContext sc;
1945+ auto type_sp = ast_parser.ParseTypeFromDWARF (sc, type_die,
1946+ /* type_is_new_ptr=*/ nullptr );
1947+ ASSERT_NE (type_sp, nullptr );
1948+
1949+ EXPECT_EQ (
1950+ llvm::expectedToOptional (type_sp->GetByteSize (nullptr )).value_or (0 ),
1951+ 8U );
1952+ uint64_t count;
1953+ EXPECT_EQ (type_sp->GetEncoding (count), lldb::eEncodingSint);
1954+ EXPECT_EQ (type_sp->GetName (), " _BitInt" );
1955+
1956+ // Older versions of Clang didn't emit a DW_AT_bit_size for _BitInt. In
1957+ // those cases we would format the CompilerType name using the byte-size.
1958+ EXPECT_EQ (type_sp->GetForwardCompilerType ().GetTypeName (), " _BitInt(64)" );
1959+ }
1960+ }
0 commit comments