Skip to content

[DebugInfo] IndVars applies wrong debug location after hoisting #116812

Open
@OCHyams

Description

@OCHyams

Reduced from the code in #70951.

https://godbolt.org/z/P4GGcPsbe

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define fastcc i32 @s(i8 %a, i1 %c, ptr %p) {
entry:
  br label %for.cond, !dbg !4

for.cond:
  %inc = add i8 %a, 1, !dbg !7
  br i1 %c, label %if.then, label %return

if.then:
  br i1 %c, label %if.then2, label %return

if.then2:
  br label %for.cond

return:
  store i8 %inc, ptr %p, align 1
  ret i32 0
}

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

!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !2, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "test.c", directory: "/")
!2 = !{}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !DILocation(line: 8, column: 3, scope: !5)
!5 = distinct !DISubprogram(name: "s", scope: !1, file: !1, line: 6, type: !6, scopeLine: 6, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!6 = !DISubroutineType(types: !2)
!7 = !DILocation(line: 18, column: 5, scope: !8)
!8 = distinct !DILexicalBlock(scope: !9, file: !1, line: 8, column: 12)
!9 = distinct !DILexicalBlock(scope: !10, file: !1, line: 8, column: 3)
!10 = distinct !DILexicalBlock(scope: !5, file: !1, line: 8, column: 3)

Run opt -S --passes=indvars (or see the godbolt link above), observe the add i8 %a, 1 gets hoisted into entry and its source attribution transforms from line: 18 to line: 8. It's inheriting the DILocation from entrys terminator, which is not ideal. Should probably be line 0 for this case?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions