nested_struct_in_place.carbon 8.7 KB

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