inline-debug-info-multiret.ll 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. ; RUN: opt -inline -S < %s | FileCheck %s
  2. ;
  3. ; A hand-edited version of inline-debug-info.ll to test inlining of a
  4. ; function with multiple returns.
  5. ;
  6. ; Make sure the branch instructions created during inlining has a debug location,
  7. ; so the range of the inlined function is correct.
  8. ; CHECK: br label %_Z4testi.exit, !dbg ![[MD:[0-9]+]]
  9. ; CHECK: br label %_Z4testi.exit, !dbg ![[MD]]
  10. ; CHECK: br label %invoke.cont, !dbg ![[MD]]
  11. ; The branch instruction has the source location of line 9 and its inlined location
  12. ; has the source location of line 14.
  13. ; CHECK: ![[INL:[0-9]+]] = distinct !DILocation(line: 14, scope: {{.*}})
  14. ; CHECK: ![[MD]] = !DILocation(line: 9, scope: {{.*}}, inlinedAt: ![[INL]])
  15. ; ModuleID = 'test.cpp'
  16. target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
  17. target triple = "x86_64-apple-darwin12.0.0"
  18. @_ZTIi = external constant i8*
  19. @global_var = external global i32
  20. ; copy of above function with multiple returns
  21. define i32 @_Z4testi(i32 %k) !dbg !4 {
  22. entry:
  23. %retval = alloca i32, align 4
  24. %k.addr = alloca i32, align 4
  25. %k2 = alloca i32, align 4
  26. store i32 %k, i32* %k.addr, align 4
  27. call void @llvm.dbg.declare(metadata i32* %k.addr, metadata !13, metadata !DIExpression()), !dbg !14
  28. call void @llvm.dbg.declare(metadata i32* %k2, metadata !15, metadata !DIExpression()), !dbg !16
  29. %0 = load i32, i32* %k.addr, align 4, !dbg !16
  30. %call = call i32 @_Z8test_exti(i32 %0), !dbg !16
  31. store i32 %call, i32* %k2, align 4, !dbg !16
  32. %1 = load i32, i32* %k2, align 4, !dbg !17
  33. %cmp = icmp sgt i32 %1, 100, !dbg !17
  34. br i1 %cmp, label %if.then, label %if.end, !dbg !17
  35. if.then: ; preds = %entry
  36. %2 = load i32, i32* %k2, align 4, !dbg !18
  37. store i32 %2, i32* %retval, !dbg !18
  38. br label %return, !dbg !18
  39. if.end: ; preds = %entry
  40. store i32 0, i32* %retval, !dbg !19
  41. %3 = load i32, i32* %retval, !dbg !20 ; hand-edited
  42. ret i32 %3, !dbg !20 ; hand-edited
  43. return: ; preds = %if.end, %if.then
  44. %4 = load i32, i32* %retval, !dbg !20
  45. ret i32 %4, !dbg !20
  46. }
  47. ; Function Attrs: nounwind readnone
  48. declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
  49. declare i32 @_Z8test_exti(i32)
  50. define i32 @_Z5test2v() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !dbg !10 {
  51. entry:
  52. %exn.slot = alloca i8*
  53. %ehselector.slot = alloca i32
  54. %e = alloca i32, align 4
  55. %0 = load i32, i32* @global_var, align 4, !dbg !21
  56. %call = invoke i32 @_Z4testi(i32 %0)
  57. to label %invoke.cont unwind label %lpad, !dbg !21
  58. invoke.cont: ; preds = %entry
  59. br label %try.cont, !dbg !23
  60. lpad: ; preds = %entry
  61. %1 = landingpad { i8*, i32 }
  62. catch i8* bitcast (i8** @_ZTIi to i8*), !dbg !21
  63. %2 = extractvalue { i8*, i32 } %1, 0, !dbg !21
  64. store i8* %2, i8** %exn.slot, !dbg !21
  65. %3 = extractvalue { i8*, i32 } %1, 1, !dbg !21
  66. store i32 %3, i32* %ehselector.slot, !dbg !21
  67. br label %catch.dispatch, !dbg !21
  68. catch.dispatch: ; preds = %lpad
  69. %sel = load i32, i32* %ehselector.slot, !dbg !23
  70. %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2, !dbg !23
  71. %matches = icmp eq i32 %sel, %4, !dbg !23
  72. br i1 %matches, label %catch, label %eh.resume, !dbg !23
  73. catch: ; preds = %catch.dispatch
  74. call void @llvm.dbg.declare(metadata i32* %e, metadata !24, metadata !DIExpression()), !dbg !25
  75. %exn = load i8*, i8** %exn.slot, !dbg !23
  76. %5 = call i8* @__cxa_begin_catch(i8* %exn) #2, !dbg !23
  77. %6 = bitcast i8* %5 to i32*, !dbg !23
  78. %7 = load i32, i32* %6, align 4, !dbg !23
  79. store i32 %7, i32* %e, align 4, !dbg !23
  80. store i32 0, i32* @global_var, align 4, !dbg !26
  81. call void @__cxa_end_catch() #2, !dbg !28
  82. br label %try.cont, !dbg !28
  83. try.cont: ; preds = %catch, %invoke.cont
  84. store i32 1, i32* @global_var, align 4, !dbg !29
  85. ret i32 0, !dbg !30
  86. eh.resume: ; preds = %catch.dispatch
  87. %exn1 = load i8*, i8** %exn.slot, !dbg !23
  88. %sel2 = load i32, i32* %ehselector.slot, !dbg !23
  89. %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn1, 0, !dbg !23
  90. %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %sel2, 1, !dbg !23
  91. resume { i8*, i32 } %lpad.val3, !dbg !23
  92. }
  93. declare i32 @__gxx_personality_v0(...)
  94. ; Function Attrs: nounwind readnone
  95. declare i32 @llvm.eh.typeid.for(i8*) #1
  96. declare i8* @__cxa_begin_catch(i8*)
  97. declare void @__cxa_end_catch()
  98. attributes #1 = { nounwind readnone }
  99. attributes #2 = { nounwind }
  100. !llvm.dbg.cu = !{!0}
  101. !llvm.module.flags = !{!31}
  102. !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.3 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
  103. !1 = !DIFile(filename: "<unknown>", directory: "")
  104. !2 = !{}
  105. !4 = distinct !DISubprogram(name: "test", linkageName: "_Z4testi", line: 4, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 4, file: !5, scope: !6, type: !7, retainedNodes: !2)
  106. !5 = !DIFile(filename: "test.cpp", directory: "")
  107. !6 = !DIFile(filename: "test.cpp", directory: "")
  108. !7 = !DISubroutineType(types: !8)
  109. !8 = !{!9, !9}
  110. !9 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
  111. !10 = distinct !DISubprogram(name: "test2", linkageName: "_Z5test2v", line: 11, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 11, file: !5, scope: !6, type: !11, retainedNodes: !2)
  112. !11 = !DISubroutineType(types: !12)
  113. !12 = !{!9}
  114. !13 = !DILocalVariable(name: "k", line: 4, arg: 1, scope: !4, file: !6, type: !9)
  115. !14 = !DILocation(line: 4, scope: !4)
  116. !15 = !DILocalVariable(name: "k2", line: 5, scope: !4, file: !6, type: !9)
  117. !16 = !DILocation(line: 5, scope: !4)
  118. !17 = !DILocation(line: 6, scope: !4)
  119. !18 = !DILocation(line: 7, scope: !4)
  120. !19 = !DILocation(line: 8, scope: !4)
  121. !20 = !DILocation(line: 9, scope: !4)
  122. !21 = !DILocation(line: 14, scope: !22)
  123. !22 = distinct !DILexicalBlock(line: 13, column: 0, file: !5, scope: !10)
  124. !23 = !DILocation(line: 15, scope: !22)
  125. !24 = !DILocalVariable(name: "e", line: 16, scope: !10, file: !6, type: !9)
  126. !25 = !DILocation(line: 16, scope: !10)
  127. !26 = !DILocation(line: 17, scope: !27)
  128. !27 = distinct !DILexicalBlock(line: 16, column: 0, file: !5, scope: !10)
  129. !28 = !DILocation(line: 18, scope: !27)
  130. !29 = !DILocation(line: 19, scope: !10)
  131. !30 = !DILocation(line: 20, scope: !10)
  132. !31 = !{i32 1, !"Debug Info Version", i32 3}