[llvm] 9f93f2b - Do not emit prologue_end for line 0 locs if there is a non-zero loc present

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 7 13:54:36 PDT 2021


Author: Adrian Prantl
Date: 2021-10-07T13:54:28-07:00
New Revision: 9f93f2bfbd3fedb94490d42e48b89c2a8f05ff0a

URL: https://github.com/llvm/llvm-project/commit/9f93f2bfbd3fedb94490d42e48b89c2a8f05ff0a
DIFF: https://github.com/llvm/llvm-project/commit/9f93f2bfbd3fedb94490d42e48b89c2a8f05ff0a.diff

LOG: 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

Added: 
    llvm/test/CodeGen/X86/line-zero-prologue-end.ll
    llvm/test/CodeGen/X86/no-non-zero-debug-loc-prologue.ll

Modified: 
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/test/DebugInfo/MIR/X86/debug-loc-0.mir
    llvm/test/DebugInfo/X86/dbg-prolog-end.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index e6c97b5d63db3..2850c12023cd6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -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

diff  --git a/llvm/test/CodeGen/X86/line-zero-prologue-end.ll b/llvm/test/CodeGen/X86/line-zero-prologue-end.ll
new file mode 100644
index 0000000000000..eb2d374597c65
--- /dev/null
+++ b/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{{$}}
+ at 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)
\ No newline at end of file

diff  --git a/llvm/test/CodeGen/X86/no-non-zero-debug-loc-prologue.ll b/llvm/test/CodeGen/X86/no-non-zero-debug-loc-prologue.ll
new file mode 100644
index 0000000000000..a9c71d1d9c36b
--- /dev/null
+++ b/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)
\ No newline at end of file

diff  --git a/llvm/test/DebugInfo/MIR/X86/debug-loc-0.mir b/llvm/test/DebugInfo/MIR/X86/debug-loc-0.mir
index faf8949715612..edde1b36c423b 100644
--- a/llvm/test/DebugInfo/MIR/X86/debug-loc-0.mir
+++ b/llvm/test/DebugInfo/MIR/X86/debug-loc-0.mir
@@ -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>'

diff  --git a/llvm/test/DebugInfo/X86/dbg-prolog-end.ll b/llvm/test/DebugInfo/X86/dbg-prolog-end.ll
index c7ea9c93c7787..7d40b2c8ad869 100644
--- a/llvm/test/DebugInfo/X86/dbg-prolog-end.ll
+++ b/llvm/test/DebugInfo/X86/dbg-prolog-end.ll
@@ -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:


        


More information about the llvm-commits mailing list