[llvm] 6da200f - Fix llvm::StripTemplateParameters to not return an empty name. (#157553)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 16 09:20:59 PST 2025
Author: Greg Clayton
Date: 2025-12-16T09:20:56-08:00
New Revision: 6da200f72c5af1ae572bbf77f11ee8471a8c8199
URL: https://github.com/llvm/llvm-project/commit/6da200f72c5af1ae572bbf77f11ee8471a8c8199
DIFF: https://github.com/llvm/llvm-project/commit/6da200f72c5af1ae572bbf77f11ee8471a8c8199.diff
LOG: Fix llvm::StripTemplateParameters to not return an empty name. (#157553)
llvm::StripTemplateParameters was used to add accelerator table entries
to the DWARF accelerator tables by adding and entry for the template
name without the template. There is a bug where if a string starts with
a '<' character, this function would return an std::optional<StringRef>
that was empty. This causes invalid entries to be added to __apple_XXXX
accelerator tables where entries with empty strings would be added and
were causing issues with the AppleAcceleratorTable::Iterator before the
fix that was submitted
(https://github.com/llvm/llvm-project/pull/157538).
Added:
Modified:
llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
llvm/unittests/DebugInfo/DWARF/DWARFAcceleratorTableTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
index cf5b7fb650b43..e442b5182f6a4 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
@@ -1150,5 +1150,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;
}
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFAcceleratorTableTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFAcceleratorTableTest.cpp
index dedcf816cf63f..82cc02c921d15 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFAcceleratorTableTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFAcceleratorTableTest.cpp
@@ -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
More information about the llvm-commits
mailing list