method.carbon 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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/class/method.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/class/method.carbon
  10. class C {
  11. var a: i32;
  12. fn Get[self: C]() -> i32;
  13. fn Set[addr self: C*](n: i32);
  14. }
  15. fn F(p: C*) {
  16. let n: i32 = (*p).Get();
  17. (*p).Set(n);
  18. }
  19. // CHECK:STDOUT: ; ModuleID = 'method.carbon'
  20. // CHECK:STDOUT: source_filename = "method.carbon"
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: declare i32 @Get(ptr)
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: declare void @Set(ptr, i32)
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: define void @F(ptr %p) {
  27. // CHECK:STDOUT: entry:
  28. // CHECK:STDOUT: %Get.call = call i32 @Get(ptr %p)
  29. // CHECK:STDOUT: call void @Set(ptr %p, i32 %Get.call)
  30. // CHECK:STDOUT: ret void
  31. // CHECK:STDOUT: }