summaryrefslogtreecommitdiff
path: root/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp')
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp48
1 files changed, 40 insertions, 8 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index 58900e1e80cb..43ed60d7f977 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -1351,12 +1351,34 @@ DWARFVerifier::verifyNameIndexAbbrevs(const DWARFDebugNames::NameIndex &NI) {
return NumErrors;
}
-static SmallVector<StringRef, 2> getNames(const DWARFDie &DIE,
- bool IncludeLinkageName = true) {
- SmallVector<StringRef, 2> Result;
- if (const char *Str = DIE.getShortName())
- Result.emplace_back(Str);
- else if (DIE.getTag() == dwarf::DW_TAG_namespace)
+static SmallVector<std::string, 3> getNames(const DWARFDie &DIE,
+ bool IncludeStrippedTemplateNames,
+ bool IncludeObjCNames = true,
+ bool IncludeLinkageName = true) {
+ SmallVector<std::string, 3> Result;
+ if (const char *Str = DIE.getShortName()) {
+ StringRef Name(Str);
+ Result.emplace_back(Name);
+ if (IncludeStrippedTemplateNames) {
+ if (std::optional<StringRef> StrippedName =
+ StripTemplateParameters(Result.back()))
+ // Convert to std::string and push; emplacing the StringRef may trigger
+ // a vector resize which may destroy the StringRef memory.
+ Result.push_back(StrippedName->str());
+ }
+
+ if (IncludeObjCNames) {
+ if (std::optional<ObjCSelectorNames> ObjCNames =
+ getObjCNamesIfSelector(Name)) {
+ Result.emplace_back(ObjCNames->ClassName);
+ Result.emplace_back(ObjCNames->Selector);
+ if (ObjCNames->ClassNameNoCategory)
+ Result.emplace_back(*ObjCNames->ClassNameNoCategory);
+ if (ObjCNames->MethodNameNoCategory)
+ Result.push_back(std::move(*ObjCNames->MethodNameNoCategory));
+ }
+ }
+ } else if (DIE.getTag() == dwarf::DW_TAG_namespace)
Result.emplace_back("(anonymous namespace)");
if (IncludeLinkageName) {
@@ -1423,7 +1445,12 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
++NumErrors;
}
- auto EntryNames = getNames(DIE);
+ // We allow an extra name for functions: their name without any template
+ // parameters.
+ auto IncludeStrippedTemplateNames =
+ DIE.getTag() == DW_TAG_subprogram ||
+ DIE.getTag() == DW_TAG_inlined_subroutine;
+ auto EntryNames = getNames(DIE, IncludeStrippedTemplateNames);
if (!is_contained(EntryNames, Str)) {
error() << formatv("Name Index @ {0:x}: Entry @ {1:x}: mismatched Name "
"of DIE @ {2:x}: index - {3}; debug_info - {4}.\n",
@@ -1496,7 +1523,12 @@ unsigned DWARFVerifier::verifyNameIndexCompleteness(
// the linkage name."
auto IncludeLinkageName = Die.getTag() == DW_TAG_subprogram ||
Die.getTag() == DW_TAG_inlined_subroutine;
- auto EntryNames = getNames(Die, IncludeLinkageName);
+ // We *allow* stripped template names / ObjectiveC names as extra entries into
+ // the table, but we don't *require* them to pass the completeness test.
+ auto IncludeStrippedTemplateNames = false;
+ auto IncludeObjCNames = false;
+ auto EntryNames = getNames(Die, IncludeStrippedTemplateNames,
+ IncludeObjCNames, IncludeLinkageName);
if (EntryNames.empty())
return 0;