[PATCH] D123201: [demangler] Buffer peeking needs buffer

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 6 04:35:09 PDT 2022


urnathan created this revision.
urnathan added reviewers: iains, libc++abi, dblaikie.
Herald added a project: All.
urnathan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The output buffer has a 'back' member, which returns NUL when you try it with an empty buffer.  But there are no use cases that need that additional functionality.  This makes the 'back' member behave more like STL containers' back members.  (It still returns a value, not a reference.)


https://reviews.llvm.org/D123201

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
@@ -171,7 +171,8 @@
   void setCurrentPosition(size_t NewPos) { CurrentPosition = NewPos; }
 
   char back() const {
-    return CurrentPosition ? Buffer[CurrentPosition - 1] : '\0';
+    assert(CurrentPosition);
+    return Buffer[CurrentPosition - 1];
   }
 
   bool empty() const { return CurrentPosition == 0; }
Index: libcxxabi/src/demangle/Utility.h
===================================================================
--- libcxxabi/src/demangle/Utility.h
+++ libcxxabi/src/demangle/Utility.h
@@ -171,7 +171,8 @@
   void setCurrentPosition(size_t NewPos) { CurrentPosition = NewPos; }
 
   char back() const {
-    return CurrentPosition ? Buffer[CurrentPosition - 1] : '\0';
+    assert(CurrentPosition);
+    return Buffer[CurrentPosition - 1];
   }
 
   bool empty() const { return CurrentPosition == 0; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123201.420782.patch
Type: text/x-patch
Size: 1008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220406/ff3bc62b/attachment.bin>


More information about the llvm-commits mailing list