impl.carbon 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/impl.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/impl/impl.carbon
  12. interface I {
  13. fn F[self: Self]() -> i32;
  14. }
  15. class A {
  16. var n: i32;
  17. }
  18. impl A as I {
  19. fn F[self: A]() -> i32 {
  20. return self.n;
  21. }
  22. }
  23. fn Call(a: A) -> i32 {
  24. return a.(I.F)();
  25. }
  26. // CHECK:STDOUT: ; ModuleID = 'impl.carbon'
  27. // CHECK:STDOUT: source_filename = "impl.carbon"
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: define i32 @"_CF.A.Main:I.Main"(ptr %self) !dbg !4 {
  30. // CHECK:STDOUT: entry:
  31. // CHECK:STDOUT: %.loc23_16.1.n = getelementptr inbounds nuw { i32 }, ptr %self, i32 0, i32 0, !dbg !7
  32. // CHECK:STDOUT: %.loc23_16.2 = load i32, ptr %.loc23_16.1.n, align 4, !dbg !7
  33. // CHECK:STDOUT: ret i32 %.loc23_16.2, !dbg !8
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: define i32 @_CCall.Main(ptr %a) !dbg !9 {
  37. // CHECK:STDOUT: entry:
  38. // CHECK:STDOUT: %A.as.I.impl.F.call = call i32 @"_CF.A.Main:I.Main"(ptr %a), !dbg !10
  39. // CHECK:STDOUT: ret i32 %A.as.I.impl.F.call, !dbg !11
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  43. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  46. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  47. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  48. // CHECK:STDOUT: !3 = !DIFile(filename: "impl.carbon", directory: "")
  49. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.A.Main:I.Main", scope: null, file: !3, line: 22, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  50. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  51. // CHECK:STDOUT: !6 = !{}
  52. // CHECK:STDOUT: !7 = !DILocation(line: 23, column: 12, scope: !4)
  53. // CHECK:STDOUT: !8 = !DILocation(line: 23, column: 5, scope: !4)
  54. // CHECK:STDOUT: !9 = distinct !DISubprogram(name: "Call", linkageName: "_CCall.Main", scope: null, file: !3, line: 27, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  55. // CHECK:STDOUT: !10 = !DILocation(line: 28, column: 10, scope: !9)
  56. // CHECK:STDOUT: !11 = !DILocation(line: 28, column: 3, scope: !9)