[PATCH] D53792: [DebugInfo] Define base function on DWARFDie reverse iterators

Eugene Sharygin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 28 03:36:08 PDT 2018


eush updated this revision to Diff 171419.
eush added a comment.

Added a test for the new function.


Repository:
  rL LLVM

https://reviews.llvm.org/D53792

Files:
  include/llvm/DebugInfo/DWARF/DWARFDie.h
  unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp


Index: unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
===================================================================
--- unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
+++ unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
@@ -1227,6 +1227,10 @@
   EXPECT_THAT(std::vector<DWARFDie>(A.rbegin(), A.rend()),
               testing::ElementsAre(D, C, B));
 
+  // Make sure conversion from reverse iterator works as expected.
+  EXPECT_EQ(A.rbegin().base(), A.end());
+  EXPECT_EQ(A.rend().base(), A.begin());
+
   // Make sure iterator is bidirectional.
   {
     auto Begin = A.begin();
Index: include/llvm/DebugInfo/DWARF/DWARFDie.h
===================================================================
--- include/llvm/DebugInfo/DWARF/DWARFDie.h
+++ include/llvm/DebugInfo/DWARF/DWARFDie.h
@@ -404,6 +404,10 @@
       Die = Die.getPreviousSibling();
   }
 
+  llvm::DWARFDie::iterator base() const {
+    return llvm::DWARFDie::iterator(AtEnd ? Die : Die.getSibling());
+  }
+
   reverse_iterator<llvm::DWARFDie::iterator> &operator++() {
     assert(!AtEnd && "Incrementing rend");
     llvm::DWARFDie D = Die.getPreviousSibling();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53792.171419.patch
Type: text/x-patch
Size: 1139 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181028/f6d7cf4a/attachment.bin>


More information about the llvm-commits mailing list