literal_member_access.carbon 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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: %int_32: Core.IntLiteral = int_value 32 [concrete]
  18. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  19. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  20. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  21. // CHECK:STDOUT: %struct_type.x.y.z: type = struct_type {.x: %i32, .y: %i32, .z: %i32} [concrete]
  22. // CHECK:STDOUT: %pattern_type.c6b: type = pattern_type %struct_type.x.y.z [concrete]
  23. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  24. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  25. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  26. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  27. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  28. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  29. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete]
  30. // CHECK:STDOUT: %struct_type.a.b.c.4ca: type = struct_type {.a: Core.IntLiteral, .b: %struct_type.x.y.z, .c: Core.IntLiteral} [concrete]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: imports {
  34. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  35. // CHECK:STDOUT: .Int = %Core.Int
  36. // CHECK:STDOUT: import Core//prelude
  37. // CHECK:STDOUT: import Core//prelude/...
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  44. // CHECK:STDOUT: .Core = imports.%Core
  45. // CHECK:STDOUT: .G = %G.decl
  46. // CHECK:STDOUT: .F = %F.decl
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core.import = import Core
  49. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  50. // CHECK:STDOUT: %return.patt: %pattern_type.c6b = return_slot_pattern [concrete]
  51. // CHECK:STDOUT: %return.param_patt: %pattern_type.c6b = out_param_pattern %return.patt, call_param0 [concrete]
  52. // CHECK:STDOUT: } {
  53. // CHECK:STDOUT: %int_32.loc11_16: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  54. // CHECK:STDOUT: %i32.loc11_16: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  55. // CHECK:STDOUT: %int_32.loc11_25: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  56. // CHECK:STDOUT: %i32.loc11_25: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  57. // CHECK:STDOUT: %int_32.loc11_34: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  58. // CHECK:STDOUT: %i32.loc11_34: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  59. // CHECK:STDOUT: %struct_type.x.y.z: type = struct_type {.x: %i32, .y: %i32, .z: %i32} [concrete = constants.%struct_type.x.y.z]
  60. // CHECK:STDOUT: %return.param: ref %struct_type.x.y.z = out_param call_param0
  61. // CHECK:STDOUT: %return: ref %struct_type.x.y.z = return_slot %return.param
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  64. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  65. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
  66. // CHECK:STDOUT: } {
  67. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  68. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  69. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  70. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @G() -> %return.param: %struct_type.x.y.z;
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @F() -> %i32 {
  77. // CHECK:STDOUT: !entry:
  78. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  79. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [concrete = constants.%G]
  80. // CHECK:STDOUT: %.loc14_26.1: ref %struct_type.x.y.z = temporary_storage
  81. // CHECK:STDOUT: %G.call: init %struct_type.x.y.z = call %G.ref() to %.loc14_26.1
  82. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete = constants.%int_3]
  83. // CHECK:STDOUT: %.loc14_35.1: %struct_type.a.b.c.4ca = struct_literal (%int_1, %G.call, %int_3)
  84. // CHECK:STDOUT: %.loc14_26.2: ref %struct_type.x.y.z = temporary %.loc14_26.1, %G.call
  85. // CHECK:STDOUT: %.loc14_26.3: ref %i32 = struct_access %.loc14_26.2, element0
  86. // CHECK:STDOUT: %.loc14_26.4: %i32 = bind_value %.loc14_26.3
  87. // CHECK:STDOUT: %.loc14_26.5: ref %i32 = struct_access %.loc14_26.2, element1
  88. // CHECK:STDOUT: %.loc14_26.6: %i32 = bind_value %.loc14_26.5
  89. // CHECK:STDOUT: %.loc14_26.7: ref %i32 = struct_access %.loc14_26.2, element2
  90. // CHECK:STDOUT: %.loc14_26.8: %i32 = bind_value %.loc14_26.7
  91. // CHECK:STDOUT: %struct.loc14_26: %struct_type.x.y.z = struct_value (%.loc14_26.4, %.loc14_26.6, %.loc14_26.8)
  92. // CHECK:STDOUT: %.loc14_35.2: %struct_type.x.y.z = converted %G.call, %struct.loc14_26
  93. // CHECK:STDOUT: %struct.loc14_35: %struct_type.a.b.c.4ca = struct_value (%int_1, %.loc14_35.2, %int_3)
  94. // CHECK:STDOUT: %.loc14_35.3: %struct_type.a.b.c.4ca = converted %.loc14_35.1, %struct.loc14_35
  95. // CHECK:STDOUT: %.loc14_36: %struct_type.x.y.z = struct_access %.loc14_35.3, element1
  96. // CHECK:STDOUT: %.loc14_38: %i32 = struct_access %.loc14_36, element1
  97. // CHECK:STDOUT: return %.loc14_38
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: