Author: Michael Buch Date: 2026-01-17T00:31:32Z New Revision: 8021b024fbe4882376a817fc2f668b653fb8a85f
URL: https://github.com/llvm/llvm-project/commit/8021b024fbe4882376a817fc2f668b653fb8a85f DIFF: https://github.com/llvm/llvm-project/commit/8021b024fbe4882376a817fc2f668b653fb8a85f.diff LOG: [llvm][Support] Move llvm::createStringErrorV to a new ErrorExtras.h header (#176491) Introducing `llvm::createStringErrorV` caused a `0.5%` compile-time regression because it's an inline function in a core header. This moves the API to a new header to prevent including this function in files that don't need it. Also includes the header in the source files that have been using `createStringErrorV` (which currently is just LLDB). Added: llvm/include/llvm/Support/ErrorExtras.h Modified: lldb/source/Expression/DWARFExpression.cpp lldb/source/Expression/Expression.cpp lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp lldb/source/Plugins/Platform/WebAssembly/PlatformWasm.cpp lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp lldb/source/Protocol/MCP/Server.cpp lldb/source/Symbol/Function.cpp llvm/include/llvm/Support/Error.h llvm/unittests/Support/ErrorTest.cpp Removed: ################################################################################ diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index 47909db410cac..c23471a2c1219 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -38,6 +38,7 @@ #include "lldb/Target/Thread.h" #include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h" #include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h" +#include "llvm/Support/ErrorExtras.h" using namespace lldb; using namespace lldb_private; diff --git a/lldb/source/Expression/Expression.cpp b/lldb/source/Expression/Expression.cpp index 4f3e26ebbf57b..cca645e5f264f 100644 --- a/lldb/source/Expression/Expression.cpp +++ b/lldb/source/Expression/Expression.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" +#include "llvm/Support/ErrorExtras.h" using namespace lldb_private; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp index 5d5535d2dd221..1276abe09c63c 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp @@ -20,6 +20,7 @@ #include "clang/Sema/Lookup.h" #include "clang/Serialization/ASTReader.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/ErrorExtras.h" #include "llvm/Support/Path.h" #include "llvm/Support/Threading.h" diff --git a/lldb/source/Plugins/Platform/WebAssembly/PlatformWasm.cpp b/lldb/source/Plugins/Platform/WebAssembly/PlatformWasm.cpp index 7d9e6af498653..30f31cb9ae75f 100644 --- a/lldb/source/Plugins/Platform/WebAssembly/PlatformWasm.cpp +++ b/lldb/source/Plugins/Platform/WebAssembly/PlatformWasm.cpp @@ -20,6 +20,7 @@ #include "lldb/Utility/Listener.h" #include "lldb/Utility/Log.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/ErrorExtras.h" using namespace lldb; using namespace lldb_private; diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index f91b59b48eb5c..cbe013755f198 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -90,6 +90,7 @@ #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/Support/ErrorExtras.h" #include "llvm/Support/FormatAdapters.h" #include "llvm/Support/Threading.h" #include "llvm/Support/raw_ostream.h" diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 1b2985820fefc..c6261910700cb 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -15,6 +15,7 @@ #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Error.h" +#include "llvm/Support/ErrorExtras.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/FormatAdapters.h" #include "llvm/Support/Threading.h" diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index c6aab08117d88..d7fe6a4b2879a 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -33,6 +33,7 @@ #include "lldb/Symbol/VariableList.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/ErrorExtras.h" #include "llvm/Support/ScopedPrinter.h" #include "lldb/Target/StackFrame.h" diff --git a/lldb/source/Protocol/MCP/Server.cpp b/lldb/source/Protocol/MCP/Server.cpp index 18d4b6f42c5bb..a8871ff5c39f0 100644 --- a/lldb/source/Protocol/MCP/Server.cpp +++ b/lldb/source/Protocol/MCP/Server.cpp @@ -14,6 +14,7 @@ #include "lldb/Protocol/MCP/Protocol.h" #include "lldb/Protocol/MCP/Transport.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Support/ErrorExtras.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/JSON.h" #include "llvm/Support/Signals.h" diff --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp index 061cc03a69ed2..fdb20bcd83ffd 100644 --- a/lldb/source/Symbol/Function.cpp +++ b/lldb/source/Symbol/Function.cpp @@ -22,6 +22,7 @@ #include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorExtras.h" using namespace lldb; using namespace lldb_private; diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h index 6638c919e2965..c9fd16fdb7c2b 100644 --- a/llvm/include/llvm/Support/Error.h +++ b/llvm/include/llvm/Support/Error.h @@ -21,7 +21,6 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/Format.h" -#include "llvm/Support/FormatVariadic.h" #include "llvm/Support/raw_ostream.h" #include <cassert> #include <cstdint> @@ -1336,21 +1335,6 @@ inline Error createStringError(std::errc EC, char const *Fmt, return createStringError(std::make_error_code(EC), Fmt, Vals...); } -// LLVM formatv versions of llvm::createStringError - -template <typename... Ts> -inline Error createStringErrorV(std::error_code EC, char const *Fmt, - Ts &&...Vals) { - return make_error<StringError>(formatv(Fmt, std::forward<Ts>(Vals)...).str(), - EC, true); -} - -template <typename... Ts> -inline Error createStringErrorV(char const *Fmt, Ts &&...Vals) { - return createStringErrorV(llvm::inconvertibleErrorCode(), Fmt, - std::forward<Ts>(Vals)...); -} - /// This class wraps a filename and another Error. /// /// In some cases, an error needs to live along a 'source' name, in order to diff --git a/llvm/include/llvm/Support/ErrorExtras.h b/llvm/include/llvm/Support/ErrorExtras.h new file mode 100644 index 0000000000000..bcfad0eab6097 --- /dev/null +++ b/llvm/include/llvm/Support/ErrorExtras.h @@ -0,0 +1,34 @@ +//===- llvm/Support/ErrorExtras.h -------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_ERROREXTRAS_H +#define LLVM_SUPPORT_ERROREXTRAS_H + +#include "llvm/Support/Error.h" +#include "llvm/Support/FormatVariadic.h" + +namespace llvm { + +// LLVM formatv versions of llvm::createStringError + +template <typename... Ts> +inline Error createStringErrorV(std::error_code EC, char const *Fmt, + Ts &&...Vals) { + return make_error<StringError>(formatv(Fmt, std::forward<Ts>(Vals)...).str(), + EC, true); +} + +template <typename... Ts> +inline Error createStringErrorV(char const *Fmt, Ts &&...Vals) { + return createStringErrorV(llvm::inconvertibleErrorCode(), Fmt, + std::forward<Ts>(Vals)...); +} + +} // namespace llvm + +#endif // LLVM_SUPPORT_ERROREXTRAS_H diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp index 8454bae666fcb..45c0a4f450b51 100644 --- a/llvm/unittests/Support/ErrorTest.cpp +++ b/llvm/unittests/Support/ErrorTest.cpp @@ -8,6 +8,7 @@ #include "llvm/Support/Error.h" #include "llvm-c/Error.h" +#include "llvm/Support/ErrorExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Errc.h" _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
