nested_struct_in_place.carbon 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/nested_struct_in_place.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/nested_struct_in_place.carbon
  10. fn F() -> (i32, i32, i32);
  11. fn G() {
  12. var v: {.a: (i32, i32, i32), .b: (i32, i32, i32)} = {.a = F(), .b = F()};
  13. }
  14. // CHECK:STDOUT: --- nested_struct_in_place.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  18. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  19. // CHECK:STDOUT: %tuple.type.1: type = tuple_type (type, type, type) [template]
  20. // CHECK:STDOUT: %tuple.type.2: type = tuple_type (i32, i32, i32) [template]
  21. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  22. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  23. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  24. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  25. // CHECK:STDOUT: %.1: type = struct_type {.a: %tuple.type.2, .b: %tuple.type.2} [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: imports {
  29. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  30. // CHECK:STDOUT: .Int32 = %import_ref
  31. // CHECK:STDOUT: import Core//prelude
  32. // CHECK:STDOUT: import Core//prelude/...
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: file {
  37. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  38. // CHECK:STDOUT: .Core = imports.%Core
  39. // CHECK:STDOUT: .F = %F.decl
  40. // CHECK:STDOUT: .G = %G.decl
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %Core.import = import Core
  43. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  44. // CHECK:STDOUT: %return.patt: %tuple.type.2 = return_slot_pattern
  45. // CHECK:STDOUT: %return.param_patt: %tuple.type.2 = out_param_pattern %return.patt, runtime_param0
  46. // CHECK:STDOUT: } {
  47. // CHECK:STDOUT: %int.make_type_32.loc11_12: init type = call constants.%Int32() [template = i32]
  48. // CHECK:STDOUT: %int.make_type_32.loc11_17: init type = call constants.%Int32() [template = i32]
  49. // CHECK:STDOUT: %int.make_type_32.loc11_22: init type = call constants.%Int32() [template = i32]
  50. // CHECK:STDOUT: %.loc11_25.1: %tuple.type.1 = tuple_literal (%int.make_type_32.loc11_12, %int.make_type_32.loc11_17, %int.make_type_32.loc11_22)
  51. // CHECK:STDOUT: %.loc11_25.2: type = value_of_initializer %int.make_type_32.loc11_12 [template = i32]
  52. // CHECK:STDOUT: %.loc11_25.3: type = converted %int.make_type_32.loc11_12, %.loc11_25.2 [template = i32]
  53. // CHECK:STDOUT: %.loc11_25.4: type = value_of_initializer %int.make_type_32.loc11_17 [template = i32]
  54. // CHECK:STDOUT: %.loc11_25.5: type = converted %int.make_type_32.loc11_17, %.loc11_25.4 [template = i32]
  55. // CHECK:STDOUT: %.loc11_25.6: type = value_of_initializer %int.make_type_32.loc11_22 [template = i32]
  56. // CHECK:STDOUT: %.loc11_25.7: type = converted %int.make_type_32.loc11_22, %.loc11_25.6 [template = i32]
  57. // CHECK:STDOUT: %.loc11_25.8: type = converted %.loc11_25.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  58. // CHECK:STDOUT: %return.param: ref %tuple.type.2 = out_param runtime_param0
  59. // CHECK:STDOUT: %return: ref %tuple.type.2 = return_slot %return.param
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: fn @F() -> %tuple.type.2;
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: fn @G() {
  67. // CHECK:STDOUT: !entry:
  68. // CHECK:STDOUT: %int.make_type_32.loc14_16: init type = call constants.%Int32() [template = i32]
  69. // CHECK:STDOUT: %int.make_type_32.loc14_21: init type = call constants.%Int32() [template = i32]
  70. // CHECK:STDOUT: %int.make_type_32.loc14_26: init type = call constants.%Int32() [template = i32]
  71. // CHECK:STDOUT: %.loc14_29.1: %tuple.type.1 = tuple_literal (%int.make_type_32.loc14_16, %int.make_type_32.loc14_21, %int.make_type_32.loc14_26)
  72. // CHECK:STDOUT: %.loc14_29.2: type = value_of_initializer %int.make_type_32.loc14_16 [template = i32]
  73. // CHECK:STDOUT: %.loc14_29.3: type = converted %int.make_type_32.loc14_16, %.loc14_29.2 [template = i32]
  74. // CHECK:STDOUT: %.loc14_29.4: type = value_of_initializer %int.make_type_32.loc14_21 [template = i32]
  75. // CHECK:STDOUT: %.loc14_29.5: type = converted %int.make_type_32.loc14_21, %.loc14_29.4 [template = i32]
  76. // CHECK:STDOUT: %.loc14_29.6: type = value_of_initializer %int.make_type_32.loc14_26 [template = i32]
  77. // CHECK:STDOUT: %.loc14_29.7: type = converted %int.make_type_32.loc14_26, %.loc14_29.6 [template = i32]
  78. // CHECK:STDOUT: %.loc14_29.8: type = converted %.loc14_29.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  79. // CHECK:STDOUT: %int.make_type_32.loc14_37: init type = call constants.%Int32() [template = i32]
  80. // CHECK:STDOUT: %int.make_type_32.loc14_42: init type = call constants.%Int32() [template = i32]
  81. // CHECK:STDOUT: %int.make_type_32.loc14_47: init type = call constants.%Int32() [template = i32]
  82. // CHECK:STDOUT: %.loc14_50.1: %tuple.type.1 = tuple_literal (%int.make_type_32.loc14_37, %int.make_type_32.loc14_42, %int.make_type_32.loc14_47)
  83. // CHECK:STDOUT: %.loc14_50.2: type = value_of_initializer %int.make_type_32.loc14_37 [template = i32]
  84. // CHECK:STDOUT: %.loc14_50.3: type = converted %int.make_type_32.loc14_37, %.loc14_50.2 [template = i32]
  85. // CHECK:STDOUT: %.loc14_50.4: type = value_of_initializer %int.make_type_32.loc14_42 [template = i32]
  86. // CHECK:STDOUT: %.loc14_50.5: type = converted %int.make_type_32.loc14_42, %.loc14_50.4 [template = i32]
  87. // CHECK:STDOUT: %.loc14_50.6: type = value_of_initializer %int.make_type_32.loc14_47 [template = i32]
  88. // CHECK:STDOUT: %.loc14_50.7: type = converted %int.make_type_32.loc14_47, %.loc14_50.6 [template = i32]
  89. // CHECK:STDOUT: %.loc14_50.8: type = converted %.loc14_50.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  90. // CHECK:STDOUT: %.loc14_51: type = struct_type {.a: %tuple.type.2, .b: %tuple.type.2} [template = constants.%.1]
  91. // CHECK:STDOUT: %v.var: ref %.1 = var v
  92. // CHECK:STDOUT: %v: ref %.1 = bind_name v, %v.var
  93. // CHECK:STDOUT: %F.ref.loc14_61: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  94. // CHECK:STDOUT: %.loc14_74.1: ref %tuple.type.2 = struct_access %v.var, element0
  95. // CHECK:STDOUT: %F.call.loc14_62: init %tuple.type.2 = call %F.ref.loc14_61() to %.loc14_74.1
  96. // CHECK:STDOUT: %F.ref.loc14_71: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  97. // CHECK:STDOUT: %.loc14_74.2: ref %tuple.type.2 = struct_access %v.var, element1
  98. // CHECK:STDOUT: %F.call.loc14_72: init %tuple.type.2 = call %F.ref.loc14_71() to %.loc14_74.2
  99. // CHECK:STDOUT: %.loc14_74.3: %.1 = struct_literal (%F.call.loc14_62, %F.call.loc14_72)
  100. // CHECK:STDOUT: %.loc14_74.4: init %.1 = struct_init (%F.call.loc14_62, %F.call.loc14_72) to %v.var
  101. // CHECK:STDOUT: %.loc14_75: init %.1 = converted %.loc14_74.3, %.loc14_74.4
  102. // CHECK:STDOUT: assign %v.var, %.loc14_75
  103. // CHECK:STDOUT: return
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: