[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:01:43 PDT 2022
BertalanD updated this revision to Diff 438791.
BertalanD added a comment.
Call `llvm-mc` directly and remove unnecessary parentheses.
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,13 @@
+## 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 -o %t.dylib %t.o
+
+.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.438791.patch
Type: text/x-patch
Size: 1611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220621/81006a50/attachment.bin>
More information about the llvm-commits
mailing list