[llvm] 6422164 - [demangler] Make OutputBuffer non-copyable

Nathan Sidwell via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 4 04:43:54 PST 2022


Author: Nathan Sidwell
Date: 2022-03-04T04:43:37-08:00
New Revision: 64221645a824f0b70ae130001b37ac01095aa806

URL: https://github.com/llvm/llvm-project/commit/64221645a824f0b70ae130001b37ac01095aa806
DIFF: https://github.com/llvm/llvm-project/commit/64221645a824f0b70ae130001b37ac01095aa806.diff

LOG: [demangler] Make OutputBuffer non-copyable

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.

Reviewed By: bruno

Differential Revision: https://reviews.llvm.org/D120901

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/libcxxabi/src/demangle/Utility.h b/libcxxabi/src/demangle/Utility.h
index 0cf70bdde403d..1c4604160749c 100644
--- a/libcxxabi/src/demangle/Utility.h
+++ b/libcxxabi/src/demangle/Utility.h
@@ -71,6 +71,10 @@ class OutputBuffer {
   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_;
@@ -97,7 +101,7 @@ class OutputBuffer {
     return *this;
   }
 
-  OutputBuffer prepend(StringView R) {
+  OutputBuffer &prepend(StringView R) {
     size_t Size = R.size();
 
     grow(Size);

diff  --git a/llvm/include/llvm/Demangle/Utility.h b/llvm/include/llvm/Demangle/Utility.h
index f3537c12d4d7d..5f012d7e818fa 100644
--- a/llvm/include/llvm/Demangle/Utility.h
+++ b/llvm/include/llvm/Demangle/Utility.h
@@ -71,6 +71,10 @@ class OutputBuffer {
   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_;
@@ -97,7 +101,7 @@ class OutputBuffer {
     return *this;
   }
 
-  OutputBuffer prepend(StringView R) {
+  OutputBuffer &prepend(StringView R) {
     size_t Size = R.size();
 
     grow(Size);


        


More information about the llvm-commits mailing list