import.carbon 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/impl/import.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/impl/import.carbon
  12. // --- impl_def.carbon
  13. library "[[@TEST_NAME]]";
  14. interface I {
  15. fn F[self: Self]() -> i32;
  16. }
  17. class A {
  18. var n: i32;
  19. }
  20. impl A as I {
  21. fn F[self: A]() -> i32 {
  22. return self.n;
  23. }
  24. }
  25. // --- impl_use.carbon
  26. import library "impl_def";
  27. fn Call(a: A) -> i32 {
  28. return a.(I.F)();
  29. }
  30. // CHECK:STDOUT: ; ModuleID = 'impl_def.carbon'
  31. // CHECK:STDOUT: source_filename = "impl_def.carbon"
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: ; Function Attrs: nounwind
  34. // CHECK:STDOUT: define i32 @"_CF.A.Main:I.Main"(ptr %self) #0 !dbg !4 {
  35. // CHECK:STDOUT: entry:
  36. // CHECK:STDOUT: %.loc14_16.1.n = getelementptr inbounds nuw { i32 }, ptr %self, i32 0, i32 0, !dbg !11
  37. // CHECK:STDOUT: %.loc14_16.2 = load i32, ptr %.loc14_16.1.n, align 4, !dbg !11
  38. // CHECK:STDOUT: ret i32 %.loc14_16.2, !dbg !12
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: attributes #0 = { nounwind }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  44. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  47. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  48. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  49. // CHECK:STDOUT: !3 = !DIFile(filename: "impl_def.carbon", directory: "")
  50. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.A.Main:I.Main", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !9)
  51. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  52. // CHECK:STDOUT: !6 = !{!7, !8}
  53. // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  54. // CHECK:STDOUT: !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 8)
  55. // CHECK:STDOUT: !9 = !{!10}
  56. // CHECK:STDOUT: !10 = !DILocalVariable(arg: 1, scope: !4, type: !8)
  57. // CHECK:STDOUT: !11 = !DILocation(line: 14, column: 12, scope: !4)
  58. // CHECK:STDOUT: !12 = !DILocation(line: 14, column: 5, scope: !4)
  59. // CHECK:STDOUT: ; ModuleID = 'impl_use.carbon'
  60. // CHECK:STDOUT: source_filename = "impl_use.carbon"
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: ; Function Attrs: nounwind
  63. // CHECK:STDOUT: define i32 @_CCall.Main(ptr %a) #0 !dbg !4 {
  64. // CHECK:STDOUT: entry:
  65. // CHECK:STDOUT: %A.as.I.impl.F.call = call i32 @"_CF.A.Main:I.Main"(ptr %a), !dbg !11
  66. // CHECK:STDOUT: ret i32 %A.as.I.impl.F.call, !dbg !12
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: declare i32 @"_CF.A.Main:I.Main"(ptr)
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: attributes #0 = { nounwind }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  74. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  77. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  78. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  79. // CHECK:STDOUT: !3 = !DIFile(filename: "impl_use.carbon", directory: "")
  80. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Call", linkageName: "_CCall.Main", scope: null, file: !3, line: 4, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !9)
  81. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  82. // CHECK:STDOUT: !6 = !{!7, !8}
  83. // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  84. // CHECK:STDOUT: !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 8)
  85. // CHECK:STDOUT: !9 = !{!10}
  86. // CHECK:STDOUT: !10 = !DILocalVariable(arg: 1, scope: !4, type: !8)
  87. // CHECK:STDOUT: !11 = !DILocation(line: 5, column: 10, scope: !4)
  88. // CHECK:STDOUT: !12 = !DILocation(line: 5, column: 3, scope: !4)