diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2757,6 +2757,11 @@ if (CUMap.empty()) return; + if (llvm::all_of(CUMap, [](const decltype(CUMap)::value_type &Pair) { + return Pair.second->getCUNode()->getMacros().empty(); + })) + return; + if (llvm::all_of(CUMap, [](const decltype(CUMap)::value_type &Pair) { return Pair.second->getCUNode()->isDebugDirectivesOnly(); })) diff --git a/llvm/test/DebugInfo/X86/empty_macinfo.ll b/llvm/test/DebugInfo/X86/empty_macinfo.ll --- a/llvm/test/DebugInfo/X86/empty_macinfo.ll +++ b/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 { diff --git a/llvm/test/DebugInfo/X86/length_symbol_difference.ll b/llvm/test/DebugInfo/X86/length_symbol_difference.ll --- a/llvm/test/DebugInfo/X86/length_symbol_difference.ll +++ b/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 {