[PATCH] D122604: [demangler] Simplify OutputBuffer initialization

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 11:32:18 PDT 2022


urnathan created this revision.
urnathan added reviewers: bruno, dblaikie, erichkeane.
Herald added a subscriber: hiraditya.
Herald added a project: All.
urnathan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This next cleanup of the demangler's OutputBuffer class addresses the initial allocation of the output buffer.  Now that the buffer extension logic has hysteresis in it, there's no need for every use of OutputBuffer to explicitly create the initial buffer (using either 128 or 1024 as initial guesses).

For the default case we can rely on the buffer extension logic to create a good initial buffer.  For the cases where the user is reusing a buffer, pass that information into the constructor.  Thus the OutputBuffer's ownership of the buffer starts at its own lifetime start -- a nice bit of RAII. 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, but that's not foolproof, as a subsequent buffer extension failure ends up calling std::terminate.  (Also, failed node allocation will call std::terminate.) I am working on addressing that unfortunate failure mode in a manner more consistent with the cxx abi design.  As one can see, there's a fixme removed in the microsoft code noting this poor failure mode.

This removes about 500 bytes from the clang executable.

I have a patch dealing with the destructing part of this API coming up.


https://reviews.llvm.org/D122604

Files:
  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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122604.418657.patch
Type: text/x-patch
Size: 9258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220328/c72b4207/attachment.bin>


More information about the llvm-commits mailing list