Index: llvm/include/llvm/CodeGen/LexicalScopes.h =================================================================== --- llvm/include/llvm/CodeGen/LexicalScopes.h +++ llvm/include/llvm/CodeGen/LexicalScopes.h @@ -25,6 +25,8 @@ #include #include +extern llvm::cl::optUnknownLocations; + namespace llvm { class MachineBasicBlock; Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -83,15 +83,9 @@ "split-dwarf-cross-cu-references", cl::Hidden, cl::desc("Enable cross-cu references in DWO files"), cl::init(false)); +//FIXME:Generalize DefaultOnOff by replacing it with boolOrDefault enum DefaultOnOff { Default, Enable, Disable }; -static cl::opt UnknownLocations( - "use-unknown-locations", cl::Hidden, - cl::desc("Make an absence of debug location information explicit."), - cl::values(clEnumVal(Default, "At top of block or after label"), - clEnumVal(Enable, "In all cases"), clEnumVal(Disable, "Never")), - cl::init(Default)); - static cl::opt AccelTables( "accel-tables", cl::Hidden, cl::desc("Output dwarf accelerator tables."), cl::values(clEnumValN(AccelTableKind::Default, "Default", @@ -2066,7 +2060,7 @@ if (LastAsmLine == 0) return; // If user said Don't Do That, don't do that. - if (UnknownLocations == Disable) + if (UnknownLocations == cl::BOU_FALSE) return; // See if we have a reason to emit a line-0 record now. // Reasons to emit a line-0 record include: @@ -2075,7 +2069,7 @@ // possibly debug information; we want it to have a source location. // - Instruction is at the top of a block; we don't want to inherit the // location from the physically previous (maybe unrelated) block. - if (UnknownLocations == Enable || PrevLabel || + if (UnknownLocations == cl::BOU_TRUE || PrevLabel || (PrevInstBB && PrevInstBB != MI->getParent())) { // Preserve the file and column numbers, if we can, to save space in // the encoded line table. Index: llvm/lib/CodeGen/LexicalScopes.cpp =================================================================== --- llvm/lib/CodeGen/LexicalScopes.cpp +++ llvm/lib/CodeGen/LexicalScopes.cpp @@ -36,6 +36,11 @@ #define DEBUG_TYPE "lexicalscopes" +cl::opt UnknownLocations( + "use-unknown-locations", cl::Hidden, + cl::desc("Make an absence of debug location information explicit."), + cl::init(cl::BOU_UNSET)); + /// reset - Reset the instance so that it's prepared for another function. void LexicalScopes::reset() { MF = nullptr; @@ -93,7 +98,8 @@ continue; } - if (RangeBeginMI) { + if (RangeBeginMI && + (MIDL->getLine() != 0 || UnknownLocations == cl::BOU_TRUE)) { // If we have already seen a beginning of an instruction range and // current instruction scope does not match scope of first instruction // in this range then create a new instruction range. Index: llvm/test/CodeGen/X86/dbg-line-0-no-discriminator.ll =================================================================== --- llvm/test/CodeGen/X86/dbg-line-0-no-discriminator.ll +++ llvm/test/CodeGen/X86/dbg-line-0-no-discriminator.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj -use-unknown-locations=Enable -mtriple=x86_64-unknown-linux %s -o %t +; RUN: llc -filetype=obj -use-unknown-locations=true -mtriple=x86_64-unknown-linux %s -o %t ; RUN: llvm-dwarfdump -debug-line %t | FileCheck %s define void @_Z3bazv() !dbg !6 { Index: llvm/test/CodeGen/X86/unknown-location.ll =================================================================== --- llvm/test/CodeGen/X86/unknown-location.ll +++ llvm/test/CodeGen/X86/unknown-location.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -asm-verbose=false -mtriple=x86_64-apple-darwin10 -use-unknown-locations=Enable | FileCheck %s +; RUN: llc < %s -asm-verbose=false -mtriple=x86_64-apple-darwin10 -use-unknown-locations=true | FileCheck %s ; The divide instruction does not have a debug location. CodeGen should ; represent this in the debug information. This is done by setting line to 0. Index: llvm/test/DebugInfo/MIR/X86/no-cfi-loc.mir =================================================================== --- llvm/test/DebugInfo/MIR/X86/no-cfi-loc.mir +++ llvm/test/DebugInfo/MIR/X86/no-cfi-loc.mir @@ -1,6 +1,6 @@ # Verify that a CFI instruction with no debug location # does not result in a line-0 location in the assembler. -# RUN: %llc_dwarf -start-after=prologepilog -march=x86-64 -use-unknown-locations=Enable %s -o - | FileCheck %s +# RUN: %llc_dwarf -start-after=prologepilog -march=x86-64 -use-unknown-locations=true %s -o - | FileCheck %s # # CHECK-NOT: .loc 1 0 # CHECK: .cfi_def_cfa_offset Index: llvm/test/DebugInfo/X86/contiguous-lexical-block.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/contiguous-lexical-block.ll @@ -0,0 +1,70 @@ +; This test verifies that the lexical block remains contiguous and is not split by runtime instructions with a line number of 0. + +; RUN: llc -filetype=obj --use-unknown-locations=true %s -o - \ +; RUN: | llvm-dwarfdump --debug-info - \ +; RUN: | FileCheck %s --check-prefixes=CHECK,ENABLE +; RUN: llc -filetype=obj --use-unknown-locations=false %s -o - \ +; RUN: | llvm-dwarfdump --debug-info - \ +; RUN: | FileCheck %s --check-prefixes=CHECK,DISABLE + +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("test") +; CHECK-NOT: NULL + +; CHECK: DW_TAG_lexical_block +; ENABLE: DW_AT_ranges (0x{{[0-9a-f]+}} +; ENABLE: [0x{{[0-9a-f]+}}, 0x{{[0-9a-f]+}}) +; ENABLE: [0x{{[0-9a-f]+}}, 0x{{[0-9a-f]+}}) +; ENABLE: [0x{{[0-9a-f]+}}, 0x{{[0-9a-f]+}}) +; ENABLE: [0x{{[0-9a-f]+}}, 0x{{[0-9a-f]+}})) + +; DISABLE-NOT: DW_AT_ranges +; DISABLE: DW_AT_low_pc (0x{{[0-9a-f]+}}) +; DISABLE: DW_AT_high_pc (0x{{[0-9a-f]+}}) + +; ModuleID = 'contiguous-lexical-block.ll' +source_filename = "test.c" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-linux" + +; Function Attrs: convergent noinline nounwind optnone +define i32 @test(i32 %0) #0 !dbg !5 { +entry: + %1 = add nsw i32 %0, 1, !dbg !14 + %2 = add nsw i32 %1, 1, !dbg !15 + %3 = add nsw i32 %2, 1, !dbg !17 + %4 = add nsw i32 %3, 1, !dbg !15 + %5 = add nsw i32 %4, 1, !dbg !21 + %6 = add nsw i32 %5, 1, !dbg !15 + %7 = add nsw i32 %6, 1, !dbg !22 + ret i32 %7 +} + +attributes #0 = { convergent noinline nounwind optnone } + +!llvm.module.flags = !{!0, !1} +!llvm.dbg.cu = !{!2} + +!0 = !{i32 7, !"Dwarf Version", i32 4} +!1 = !{i32 2, !"Debug Info Version", i32 3} +!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4) +!3 = !DIFile(filename: "test.c", directory: "/path/to") +!4 = !{} +!5 = distinct !DISubprogram(name: "test", scope: null, file: !3, line: 34, type: !6, scopeLine: 34, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagMainSubprogram, unit: !2, templateParams: !4, retainedNodes: !8) +!6 = !DISubroutineType(types: !7) +!7 = !{null} +!8 = !{!9} +!9 = !DILocalVariable(name: "i", scope: !10, file: !3, line: 17, type: !13) +!10 = distinct !DILexicalBlock(scope: !11, file: !3, line: 34, column: 1) +!11 = distinct !DILexicalBlock(scope: !12, file: !3, line: 30, column: 3) +!12 = distinct !DILexicalBlock(scope: !5, file: !3, line: 29, column: 1) +!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!14 = !DILocation(line: 34, column: 1, scope: !10) +!15 = !DILocation(line: 0, scope: !16) +!16 = !DILexicalBlockFile(scope: !5, file: !3, discriminator: 0) +!17 = !DILocation(line: 36, column: 21, scope: !18) +!18 = distinct !DILexicalBlock(scope: !19, file: !3, line: 36, column: 7) +!19 = distinct !DILexicalBlock(scope: !20, file: !3, line: 36, column: 7) +!20 = distinct !DILexicalBlock(scope: !10, file: !3, line: 35, column: 5) +!21 = !DILocation(line: 37, column: 23, scope: !18) +!22 = !DILocation(line: 36, column: 27, scope: !18) Index: llvm/test/DebugInfo/X86/dwarf-no-source-loc.ll =================================================================== --- llvm/test/DebugInfo/X86/dwarf-no-source-loc.ll +++ llvm/test/DebugInfo/X86/dwarf-no-source-loc.ll @@ -1,7 +1,7 @@ ; Verify "no source location" directives appear in appropriate places, ; but don't appear when we explicitly suppress them. ; RUN: llc < %s -o - | FileCheck %s -; RUN: llc < %s -o - -use-unknown-locations=Disable | FileCheck %s --check-prefix=DISABLE +; RUN: llc < %s -o - -use-unknown-locations=false | FileCheck %s --check-prefix=DISABLE ; Generated from this .cpp targeting linux using -g ; and then removed function attributes as clutter. Index: llvm/test/DebugInfo/X86/tail-merge.ll =================================================================== --- llvm/test/DebugInfo/X86/tail-merge.ll +++ llvm/test/DebugInfo/X86/tail-merge.ll @@ -1,4 +1,4 @@ -; RUN: llc %s -mtriple=x86_64-unknown-unknown -use-unknown-locations=Enable -o - | FileCheck %s +; RUN: llc %s -mtriple=x86_64-unknown-unknown -use-unknown-locations=true -o - | FileCheck %s ; Generated with "clang -gline-tables-only -c -emit-llvm -o - | opt -passes=sroa -S" ; from source: