Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,17 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
m_ast.CreateClassTemplateSpecializationDecl(
containing_decl_ctx, GetOwningClangModule(die), class_template_decl,
tag_decl_kind, template_param_infos);
if (!class_specialization_decl) {
if (log) {
dwarf->GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF({0:p}) - Failed to create specialization for "
"clang::ClassTemplateDecl({1}, {2:p}).",
this, llvm::StringRef(attrs.name), class_template_decl);
}
return TypeSP();
}

clang_type =
m_ast.CreateClassTemplateSpecializationType(class_specialization_decl);

Expand Down
5 changes: 5 additions & 0 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,11 @@ TypeSystemClang::CreateClassTemplateSpecializationDecl(
class_template_specialization_decl->setInstantiationOf(class_template_decl);
class_template_specialization_decl->setTemplateArgs(
TemplateArgumentList::CreateCopy(ast, args));
void *insert_pos = nullptr;
if (class_template_decl->findSpecialization(args, insert_pos))
return nullptr;
class_template_decl->AddSpecialization(class_template_specialization_decl,
insert_pos);
class_template_specialization_decl->setDeclName(
class_template_decl->getDeclName());

Expand Down
3 changes: 2 additions & 1 deletion lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_lldb_unittest(SymbolFileDWARFTests

set(test_inputs
test-dwarf.exe
DW_AT_default_value-test.yaml)
DW_AT_default_value-test.yaml
DW_AT_spec_decl_exists-test.yaml)

add_unittest_inputs(SymbolFileDWARFTests "${test_inputs}")
34 changes: 34 additions & 0 deletions lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,40 @@ TEST_F(DWARFASTParserClangTests, TestDefaultTemplateParamParsing) {
}
}

TEST_F(DWARFASTParserClangTests, TestSpecDeclExistsError) {
// Tests that parsing a ClassTemplateSpecializationDecl that already exists
// is handled gracefully.
auto BufferOrError = llvm::MemoryBuffer::getFile(
GetInputFilePath("DW_AT_spec_decl_exists-test.yaml"), /*IsText=*/true);
ASSERT_TRUE(BufferOrError);
YAMLModuleTester t(BufferOrError.get()->getBuffer());

DWARFUnit *unit = t.GetDwarfUnit();
ASSERT_NE(unit, nullptr);
const DWARFDebugInfoEntry *cu_entry = unit->DIE().GetDIE();
ASSERT_EQ(cu_entry->Tag(), DW_TAG_compile_unit);
DWARFDIE cu_die(unit, cu_entry);

auto holder = std::make_unique<clang_utils::TypeSystemClangHolder>("ast");
auto &ast_ctx = *holder->GetAST();
DWARFASTParserClangStub ast_parser(ast_ctx);

llvm::SmallVector<lldb::TypeSP, 2> specializations;
for (DWARFDIE die : cu_die.children()) {
SymbolContext sc;
bool new_type = false;
auto type = ast_parser.ParseTypeFromDWARF(sc, die, &new_type);
llvm::StringRef die_name = llvm::StringRef(die.GetName());
if (die_name.starts_with("_Optional_payload")) {
specializations.push_back(std::move(type));
}
}

ASSERT_EQ(specializations.size(), 2U);
ASSERT_NE(specializations[0], nullptr);
ASSERT_EQ(specializations[1], nullptr);
}

TEST_F(DWARFASTParserClangTests, TestUniqueDWARFASTTypeMap_CppInsertMapFind) {
// This tests the behaviour of UniqueDWARFASTTypeMap under
// following scenario:
Expand Down
Loading
Loading