inline-debug-info.ll 6.8 KB

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