[llvm] [DebugInfo] Avoid std::function in DWARF verifier internals (PR #202866)
David Zbarsky via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 06:24:47 PDT 2026
https://github.com/dzbarsky updated https://github.com/llvm/llvm-project/pull/202866
>From 4eb3849fbf4cb00801a539a65dabeb122f14475d Mon Sep 17 00:00:00 2001
From: David Zbarsky <dzbarsky at gmail.com>
Date: Wed, 10 Jun 2026 02:32:39 -0400
Subject: [PATCH] [DebugInfo] Avoid std::function in DWARF verifier internals
Change OutputCategoryAggregator's synchronous callback parameters from
std::function to function_ref. This avoids constructing type-erased callbacks
at 75 DWARFVerifier diagnostic sites and removes the private forwarding API.
In an arm64 Release build, DWARFVerifier.cpp.o decreases by 174,464 bytes,
including 18,180 bytes of text and 2,294 relocations. llvm-dwarfdump decreases
by 133,680 bytes raw and 17,040 bytes stripped; linked text decreases by
17,908 bytes, __DATA_CONST,__const decreases by 5,616 bytes, and linked fixups
decrease by 546.
The final source compiles and links, and the llvm-dwarfdump command-line,
error-handling, and filtering tests pass. The callback implementation is
unchanged apart from removing a boolean return from a void callback.
---
.../llvm/DebugInfo/DWARF/DWARFVerifier.h | 11 +++++------
llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp | 17 ++++++++---------
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h
index f667496ab1059..6d2d62261e3ce 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h
@@ -9,6 +9,7 @@
#ifndef LLVM_DEBUGINFO_DWARF_DWARFVERIFIER_H
#define LLVM_DEBUGINFO_DWARF_DWARFVERIFIER_H
+#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
@@ -51,15 +52,13 @@ class OutputCategoryAggregator {
: IncludeDetail(includeDetail) {}
void ShowDetail(bool showDetail) { IncludeDetail = showDetail; }
size_t GetNumCategories() const { return Aggregation.size(); }
- LLVM_ABI void Report(StringRef category,
- std::function<void()> detailCallback);
+ LLVM_ABI void Report(StringRef category, function_ref<void()> detailCallback);
LLVM_ABI void Report(StringRef category, StringRef sub_category,
- std::function<void()> detailCallback);
+ function_ref<void()> detailCallback);
LLVM_ABI void
- EnumerateResults(std::function<void(StringRef, unsigned)> handleCounts);
+ EnumerateResults(function_ref<void(StringRef, unsigned)> handleCounts);
LLVM_ABI void EnumerateDetailedResultsFor(
- StringRef category,
- std::function<void(StringRef, unsigned)> handleCounts);
+ StringRef category, function_ref<void(StringRef, unsigned)> handleCounts);
/// Return the number of errors that have been reported.
uint64_t GetNumErrors() const { return NumErrors; }
};
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index 17d1bfb3f575c..32775f348bb22 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -2343,20 +2343,19 @@ bool DWARFVerifier::verifyDebugStrOffsets(
std::string Msg = toString(std::move(E));
ErrorCategory.Report("String offset error", [&]() {
error() << formatv("{0}: {1}\n", SectionName, Msg);
- return false;
});
}
return Success;
}
-void OutputCategoryAggregator::Report(
- StringRef s, std::function<void(void)> detailCallback) {
- this->Report(s, "", detailCallback);
+void OutputCategoryAggregator::Report(StringRef s,
+ function_ref<void(void)> detailCallback) {
+ Report(s, "", detailCallback);
}
-void OutputCategoryAggregator::Report(
- StringRef category, StringRef sub_category,
- std::function<void(void)> detailCallback) {
+void OutputCategoryAggregator::Report(StringRef category,
+ StringRef sub_category,
+ function_ref<void(void)> detailCallback) {
std::lock_guard<std::mutex> Lock(WriteMutex);
++NumErrors;
std::string category_str = std::string(category);
@@ -2370,13 +2369,13 @@ void OutputCategoryAggregator::Report(
}
void OutputCategoryAggregator::EnumerateResults(
- std::function<void(StringRef, unsigned)> handleCounts) {
+ function_ref<void(StringRef, unsigned)> handleCounts) {
for (const auto &[name, aggData] : Aggregation) {
handleCounts(name, aggData.OverallCount);
}
}
void OutputCategoryAggregator::EnumerateDetailedResultsFor(
- StringRef category, std::function<void(StringRef, unsigned)> handleCounts) {
+ StringRef category, function_ref<void(StringRef, unsigned)> handleCounts) {
const auto Agg = Aggregation.find(category);
if (Agg != Aggregation.end()) {
for (const auto &[name, aggData] : Agg->second.DetailedCounts) {
More information about the llvm-commits
mailing list