import_facet.carbon 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // This is testing a facet type that combines two interfaces across multiple
  6. // import boundaries.
  7. //
  8. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon
  9. //
  10. // AUTOUPDATE
  11. // TIP: To test this file alone, run:
  12. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/impl/import_facet.carbon
  13. // TIP: To dump output, run:
  14. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/impl/import_facet.carbon
  15. // --- a.carbon
  16. library "[[@TEST_NAME]]";
  17. class C(T:! Core.Copy & Core.UnformedInit & Core.Destroy) {
  18. fn GetC[unused self: Self]() -> T {
  19. var value: T;
  20. return value;
  21. }
  22. }
  23. // --- b.carbon
  24. library "[[@TEST_NAME]]";
  25. export import library "a";
  26. interface I {
  27. let T:! Core.Copy & Core.UnformedInit & Core.Destroy;
  28. fn GetI[unused self: Self]() -> C(T);
  29. }
  30. // --- c.carbon
  31. library "[[@TEST_NAME]]";
  32. export import library "b";
  33. class D(T:! type) {
  34. impl as I where .T = T* {
  35. fn GetI[unused self: Self]() -> C(T*) {
  36. return {};
  37. }
  38. }
  39. }
  40. // --- d.carbon
  41. library "[[@TEST_NAME]]";
  42. import library "c";
  43. fn F(d: D(i32)) -> i32* {
  44. return d.(I.GetI)().GetC();
  45. }
  46. // CHECK:STDOUT: ; ModuleID = 'a.carbon'
  47. // CHECK:STDOUT: source_filename = "a.carbon"
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  50. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  53. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  54. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  55. // CHECK:STDOUT: !3 = !DIFile(filename: "a.carbon", directory: "")
  56. // CHECK:STDOUT: ; ModuleID = 'b.carbon'
  57. // CHECK:STDOUT: source_filename = "b.carbon"
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  60. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  63. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  64. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  65. // CHECK:STDOUT: !3 = !DIFile(filename: "b.carbon", directory: "")
  66. // CHECK:STDOUT: ; ModuleID = 'c.carbon'
  67. // CHECK:STDOUT: source_filename = "c.carbon"
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  70. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  73. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  74. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  75. // CHECK:STDOUT: !3 = !DIFile(filename: "c.carbon", directory: "")
  76. // CHECK:STDOUT: ; ModuleID = 'd.carbon'
  77. // CHECK:STDOUT: source_filename = "d.carbon"
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: @C.val.23a.anon = internal constant {} zeroinitializer
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: ; Function Attrs: nounwind
  82. // CHECK:STDOUT: define ptr @_CF.Main(ptr %d) #0 !dbg !4 {
  83. // CHECK:STDOUT: entry:
  84. // CHECK:STDOUT: %.loc5_21.1.temp = alloca {}, align 8, !dbg !10
  85. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc5_21.1.temp), !dbg !10
  86. // CHECK:STDOUT: call void @"_CGetI.D.eb057aa32837c84e.Main:I.Main.b88d1103f417c6d4"(ptr %.loc5_21.1.temp, ptr %d), !dbg !10
  87. // CHECK:STDOUT: %C.GetC.call = call ptr @_CGetC.C.Main.541f3e0ecf5901d3(ptr %.loc5_21.1.temp), !dbg !10
  88. // CHECK:STDOUT: call void @"_COp.82ecdab79d079066:core.Destroy.Core"(ptr %.loc5_21.1.temp), !dbg !10
  89. // CHECK:STDOUT: ret ptr %C.GetC.call, !dbg !11
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: ; Function Attrs: nounwind
  93. // CHECK:STDOUT: define weak_odr void @"_COp.82ecdab79d079066:core.Destroy.Core"(ptr %self) #0 !dbg !12 {
  94. // CHECK:STDOUT: entry:
  95. // CHECK:STDOUT: ret void, !dbg !17
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  99. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: ; Function Attrs: nounwind
  102. // CHECK:STDOUT: define linkonce_odr void @"_CGetI.D.eb057aa32837c84e.Main:I.Main.b88d1103f417c6d4"(ptr sret({}) %return, ptr %self) #0 !dbg !18 {
  103. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %return, ptr align 1 @C.val.23a.anon, i64 0, i1 false), !dbg !22
  104. // CHECK:STDOUT: ret void, !dbg !22
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: ; Function Attrs: nounwind
  108. // CHECK:STDOUT: define linkonce_odr ptr @_CGetC.C.Main.541f3e0ecf5901d3(ptr %self) #0 !dbg !23 {
  109. // CHECK:STDOUT: %1 = alloca ptr, align 8, !dbg !27
  110. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %1), !dbg !27
  111. // CHECK:STDOUT: store ptr poison, ptr %1, align 8, !dbg !27
  112. // CHECK:STDOUT: %2 = load ptr, ptr %1, align 8, !dbg !28
  113. // CHECK:STDOUT: ret ptr %2, !dbg !29
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  117. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: attributes #0 = { nounwind }
  120. // CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  121. // CHECK:STDOUT: attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  124. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  127. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  128. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  129. // CHECK:STDOUT: !3 = !DIFile(filename: "d.carbon", directory: "")
  130. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !3, line: 4, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
  131. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  132. // CHECK:STDOUT: !6 = !{!7, !7}
  133. // CHECK:STDOUT: !7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
  134. // CHECK:STDOUT: !8 = !{!9}
  135. // CHECK:STDOUT: !9 = !DILocalVariable(arg: 1, scope: !4, type: !7)
  136. // CHECK:STDOUT: !10 = !DILocation(line: 5, column: 10, scope: !4)
  137. // CHECK:STDOUT: !11 = !DILocation(line: 5, column: 3, scope: !4)
  138. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "Op", linkageName: "_COp.82ecdab79d079066:core.Destroy.Core", scope: null, file: !3, line: 5, type: !13, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !15)
  139. // CHECK:STDOUT: !13 = !DISubroutineType(types: !14)
  140. // CHECK:STDOUT: !14 = !{null, !7}
  141. // CHECK:STDOUT: !15 = !{!16}
  142. // CHECK:STDOUT: !16 = !DILocalVariable(arg: 1, scope: !12, type: !7)
  143. // CHECK:STDOUT: !17 = !DILocation(line: 5, column: 10, scope: !12)
  144. // CHECK:STDOUT: !18 = distinct !DISubprogram(name: "GetI", linkageName: "_CGetI.D.eb057aa32837c84e.Main:I.Main.b88d1103f417c6d4", scope: null, file: !19, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !20)
  145. // CHECK:STDOUT: !19 = !DIFile(filename: "c.carbon", directory: "")
  146. // CHECK:STDOUT: !20 = !{!21}
  147. // CHECK:STDOUT: !21 = !DILocalVariable(arg: 1, scope: !18, type: !7)
  148. // CHECK:STDOUT: !22 = !DILocation(line: 7, column: 7, scope: !18)
  149. // CHECK:STDOUT: !23 = distinct !DISubprogram(name: "GetC", linkageName: "_CGetC.C.Main.541f3e0ecf5901d3", scope: null, file: !24, line: 4, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !25)
  150. // CHECK:STDOUT: !24 = !DIFile(filename: "a.carbon", directory: "")
  151. // CHECK:STDOUT: !25 = !{!26}
  152. // CHECK:STDOUT: !26 = !DILocalVariable(arg: 1, scope: !23, type: !7)
  153. // CHECK:STDOUT: !27 = !DILocation(line: 5, column: 5, scope: !23)
  154. // CHECK:STDOUT: !28 = !DILocation(line: 6, column: 12, scope: !23)
  155. // CHECK:STDOUT: !29 = !DILocation(line: 6, column: 5, scope: !23)