[PATCH] D82139: [DWARFYAML][debug_info] Fix array index out of bounds error. NFC.

Xing GUO via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 19 04:49:26 PDT 2020


Higuoxing updated this revision to Diff 272012.
Higuoxing added a comment.
Herald added a subscriber: emaste.
Herald added a reviewer: espindola.

Add one test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82139

Files:
  llvm/lib/ObjectYAML/DWARFVisitor.cpp
  llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml


Index: llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
===================================================================
--- llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
+++ llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
@@ -548,3 +548,29 @@
       Entries:
         - AbbrCode: 0
           Values:   []
+
+## h) Test that yaml2obj doesn't crash when the 'Entries' of a compilation unit is empty.
+
+# RUN: yaml2obj --docnum=8 %s -o %t8.o
+# RUN: llvm-readelf --hex-dump=.debug_info %t8.o | FileCheck %s --check-prefix=EMPTY-ENTRIES
+
+#       EMPTY-ENTRIES: Hex dump of section '.debug_info':
+#  EMPTY-ENTRIES-NEXT: 0x00000000 34120000 05000204 34120000
+# EMPTY-ENTRIES-EMPTY:
+##                                ^- 'Entries' is empty
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+DWARF:
+  debug_info:
+    - Length:
+        TotalLength: 0x1234
+      Version:    5
+      UnitType:   DW_UT_type
+      AbbrOffset: 0x1234
+      AddrSize:   4
+      Entries:    []
Index: llvm/lib/ObjectYAML/DWARFVisitor.cpp
===================================================================
--- llvm/lib/ObjectYAML/DWARFVisitor.cpp
+++ llvm/lib/ObjectYAML/DWARFVisitor.cpp
@@ -46,6 +46,8 @@
 template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
   for (auto &Unit : DebugInfo.CompileUnits) {
     onStartCompileUnit(Unit);
+    if (Unit.Entries.size() == 0)
+      continue;
     auto FirstAbbrevCode = Unit.Entries[0].AbbrCode;
 
     for (auto &Entry : Unit.Entries) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82139.272012.patch
Type: text/x-patch
Size: 1569 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200619/50bb0467/attachment.bin>


More information about the llvm-commits mailing list