inline_dbg_declare.ll 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ; RUN: opt < %s -S -inline | FileCheck %s
  2. ;
  3. ; The purpose of this test is to check that inline pass preserves debug info
  4. ; for variable using the dbg.declare intrinsic.
  5. ;
  6. ;; This test was generated by running this command:
  7. ;; clang.exe -S -O0 -emit-llvm -g foo.c
  8. ;;
  9. ;; foo.c
  10. ;; ==========================
  11. ;; float foo(float x)
  12. ;; {
  13. ;; return x;
  14. ;; }
  15. ;;
  16. ;; void bar(float *dst)
  17. ;; {
  18. ;; dst[0] = foo(dst[0]);
  19. ;; }
  20. ;; ==========================
  21. target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
  22. target triple = "i686-pc-windows-msvc"
  23. ; Function Attrs: nounwind
  24. define float @foo(float %x) #0 {
  25. entry:
  26. %x.addr = alloca float, align 4
  27. store float %x, float* %x.addr, align 4
  28. call void @llvm.dbg.declare(metadata float* %x.addr, metadata !16, metadata !17), !dbg !18
  29. %0 = load float, float* %x.addr, align 4, !dbg !19
  30. ret float %0, !dbg !19
  31. }
  32. ; Function Attrs: nounwind readnone
  33. declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
  34. ; CHECK: define void @bar
  35. ; Function Attrs: nounwind
  36. define void @bar(float* %dst) #0 {
  37. entry:
  38. ; CHECK: [[x_addr_i:%[a-zA-Z0-9.]+]] = alloca float, align 4
  39. %dst.addr = alloca float*, align 4
  40. store float* %dst, float** %dst.addr, align 4
  41. call void @llvm.dbg.declare(metadata float** %dst.addr, metadata !20, metadata !17), !dbg !21
  42. %0 = load float*, float** %dst.addr, align 4, !dbg !22
  43. %arrayidx = getelementptr inbounds float, float* %0, i32 0, !dbg !22
  44. %1 = load float, float* %arrayidx, align 4, !dbg !22
  45. %call = call float @foo(float %1), !dbg !22
  46. ; CHECK-NOT: call float @foo
  47. ; CHECK: void @llvm.dbg.declare(metadata float* [[x_addr_i]], metadata [[m23:![0-9]+]], metadata !{{[0-9]+}}), !dbg [[m24:![0-9]+]]
  48. %2 = load float*, float** %dst.addr, align 4, !dbg !22
  49. %arrayidx1 = getelementptr inbounds float, float* %2, i32 0, !dbg !22
  50. store float %call, float* %arrayidx1, align 4, !dbg !22
  51. ret void, !dbg !23
  52. }
  53. attributes #0 = { nounwind }
  54. attributes #1 = { nounwind readnone }
  55. !llvm.dbg.cu = !{!0}
  56. !llvm.module.flags = !{!13, !14}
  57. !llvm.ident = !{!15}
  58. !0 = !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.6.0 (trunk)", isOptimized: false, emissionKind: 1, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
  59. !1 = !DIFile(filename: "foo.c", directory: "")
  60. !2 = !{}
  61. !3 = !{!4, !9}
  62. !4 = !DISubprogram(name: "foo", line: 1, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 2, file: !1, scope: !5, type: !6, function: float (float)* @foo, variables: !2)
  63. !5 = !DIFile(filename: "foo.c", directory: "")
  64. !6 = !DISubroutineType(types: !7)
  65. !7 = !{!8, !8}
  66. !8 = !DIBasicType(tag: DW_TAG_base_type, name: "float", size: 32, align: 32, encoding: DW_ATE_float)
  67. !9 = !DISubprogram(name: "bar", line: 6, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 7, file: !1, scope: !5, type: !10, function: void (float*)* @bar, variables: !2)
  68. !10 = !DISubroutineType(types: !11)
  69. !11 = !{null, !12}
  70. !12 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 32, align: 32, baseType: !8)
  71. !13 = !{i32 2, !"Dwarf Version", i32 4}
  72. !14 = !{i32 2, !"Debug Info Version", i32 3}
  73. !15 = !{!"clang version 3.6.0 (trunk)"}
  74. !16 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "x", line: 1, arg: 1, scope: !4, file: !5, type: !8)
  75. !17 = !DIExpression()
  76. !18 = !DILocation(line: 1, column: 17, scope: !4)
  77. !19 = !DILocation(line: 3, column: 5, scope: !4)
  78. !20 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "dst", line: 6, arg: 1, scope: !9, file: !5, type: !12)
  79. !21 = !DILocation(line: 6, column: 17, scope: !9)
  80. !22 = !DILocation(line: 8, column: 14, scope: !9)
  81. !23 = !DILocation(line: 9, column: 1, scope: !9)
  82. ; CHECK: [[FOO:![0-9]+]] = !DISubprogram(name: "foo",
  83. ; CHECK: [[BAR:![0-9]+]] = !DISubprogram(name: "bar",
  84. ; CHECK: [[m23]] = !DILocalVariable(tag: DW_TAG_arg_variable, name: "x", arg: 1, scope: [[FOO]]
  85. ; CHECK: [[CALL_SITE:![0-9]+]] = distinct !DILocation(line: 8, column: 14, scope: [[BAR]])
  86. ; CHECK: [[m24]] = !DILocation(line: 1, column: 17, scope: [[FOO]], inlinedAt: [[CALL_SITE]])