Compiler projects using llvm
# REQUIRES: x86-registered-target
# RUN: llc -mtriple=x86_64-unknown-linux-gnu -run-pass=mir-check-debugify -o - %s 2>&1 | FileCheck %s
--- |
  ; ModuleID = 'check-line-and-variables.mir'
  source_filename = "check-line-and-variables.c"

  @ga = dso_local local_unnamed_addr global i32 2, align 4

  ; Function Attrs: nofree norecurse nounwind uwtable writeonly
  define dso_local i32 @foo(i32 %a, i32 %b) local_unnamed_addr #0 !dbg !9 {
  entry:
    %add = add nsw i32 %b, %a, !dbg !15
    call void @llvm.dbg.value(metadata i32 %add, metadata !12, metadata !DIExpression()), !dbg !15
    %mul = shl nsw i32 %add, 1, !dbg !16
    call void @llvm.dbg.value(metadata i32 %mul, metadata !14, metadata !DIExpression()), !dbg !16
    store i32 %mul, i32* @ga, align 4, !dbg !17
    ret i32 %add, !dbg !18
  }

  declare void @llvm.dbg.value(metadata, metadata, metadata) #1

  !llvm.module.flags = !{!0, !1}
  !llvm.ident = !{!2}
  !llvm.dbg.cu = !{!3}
  !llvm.mir.debugify = !{!6, !7}
  !llvm.debugify = !{!8, !7}

  !0 = !{i32 1, !"wchar_size", i32 4}
  !1 = !{i32 2, !"Debug Info Version", i32 3}
  !2 = !{!"clang version 12.0.0 (https://github.com/llvm/llvm-project.git c0a922b3db2d39f36c0c01776cce90cc160a7d62)"}
  !3 = distinct !DICompileUnit(language: DW_LANG_C, file: !4, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !5)
  !4 = !DIFile(filename: "main.mir", directory: "/")
  !5 = !{}
  !6 = !{i32 6}
  !7 = !{i32 2}
  !8 = !{i32 4}
  !9 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !4, line: 1, type: !10, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !3, retainedNodes: !11)
  !10 = !DISubroutineType(types: !5)
  !11 = !{!12, !14}
  !12 = !DILocalVariable(name: "1", scope: !9, file: !4, line: 1, type: !13)
  !13 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
  !14 = !DILocalVariable(name: "2", scope: !9, file: !4, line: 2, type: !13)
  !15 = !DILocation(line: 1, column: 1, scope: !9)
  !16 = !DILocation(line: 2, column: 1, scope: !9)
  !17 = !DILocation(line: 3, column: 1, scope: !9)
  !18 = !DILocation(line: 4, column: 1, scope: !9)

...
---
name:            foo
body:             |
  bb.0.entry:
    liveins: $edi, $esi

    %1:gr32 = COPY $esi, debug-location !15
    DBG_VALUE %1, $noreg, !12, !DIExpression(), debug-location !15
    ; Let it missing !14 and debug-location !16
    ; %0:gr32 = COPY $edi, debug-location !16
    ; DBG_VALUE %0, $noreg, !14, !DIExpression(), debug-location !16
    %0:gr32 = COPY $edi
    %2:gr32 = nsw ADD32rr %1, %0, implicit-def dead $eflags, debug-location !17
    DBG_VALUE %2, $noreg, !12, !DIExpression(), debug-location !17
    DBG_VALUE $eflags, $noreg, !12, !DIExpression(), debug-location !17
    %3:gr32 = nsw ADD32rr %2, %2, implicit-def dead $eflags, debug-location !18
    DBG_VALUE %3, $noreg, !12, !DIExpression(), debug-location !18
    DBG_VALUE $eflags, $noreg, !12, !DIExpression(), debug-location !18
    MOV32mr $rip, 1, $noreg, @ga, $noreg, killed %3, debug-location !DILocation(line: 5, column: 1, scope: !9) :: (store (s32) into @ga, !tbaa !18)
    DBG_VALUE 0, $noreg, !12, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !9)
    ; Let it miss Line 6: Change "!DILocation(line: 6, ..." to "!DILocation(line: 5, ..."
    $eax = COPY %2, debug-location !DILocation(line: 5, column: 1, scope: !9)
    DBG_VALUE $eax, $noreg, !12, !DIExpression(), debug-location !DILocation(line: 6, column: 1, scope: !9)
    RET 0, $eax, debug-location !DILocation(line: 7, column: 1, scope: !9)

    ;CHECK:      WARNING: Instruction with empty DebugLoc in function foo --%1:gr32 = COPY $edi
    ;CHECK-NEXT: WARNING: Missing line 2
    ;CHECK-NEXT: WARNING: Missing line 6
    ;CHECK-NEXT: WARNING: Missing variable 2
    ;CHECK-NEXT: Machine IR debug info check: FAIL

...