Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2732,30 +2732,25 @@ if (CUMap.empty()) return; - if (llvm::all_of(CUMap, [](const decltype(CUMap)::value_type &Pair) { - return Pair.second->getCUNode()->isDebugDirectivesOnly(); - })) - return; - - // Start the dwarf macinfo section. - Asm->OutStreamer->SwitchSection( - Asm->getObjFileLowering().getDwarfMacinfoSection()); - for (const auto &P : CUMap) { auto &TheCU = *P.second; if (TheCU.getCUNode()->isDebugDirectivesOnly()) continue; + auto *SkCU = TheCU.getSkeleton(); DwarfCompileUnit &U = SkCU ? *SkCU : TheCU; auto *CUNode = cast(P.first); DIMacroNodeArray Macros = CUNode->getMacros(); - if (!Macros.empty()) { - Asm->OutStreamer->EmitLabel(U.getMacroLabelBegin()); - handleMacroNodes(Macros, U); - } + if (Macros.empty()) + continue; + // Start the dwarf macinfo section. + Asm->OutStreamer->SwitchSection( + Asm->getObjFileLowering().getDwarfMacinfoSection()); + Asm->OutStreamer->EmitLabel(U.getMacroLabelBegin()); + handleMacroNodes(Macros, U); + Asm->OutStreamer->AddComment("End Of Macro List Mark"); + Asm->emitInt8(0); } - Asm->OutStreamer->AddComment("End Of Macro List Mark"); - Asm->emitInt8(0); } // DWARF5 Experimental Separate Dwarf emitters. Index: llvm/test/DebugInfo/X86/debug-macro.ll =================================================================== --- llvm/test/DebugInfo/X86/debug-macro.ll +++ llvm/test/DebugInfo/X86/debug-macro.ll @@ -9,7 +9,7 @@ ; CHECK: DW_TAG_compile_unit ; CHECK-NOT: DW_TAG ; CHECK: DW_AT_name {{.*}}"debug-macro1.cpp") -; CHECK: DW_AT_macro_info {{.*}}(0x00000044) +; CHECK: DW_AT_macro_info {{.*}}(0x00000045) ; CHECK: DW_TAG_compile_unit ; CHECK-NOT: DW_TAG ; CHECK: DW_AT_name {{.*}}"debug-macro2.cpp") @@ -24,8 +24,6 @@ ; CHECK-NEXT: DW_MACINFO_end_file ; CHECK-NEXT: DW_MACINFO_undef - lineno: 10 macro: NameUndef2 ; CHECK-NEXT: DW_MACINFO_end_file -; CHECK-NEXT: DW_MACINFO_start_file - lineno: 0 filenum: 1 -; CHECK-NEXT: DW_MACINFO_end_file ; CHECK-LABEL: .debug_line contents: ; CHECK: file_names[ 1]: Index: llvm/test/DebugInfo/X86/empty_macinfo.ll =================================================================== --- llvm/test/DebugInfo/X86/empty_macinfo.ll +++ llvm/test/DebugInfo/X86/empty_macinfo.ll @@ -2,9 +2,7 @@ ; Test that we don't pollute the start of the file with debug sections -; CHECK: .section .debug_macinfo,"",@progbits -; CHECK-NEXT: .byte 0 # End Of Macro List Mark -; CHECK-NEXT: .section +; CHECK-NOT: .section .debug_macinfo,"",@progbits ; CHECK-NOT: .debug_macinfo define void @f() !dbg !4 { Index: llvm/test/DebugInfo/X86/length_symbol_difference.ll =================================================================== --- llvm/test/DebugInfo/X86/length_symbol_difference.ll +++ llvm/test/DebugInfo/X86/length_symbol_difference.ll @@ -1,11 +1,11 @@ -; RUN: llc -filetype=asm -O0 -mtriple=x86_64-linux-gnu < %s | FileCheck %s +; RUN: llc -dwarf-version 4 -filetype=asm -O0 -mtriple=x86_64-linux-gnu < %s | FileCheck %s ; CHECK: .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit ; CHECK-NEXT: .Ldebug_info_start0: ; CHECK-NOT: .byte 0 ; CHECK: .byte 0 # End Of Children Mark ; CHECK-NEXT: .Ldebug_info_end0: -; CHECK-NEXT: .section +; CHECK-NOT: .section .debug_macinfo define dso_local void @_Z2f1v() !dbg !7 {