Skip to content

Commit 5fef40c

Browse files
committed
Reapply "[DebugInfo][DWARF] Set is_stmt on first non-line-0 instruction in BB (#105524)"
Fixes the previous buildbot error by adding an explicit triple to the test, ensuring that llc can produce a valid object file. This reverts commit 926f097.
1 parent 56152fa commit 5fef40c

File tree

7 files changed

+53
-14
lines changed

7 files changed

+53
-14
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,10 +2061,8 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
20612061
unsigned LastAsmLine =
20622062
Asm->OutStreamer->getContext().getCurrentDwarfLoc().getLine();
20632063

2064-
bool PrevInstInSameSection =
2065-
(!PrevInstBB ||
2066-
PrevInstBB->getSectionID() == MI->getParent()->getSectionID());
2067-
if (DL == PrevInstLoc && PrevInstInSameSection) {
2064+
bool PrevInstInDiffBB = PrevInstBB && PrevInstBB != MI->getParent();
2065+
if (DL == PrevInstLoc && !PrevInstInDiffBB) {
20682066
// If we have an ongoing unspecified location, nothing to do here.
20692067
if (!DL)
20702068
return;
@@ -2093,8 +2091,7 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
20932091
// possibly debug information; we want it to have a source location.
20942092
// - Instruction is at the top of a block; we don't want to inherit the
20952093
// location from the physically previous (maybe unrelated) block.
2096-
if (UnknownLocations == Enable || PrevLabel ||
2097-
(PrevInstBB && PrevInstBB != MI->getParent())) {
2094+
if (UnknownLocations == Enable || PrevLabel || PrevInstInDiffBB) {
20982095
// Preserve the file and column numbers, if we can, to save space in
20992096
// the encoded line table.
21002097
// Do not update PrevInstLoc, it remembers the last non-0 line.
@@ -2119,9 +2116,11 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
21192116
PrologEndLoc = DebugLoc();
21202117
}
21212118
// If the line changed, we call that a new statement; unless we went to
2122-
// line 0 and came back, in which case it is not a new statement.
2119+
// line 0 and came back, in which case it is not a new statement. We also
2120+
// mark is_stmt for the first non-0 line in each BB, in case a predecessor BB
2121+
// ends with a different line.
21232122
unsigned OldLine = PrevInstLoc ? PrevInstLoc.getLine() : LastAsmLine;
2124-
if (DL.getLine() && DL.getLine() != OldLine)
2123+
if (DL.getLine() && (DL.getLine() != OldLine || PrevInstInDiffBB))
21252124
Flags |= DWARF2_FLAG_IS_STMT;
21262125

21272126
const MDNode *Scope = DL.getScope();

llvm/test/CodeGen/Thumb2/pr52817.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ define i32 @test(ptr %arg, ptr %arg1, ptr %arg2) #0 !dbg !6 {
2424
; CHECK-NEXT: movs r3, #0
2525
; CHECK-NEXT: LBB0_1: @ %bb3
2626
; CHECK-NEXT: @ =>This Inner Loop Header: Depth=1
27+
; CHECK-NEXT: .loc 1 0 0 is_stmt 0 @ :0:0
2728
; CHECK-NEXT: adds r5, r3, #1
2829
; CHECK-NEXT: str.w lr, [r2]
2930
; CHECK-NEXT: cmp.w lr, #0
@@ -36,7 +37,7 @@ define i32 @test(ptr %arg, ptr %arg1, ptr %arg2) #0 !dbg !6 {
3637
; CHECK-NEXT: movne r6, #0
3738
; CHECK-NEXT: Ltmp0:
3839
; CHECK-NEXT: @DEBUG_VALUE: test:this <- [DW_OP_LLVM_arg 0, DW_OP_plus_uconst 135168, DW_OP_LLVM_arg 1, DW_OP_constu 4, DW_OP_mul, DW_OP_plus, DW_OP_plus_uconst 4, DW_OP_stack_value] $r0, $r5
39-
; CHECK-NEXT: .loc 1 28 24 prologue_end @ test.cpp:28:24
40+
; CHECK-NEXT: .loc 1 28 24 prologue_end is_stmt 1 @ test.cpp:28:24
4041
; CHECK-NEXT: strne.w r6, [r8]
4142
; CHECK-NEXT: moveq r6, #1
4243
; CHECK-NEXT: ldr r4, [r4, #4]

llvm/test/CodeGen/X86/fsafdo_test1.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
; Check that fs-afdo discriminators are generated.
55
; V01: .loc 1 7 3 is_stmt 0 discriminator 2 # foo.c:7:3
66
; V01: .loc 1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5
7-
; V0: .loc 1 9 5 discriminator 11266 # foo.c:9:5
7+
; V0: .loc 1 9 5 is_stmt 1 discriminator 11266 # foo.c:9:5
88
; V0: .loc 1 7 3 is_stmt 1 discriminator 11266 # foo.c:7:3
9-
; V1: .loc 1 9 5 discriminator 514 # foo.c:9:5
9+
; V1: .loc 1 9 5 is_stmt 1 discriminator 514 # foo.c:9:5
1010
; V1: .loc 1 7 3 is_stmt 1 discriminator 258 # foo.c:7:3
1111
; Check that variable __llvm_fs_discriminator__ is generated.
1212
; V01: .type __llvm_fs_discriminator__,@object # @__llvm_fs_discriminator__

llvm/test/CodeGen/X86/fsafdo_test4.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
; CHECK: .loc 1 0 3 # foo.c:0:3
88
; CHECK: .loc 1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5
99
; CHECK: .loc 1 0 5 is_stmt 0 # :0:5
10-
; CHECK: .loc 1 9 5 discriminator 2 # foo.c:9:5
11-
; CHECK: .loc 1 0 5 # :0:5
10+
; CHECK: .loc 1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5
11+
; CHECK: .loc 1 0 5 is_stmt 0 # :0:5
1212
; CHECK: .loc 1 7 3 is_stmt 1 discriminator 2 # foo.c:7:3
1313
; CHECK: .loc 1 14 3 # foo.c:14:3
1414
; Check that variable __llvm_fs_discriminator__ is NOT generated.

llvm/test/DebugInfo/MIR/X86/empty-inline.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
# CHECK: Address Line Column File ISA Discriminator OpIndex Flags
1515
# CHECK-NEXT: ---
1616
# CHECK-NEXT: 25 0 1 0 0 0 is_stmt
17+
# CHECK-NEXT: 0 0 1 0 0 0
1718
# CHECK-NEXT: 29 28 1 0 0 0 is_stmt prologue_end
19+
# CHECK-NEXT: 29 28 1 0 0 0 is_stmt
1820
# CHECK-NEXT: 29 28 1 0 0 0 is_stmt end_sequence
1921
--- |
2022
source_filename = "t.ll"

llvm/test/DebugInfo/X86/discriminator.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "frame-pointer"=
5959

6060
; CHECK: Address Line Column File ISA Discriminator OpIndex Flags
6161
; CHECK: ------------------ ------ ------ ------ --- ------------- ------- -------------
62-
; CHECK: 0x000000000000000a 2 0 1 0 42 0 {{$}}
62+
; CHECK: 0x000000000000000a 2 0 1 0 42 0 is_stmt{{$}}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
;; Checks that when an instruction at the start of a BasicBlock has the same
2+
;; DebugLoc as the instruction at the end of the previous BasicBlock, we add
3+
;; is_stmt to the new line, to ensure that we still step on it if we arrive from
4+
;; a BasicBlock other than the immediately preceding one.
5+
6+
; RUN: %llc_dwarf -mtriple=x86_64-unknown-linux -O0 -filetype=obj < %s | llvm-dwarfdump --debug-line - | FileCheck %s
7+
8+
; CHECK: {{0x[0-9a-f]+}} 13 5 {{.+}} is_stmt
9+
; CHECK-NEXT: {{0x[0-9a-f]+}} 13 5 {{.+}} is_stmt
10+
11+
define void @_Z1fi(i1 %cond) !dbg !21 {
12+
entry:
13+
br i1 %cond, label %if.then2, label %if.else4
14+
15+
if.then2: ; preds = %entry
16+
br label %if.end8, !dbg !24
17+
18+
if.else4: ; preds = %entry
19+
%0 = load i32, ptr null, align 4, !dbg !24
20+
%call5 = call i1 null(i32 %0)
21+
ret void
22+
23+
if.end8: ; preds = %if.then2
24+
ret void
25+
}
26+
27+
!llvm.dbg.cu = !{!0}
28+
!llvm.module.flags = !{!20}
29+
30+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
31+
!1 = !DIFile(filename: "test.cpp", directory: "/home/gbtozers/dev/upstream-llvm")
32+
!20 = !{i32 2, !"Debug Info Version", i32 3}
33+
!21 = distinct !DISubprogram(name: "f", linkageName: "_Z1fi", scope: !1, file: !1, line: 7, type: !22, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
34+
!22 = distinct !DISubroutineType(types: !23)
35+
!23 = !{null}
36+
!24 = !DILocation(line: 13, column: 5, scope: !25)
37+
!25 = distinct !DILexicalBlock(scope: !21, file: !1, line: 11, column: 27)

0 commit comments

Comments
 (0)