[PATCH] D120901: [demangler] Make OutputBuffer non-copyable

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 3 06:22:00 PST 2022


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

In addressing the buffer ownership API, I discovered a rogue member function that returned by value rather than by reference. It clearly intended to return by reference, but because the copy ctor wasn't deleted this wasn't caught.

It is not necessary to make this a move-only type, although that would be an alternative.


https://reviews.llvm.org/D120901

Files:
  libcxxabi/src/demangle/Utility.h
  llvm/include/llvm/Demangle/Utility.h


Index: llvm/include/llvm/Demangle/Utility.h
===================================================================
--- llvm/include/llvm/Demangle/Utility.h
+++ llvm/include/llvm/Demangle/Utility.h
@@ -71,6 +71,10 @@
   OutputBuffer(char *StartBuf, size_t Size)
       : Buffer(StartBuf), CurrentPosition(0), BufferCapacity(Size) {}
   OutputBuffer() = default;
+  // Non-copyable
+  OutputBuffer(const OutputBuffer &) = delete;
+  OutputBuffer &operator=(const OutputBuffer &) = delete;
+
   void reset(char *Buffer_, size_t BufferCapacity_) {
     CurrentPosition = 0;
     Buffer = Buffer_;
@@ -112,7 +116,7 @@
     return *this;
   }
 
-  OutputBuffer prepend(StringView R) {
+  OutputBuffer &prepend(StringView R) {
     size_t Size = R.size();
 
     grow(Size);
Index: libcxxabi/src/demangle/Utility.h
===================================================================
--- libcxxabi/src/demangle/Utility.h
+++ libcxxabi/src/demangle/Utility.h
@@ -71,6 +71,10 @@
   OutputBuffer(char *StartBuf, size_t Size)
       : Buffer(StartBuf), CurrentPosition(0), BufferCapacity(Size) {}
   OutputBuffer() = default;
+  // Non-copyable
+  OutputBuffer(const OutputBuffer &) = delete;
+  OutputBuffer &operator=(const OutputBuffer &) = delete;
+
   void reset(char *Buffer_, size_t BufferCapacity_) {
     CurrentPosition = 0;
     Buffer = Buffer_;
@@ -112,7 +116,7 @@
     return *this;
   }
 
-  OutputBuffer prepend(StringView R) {
+  OutputBuffer &prepend(StringView R) {
     size_t Size = R.size();
 
     grow(Size);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120901.412695.patch
Type: text/x-patch
Size: 1518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220303/6d9a0136/attachment.bin>


More information about the llvm-commits mailing list