diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -558,11 +558,10 @@ void DwarfCompileUnit::attachRangesOrLowHighPC( DIE &Die, SmallVector Ranges) { - if (Ranges.size() == 1 || !DD->useRangesSection()) { + if (Ranges.size() == 1) { const RangeSpan &Front = Ranges.front(); - const RangeSpan &Back = Ranges.back(); - attachLowHighPC(Die, Front.Begin, Back.End); - } else + attachLowHighPC(Die, Front.Begin, Front.End); + } else if (DD->useRangesSection()) addScopeRangeList(Die, std::move(Ranges)); } 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 @@ -1316,7 +1316,7 @@ DwarfCompileUnit &U = SkCU ? *SkCU : TheCU; if (unsigned NumRanges = TheCU.getRanges().size()) { - if (NumRanges > 1 && useRangesSection()) + if (NumRanges > 1) // A DW_AT_low_pc attribute may also be specified in combination with // DW_AT_ranges to specify the default base address for use in // location lists (see Section 2.6.2) and range lists (see Section @@ -1324,7 +1324,8 @@ U.addUInt(U.getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0); else U.setBaseAddress(TheCU.getRanges().front().Begin); - U.attachRangesOrLowHighPC(U.getUnitDie(), TheCU.takeRanges()); + if (useRangesSection()) + U.attachRangesOrLowHighPC(U.getUnitDie(), TheCU.takeRanges()); } // We don't keep track of which addresses are used in which CU so this diff --git a/llvm/test/DebugInfo/X86/no_debug_ranges.ll b/llvm/test/DebugInfo/X86/no_debug_ranges.ll --- a/llvm/test/DebugInfo/X86/no_debug_ranges.ll +++ b/llvm/test/DebugInfo/X86/no_debug_ranges.ll @@ -1,12 +1,17 @@ -; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu < %s -o - -dwarf-version=2 -no-dwarf-ranges-section | FileCheck %s --check-prefix=DISABLED +; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu < %s -o - -dwarf-version=2 -no-dwarf-ranges-section \ +; RUN: | FileCheck %s --check-prefix=DISABLED "--implicit-check-not={{DW_AT_ranges|.debug_ranges}}" ; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu < %s -o - -dwarf-version=2 | FileCheck %s -; DISABLED-NOT: {{DW_AT_ranges|.debug_ranges}} -; DISABLED: .section .debug_info -; DISABLED-NOT: {{DW_AT_ranges|.section}} -; DISABLED: .quad .Lfunc_begin0 # DW_AT_low_pc +; DISABLED: .section .debug_info +; DISABLED-NOT: {{DW_AT_low_pc|DW_AT_high_pc}} +; DISABLED: .quad 0 # DW_AT_low_pc +; DISABLED-NOT: {{DW_AT_low_pc|DW_AT_high_pc}} +; DISABLED: .quad .Lfunc_begin0 # DW_AT_low_pc +; DISABLED-NEXT: .quad .Lfunc_end0 # DW_AT_high_pc +; DISABLED-NOT: {{DW_AT_low_pc|DW_AT_high_pc}} +; DISABLED: .quad .Lfunc_begin1 # DW_AT_low_pc ; DISABLED-NEXT: .quad .Lfunc_end1 # DW_AT_high_pc -; DISABLED-NOT: {{DW_AT_ranges|.debug_ranges}} +; DISABLED-NOT: {{DW_AT_low_pc|DW_AT_high_pc}} ; .debug_ranges section must be emitted by default ; CHECK: .section .debug_info