Skip to content

Commit

Permalink
Do not emit prologue_end for line 0 locs if there is a non-zero loc p…
Browse files Browse the repository at this point in the history
…resent

This change fixes a bug where the compiler generates a prologue_end
for line 0 locs. That is because line 0 is not associated with any
source location, so there should not be a prolgoue_end at a location
that doesn't correspond to a source location.

There were some LLVM tests that were explicitly checking for line 0
prologue_end's as well since I believe that to be incorrect, I had to
change those tests as well.

Patch by Shubham Rastogi!

Differential Revision: https://reviews.llvm.org/D110740
  • Loading branch information
adrian-prantl committed Oct 7, 2021
1 parent 4651576 commit 9f93f2b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 deletions.
20 changes: 15 additions & 5 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Expand Up @@ -2087,12 +2087,22 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {
// First known non-DBG_VALUE and non-frame setup location marks
// the beginning of the function body.
for (const auto &MBB : *MF)
for (const auto &MI : MBB)
DebugLoc LineZeroLoc;
for (const auto &MBB : *MF) {
for (const auto &MI : MBB) {
if (!MI.isMetaInstruction() && !MI.getFlag(MachineInstr::FrameSetup) &&
MI.getDebugLoc())
return MI.getDebugLoc();
return DebugLoc();
MI.getDebugLoc()) {
// Scan forward to try to find a non-zero line number. The prologue_end
// marks the first breakpoint in the function after the frame setup, and
// a compiler-generated line 0 location is not a meaningful breakpoint.
// If none is found, return the first location after the frame setup.
if (MI.getDebugLoc().getLine())
return MI.getDebugLoc();
LineZeroLoc = MI.getDebugLoc();
}
}
}
return LineZeroLoc;
}

/// Register a source line with debug info. Returns the unique label that was
Expand Down
25 changes: 25 additions & 0 deletions llvm/test/CodeGen/X86/line-zero-prologue-end.ll
@@ -0,0 +1,25 @@
; RUN: llc -filetype=asm -mtriple=x86_64-apple-macosx12.0.0 -O0 %s -o - | FileCheck %s
; CHECK: Lfunc_begin0:
; CHECK-NEXT: .file{{.+}}
; CHECK-NEXT: .loc 1 2 0 ## test/test.c:2:0{{$}}
; CHECK-NEXT: .cfi_startproc
; CHECK-NEXT: ## %bb.{{[0-9]+}}:
; CHECK-NEXT: .loc 1 0 5 {{is_stmt [0-9]+}} ## test/test.c:0:5{{$}}
@x = common global i32 0, align 4
define void @test() #0 !dbg !9 {
store i32 1, i32* @x, align 4, !dbg !12
ret void, !dbg !14
}
!llvm.module.flags = !{!0,!2,!4}
!llvm.dbg.cu = !{!5}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 12, i32 0]}
!2 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 7, !"PIC Level", i32 2}
!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "Apple clang version 13.0.0 (clang-1300.0.29.3)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !7, nameTableKind: None, sysroot: "/Library/Developer/CommandLineTools/SDKs/MacOSX12.0.sdk", sdk: "MacOSX12.0.sdk")
!6 = !DIFile(filename: "/Users/shubham/Development/test/test.c", directory: "/Users/shubham/Development/deltaTest")
!7 = !{}
!9 = distinct !DISubprogram(name: "test", scope: !10, file: !10, line: 2, type: !11, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !7)
!10 = !DIFile(filename: "test/test.c", directory: "/Users/shubham/Development")
!11 = !DISubroutineType(types: !7)
!12 = !DILocation(line: 0, column: 5, scope: !9)
!14 = !DILocation(line: 3, column: 1, scope: !9)
22 changes: 22 additions & 0 deletions llvm/test/CodeGen/X86/no-non-zero-debug-loc-prologue.ll
@@ -0,0 +1,22 @@
; RUN: llc -filetype=asm -mtriple=x86_64-apple-macosx12.0.0 -O0 %s -o - | FileCheck %s
; CHECK: Lfunc_begin0:
; CHECK-NEXT: .file{{.+}}
; CHECK-NEXT: .loc 1 1 0 ## test-small.c:1:0{{$}}
; CHECK-NEXT: .cfi_startproc
; CHECK-NEXT: ## %bb.{{[0-9]+}}:
; CHECK-NEXT: .loc 1 0 1 prologue_end{{.*}}
define void @test() #0 !dbg !9 {
ret void, !dbg !12
}
!llvm.module.flags = !{!0, !2, !4}
!llvm.dbg.cu = !{!5}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 12, i32 0]}
!2 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 7, !"PIC Level", i32 2}
!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "Apple clang version 13.0.0 (clang-1300.0.29.3)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !7, nameTableKind: None, sysroot: "/Library/Developer/CommandLineTools/SDKs/MacOSX12.0.sdk", sdk: "MacOSX12.0.sdk")
!6 = !DIFile(filename: "/Users/shubham/Development/test/test-small.c", directory: "/Users/shubham/Development/test")
!7 = !{}
!9 = distinct !DISubprogram(name: "test", scope: !10, file: !10, line: 1, type: !11, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !7)
!10 = !DIFile(filename: "test-small.c", directory: "/Users/shubham/Development/test")
!11 = !DISubroutineType(types: !7)
!12 = !DILocation(line: 0, column: 1, scope: !9)
4 changes: 2 additions & 2 deletions llvm/test/DebugInfo/MIR/X86/debug-loc-0.mir
Expand Up @@ -3,9 +3,9 @@
# RUN: llc -start-before=machine-cp -O2 -filetype=asm -mtriple=x86_64-apple-macosx10.9.0 -o - %s | FileCheck %s

# CHECK: Ltmp0:
# CHECK: .loc 1 0 0 prologue_end
# CHECK: .loc 1 0 0
# CHECK-NOT: .loc 1 0 0
# CHECK: .loc 1 37 1
# CHECK: .loc 1 37 1 prologue_end

--- |
; ModuleID = '<stdin>'
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/X86/dbg-prolog-end.ll
Expand Up @@ -26,7 +26,7 @@ entry:
declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone

;CHECK-LABEL: main:
;CHECK: .loc 1 0 0 prologue_end
;CHECK: .loc 1 8 2 prologue_end

define i32 @main() nounwind ssp !dbg !6 {
entry:
Expand Down

0 comments on commit 9f93f2b

Please sign in to comment.