diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp index 5daa093ee8a1b..9c26c4f8892b0 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -291,13 +291,12 @@ DWARFDie::findRecursively(ArrayRef Attrs) const { if (auto Value = Die.find(Attrs)) return Value; - if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin)) - if (Seen.insert(D).second) - Worklist.push_back(D); - - if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification)) - if (Seen.insert(D).second) - Worklist.push_back(D); + for (dwarf::Attribute Attr : + {DW_AT_abstract_origin, DW_AT_specification, DW_AT_signature}) { + if (auto D = Die.getAttributeValueAsReferencedDie(Attr)) + if (Seen.insert(D).second) + Worklist.push_back(D); + } } return std::nullopt; diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp index e1057b214ee4d..485ec720ffad6 100644 --- a/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp @@ -643,4 +643,65 @@ TEST(DWARFDie, getDeclFileSpecificationAcrossCUBoundary) { EXPECT_EQ(DeclFile, Ref); } +TEST(DWARFDie, getNameFromTypeUnit) { + const char *yamldata = R"( + debug_abbrev: + - ID: 0 + Table: + - Code: 0x1 + Tag: DW_TAG_compile_unit + Children: DW_CHILDREN_yes + - Code: 0x2 + Tag: DW_TAG_structure_type + Children: DW_CHILDREN_no + Attributes: + - Attribute: DW_AT_signature + Form: DW_FORM_ref_sig8 + - Code: 0x3 + Tag: DW_TAG_type_unit + Children: DW_CHILDREN_yes + - Code: 0x4 + Tag: DW_TAG_structure_type + Children: DW_CHILDREN_no + Attributes: + - Attribute: DW_AT_name + Form: DW_FORM_string + debug_info: + - Version: 5 + UnitType: DW_UT_compile + AbbrevTableID: 0 + Entries: + - AbbrCode: 0x1 + - AbbrCode: 0x2 + Values: + - Value: 0xdeadbeefbaadf00d + - AbbrCode: 0x0 + - Version: 5 + UnitType: DW_UT_type + AbbrevTableID: 0 + TypeSignature: 0xdeadbeefbaadf00d + TypeOffset: 25 + Entries: + - AbbrCode: 0x3 + - AbbrCode: 0x4 + Values: + - CStr: "STRUCT" + - AbbrCode: 0x0 + )"; + + Expected>> Sections = + DWARFYAML::emitDebugSections(StringRef(yamldata), + /*IsLittleEndian=*/true, + /*Is64BitAddrSize=*/true); + ASSERT_THAT_EXPECTED(Sections, Succeeded()); + std::unique_ptr Ctx = + DWARFContext::create(*Sections, 4, /*isLittleEndian=*/true); + DWARFCompileUnit *CU = Ctx->getCompileUnitForOffset(0); + ASSERT_NE(nullptr, CU); + DWARFDie Die = CU->getUnitDIE(/*ExtractUnitDIEOnly=*/false).getFirstChild(); + ASSERT_TRUE(Die.isValid()); + + ASSERT_STREQ(Die.getName(DINameKind::ShortName), "STRUCT"); +} + } // end anonymous namespace