Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1180,6 +1180,18 @@ LLVM_DEBUG(dbgs() << "DotDebugLoc: " << *Begin << "\n"); auto Value = getDebugLocValue(Begin); + + // Omit entries with empty ranges as they do not have any effect in DWARF. + if (StartLabel == EndLabel) { + // If this is a fragment, we must still add the value to the list of + // open ranges, since it may describe non-overlapping parts of the + // variable. + if (DIExpr->isFragment()) + OpenRanges.push_back(Value); + LLVM_DEBUG(dbgs() << "Omitting location list entry with empty range.\n"); + continue; + } + DebugLocEntry Loc(StartLabel, EndLabel, Value); bool couldMerge = false; @@ -1918,6 +1930,7 @@ void DebugLocEntry::finalize(const AsmPrinter &AP, DebugLocStream::ListBuilder &List, const DIBasicType *BT) { + assert(Begin != End && "unexpected location list entry with empty range"); DebugLocStream::EntryBuilder Entry(List, Begin, End); BufferByteStreamer Streamer = Entry.getStreamer(); DebugLocDwarfExpression DwarfExpr(AP.getDwarfVersion(), Streamer); Index: llvm/trunk/test/DebugInfo/ARM/PR26163.ll =================================================================== --- llvm/trunk/test/DebugInfo/ARM/PR26163.ll +++ llvm/trunk/test/DebugInfo/ARM/PR26163.ll @@ -1,16 +1,17 @@ ; RUN: llc -filetype=obj -o - < %s | llvm-dwarfdump -v -debug-info - | FileCheck %s ; -; Checks that we're creating two ranges, one that terminates immediately -; and one that spans the rest of the function. This isn't necessarily the -; best thing to do here (and also not necessarily correct, since the first -; one has a bit_piece), but it is what is currently being emitted, any -; change here needs to be intentional, so the test is very specific. +; Checks that we're omitting the first range, as it is empty, and that we're +; emitting one that spans the rest of the function. In this case, the first +; range, which we omit, describes 8 bytes of the variable using DW_OP_litX, +; whereas the second one only describes 4 bytes, so clobbering the whole 8 byte +; fragment with the 4 bytes fragment isn't necessarily best thing to do here, +; but it is what is currently being emitted. Any change here needs to be +; intentional, so the test is very specific. ; ; CHECK: DW_TAG_inlined_subroutine ; CHECK: DW_TAG_variable ; CHECK: DW_AT_location [DW_FORM_sec_offset] ({{.*}} -; CHECK: [0x00000004, 0x00000004): DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x8 -; CHECK: [0x00000004, 0x00000014): DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x4) +; CHECK-NEXT: [0x00000004, 0x00000014): DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x4) ; Created form the following test case (PR26163) with ; clang -cc1 -triple armv4t--freebsd11.0-gnueabi -emit-obj -debug-info-kind=standalone -O2 -x c test.c Index: llvm/trunk/test/DebugInfo/X86/PR26148.ll =================================================================== --- llvm/trunk/test/DebugInfo/X86/PR26148.ll +++ llvm/trunk/test/DebugInfo/X86/PR26148.ll @@ -16,11 +16,10 @@ ; This is similar to the bug in test/DebugInfo/ARM/PR26163.ll, except that there is an ; extra non-overlapping range first. Thus, we make sure that the backend actually looks ; at all expressions when determining whether to merge ranges, not just the first one. -; AS in 26163, we expect two ranges (as opposed to one), the first one being zero sized +; AS in 26163, we only expect one range as the first one is zero sized. ; ; -; CHECK: [0x0000000000000004, 0x0000000000000004): DW_OP_lit3, DW_OP_piece 0x4, DW_OP_reg5 RDI, DW_OP_piece 0x2 -; CHECK: [0x0000000000000004, 0x0000000000000014): DW_OP_lit3, DW_OP_piece 0x4, DW_OP_lit0, DW_OP_piece 0x4 +; CHECK: [0x0000000000000000, 0x000000000000000f): DW_OP_lit3, DW_OP_piece 0x4, DW_OP_lit0, DW_OP_piece 0x4 source_filename = "test/DebugInfo/X86/PR26148.ll" target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" @@ -35,11 +34,8 @@ ; Function Attrs: nounwind readnone declare void @llvm.dbg.value(metadata, metadata, metadata) #0 -; The attributes are here to force the zero-sized range not to be at the start of -; the function, which has special interpretation in DWARF. The fact that this happens -; at all is probably an LLVM bug. -define void @fn1(i16 signext %p1) #1 !dbg !16 { +define void @fn1(i16 signext %p1) !dbg !16 { entry: tail call void @llvm.dbg.value(metadata i16 %p1, metadata !20, metadata !23), !dbg !24 tail call void @llvm.dbg.declare(metadata %struct.S0* undef, metadata !21, metadata !23), !dbg !25 @@ -60,7 +56,6 @@ } attributes #0 = { nounwind readnone } -attributes #1 = { "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" } !llvm.dbg.cu = !{!2} !llvm.module.flags = !{!12, !13, !14} Index: llvm/trunk/test/DebugInfo/X86/pieces-3.ll =================================================================== --- llvm/trunk/test/DebugInfo/X86/pieces-3.ll +++ llvm/trunk/test/DebugInfo/X86/pieces-3.ll @@ -18,12 +18,10 @@ ; CHECK: DW_TAG_formal_parameter [3] ; CHECK-NEXT: DW_AT_location [DW_FORM_data4] ( ; CHECK-NEXT: [0x0000000000000000, 0x0000000000000007): DW_OP_reg5 RDI, DW_OP_piece 0x8, DW_OP_piece 0x4, DW_OP_reg4 RSI, DW_OP_piece 0x4 -; CHECK-NEXT: [0x0000000000000007, 0x0000000000000007): DW_OP_reg5 RDI, DW_OP_piece 0x8, DW_OP_piece 0x4, DW_OP_reg0 RAX, DW_OP_piece 0x4) ; CHECK-NEXT: DW_AT_name {{.*}}"outer" ; CHECK: DW_TAG_variable -; CHECK-NEXT: DW_AT_location [DW_FORM_data4] (0x00000044 -; CHECK-NEXT: [0x0000000000000007, 0x0000000000000007): DW_OP_reg0 RAX, DW_OP_piece 0x4) -; CHECK-NEXT: "i1" +; CHECK-NEXT: DW_AT_name {{.*}}"i1" +; CHECK-NOT: DW_AT_location ; ModuleID = '/Volumes/Data/llvm/test/DebugInfo/X86/sroasplit-2.ll' target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"