dbg-value-lower-linenos.ll 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ; RUN: opt < %s -S -mem2reg -instcombine | FileCheck %s
  2. ; The '%bar' alloca will be promoted to an SSA register by mem2reg: test that
  3. ; zero line number are assigned to the dbg.value intrinsics that are inserted
  4. ; to represent changes in variable value. No machine instructions are
  5. ; generated from these dbg.values so their lines are irrelevant, only the
  6. ; scope and inlining information must be correct.
  7. ; In the second function here, LowerDbgDeclare will promote various variable
  8. ; accesses of a dbg.declare'd alloca into dbg.values. Check that their line
  9. ; numbers are sane too. (IR copied from DebugInfo/X86/formal_parameter.ll).
  10. ; CHECK-LABEL: define i32 @foo
  11. ; CHECK-LABEL: bb1:
  12. ; CHECK-NEXT: %bar.0 = phi i32
  13. ; CHECK-NEXT: dbg.value(metadata i32 %bar.0,{{.*}}), !dbg ![[UNKNOWN:[0-9]+]]
  14. ; CHECK-NEXT: %totest = load
  15. ; CHECK-NEXT: %add = add i32 %bar.0
  16. ; CHECK-NEXT: dbg.value(metadata i32 %add, {{.*}}), !dbg ![[UNKNOWN]]
  17. ; CHECK-NEXT: %cond = icmp ult
  18. ; CHECK-NEXT: br i1 %cond, label %bb1, label %bb2
  19. ;
  20. ; CHECK-LABEL: bb2:
  21. ; CHECK-NEXT: %toret = add i32 %bar.0, 3
  22. ; CHECK-NEXT: dbg.value(metadata i32 %toret, {{.*}}), !dbg ![[UNKNOWN]]
  23. ; CHECK-NEXT: ret i32 %toret
  24. define i32 @foo(i32 *%bees, i32 *%output) {
  25. entry:
  26. %bar = alloca i32
  27. call void @llvm.dbg.declare(metadata i32 *%bar, metadata !7, metadata !DIExpression()), !dbg !6
  28. store i32 0, i32 *%bar
  29. br label %bb1, !dbg !6
  30. bb1:
  31. %totest = load i32, i32 *%bees, !dbg !8
  32. %load1 = load i32, i32 *%bar, !dbg !9
  33. %add = add i32 %load1, 1, !dbg !10
  34. store i32 %add, i32 *%bar, !dbg !11
  35. %toret = add i32 %add, 2, !dbg !12
  36. %cond = icmp ult i32 %totest, %load1, !dbg !13
  37. br i1 %cond, label %bb1, label %bb2, !dbg !14
  38. bb2:
  39. store i32 %toret, i32 *%bar, !dbg !16
  40. ret i32 %toret
  41. }
  42. ; In the following, the dbg.value created for the store should get the stores
  43. ; line number, the other dbg.values should be unknown.
  44. ; CHECK-LABEL: define void @bar
  45. ;
  46. ; CHECK: dbg.value(metadata i32 %map, metadata ![[MAPVAR:[0-9]+]],{{.*}}),
  47. ; CHECK-SAME: !dbg ![[UNKNOWN2:[0-9]+]]
  48. ; CHECK-NEXT: store
  49. ; CHECK-NEXT: dbg.value(metadata i32* %map.addr, metadata ![[MAPVAR]],
  50. ; CHECK-SAME: metadata !DIExpression(DW_OP_deref)),
  51. ; CHECK-SAME: !dbg ![[UNKNOWN2]]
  52. ; CHECK-NEXT: call
  53. ; CHECK-NEXT: load
  54. ; CHECK-NEXT: dbg.value(metadata i32 %{{[0-9]+}}, metadata ![[MAPVAR]],
  55. ; CHECK-SAME: !dbg ![[UNKNOWN2]]
  56. define void @bar(i32 %map) !dbg !20 {
  57. entry:
  58. %map.addr = alloca i32, align 4
  59. store i32 %map, i32* %map.addr, align 4, !dbg !27
  60. call void @llvm.dbg.declare(metadata i32* %map.addr, metadata !21, metadata !DIExpression()), !dbg !22
  61. %call = call i32 (i32*, ...) bitcast (i32 (...)* @lookup to i32 (i32*, ...)*)(i32* %map.addr), !dbg !23
  62. %0 = load i32, i32* %map.addr, align 4, !dbg !24
  63. %call1 = call i32 (i32, ...) bitcast (i32 (...)* @verify to i32 (i32, ...)*)(i32 %0), !dbg !25
  64. ret void, !dbg !26
  65. }
  66. declare void @llvm.dbg.value(metadata, metadata, metadata)
  67. declare void @llvm.dbg.declare(metadata, metadata, metadata)
  68. declare i32 @verify(...)
  69. declare i32 @lookup(...)
  70. ; CHECK: ![[SUBPROG:[0-9]+]] = distinct !DISubprogram(name: "nope",
  71. ; CHECK: ![[UNKNOWN]] = !DILocation(line: 0, scope: ![[SUBPROG]])
  72. ; CHECK: ![[SUBPROG2:[0-9]+]] = distinct !DISubprogram(name: "thin",
  73. ; CHECK: ![[MAPVAR]] = !DILocalVariable(name: "floogie",
  74. ; CHECK: ![[UNKNOWN2]] = !DILocation(line: 0
  75. !llvm.module.flags = !{!4}
  76. !llvm.dbg.cu = !{!2}
  77. !1 = !DILocalVariable(name: "bees", scope: !5, type: null)
  78. !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "beards", isOptimized: true, runtimeVersion: 4, emissionKind: FullDebug)
  79. !3 = !DIFile(filename: "bees.cpp", directory: "")
  80. !4 = !{i32 2, !"Debug Info Version", i32 3}
  81. !5 = distinct !DISubprogram(name: "nope", scope: !3, file: !3, line: 1, unit: !2)
  82. !6 = !DILocation(line: 1, scope: !5)
  83. !7 = !DILocalVariable(name: "flannel", scope: !5, type: null)
  84. !8 = !DILocation(line: 2, scope: !5)
  85. !9 = !DILocation(line: 3, scope: !5)
  86. !10 = !DILocation(line: 4, scope: !5)
  87. !11 = !DILocation(line: 5, scope: !5)
  88. !12 = !DILocation(line: 6, scope: !5)
  89. !13 = !DILocation(line: 7, scope: !5)
  90. !14 = !DILocation(line: 8, scope: !5)
  91. !15 = distinct !DISubprogram(name: "wat", scope: !2, file: !3, line: 10, unit: !2)
  92. !16 = !DILocation(line: 9, scope: !15, inlinedAt: !14)
  93. !20 = distinct !DISubprogram(name: "thin", scope: !3, file: !3, line: 20, unit: !2)
  94. !21 = !DILocalVariable(name: "floogie", scope: !20, type: null)
  95. !22 = !DILocation(line: 21, scope: !20)
  96. !23 = !DILocation(line: 22, scope: !20)
  97. !24 = !DILocation(line: 23, scope: !20)
  98. !25 = !DILocation(line: 24, scope: !20)
  99. !26 = !DILocation(line: 25, scope: !20)
  100. !27 = !DILocation(line: 20, scope: !20)