import_facet.carbon 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.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.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.02c.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.8ef080b43913f36e(ptr %.loc5_21.1.temp), !dbg !10
  88. // CHECK:STDOUT: ret ptr %C.GetC.call, !dbg !11
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  92. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: ; Function Attrs: nounwind
  95. // CHECK:STDOUT: define linkonce_odr void @"_CGetI.D.eb057aa32837c84e.Main:I.Main.b88d1103f417c6d4"(ptr sret({}) %return, ptr %self) #0 !dbg !12 {
  96. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %return, ptr align 1 @C.val.02c.anon, i64 0, i1 false), !dbg !16
  97. // CHECK:STDOUT: ret void, !dbg !16
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: ; Function Attrs: nounwind
  101. // CHECK:STDOUT: define linkonce_odr ptr @_CGetC.C.Main.8ef080b43913f36e(ptr %self) #0 !dbg !17 {
  102. // CHECK:STDOUT: %1 = alloca ptr, align 8, !dbg !21
  103. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %1), !dbg !21
  104. // CHECK:STDOUT: %2 = load ptr, ptr %1, align 8, !dbg !22
  105. // CHECK:STDOUT: ret ptr %2, !dbg !23
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  109. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: attributes #0 = { nounwind }
  112. // CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  113. // CHECK:STDOUT: attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  116. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  119. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  120. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  121. // CHECK:STDOUT: !3 = !DIFile(filename: "d.carbon", directory: "")
  122. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !3, line: 4, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
  123. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  124. // CHECK:STDOUT: !6 = !{!7, !7}
  125. // CHECK:STDOUT: !7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 8)
  126. // CHECK:STDOUT: !8 = !{!9}
  127. // CHECK:STDOUT: !9 = !DILocalVariable(arg: 1, scope: !4, type: !7)
  128. // CHECK:STDOUT: !10 = !DILocation(line: 5, column: 10, scope: !4)
  129. // CHECK:STDOUT: !11 = !DILocation(line: 5, column: 3, scope: !4)
  130. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "GetI", linkageName: "_CGetI.D.eb057aa32837c84e.Main:I.Main.b88d1103f417c6d4", scope: null, file: !13, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !14)
  131. // CHECK:STDOUT: !13 = !DIFile(filename: "c.carbon", directory: "")
  132. // CHECK:STDOUT: !14 = !{!15}
  133. // CHECK:STDOUT: !15 = !DILocalVariable(arg: 1, scope: !12, type: !7)
  134. // CHECK:STDOUT: !16 = !DILocation(line: 7, column: 7, scope: !12)
  135. // CHECK:STDOUT: !17 = distinct !DISubprogram(name: "GetC", linkageName: "_CGetC.C.Main.8ef080b43913f36e", scope: null, file: !18, line: 4, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !19)
  136. // CHECK:STDOUT: !18 = !DIFile(filename: "a.carbon", directory: "")
  137. // CHECK:STDOUT: !19 = !{!20}
  138. // CHECK:STDOUT: !20 = !DILocalVariable(arg: 1, scope: !17, type: !7)
  139. // CHECK:STDOUT: !21 = !DILocation(line: 5, column: 5, scope: !17)
  140. // CHECK:STDOUT: !22 = !DILocation(line: 6, column: 12, scope: !17)
  141. // CHECK:STDOUT: !23 = !DILocation(line: 6, column: 5, scope: !17)