Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2119,9 +2119,12 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
PrologEndLoc = DebugLoc();
}
// If the line changed, we call that a new statement; unless we went to
// line 0 and came back, in which case it is not a new statement.
// line 0 and came back, in which case it is not a new statement. We also
// mark is_stmt for the first non-0 line in each BB, in case a predecessor BB
// ends with a different line.
unsigned OldLine = PrevInstLoc ? PrevInstLoc.getLine() : LastAsmLine;
if (DL.getLine() && DL.getLine() != OldLine)
if (DL.getLine() &&
(DL.getLine() != OldLine || PrevInstBB != MI->getParent()))
Flags |= DWARF2_FLAG_IS_STMT;

const MDNode *Scope = DL.getScope();
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/X86/fsafdo_test1.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
; Check that fs-afdo discriminators are generated.
; V01: .loc 1 7 3 is_stmt 0 discriminator 2 # foo.c:7:3
; V01: .loc 1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5
; V0: .loc 1 9 5 discriminator 11266 # foo.c:9:5
; V0: .loc 1 9 5 is_stmt 1 discriminator 11266 # foo.c:9:5
; V0: .loc 1 7 3 is_stmt 1 discriminator 11266 # foo.c:7:3
; V1: .loc 1 9 5 discriminator 514 # foo.c:9:5
; V1: .loc 1 9 5 is_stmt 1 discriminator 514 # foo.c:9:5
; V1: .loc 1 7 3 is_stmt 1 discriminator 258 # foo.c:7:3
; Check that variable __llvm_fs_discriminator__ is generated.
; V01: .type __llvm_fs_discriminator__,@object # @__llvm_fs_discriminator__
Expand Down
38 changes: 38 additions & 0 deletions llvm/test/DebugInfo/Generic/is_stmt-at-block-start.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;; Checks that when an instruction at the start of a BasicBlock has the same
;; DebugLoc as the instruction at the end of the previous BasicBlock, we add
;; is_stmt to the new line, to ensure that we still step on it if we arrive from
;; a BasicBlock other than the immediately preceding one.

; RUN: %llc_dwarf -O0 -filetype=obj < %s | llvm-dwarfdump --debug-line - | FileCheck %s

; CHECK: {{0x[0-9a-f]+}} 13 5 {{.+}} is_stmt
; CHECK-NEXT: {{0x[0-9a-f]+}} 13 25 {{.+}} is_stmt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ISTM the first check is for block if.then2, the second is for if.else4? Should there also be one for if.end8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this test specifically, as only these two instructions have non-0 line numbers (excluding 0x0, which has the function header).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, !dbg isn't inherited the way it is for asm.
But, you could use the same !dbg for both, showing that it really is the BB that triggers it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, trying to make this work has revealed another an issue - when the lines are actually identical, they will be merged into a single entry (whether this patch is in effect or not), which any jump to the branch would land in the middle of. I'm not sure whether that would result in a step in the debugger or not; it prevents the test from working, at the very least.


define void @_Z1fi(i1 %cond) !dbg !21 {
entry:
br i1 %cond, label %if.then2, label %if.else4

if.then2: ; preds = %entry
br label %if.end8, !dbg !24

if.else4: ; preds = %entry
%0 = load i32, ptr null, align 4, !dbg !28
%call5 = call i1 null(i32 %0)
ret void

if.end8: ; preds = %if.then2
ret void
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!20}

!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)
!1 = !DIFile(filename: "test.cpp", directory: "/home/gbtozers/dev/upstream-llvm")
!20 = !{i32 2, !"Debug Info Version", i32 3}
!21 = distinct !DISubprogram(name: "f", linkageName: "_Z1fi", scope: !1, file: !1, line: 7, type: !22, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
!22 = distinct !DISubroutineType(types: !23)
!23 = !{null}
!24 = !DILocation(line: 13, column: 5, scope: !25)
!25 = distinct !DILexicalBlock(scope: !21, file: !1, line: 11, column: 27)
!28 = !DILocation(line: 13, column: 25, scope: !25)
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/X86/discriminator.ll
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "frame-pointer"=

; CHECK: Address Line Column File ISA Discriminator OpIndex Flags
; CHECK: ------------------ ------ ------ ------ --- ------------- ------- -------------
; CHECK: 0x000000000000000a 2 0 1 0 42 0 {{$}}
; CHECK: 0x000000000000000a 2 0 1 0 42 0 is_stmt{{$}}