literal_member_access.carbon 5.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/literal_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/literal_member_access.carbon
  10. fn G() -> {.x: i32, .y: i32, .z: i32};
  11. fn F() -> i32 {
  12. return {.a = 1, .b = G(), .c = 3}.b.y;
  13. }
  14. // CHECK:STDOUT: --- literal_member_access.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: %.2: type = struct_type {.x: i32, .y: i32, .z: i32} [template]
  21. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  22. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  23. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  24. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  25. // CHECK:STDOUT: %.3: i32 = int_literal 1 [template]
  26. // CHECK:STDOUT: %.4: type = ptr_type %.2 [template]
  27. // CHECK:STDOUT: %.5: i32 = int_literal 3 [template]
  28. // CHECK:STDOUT: %.6: type = struct_type {.a: i32, .b: %.2, .c: i32} [template]
  29. // CHECK:STDOUT: %.7: type = struct_type {.a: i32, .b: %.4, .c: i32} [template]
  30. // CHECK:STDOUT: %.8: type = ptr_type %.7 [template]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: file {
  34. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  35. // CHECK:STDOUT: .Core = %Core
  36. // CHECK:STDOUT: .G = %G.decl
  37. // CHECK:STDOUT: .F = %F.decl
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  40. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  41. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  42. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  43. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  44. // CHECK:STDOUT: %int.make_type_32.loc11_16: init type = call constants.%Int32() [template = i32]
  45. // CHECK:STDOUT: %.loc11_16.1: type = value_of_initializer %int.make_type_32.loc11_16 [template = i32]
  46. // CHECK:STDOUT: %.loc11_16.2: type = converted %int.make_type_32.loc11_16, %.loc11_16.1 [template = i32]
  47. // CHECK:STDOUT: %int.make_type_32.loc11_25: init type = call constants.%Int32() [template = i32]
  48. // CHECK:STDOUT: %.loc11_25.1: type = value_of_initializer %int.make_type_32.loc11_25 [template = i32]
  49. // CHECK:STDOUT: %.loc11_25.2: type = converted %int.make_type_32.loc11_25, %.loc11_25.1 [template = i32]
  50. // CHECK:STDOUT: %int.make_type_32.loc11_34: init type = call constants.%Int32() [template = i32]
  51. // CHECK:STDOUT: %.loc11_34.1: type = value_of_initializer %int.make_type_32.loc11_34 [template = i32]
  52. // CHECK:STDOUT: %.loc11_34.2: type = converted %int.make_type_32.loc11_34, %.loc11_34.1 [template = i32]
  53. // CHECK:STDOUT: %.loc11_37: type = struct_type {.x: i32, .y: i32, .z: i32} [template = constants.%.2]
  54. // CHECK:STDOUT: @G.%return: ref %.2 = var <return slot>
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  57. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  58. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  59. // CHECK:STDOUT: %.loc13_11.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  60. // CHECK:STDOUT: %.loc13_11.2: type = converted %int.make_type_32.loc13, %.loc13_11.1 [template = i32]
  61. // CHECK:STDOUT: @F.%return: ref i32 = var <return slot>
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: fn @G() -> %.2;
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: fn @F() -> i32 {
  70. // CHECK:STDOUT: !entry:
  71. // CHECK:STDOUT: %.loc14_16: i32 = int_literal 1 [template = constants.%.3]
  72. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [template = constants.%G]
  73. // CHECK:STDOUT: %.loc14_25.1: ref %.2 = temporary_storage
  74. // CHECK:STDOUT: %G.call: init %.2 = call %G.ref() to %.loc14_25.1
  75. // CHECK:STDOUT: %.loc14_34: i32 = int_literal 3 [template = constants.%.5]
  76. // CHECK:STDOUT: %.loc14_35.1: %.6 = struct_literal (%.loc14_16, %G.call, %.loc14_34)
  77. // CHECK:STDOUT: %.loc14_25.2: ref %.2 = temporary %.loc14_25.1, %G.call
  78. // CHECK:STDOUT: %.loc14_25.3: ref i32 = struct_access %.loc14_25.2, element0
  79. // CHECK:STDOUT: %.loc14_25.4: i32 = bind_value %.loc14_25.3
  80. // CHECK:STDOUT: %.loc14_25.5: ref i32 = struct_access %.loc14_25.2, element1
  81. // CHECK:STDOUT: %.loc14_25.6: i32 = bind_value %.loc14_25.5
  82. // CHECK:STDOUT: %.loc14_25.7: ref i32 = struct_access %.loc14_25.2, element2
  83. // CHECK:STDOUT: %.loc14_25.8: i32 = bind_value %.loc14_25.7
  84. // CHECK:STDOUT: %struct.loc14_25: %.2 = struct_value (%.loc14_25.4, %.loc14_25.6, %.loc14_25.8)
  85. // CHECK:STDOUT: %.loc14_35.2: %.2 = converted %G.call, %struct.loc14_25
  86. // CHECK:STDOUT: %struct.loc14_35: %.6 = struct_value (%.loc14_16, %.loc14_35.2, %.loc14_34)
  87. // CHECK:STDOUT: %.loc14_35.3: %.6 = converted %.loc14_35.1, %struct.loc14_35
  88. // CHECK:STDOUT: %.loc14_36: %.2 = struct_access %.loc14_35.3, element1
  89. // CHECK:STDOUT: %.loc14_38: i32 = struct_access %.loc14_36, element1
  90. // CHECK:STDOUT: return %.loc14_38
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: