[demangler] Simplify OutputBuffer initialization
authorNathan Sidwell <nathan@acm.org>
Mon, 28 Feb 2022 18:13:44 +0000 (10:13 -0800)
committerNathan Sidwell <nathan@acm.org>
Tue, 26 Apr 2022 11:23:12 +0000 (04:23 -0700)
commit5b3ca24a35e91bf9c19af856e7f92c69b17f989e
tree88a2a3a91c91f1211fc9046876b3ddf3d7ae3e58
parent2b985a7ae81f71171cb4167d32a3ff4d49b66305
[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
libcxxabi/src/cxa_demangle.cpp
libcxxabi/src/demangle/Utility.h
llvm/include/llvm/Demangle/Utility.h
llvm/lib/Demangle/DLangDemangle.cpp
llvm/lib/Demangle/ItaniumDemangle.cpp
llvm/lib/Demangle/MicrosoftDemangle.cpp
llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
llvm/lib/Demangle/RustDemangle.cpp