recursive_inlining.ll 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. ; REQUIRES: object-emission
  2. ; RUN: %llc_dwarf -filetype=obj -O0 < %s | llvm-dwarfdump -v -debug-info - | FileCheck %s
  3. ; This isn't a very pretty test case - I imagine there might be other ways to
  4. ; tickle the optimizers into producing the desired code, but I haven't found
  5. ; them.
  6. ; The issue is when a function is inlined into itself, the inlined argument
  7. ; accidentally overwrote the concrete argument and was lost.
  8. ; IR generated from the following source compiled with clang -g:
  9. ; void fn1(void *);
  10. ; void fn2(int, int, int, int);
  11. ; void fn3();
  12. ; void fn8();
  13. ; struct C {
  14. ; int b;
  15. ; void m_fn2() {
  16. ; fn8();
  17. ; if (b) fn2(0, 0, 0, 0);
  18. ; fn3();
  19. ; }
  20. ; };
  21. ; C *x;
  22. ; inline void fn7() {}
  23. ; void fn6() {
  24. ; fn8();
  25. ; x->m_fn2();
  26. ; fn7();
  27. ; }
  28. ; void fn3() { fn6(); }
  29. ; void fn4() { x->m_fn2(); }
  30. ; void fn5() { x->m_fn2(); }
  31. ; The definition of C and declaration of C::m_fn2
  32. ; CHECK: DW_TAG_structure_type
  33. ; CHECK-NOT: {{DW_TAG|NULL}}
  34. ; CHECK: DW_TAG_member
  35. ; CHECK-NOT: {{DW_TAG|NULL}}
  36. ; CHECK: [[M_FN2_DECL:.*]]: DW_TAG_subprogram
  37. ; CHECK-NOT: DW_TAG
  38. ; CHECK: DW_AT_name {{.*}} "m_fn2"
  39. ; CHECK-NOT: {{DW_TAG|NULL}}
  40. ; CHECK: DW_TAG_formal_parameter
  41. ; The abstract definition of C::m_fn2
  42. ; CHECK: [[M_FN2_ABS_DEF:.*]]: DW_TAG_subprogram
  43. ; CHECK-NOT: DW_TAG
  44. ; CHECK: DW_AT_specification {{.*}} {[[M_FN2_DECL]]}
  45. ; CHECK-NOT: DW_TAG
  46. ; CHECK: DW_AT_inline
  47. ; CHECK-NOT: {{DW_TAG|NULL}}
  48. ; CHECK: [[M_FN2_THIS_ABS_DEF:.*]]: DW_TAG_formal_parameter
  49. ; CHECK-NOT: DW_TAG
  50. ; CHECK: DW_AT_name {{.*}} "this"
  51. ; Skip some other functions
  52. ; CHECK: DW_TAG_subprogram
  53. ; CHECK: DW_TAG_subprogram
  54. ; CHECK: DW_TAG_subprogram
  55. ; The concrete definition of C::m_fn2
  56. ; CHECK: DW_TAG_subprogram
  57. ; CHECK-NOT: DW_TAG
  58. ; CHECK: DW_AT_abstract_origin {{.*}} {[[M_FN2_ABS_DEF]]}
  59. ; CHECK-NOT: {{DW_TAG|NULL}}
  60. ; CHECK: DW_TAG_formal_parameter
  61. ; CHECK-NOT: DW_TAG
  62. ; CHECK: DW_AT_abstract_origin {{.*}} {[[M_FN2_THIS_ABS_DEF]]}
  63. ; CHECK-NOT: {{DW_TAG|NULL}}
  64. ; Inlined fn3:
  65. ; CHECK: DW_TAG_inlined_subroutine
  66. ; CHECK-NOT: {{DW_TAG|NULL}}
  67. ; Inlined fn6:
  68. ; CHECK: DW_TAG_inlined_subroutine
  69. ; CHECK-NOT: {{DW_TAG|NULL}}
  70. ; Inlined C::m_fn2:
  71. ; CHECK: DW_TAG_inlined_subroutine
  72. ; CHECK-NOT: DW_TAG
  73. ; CHECK: DW_AT_abstract_origin {{.*}} {[[M_FN2_ABS_DEF]]}
  74. ; CHECK-NOT: {{DW_TAG|NULL}}
  75. ; CHECK: DW_TAG_formal_parameter
  76. ; CHECK-NOT: DW_TAG
  77. ; CHECK: DW_AT_abstract_origin {{.*}} {[[M_FN2_THIS_ABS_DEF]]}
  78. source_filename = "test/DebugInfo/Generic/recursive_inlining.ll"
  79. %struct.C = type { i32 }
  80. @x = global %struct.C* null, align 8, !dbg !0
  81. ; Function Attrs: nounwind
  82. define void @_Z3fn6v() #0 !dbg !20 {
  83. entry:
  84. tail call void @_Z3fn8v() #3, !dbg !23
  85. %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !24, !tbaa !25
  86. tail call void @llvm.dbg.value(metadata %struct.C* %0, metadata !29, metadata !32) #3, !dbg !33
  87. tail call void @_Z3fn8v() #3, !dbg !34
  88. %b.i = getelementptr inbounds %struct.C, %struct.C* %0, i64 0, i32 0, !dbg !35
  89. %1 = load i32, i32* %b.i, align 4, !dbg !35, !tbaa !37
  90. %tobool.i = icmp eq i32 %1, 0, !dbg !35
  91. br i1 %tobool.i, label %_ZN1C5m_fn2Ev.exit, label %if.then.i, !dbg !35
  92. if.then.i: ; preds = %entry
  93. tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !40
  94. br label %_ZN1C5m_fn2Ev.exit, !dbg !40
  95. _ZN1C5m_fn2Ev.exit: ; preds = %if.then.i, %entry
  96. tail call void @_Z3fn3v() #3, !dbg !42
  97. ret void, !dbg !43
  98. }
  99. declare void @_Z3fn8v() #1
  100. ; Function Attrs: nounwind
  101. define linkonce_odr void @_ZN1C5m_fn2Ev(%struct.C* nocapture readonly %this) #0 align 2 !dbg !30 {
  102. entry:
  103. tail call void @llvm.dbg.value(metadata %struct.C* %this, metadata !29, metadata !32), !dbg !44
  104. tail call void @_Z3fn8v() #3, !dbg !45
  105. %b = getelementptr inbounds %struct.C, %struct.C* %this, i64 0, i32 0, !dbg !46
  106. %0 = load i32, i32* %b, align 4, !dbg !46, !tbaa !37
  107. %tobool = icmp eq i32 %0, 0, !dbg !46
  108. br i1 %tobool, label %if.end, label %if.then, !dbg !46
  109. if.then: ; preds = %entry
  110. tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !47
  111. br label %if.end, !dbg !47
  112. if.end: ; preds = %if.then, %entry
  113. tail call void @_Z3fn8v() #3, !dbg !48
  114. %1 = load %struct.C*, %struct.C** @x, align 8, !dbg !52, !tbaa !25
  115. tail call void @llvm.dbg.value(metadata %struct.C* %1, metadata !29, metadata !32) #3, !dbg !53
  116. tail call void @_Z3fn8v() #3, !dbg !54
  117. %b.i.i = getelementptr inbounds %struct.C, %struct.C* %1, i64 0, i32 0, !dbg !55
  118. %2 = load i32, i32* %b.i.i, align 4, !dbg !55, !tbaa !37
  119. %tobool.i.i = icmp eq i32 %2, 0, !dbg !55
  120. br i1 %tobool.i.i, label %_Z3fn6v.exit, label %if.then.i.i, !dbg !55
  121. if.then.i.i: ; preds = %if.end
  122. tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !56
  123. br label %_Z3fn6v.exit, !dbg !56
  124. _Z3fn6v.exit: ; preds = %if.then.i.i, %if.end
  125. tail call void @_Z3fn3v() #3, !dbg !57
  126. ret void, !dbg !58
  127. }
  128. ; Function Attrs: nounwind
  129. define void @_Z3fn3v() #0 !dbg !50 {
  130. entry:
  131. br label %tailrecurse
  132. tailrecurse: ; preds = %tailrecurse.backedge, %entry
  133. tail call void @_Z3fn8v() #3, !dbg !59
  134. %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !61, !tbaa !25
  135. tail call void @llvm.dbg.value(metadata %struct.C* %0, metadata !29, metadata !32) #3, !dbg !62
  136. tail call void @_Z3fn8v() #3, !dbg !63
  137. %b.i.i = getelementptr inbounds %struct.C, %struct.C* %0, i64 0, i32 0, !dbg !64
  138. %1 = load i32, i32* %b.i.i, align 4, !dbg !64, !tbaa !37
  139. %tobool.i.i = icmp eq i32 %1, 0, !dbg !64
  140. br i1 %tobool.i.i, label %tailrecurse.backedge, label %if.then.i.i, !dbg !64
  141. tailrecurse.backedge: ; preds = %if.then.i.i, %tailrecurse
  142. br label %tailrecurse
  143. if.then.i.i: ; preds = %tailrecurse
  144. tail call void @_Z3fn2iiii(i32 0, i32 0, i32 0, i32 0) #3, !dbg !65
  145. br label %tailrecurse.backedge, !dbg !65
  146. }
  147. ; Function Attrs: nounwind
  148. define void @_Z3fn4v() #0 !dbg !66 {
  149. entry:
  150. %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !67, !tbaa !25
  151. tail call void @_ZN1C5m_fn2Ev(%struct.C* %0), !dbg !67
  152. ret void, !dbg !67
  153. }
  154. ; Function Attrs: nounwind
  155. define void @_Z3fn5v() #0 !dbg !68 {
  156. entry:
  157. %0 = load %struct.C*, %struct.C** @x, align 8, !dbg !69, !tbaa !25
  158. tail call void @_ZN1C5m_fn2Ev(%struct.C* %0), !dbg !69
  159. ret void, !dbg !69
  160. }
  161. declare void @_Z3fn2iiii(i32, i32, i32, i32) #1
  162. ; Function Attrs: nounwind readnone
  163. declare void @llvm.dbg.value(metadata, metadata, metadata) #2
  164. attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
  165. attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
  166. attributes #2 = { nounwind readnone }
  167. attributes #3 = { nounwind }
  168. !llvm.dbg.cu = !{!12}
  169. !llvm.module.flags = !{!17, !18}
  170. !llvm.ident = !{!19}
  171. !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
  172. !1 = !DIGlobalVariable(name: "x", scope: null, file: !2, line: 13, type: !3, isLocal: false, isDefinition: true)
  173. !2 = !DIFile(filename: "recursive_inlining.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch/missing_concrete_variable_on_darwin/reduce")
  174. !3 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64, align: 64)
  175. !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "C", file: !2, line: 5, size: 32, align: 32, elements: !5, identifier: "_ZTS1C")
  176. !5 = !{!6, !8}
  177. !6 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !4, file: !2, line: 6, baseType: !7, size: 32, align: 32)
  178. !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
  179. !8 = !DISubprogram(name: "m_fn2", linkageName: "_ZN1C5m_fn2Ev", scope: !4, file: !2, line: 7, type: !9, isLocal: false, isDefinition: false, scopeLine: 7, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true)
  180. !9 = !DISubroutineType(types: !10)
  181. !10 = !{null, !11}
  182. !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
  183. !12 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !13, producer: "clang version 3.6.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !14, retainedTypes: !15, globals: !16, imports: !14)
  184. !13 = !DIFile(filename: "<stdin>", directory: "/usr/local/google/home/blaikie/dev/scratch/missing_concrete_variable_on_darwin/reduce")
  185. !14 = !{}
  186. !15 = !{!4}
  187. !16 = !{!0}
  188. !17 = !{i32 2, !"Dwarf Version", i32 4}
  189. !18 = !{i32 2, !"Debug Info Version", i32 3}
  190. !19 = !{!"clang version 3.6.0 "}
  191. !20 = distinct !DISubprogram(name: "fn6", linkageName: "_Z3fn6v", scope: !2, file: !2, line: 15, type: !21, isLocal: false, isDefinition: true, scopeLine: 15, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !12, retainedNodes: !14)
  192. !21 = !DISubroutineType(types: !22)
  193. !22 = !{null}
  194. !23 = !DILocation(line: 16, scope: !20)
  195. !24 = !DILocation(line: 17, scope: !20)
  196. !25 = !{!26, !26, i64 0}
  197. !26 = !{!"any pointer", !27, i64 0}
  198. !27 = !{!"omnipotent char", !28, i64 0}
  199. !28 = !{!"Simple C/C++ TBAA"}
  200. !29 = !DILocalVariable(name: "this", arg: 1, scope: !30, type: !3, flags: DIFlagArtificial | DIFlagObjectPointer)
  201. !30 = distinct !DISubprogram(name: "m_fn2", linkageName: "_ZN1C5m_fn2Ev", scope: !4, file: !2, line: 7, type: !9, isLocal: false, isDefinition: true, scopeLine: 7, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !12, declaration: !8, retainedNodes: !31)
  202. !31 = !{!29}
  203. !32 = !DIExpression()
  204. !33 = !DILocation(line: 0, scope: !30, inlinedAt: !24)
  205. !34 = !DILocation(line: 8, scope: !30, inlinedAt: !24)
  206. !35 = !DILocation(line: 9, scope: !36, inlinedAt: !24)
  207. !36 = distinct !DILexicalBlock(scope: !30, file: !2, line: 9)
  208. !37 = !{!38, !39, i64 0}
  209. !38 = !{!"struct", !39, i64 0}
  210. !39 = !{!"int", !27, i64 0}
  211. !40 = !DILocation(line: 9, scope: !41, inlinedAt: !24)
  212. !41 = distinct !DILexicalBlock(scope: !36, file: !2, line: 9)
  213. !42 = !DILocation(line: 10, scope: !30, inlinedAt: !24)
  214. !43 = !DILocation(line: 19, scope: !20)
  215. !44 = !DILocation(line: 0, scope: !30)
  216. !45 = !DILocation(line: 8, scope: !30)
  217. !46 = !DILocation(line: 9, scope: !36)
  218. !47 = !DILocation(line: 9, scope: !41)
  219. !48 = !DILocation(line: 16, scope: !20, inlinedAt: !49)
  220. !49 = !DILocation(line: 20, scope: !50, inlinedAt: !51)
  221. !50 = distinct !DISubprogram(name: "fn3", linkageName: "_Z3fn3v", scope: !2, file: !2, line: 20, type: !21, isLocal: false, isDefinition: true, scopeLine: 20, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !12, retainedNodes: !14)
  222. !51 = !DILocation(line: 10, scope: !30)
  223. !52 = !DILocation(line: 17, scope: !20, inlinedAt: !49)
  224. !53 = !DILocation(line: 0, scope: !30, inlinedAt: !52)
  225. !54 = !DILocation(line: 8, scope: !30, inlinedAt: !52)
  226. !55 = !DILocation(line: 9, scope: !36, inlinedAt: !52)
  227. !56 = !DILocation(line: 9, scope: !41, inlinedAt: !52)
  228. !57 = !DILocation(line: 10, scope: !30, inlinedAt: !52)
  229. !58 = !DILocation(line: 11, scope: !30)
  230. !59 = !DILocation(line: 16, scope: !20, inlinedAt: !60)
  231. !60 = !DILocation(line: 20, scope: !50)
  232. !61 = !DILocation(line: 17, scope: !20, inlinedAt: !60)
  233. !62 = !DILocation(line: 0, scope: !30, inlinedAt: !61)
  234. !63 = !DILocation(line: 8, scope: !30, inlinedAt: !61)
  235. !64 = !DILocation(line: 9, scope: !36, inlinedAt: !61)
  236. !65 = !DILocation(line: 9, scope: !41, inlinedAt: !61)
  237. !66 = distinct !DISubprogram(name: "fn4", linkageName: "_Z3fn4v", scope: !2, file: !2, line: 21, type: !21, isLocal: false, isDefinition: true, scopeLine: 21, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !12, retainedNodes: !14)
  238. !67 = !DILocation(line: 21, scope: !66)
  239. !68 = distinct !DISubprogram(name: "fn5", linkageName: "_Z3fn5v", scope: !2, file: !2, line: 22, type: !21, isLocal: false, isDefinition: true, scopeLine: 22, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !12, retainedNodes: !14)
  240. !69 = !DILocation(line: 22, scope: !68)