diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -869,6 +869,8 @@ Offset = Header.getNextUnitOffset(); } }); + if (Map.empty()) + return; for (DWARFUnitIndex::Entry &E : Index.getMutableRows()) { if (!E.isValid()) continue; diff --git a/llvm/test/DebugInfo/X86/dwp-v5-tu-index.s b/llvm/test/DebugInfo/X86/dwp-v5-tu-index.s --- a/llvm/test/DebugInfo/X86/dwp-v5-tu-index.s +++ b/llvm/test/DebugInfo/X86/dwp-v5-tu-index.s @@ -2,8 +2,8 @@ ## compliant to the DWARFv5 standard. # RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o - | \ -# RUN: llvm-dwarfdump -debug-tu-index - | \ -# RUN: FileCheck %s +# RUN: llvm-dwarfdump -debug-tu-index - 2>&1 | \ +# RUN: FileCheck %s --implicit-check-not "could not find unit with signature" # CHECK: .debug_tu_index contents: # CHECK-NEXT: version = 5, units = 1, slots = 2