member_access.carbon 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/struct/member_access.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/member_access.carbon
  10. var x: {.a: f64, .b: i32} = {.a = 0.0, .b = 1};
  11. var y: i32 = x.b;
  12. var z: i32 = y;
  13. // CHECK:STDOUT: --- member_access.carbon
  14. // CHECK:STDOUT:
  15. // CHECK:STDOUT: constants {
  16. // CHECK:STDOUT: %.1: i32 = int_literal 64 [template]
  17. // CHECK:STDOUT: %Float.type: type = fn_type @Float [template]
  18. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  19. // CHECK:STDOUT: %Float: %Float.type = struct_value () [template]
  20. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  21. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  22. // CHECK:STDOUT: %.3: type = struct_type {.a: f64, .b: i32} [template]
  23. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  24. // CHECK:STDOUT: %.5: f64 = float_literal 0 [template]
  25. // CHECK:STDOUT: %.6: i32 = int_literal 1 [template]
  26. // CHECK:STDOUT: %struct: %.3 = struct_value (%.5, %.6) [template]
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: file {
  30. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  31. // CHECK:STDOUT: .Core = %Core
  32. // CHECK:STDOUT: .x = %x
  33. // CHECK:STDOUT: .y = %y
  34. // CHECK:STDOUT: .z = %z
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  37. // CHECK:STDOUT: %.loc11_13.1: i32 = int_literal 64 [template = constants.%.1]
  38. // CHECK:STDOUT: %import_ref.1: %Float.type = import_ref ir3, inst+31, loaded [template = constants.%Float]
  39. // CHECK:STDOUT: %float.make_type: init type = call constants.%Float(%.loc11_13.1) [template = f64]
  40. // CHECK:STDOUT: %.loc11_13.2: type = value_of_initializer %float.make_type [template = f64]
  41. // CHECK:STDOUT: %.loc11_13.3: type = converted %float.make_type, %.loc11_13.2 [template = f64]
  42. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  43. // CHECK:STDOUT: %int.make_type_32.loc11: init type = call constants.%Int32() [template = i32]
  44. // CHECK:STDOUT: %.loc11_22.1: type = value_of_initializer %int.make_type_32.loc11 [template = i32]
  45. // CHECK:STDOUT: %.loc11_22.2: type = converted %int.make_type_32.loc11, %.loc11_22.1 [template = i32]
  46. // CHECK:STDOUT: %.loc11_25: type = struct_type {.a: f64, .b: i32} [template = constants.%.3]
  47. // CHECK:STDOUT: %x.var: ref %.3 = var x
  48. // CHECK:STDOUT: %x: ref %.3 = bind_name x, %x.var
  49. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  50. // CHECK:STDOUT: %int.make_type_32.loc12: init type = call constants.%Int32() [template = i32]
  51. // CHECK:STDOUT: %.loc12_8.1: type = value_of_initializer %int.make_type_32.loc12 [template = i32]
  52. // CHECK:STDOUT: %.loc12_8.2: type = converted %int.make_type_32.loc12, %.loc12_8.1 [template = i32]
  53. // CHECK:STDOUT: %y.var: ref i32 = var y
  54. // CHECK:STDOUT: %y: ref i32 = bind_name y, %y.var
  55. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  56. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  57. // CHECK:STDOUT: %.loc13_8.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  58. // CHECK:STDOUT: %.loc13_8.2: type = converted %int.make_type_32.loc13, %.loc13_8.1 [template = i32]
  59. // CHECK:STDOUT: %z.var: ref i32 = var z
  60. // CHECK:STDOUT: %z: ref i32 = bind_name z, %z.var
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: fn @Float(%size: i32) -> type = "float.make_type";
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: fn @__global_init() {
  68. // CHECK:STDOUT: !entry:
  69. // CHECK:STDOUT: %.loc11_35: f64 = float_literal 0 [template = constants.%.5]
  70. // CHECK:STDOUT: %.loc11_45: i32 = int_literal 1 [template = constants.%.6]
  71. // CHECK:STDOUT: %.loc11_46.1: %.3 = struct_literal (%.loc11_35, %.loc11_45)
  72. // CHECK:STDOUT: %.loc11_46.2: ref f64 = struct_access file.%x.var, element0
  73. // CHECK:STDOUT: %.loc11_46.3: init f64 = initialize_from %.loc11_35 to %.loc11_46.2 [template = constants.%.5]
  74. // CHECK:STDOUT: %.loc11_46.4: ref i32 = struct_access file.%x.var, element1
  75. // CHECK:STDOUT: %.loc11_46.5: init i32 = initialize_from %.loc11_45 to %.loc11_46.4 [template = constants.%.6]
  76. // CHECK:STDOUT: %.loc11_46.6: init %.3 = struct_init (%.loc11_46.3, %.loc11_46.5) to file.%x.var [template = constants.%struct]
  77. // CHECK:STDOUT: %.loc11_47: init %.3 = converted %.loc11_46.1, %.loc11_46.6 [template = constants.%struct]
  78. // CHECK:STDOUT: assign file.%x.var, %.loc11_47
  79. // CHECK:STDOUT: %x.ref: ref %.3 = name_ref x, file.%x
  80. // CHECK:STDOUT: %.loc12_15.1: ref i32 = struct_access %x.ref, element1
  81. // CHECK:STDOUT: %.loc12_15.2: i32 = bind_value %.loc12_15.1
  82. // CHECK:STDOUT: assign file.%y.var, %.loc12_15.2
  83. // CHECK:STDOUT: %y.ref: ref i32 = name_ref y, file.%y
  84. // CHECK:STDOUT: %.loc13: i32 = bind_value %y.ref
  85. // CHECK:STDOUT: assign file.%z.var, %.loc13
  86. // CHECK:STDOUT: return
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: