[PATCH] D128294: [ADT] [lld-macho] Check for end iterator deref in filter_iterator_base

Daniel Bertalan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 12:11:23 PDT 2022


BertalanD updated this revision to Diff 438792.
BertalanD added a comment.
This revision is now accepted and ready to land.

Third time's the charm (hopefully)

added missing REQUIRES and switched to `-o /dev/null`

Thank you for all the suggestions.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128294/new/

https://reviews.llvm.org/D128294

Files:
  lld/MachO/InputFiles.cpp
  lld/test/MachO/dwarf-no-compile-unit.s
  llvm/include/llvm/ADT/STLExtras.h


Index: llvm/include/llvm/ADT/STLExtras.h
===================================================================
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -444,6 +444,16 @@
     findNextValid();
     return *this;
   }
+
+  decltype(auto) operator*() const {
+    assert(BaseT::wrapped() != End && "Cannot dereference end iterator!");
+    return BaseT::operator*();
+  }
+
+  decltype(auto) operator->() const {
+    assert(BaseT::wrapped() != End && "Cannot dereference end iterator!");
+    return BaseT::operator->();
+  }
 };
 
 /// Specialization of filter_iterator_base for forward iteration only.
Index: lld/test/MachO/dwarf-no-compile-unit.s
===================================================================
--- /dev/null
+++ lld/test/MachO/dwarf-no-compile-unit.s
@@ -0,0 +1,15 @@
+# REQUIRES: aarch64
+
+## Check that LLD does not crash if it encounters DWARF sections
+## without __debug_info compile unit DIEs being present.
+
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t.o
+# RUN: %lld -arch arm64 %t.o -o /dev/null
+
+.text
+.globl _main
+_main:
+  ret
+
+.section  __DWARF,__debug_abbrev,regular,debug
+  .byte 0
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -1013,7 +1013,7 @@
   // FIXME: There can be more than one compile unit per object file. See
   // PR48637.
   auto it = units.begin();
-  compileUnit = it->get();
+  compileUnit = it != units.end() ? it->get() : nullptr;
 }
 
 ArrayRef<data_in_code_entry> ObjFile::getDataInCode() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128294.438792.patch
Type: text/x-patch
Size: 1636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220621/2b1ba6fd/attachment.bin>


More information about the llvm-commits mailing list