impl.carbon 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/impl/impl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/impl/impl.carbon
  10. interface I {
  11. fn F[self: Self]() -> i32;
  12. }
  13. class A {
  14. var n: i32;
  15. }
  16. impl A as I {
  17. fn F[self: A]() -> i32 {
  18. return self.n;
  19. }
  20. }
  21. fn Call(a: A) -> i32 {
  22. return a.(I.F)();
  23. }
  24. // CHECK:STDOUT: ; ModuleID = 'impl.carbon'
  25. // CHECK:STDOUT: source_filename = "impl.carbon"
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: define i32 @F(ptr %self) {
  28. // CHECK:STDOUT: entry:
  29. // CHECK:STDOUT: %.loc21_16.1.n = getelementptr inbounds { i32 }, ptr %self, i32 0, i32 0
  30. // CHECK:STDOUT: %.loc21_16.2 = load i32, ptr %.loc21_16.1.n, align 4
  31. // CHECK:STDOUT: ret i32 %.loc21_16.2
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: define i32 @Call(ptr %a) {
  35. // CHECK:STDOUT: entry:
  36. // CHECK:STDOUT: %F.call = call i32 @F(ptr %a)
  37. // CHECK:STDOUT: ret i32 %F.call
  38. // CHECK:STDOUT: }