address_of_deref.carbon 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/check/testdata/pointer/address_of_deref.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/address_of_deref.carbon
  10. fn F() -> i32 {
  11. var n: i32 = 0;
  12. return *&*&n;
  13. }
  14. // CHECK:STDOUT: --- address_of_deref.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  18. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  19. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  20. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  21. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  22. // CHECK:STDOUT: %.2: i32 = int_literal 0 [template]
  23. // CHECK:STDOUT: %.3: type = ptr_type i32 [template]
  24. // CHECK:STDOUT: }
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: file {
  27. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  28. // CHECK:STDOUT: .Core = %Core
  29. // CHECK:STDOUT: .F = %F.decl
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  32. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  33. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  34. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  35. // CHECK:STDOUT: %.loc11_11.1: type = value_of_initializer %int.make_type_32 [template = i32]
  36. // CHECK:STDOUT: %.loc11_11.2: type = converted %int.make_type_32, %.loc11_11.1 [template = i32]
  37. // CHECK:STDOUT: @F.%return: ref i32 = var <return slot>
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: fn @F() -> i32 {
  45. // CHECK:STDOUT: !entry:
  46. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  47. // CHECK:STDOUT: %.loc12_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  48. // CHECK:STDOUT: %.loc12_10.2: type = converted %int.make_type_32, %.loc12_10.1 [template = i32]
  49. // CHECK:STDOUT: %n.var: ref i32 = var n
  50. // CHECK:STDOUT: %n: ref i32 = bind_name n, %n.var
  51. // CHECK:STDOUT: %.loc12_16: i32 = int_literal 0 [template = constants.%.2]
  52. // CHECK:STDOUT: assign %n.var, %.loc12_16
  53. // CHECK:STDOUT: %n.ref: ref i32 = name_ref n, %n
  54. // CHECK:STDOUT: %.loc13_13: %.3 = addr_of %n.ref
  55. // CHECK:STDOUT: %.loc13_12: ref i32 = deref %.loc13_13
  56. // CHECK:STDOUT: %.loc13_11: %.3 = addr_of %.loc13_12
  57. // CHECK:STDOUT: %.loc13_10.1: ref i32 = deref %.loc13_11
  58. // CHECK:STDOUT: %.loc13_10.2: i32 = bind_value %.loc13_10.1
  59. // CHECK:STDOUT: return %.loc13_10.2
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: