Index: llvm/test/tools/dsymutil/X86/empty-CU.test =================================================================== --- llvm/test/tools/dsymutil/X86/empty-CU.test +++ llvm/test/tools/dsymutil/X86/empty-CU.test @@ -1,7 +1,4 @@ -RUN: dsymutil --update -f %p/../Inputs/empty-CU.o -o - | llvm-dwarfdump -v - -debug-info | FileCheck %s +RUN: dsymutil --update -f %p/../Inputs/empty-CU.o -verify -o - | llvm-dwarfdump -v - -debug-info | FileCheck %s CHECK: .debug_info contents: -CHECK: 0x00000000: Compile Unit: length = 0x00000008 version = 0x0003 abbr_offset = 0x0000 addr_size = 0x04 (next unit at 0x0000000c) - -CHECK: 0x0000000b: DW_TAG_compile_unit [1] -CHECK: 0x0000000c: Compile Unit: length = 0x00000007 version = 0x0003 abbr_offset = 0x0000 addr_size = 0x04 (next unit at 0x00000017) +CHECK-NOT: Compile Unit Index: llvm/tools/dsymutil/CompileUnit.h =================================================================== --- llvm/tools/dsymutil/CompileUnit.h +++ llvm/tools/dsymutil/CompileUnit.h @@ -112,6 +112,13 @@ return nullptr; } + operator bool() const { + auto UnitDIE = getOrigUnit().getUnitDIE(); + if (UnitDIE) + return UnitDIE.hasChildren(); + return false; + } + bool hasODR() const { return HasODR; } bool isClangModule() const { return !ClangModuleName.empty(); } const std::string &getClangModuleName() const { return ClangModuleName; } Index: llvm/tools/dsymutil/DwarfLinker.cpp =================================================================== --- llvm/tools/dsymutil/DwarfLinker.cpp +++ llvm/tools/dsymutil/DwarfLinker.cpp @@ -2208,8 +2208,7 @@ Unit->markEverythingAsKept(); } } - if (!Unit->getOrigUnit().getUnitDIE().hasChildren()) - return Error::success(); + if (!Quiet && Options.Verbose) { outs().indent(Indent); outs() << "cloning .debug_info from " << Filename << "\n"; @@ -2229,6 +2228,9 @@ return; for (auto &CurrentUnit : CompileUnits) { + if (!*CurrentUnit) + continue; + auto InputDIE = CurrentUnit->getOrigUnit().getUnitDIE(); CurrentUnit->setStartOffset(Linker.OutputDebugInfoSize); if (!InputDIE) { @@ -2263,6 +2265,9 @@ // Emit all the compile unit's debug information. for (auto &CurrentUnit : CompileUnits) { + if (!*CurrentUnit) + continue; + if (LLVM_LIKELY(!Linker.Options.Update)) Linker.generateUnitRanges(*CurrentUnit); CurrentUnit->fixupForwardReferences();