Skip to content

Commit 1813652

Browse files
adrian-prantlrastogishubham
authored andcommitted
Do not emit prologue_end for line 0 locs if there is a non-zero loc present
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 (cherry picked from commit 9f93f2b)
1 parent 68c4df6 commit 1813652

File tree

5 files changed

+65
-8
lines changed

5 files changed

+65
-8
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,12 +2102,22 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
21022102
static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {
21032103
// First known non-DBG_VALUE and non-frame setup location marks
21042104
// the beginning of the function body.
2105-
for (const auto &MBB : *MF)
2106-
for (const auto &MI : MBB)
2105+
DebugLoc LineZeroLoc;
2106+
for (const auto &MBB : *MF) {
2107+
for (const auto &MI : MBB) {
21072108
if (!MI.isMetaInstruction() && !MI.getFlag(MachineInstr::FrameSetup) &&
2108-
MI.getDebugLoc())
2109-
return MI.getDebugLoc();
2110-
return DebugLoc();
2109+
MI.getDebugLoc()) {
2110+
// Scan forward to try to find a non-zero line number. The prologue_end
2111+
// marks the first breakpoint in the function after the frame setup, and
2112+
// a compiler-generated line 0 location is not a meaningful breakpoint.
2113+
// If none is found, return the first location after the frame setup.
2114+
if (MI.getDebugLoc().getLine())
2115+
return MI.getDebugLoc();
2116+
LineZeroLoc = MI.getDebugLoc();
2117+
}
2118+
}
2119+
}
2120+
return LineZeroLoc;
21112121
}
21122122

21132123
/// Register a source line with debug info. Returns the unique label that was
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: llc -filetype=asm -mtriple=x86_64-apple-macosx12.0.0 -O0 %s -o - | FileCheck %s
2+
; CHECK: Lfunc_begin0:
3+
; CHECK-NEXT: .file{{.+}}
4+
; CHECK-NEXT: .loc 1 2 0 ## test/test.c:2:0{{$}}
5+
; CHECK-NEXT: .cfi_startproc
6+
; CHECK-NEXT: ## %bb.{{[0-9]+}}:
7+
; CHECK-NEXT: .loc 1 0 5 {{is_stmt [0-9]+}} ## test/test.c:0:5{{$}}
8+
@x = common global i32 0, align 4
9+
define void @test() #0 !dbg !9 {
10+
store i32 1, i32* @x, align 4, !dbg !12
11+
ret void, !dbg !14
12+
}
13+
!llvm.module.flags = !{!0,!2,!4}
14+
!llvm.dbg.cu = !{!5}
15+
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 12, i32 0]}
16+
!2 = !{i32 2, !"Debug Info Version", i32 3}
17+
!4 = !{i32 7, !"PIC Level", i32 2}
18+
!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")
19+
!6 = !DIFile(filename: "/Users/shubham/Development/test/test.c", directory: "/Users/shubham/Development/deltaTest")
20+
!7 = !{}
21+
!9 = distinct !DISubprogram(name: "test", scope: !10, file: !10, line: 2, type: !11, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !7)
22+
!10 = !DIFile(filename: "test/test.c", directory: "/Users/shubham/Development")
23+
!11 = !DISubroutineType(types: !7)
24+
!12 = !DILocation(line: 0, column: 5, scope: !9)
25+
!14 = !DILocation(line: 3, column: 1, scope: !9)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: llc -filetype=asm -mtriple=x86_64-apple-macosx12.0.0 -O0 %s -o - | FileCheck %s
2+
; CHECK: Lfunc_begin0:
3+
; CHECK-NEXT: .file{{.+}}
4+
; CHECK-NEXT: .loc 1 1 0 ## test-small.c:1:0{{$}}
5+
; CHECK-NEXT: .cfi_startproc
6+
; CHECK-NEXT: ## %bb.{{[0-9]+}}:
7+
; CHECK-NEXT: .loc 1 0 1 prologue_end{{.*}}
8+
define void @test() #0 !dbg !9 {
9+
ret void, !dbg !12
10+
}
11+
!llvm.module.flags = !{!0, !2, !4}
12+
!llvm.dbg.cu = !{!5}
13+
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 12, i32 0]}
14+
!2 = !{i32 2, !"Debug Info Version", i32 3}
15+
!4 = !{i32 7, !"PIC Level", i32 2}
16+
!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")
17+
!6 = !DIFile(filename: "/Users/shubham/Development/test/test-small.c", directory: "/Users/shubham/Development/test")
18+
!7 = !{}
19+
!9 = distinct !DISubprogram(name: "test", scope: !10, file: !10, line: 1, type: !11, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !7)
20+
!10 = !DIFile(filename: "test-small.c", directory: "/Users/shubham/Development/test")
21+
!11 = !DISubroutineType(types: !7)
22+
!12 = !DILocation(line: 0, column: 1, scope: !9)

llvm/test/DebugInfo/MIR/X86/debug-loc-0.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# RUN: llc -start-before=machine-cp -O2 -filetype=asm -mtriple=x86_64-apple-macosx10.9.0 -o - %s | FileCheck %s
44

55
# CHECK: Ltmp0:
6-
# CHECK: .loc 1 0 0 prologue_end
6+
# CHECK: .loc 1 0 0
77
# CHECK-NOT: .loc 1 0 0
8-
# CHECK: .loc 1 37 1
8+
# CHECK: .loc 1 37 1 prologue_end
99

1010
--- |
1111
; ModuleID = '<stdin>'

llvm/test/DebugInfo/X86/dbg-prolog-end.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ entry:
2626
declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
2727

2828
;CHECK-LABEL: main:
29-
;CHECK: .loc 1 0 0 prologue_end
29+
;CHECK: .loc 1 8 2 prologue_end
3030

3131
define i32 @main() nounwind ssp !dbg !6 {
3232
entry:

0 commit comments

Comments
 (0)