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
5 changes: 4 additions & 1 deletion llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,5 +1138,8 @@ std::optional<StringRef> llvm::StripTemplateParameters(StringRef Name) {
while (NumLeftAnglesToSkip--)
StartOfTemplate = Name.find('<', StartOfTemplate) + 1;

return Name.substr(0, StartOfTemplate - 1);
StringRef Result = Name.substr(0, StartOfTemplate - 1);
if (Result.empty())
return std::nullopt;
return Result;
}
14 changes: 14 additions & 0 deletions llvm/unittests/DebugInfo/DWARF/DWARFAcceleratorTableTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,18 @@ TEST(DWARFDebugNames, UnsupportedForm) {
Sections,
FailedWithMessage("unsupported Form for YAML debug_names emitter"));
}

TEST(DWARFDebugNames, TestStripTemplateParameters) {

std::optional<StringRef> stripped_name;
// Make sure we can extract the name "foo" from the template parameters.
stripped_name = StripTemplateParameters("foo<int>");
ASSERT_TRUE(stripped_name.has_value());
ASSERT_EQ(*stripped_name, StringRef("foo"));
// Make sure that we don't get a valid name back when the string starts with
// '<'.
stripped_name = StripTemplateParameters("<int>");
ASSERT_FALSE(stripped_name.has_value());
}

} // end anonymous namespace
Loading