Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
8 changes: 6 additions & 2 deletions llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,8 @@ std::optional<StringRef> llvm::StripTemplateParameters(StringRef Name) {
//
// We look for > at the end but if it does not contain any < then we
// have something like operator>>. We check for the operator<=> case.
if (!Name.ends_with(">") || Name.count("<") == 0 || Name.ends_with("<=>"))
if (Name.starts_with("<") || !Name.ends_with(">") || Name.count("<") == 0 ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this Name.starts_with("<") check anymore right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct. I can remove it.

Name.ends_with("<=>"))
return {};

// How many < until we have the start of the template parameters.
Expand All @@ -1138,5 +1139,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