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,15 +1316,19 @@ 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 // 2.17.3). 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()); + } else { + const auto &E = TheCU.getRanges().front(); + U.setBaseAddress(E.Begin); + U.attachLowHighPC(U.getUnitDie(), E.Begin, E.End); + } } // We don't keep track of which addresses are used in which CU so this diff --git a/llvm/test/DebugInfo/NVPTX/cu-range-hole.ll b/llvm/test/DebugInfo/NVPTX/cu-range-hole.ll --- a/llvm/test/DebugInfo/NVPTX/cu-range-hole.ll +++ b/llvm/test/DebugInfo/NVPTX/cu-range-hole.ll @@ -89,8 +89,6 @@ ; CHECK-NEXT: .b8 8 // DW_FORM_string ; CHECK-NEXT: .b8 17 // DW_AT_low_pc ; CHECK-NEXT: .b8 1 // DW_FORM_addr -; CHECK-NEXT: .b8 18 // DW_AT_high_pc -; CHECK-NEXT: .b8 1 // DW_FORM_addr ; CHECK-NEXT: .b8 0 // EOM(1) ; CHECK-NEXT: .b8 0 // EOM(2) ; CHECK-NEXT: .b8 2 // Abbreviation Code @@ -144,12 +142,12 @@ ; CHECK-NEXT: } ; CHECK-NEXT: .section .debug_info ; CHECK-NEXT: { -; CHECK-NEXT: .b32 183 // Length of Unit +; CHECK-NEXT: .b32 175 // Length of Unit ; CHECK-NEXT: .b8 2 // DWARF version number ; CHECK-NEXT: .b8 0 ; CHECK-NEXT: .b32 .debug_abbrev // Offset Into Abbrev. Section ; CHECK-NEXT: .b8 8 // Address Size (in bytes) -; CHECK-NEXT: .b8 1 // Abbrev [1] 0xb:0xb0 DW_TAG_compile_unit +; CHECK-NEXT: .b8 1 // Abbrev [1] 0xb:0xa8 DW_TAG_compile_unit ; CHECK-NEXT: .b8 99 // DW_AT_producer ; CHECK-NEXT: .b8 108 ; CHECK-NEXT: .b8 97 @@ -220,9 +218,8 @@ ; CHECK-NEXT: .b8 99 ; CHECK-NEXT: .b8 101 ; CHECK-NEXT: .b8 0 -; CHECK-NEXT: .b64 Lfunc_begin0 // DW_AT_low_pc -; CHECK-NEXT: .b64 Lfunc_end2 // DW_AT_high_pc -; CHECK-NEXT: .b8 2 // Abbrev [2] 0x65:0x27 DW_TAG_subprogram +; CHECK-NEXT: .b64 0 // DW_AT_low_pc +; CHECK-NEXT: .b8 2 // Abbrev [2] 0x5d:0x27 DW_TAG_subprogram ; CHECK-NEXT: .b64 Lfunc_begin0 // DW_AT_low_pc ; CHECK-NEXT: .b64 Lfunc_end0 // DW_AT_high_pc ; CHECK-NEXT: .b8 1 // DW_AT_frame_base @@ -232,16 +229,16 @@ ; CHECK-NEXT: .b8 1 // DW_AT_decl_file ; CHECK-NEXT: .b8 1 // DW_AT_decl_line ; CHECK-NEXT: .b8 1 // DW_AT_prototyped -; CHECK-NEXT: .b32 179 // DW_AT_type +; CHECK-NEXT: .b32 171 // DW_AT_type ; CHECK-NEXT: .b8 1 // DW_AT_external -; CHECK-NEXT: .b8 3 // Abbrev [3] 0x82:0x9 DW_TAG_formal_parameter +; CHECK-NEXT: .b8 3 // Abbrev [3] 0x7a:0x9 DW_TAG_formal_parameter ; CHECK-NEXT: .b8 99 // DW_AT_name ; CHECK-NEXT: .b8 0 ; CHECK-NEXT: .b8 1 // DW_AT_decl_file ; CHECK-NEXT: .b8 1 // DW_AT_decl_line -; CHECK-NEXT: .b32 179 // DW_AT_type +; CHECK-NEXT: .b32 171 // DW_AT_type ; CHECK-NEXT: .b8 0 // End Of Children Mark -; CHECK-NEXT: .b8 2 // Abbrev [2] 0x8c:0x27 DW_TAG_subprogram +; CHECK-NEXT: .b8 2 // Abbrev [2] 0x84:0x27 DW_TAG_subprogram ; CHECK-NEXT: .b64 Lfunc_begin2 // DW_AT_low_pc ; CHECK-NEXT: .b64 Lfunc_end2 // DW_AT_high_pc ; CHECK-NEXT: .b8 1 // DW_AT_frame_base @@ -251,16 +248,16 @@ ; CHECK-NEXT: .b8 1 // DW_AT_decl_file ; CHECK-NEXT: .b8 3 // DW_AT_decl_line ; CHECK-NEXT: .b8 1 // DW_AT_prototyped -; CHECK-NEXT: .b32 179 // DW_AT_type +; CHECK-NEXT: .b32 171 // DW_AT_type ; CHECK-NEXT: .b8 1 // DW_AT_external -; CHECK-NEXT: .b8 3 // Abbrev [3] 0xa9:0x9 DW_TAG_formal_parameter +; CHECK-NEXT: .b8 3 // Abbrev [3] 0xa1:0x9 DW_TAG_formal_parameter ; CHECK-NEXT: .b8 101 // DW_AT_name ; CHECK-NEXT: .b8 0 ; CHECK-NEXT: .b8 1 // DW_AT_decl_file ; CHECK-NEXT: .b8 3 // DW_AT_decl_line -; CHECK-NEXT: .b32 179 // DW_AT_type +; CHECK-NEXT: .b32 171 // DW_AT_type ; CHECK-NEXT: .b8 0 // End Of Children Mark -; CHECK-NEXT: .b8 4 // Abbrev [4] 0xb3:0x7 DW_TAG_base_type +; CHECK-NEXT: .b8 4 // Abbrev [4] 0xab:0x7 DW_TAG_base_type ; CHECK-NEXT: .b8 105 // DW_AT_name ; CHECK-NEXT: .b8 110 ; CHECK-NEXT: .b8 116 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