[PATCH] D81597: Overload != operator, make overloaded - operator const, for libunwind::EHABISectionIterator.

Chad Duffin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 11:05:28 PDT 2020


chadduffin created this revision.
chadduffin added reviewers: ed, abdulras.
chadduffin added a project: libunwind.
Herald added subscribers: libcxx-commits, llvm-commits, kristof.beyls.
Herald added a project: LLVM.
Herald added a reviewer: libunwind.

This change fixes two issues that arise when compiling libunwind with GCC and specifying the flag "-D_GLIBCXX_DEBUG". The first issue is that there is no overloaded != operator for libunwind::EHABISectionIterator:

  In file included from /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/debug/debug.h:127:0,
                   from /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/bits/stl_iterator_base_funcs.h:65,
                   from /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/bits/stl_algobase.h:66,
                   from /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/algorithm:61,
                   from ../../third_party/llvm-project/libunwind/src/libunwind.cpp:19:
  /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/debug/functions.h: In instantiation of ‘bool __gnu_debug::__check_partitioned_upper(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = libunwind::EHABISectionIterator<libunwind::LocalAddressSpace>; _Tp = unsigned int]’:
  /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/bits/stl_algo.h:2483:7:   required from ‘_FIter std::upper_bound(_FIter, _FIter, const _Tp&) [with _FIter = libunwind::EHABISectionIterator<libunwind::LocalAddressSpace>; _Tp = unsigned int]’
  ../../third_party/llvm-project/libunwind/src/UnwindCursor.hpp:806:69:   required from ‘bool libunwind::UnwindCursor<A, R>::getInfoFromEHABISection(libunwind::UnwindCursor<A, R>::pint_t, const libunwind::UnwindInfoSections&) [with A = libunwind::LocalAddressSpace; R = libunwind::Registers_arm; libunwind::UnwindCursor<A, R>::pint_t = unsigned int]’
  ../../third_party/llvm-project/libunwind/src/UnwindCursor.hpp:1320:32:   required from ‘void libunwind::UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool) [with A = libunwind::LocalAddressSpace; R = libunwind::Registers_arm]’
  ../../third_party/llvm-project/libunwind/src/libunwind.cpp:420:1:   required from here
  /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/debug/functions.h:372:22: error: no match for ‘operator!=’ (operand types are ‘libunwind::EHABISectionIterator<libunwind::LocalAddressSpace>’ and ‘libunwind::EHABISectionIterator<libunwind::LocalAddressSpace>’)
         while (__first != __last && !(__value < *__first))

The next issue was that the overloaded - operator was not a const member:

  In file included from /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/debug/debug.h:127:0,
                   from /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/bits/stl_iterator_base_funcs.h:65,
                   from /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/bits/stl_algobase.h:66,
                   from /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/algorithm:61,
                   from ../../third_party/llvm-project/libunwind/src/libunwind.cpp:19:
  /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/debug/functions.h: In instantiation of ‘bool __gnu_debug::__valid_range_aux2(const _RandomAccessIterator&, const _RandomAccessIterator&, std::random_access_iterator_tag) [with _RandomAccessIterator = libunwind::EHABISectionIterator<libunwind::LocalAddressSpace>]’:
  /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/debug/functions.h:122:43:   required from ‘bool __gnu_debug::__valid_range_aux(const _InputIterator&, const _InputIterator&, std::__false_type) [with _InputIterator = libunwind::EHABISectionIterator<libunwind::LocalAddressSpace>]’
  /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/debug/functions.h:134:60:   required from ‘bool __gnu_debug::__valid_range(const _InputIterator&, const _InputIterator&) [with _InputIterator = libunwind::EHABISectionIterator<libunwind::LocalAddressSpace>]’
  /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/bits/stl_algo.h:2483:7:   required from ‘_FIter std::upper_bound(_FIter, _FIter, const _Tp&) [with _FIter = libunwind::EHABISectionIterator<libunwind::LocalAddressSpace>; _Tp = unsigned int]’
  ../../third_party/llvm-project/libunwind/src/UnwindCursor.hpp:813:69:   required from ‘bool libunwind::UnwindCursor<A, R>::getInfoFromEHABISection(libunwind::UnwindCursor<A, R>::pint_t, const libunwind::UnwindInfoSections&) [with A = libunwind::LocalAddressSpace; R = libunwind::Registers_arm; libunwind::UnwindCursor<A, R>::pint_t = unsigned int]’
  ../../third_party/llvm-project/libunwind/src/UnwindCursor.hpp:1327:32:   required from ‘void libunwind::UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool) [with A = libunwind::LocalAddressSpace; R = libunwind::Registers_arm]’
  ../../third_party/llvm-project/libunwind/src/libunwind.cpp:420:1:   required from here
  /usr/local/google/home/chadduffin/raspi_tools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/include/c++/4.8.3/debug/functions.h:93:21: error: passing ‘const libunwind::EHABISectionIterator<libunwind::LocalAddressSpace>’ as ‘this’ argument of ‘size_t libunwind::EHABISectionIterator<A>::operator-(const _Self&) [with A = libunwind::LocalAddressSpace; size_t = unsigned int; libunwind::EHABISectionIterator<A>::_Self = libunwind::EHABISectionIterator<libunwind::LocalAddressSpace>]’ discards qualifiers [-fpermissive]
       { return __last - __first >= 0; }

With both of these operators overloaded the issue is resolved.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81597

Files:
  libunwind/src/UnwindCursor.hpp


Index: libunwind/src/UnwindCursor.hpp
===================================================================
--- libunwind/src/UnwindCursor.hpp
+++ libunwind/src/UnwindCursor.hpp
@@ -1276,6 +1276,7 @@
   _Self operator-(size_t a) { assert(_i >= a); _Self out = *this; out._i -= a; return out; }
 
   size_t operator-(const _Self& other) { return _i - other._i; }
+  size_t operator-(const _Self& other) const { return _i - other._i; }
 
   bool operator==(const _Self& other) const {
     assert(_addressSpace == other._addressSpace);
@@ -1283,6 +1284,12 @@
     return _i == other._i;
   }
 
+  bool operator!=(const _Self& other) const {
+    assert(_addressSpace == other._addressSpace);
+    assert(_sects == other._sects);
+    return _i != other._i;
+  }
+
   typename A::pint_t operator*() const { return functionAddress(); }
 
   typename A::pint_t functionAddress() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81597.269891.patch
Type: text/x-patch
Size: 880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200610/969fefab/attachment.bin>


More information about the llvm-commits mailing list