cross-cu-inlining.ll 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ; REQUIRES: object-emission
  2. ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -v -debug-info - | FileCheck -implicit-check-not=DW_TAG %s
  3. ; RUN: %llc_dwarf -accel-tables=Apple -dwarf-linkage-names=All -O0 -filetype=obj < %s | llvm-dwarfdump -v - | FileCheck --check-prefix=CHECK-ACCEL --check-prefix=CHECK %s
  4. ; Build from source:
  5. ; $ clang++ a.cpp b.cpp -g -c -emit-llvm
  6. ; $ llvm-link a.bc b.bc -o ab.bc
  7. ; $ opt -inline ab.bc -o ab-opt.bc
  8. ; $ cat a.cpp
  9. ; extern int i;
  10. ; int func(int);
  11. ; int main() {
  12. ; return func(i);
  13. ; }
  14. ; $ cat b.cpp
  15. ; int __attribute__((always_inline)) func(int x) {
  16. ; return x * 2;
  17. ; }
  18. ; Ensure that func inlined into main is described and references the abstract
  19. ; definition in b.cpp's CU.
  20. ; CHECK: DW_TAG_compile_unit
  21. ; CHECK: DW_AT_name {{.*}} "a.cpp"
  22. ; CHECK: DW_TAG_subprogram
  23. ; CHECK: DW_AT_type [DW_FORM_ref_addr] (0x00000000[[INT:[a-f0-9]+]]
  24. ; CHECK: 0x[[INLINED:[0-9a-f]*]]:{{.*}}DW_TAG_inlined_subroutine
  25. ; CHECK: DW_AT_abstract_origin {{.*}}[[ABS_FUNC:........]] "_Z4funci"
  26. ; CHECK: DW_TAG_formal_parameter
  27. ; CHECK: DW_AT_abstract_origin {{.*}}[[ABS_VAR:........]] "x"
  28. ; Check the abstract definition is in the 'b.cpp' CU and doesn't contain any
  29. ; concrete information (address range or variable location)
  30. ; CHECK: DW_TAG_compile_unit
  31. ; CHECK: DW_AT_name {{.*}} "b.cpp"
  32. ; CHECK: 0x[[ABS_FUNC]]: DW_TAG_subprogram
  33. ; CHECK-NOT: DW_AT_low_pc
  34. ; CHECK: 0x[[ABS_VAR]]: DW_TAG_formal_parameter
  35. ; CHECK-NOT: DW_AT_location
  36. ; CHECK: DW_AT_type [DW_FORM_ref4] {{.*}} {0x[[INT]]}
  37. ; CHECK-NOT: DW_AT_location
  38. ; CHECK: 0x[[INT]]: DW_TAG_base_type
  39. ; CHECK: DW_AT_name {{.*}} "int"
  40. ; Check the concrete out of line definition references the abstract and
  41. ; provides the address range and variable location
  42. ; CHECK: 0x[[FUNC:[0-9a-f]*]]{{.*}}DW_TAG_subprogram
  43. ; CHECK: DW_AT_low_pc
  44. ; CHECK: DW_AT_abstract_origin {{.*}} {0x[[ABS_FUNC]]} "_Z4funci"
  45. ; CHECK: DW_TAG_formal_parameter
  46. ; CHECK: DW_AT_location
  47. ; CHECK: DW_AT_abstract_origin {{.*}} {0x[[ABS_VAR]]} "x"
  48. ; Check that both the inline and the non out of line version of func are
  49. ; correctly referenced in the accelerator table. Before r221837, the one
  50. ; in the second compilation unit had a wrong offset
  51. ; CHECK-ACCEL: .apple_names contents:
  52. ; CHECK-ACCEL: String{{.*}}"func"
  53. ; CHECK-ACCEL-NOT: String
  54. ; CHECK-ACCEL: Atom[0]{{.*}}[[INLINED]]
  55. ; CHECK-ACCEL-NOT: String
  56. ; CHECK-ACCEL: Atom[0]{{.*}}[[FUNC]]
  57. @i = external global i32
  58. ; Function Attrs: uwtable
  59. define i32 @main() #0 !dbg !4 {
  60. entry:
  61. %x.addr.i = alloca i32, align 4
  62. %retval = alloca i32, align 4
  63. store i32 0, i32* %retval
  64. %0 = load i32, i32* @i, align 4, !dbg !19
  65. %1 = bitcast i32* %x.addr.i to i8*
  66. call void @llvm.lifetime.start(i64 4, i8* %1)
  67. store i32 %0, i32* %x.addr.i, align 4
  68. call void @llvm.dbg.declare(metadata i32* %x.addr.i, metadata !120, metadata !DIExpression()), !dbg !21
  69. %2 = load i32, i32* %x.addr.i, align 4, !dbg !22
  70. %mul.i = mul nsw i32 %2, 2, !dbg !22
  71. %3 = bitcast i32* %x.addr.i to i8*, !dbg !22
  72. call void @llvm.lifetime.end(i64 4, i8* %3), !dbg !22
  73. ret i32 %mul.i, !dbg !19
  74. }
  75. ; Function Attrs: alwaysinline nounwind uwtable
  76. define i32 @_Z4funci(i32 %x) #1 !dbg !12 {
  77. entry:
  78. %x.addr = alloca i32, align 4
  79. store i32 %x, i32* %x.addr, align 4
  80. call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !20, metadata !DIExpression()), !dbg !23
  81. %0 = load i32, i32* %x.addr, align 4, !dbg !24
  82. %mul = mul nsw i32 %0, 2, !dbg !24
  83. ret i32 %mul, !dbg !24
  84. }
  85. ; Function Attrs: nounwind readnone
  86. declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
  87. ; Function Attrs: nounwind
  88. declare void @llvm.lifetime.start(i64, i8* nocapture) #3
  89. ; Function Attrs: nounwind
  90. declare void @llvm.lifetime.end(i64, i8* nocapture) #3
  91. attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
  92. attributes #1 = { alwaysinline nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
  93. attributes #2 = { nounwind readnone }
  94. attributes #3 = { nounwind }
  95. !llvm.dbg.cu = !{!0, !9}
  96. !llvm.module.flags = !{!16, !17}
  97. !llvm.ident = !{!18, !18}
  98. !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
  99. !1 = !DIFile(filename: "a.cpp", directory: "/tmp/dbginfo")
  100. !2 = !{}
  101. !4 = distinct !DISubprogram(name: "main", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2)
  102. !5 = !DIFile(filename: "a.cpp", directory: "/tmp/dbginfo")
  103. !6 = !DISubroutineType(types: !7)
  104. !7 = !{!8}
  105. !8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
  106. !9 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: false, emissionKind: FullDebug, file: !10, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
  107. !10 = !DIFile(filename: "b.cpp", directory: "/tmp/dbginfo")
  108. !12 = distinct !DISubprogram(name: "func", linkageName: "_Z4funci", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !9, scopeLine: 1, file: !10, scope: !13, type: !14, retainedNodes: !2)
  109. !13 = !DIFile(filename: "b.cpp", directory: "/tmp/dbginfo")
  110. !14 = !DISubroutineType(types: !15)
  111. !15 = !{!8, !8}
  112. !16 = !{i32 2, !"Dwarf Version", i32 4}
  113. !17 = !{i32 2, !"Debug Info Version", i32 3}
  114. !18 = !{!"clang version 3.5.0 "}
  115. !19 = !DILocation(line: 4, scope: !4)
  116. !20 = !DILocalVariable(name: "x", line: 1, arg: 1, scope: !12, file: !13, type: !8)
  117. !120 = !DILocalVariable(name: "x", line: 1, arg: 1, scope: !12, file: !13, type: !8)
  118. !21 = !DILocation(line: 1, scope: !12, inlinedAt: !19)
  119. !22 = !DILocation(line: 2, scope: !12, inlinedAt: !19)
  120. !23 = !DILocation(line: 1, scope: !12)
  121. !24 = !DILocation(line: 2, scope: !12)