diff options
author | Nathan Sidwell <nathan@acm.org> | 2022-02-28 10:13:44 -0800 |
---|---|---|
committer | Nathan Sidwell <nathan@acm.org> | 2022-04-26 04:23:12 -0700 |
commit | 5b3ca24a35e91bf9c19af856e7f92c69b17f989e (patch) | |
tree | 88a2a3a91c91f1211fc9046876b3ddf3d7ae3e58 /llvm/lib/Demangle/MicrosoftDemangle.cpp | |
parent | 2b985a7ae81f71171cb4167d32a3ff4d49b66305 (diff) | |
download | llvm-5b3ca24a35e91bf9c19af856e7f92c69b17f989e.zip llvm-5b3ca24a35e91bf9c19af856e7f92c69b17f989e.tar.gz llvm-5b3ca24a35e91bf9c19af856e7f92c69b17f989e.tar.bz2 |
[demangler] Simplify OutputBuffer initialization
Every non-testcase use of OutputBuffer contains code to allocate an
initial buffer (using either 128 or 1024 as initial guesses). There's
now no need to do that, given recent changes to the buffer extension
heuristics -- it allocates a 1k(ish) buffer on first need.
Just pass in a buffer (if any) to the constructor. Thus the
OutputBuffer's ownership of the buffer starts at its own lifetime
start. We can reduce the lifetime of this object in several cases.
That new constructor takes a 'size_t *' for the size argument, as all
uses with a non-null buffer are passing through a malloc'd buffer from
their own caller in this manner.
The buffer reset member function is never used, and is deleted.
The original buffer initialization code would return a failure code if
that first malloc failed. Existing code either ignored that, called
std::terminate with a FIXME, or returned an error code.
But that's not foolproof anyway, as a subsequent buffer extension
failure ends up calling std::terminate. I am working on addressing
that unfortunate failure mode in a manner more consistent with the C++
ABI design.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D122604
Diffstat (limited to 'llvm/lib/Demangle/MicrosoftDemangle.cpp')
-rw-r--r-- | llvm/lib/Demangle/MicrosoftDemangle.cpp | 17 |
1 files changed, 1 insertions, 16 deletions
diff --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp index aca8cf7..26087a5 100644 --- a/llvm/lib/Demangle/MicrosoftDemangle.cpp +++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp @@ -966,9 +966,6 @@ void Demangler::memorizeIdentifier(IdentifierNode *Identifier) { // Render this class template name into a string buffer so that we can // memorize it for the purpose of back-referencing. OutputBuffer OB; - if (!initializeOutputBuffer(nullptr, nullptr, OB, 1024)) - // FIXME: Propagate out-of-memory as an error? - std::terminate(); Identifier->output(OB, OF_Default); StringView Owned = copyString(OB); memorizeString(Owned); @@ -1279,11 +1276,6 @@ Demangler::demangleStringLiteral(StringView &MangledName) { EncodedStringLiteralNode *Result = Arena.alloc<EncodedStringLiteralNode>(); - // Must happen before the first `goto StringLiteralError`. - if (!initializeOutputBuffer(nullptr, nullptr, OB, 1024)) - // FIXME: Propagate out-of-memory as an error? - std::terminate(); - // Prefix indicating the beginning of a string literal if (!MangledName.consumeFront("@_")) goto StringLiteralError; @@ -1442,9 +1434,6 @@ Demangler::demangleLocallyScopedNamePiece(StringView &MangledName) { // Render the parent symbol's name into a buffer. OutputBuffer OB; - if (!initializeOutputBuffer(nullptr, nullptr, OB, 1024)) - // FIXME: Propagate out-of-memory as an error? - std::terminate(); OB << '`'; Scope->output(OB, OF_Default); OB << '\''; @@ -2307,8 +2296,6 @@ void Demangler::dumpBackReferences() { // Create an output stream so we can render each type. OutputBuffer OB; - if (!initializeOutputBuffer(nullptr, nullptr, OB, 1024)) - std::terminate(); for (size_t I = 0; I < Backrefs.FunctionParamCount; ++I) { OB.setCurrentPosition(0); @@ -2335,7 +2322,6 @@ char *llvm::microsoftDemangle(const char *MangledName, size_t *NMangled, char *Buf, size_t *N, int *Status, MSDemangleFlags Flags) { Demangler D; - OutputBuffer OB; StringView Name{MangledName}; SymbolNode *AST = D.parse(Name); @@ -2360,9 +2346,8 @@ char *llvm::microsoftDemangle(const char *MangledName, size_t *NMangled, int InternalStatus = demangle_success; if (D.Error) InternalStatus = demangle_invalid_mangled_name; - else if (!initializeOutputBuffer(Buf, N, OB, 1024)) - InternalStatus = demangle_memory_alloc_failure; else { + OutputBuffer OB(Buf, N); AST->output(OB, OF); OB += '\0'; if (N != nullptr) |