nested_struct_in_place.carbon 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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: %int_32: Core.IntLiteral = int_value 32 [template]
  18. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  19. // CHECK:STDOUT: %tuple.type.ff9: type = tuple_type (type, type, type) [template]
  20. // CHECK:STDOUT: %tuple.type.dc6: 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: %struct_type.a.b.890: type = struct_type {.a: %tuple.type.dc6, .b: %tuple.type.dc6} [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: imports {
  29. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  30. // CHECK:STDOUT: .Int = %import_ref.187
  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.dc6 = return_slot_pattern
  45. // CHECK:STDOUT: %return.param_patt: %tuple.type.dc6 = out_param_pattern %return.patt, runtime_param0
  46. // CHECK:STDOUT: } {
  47. // CHECK:STDOUT: %int_32.loc11_12: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  48. // CHECK:STDOUT: %i32.loc11_12: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  49. // CHECK:STDOUT: %int_32.loc11_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  50. // CHECK:STDOUT: %i32.loc11_17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  51. // CHECK:STDOUT: %int_32.loc11_22: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  52. // CHECK:STDOUT: %i32.loc11_22: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  53. // CHECK:STDOUT: %.loc11_25.1: %tuple.type.ff9 = tuple_literal (%i32.loc11_12, %i32.loc11_17, %i32.loc11_22)
  54. // CHECK:STDOUT: %.loc11_25.2: type = converted %.loc11_25.1, constants.%tuple.type.dc6 [template = constants.%tuple.type.dc6]
  55. // CHECK:STDOUT: %return.param: ref %tuple.type.dc6 = out_param runtime_param0
  56. // CHECK:STDOUT: %return: ref %tuple.type.dc6 = return_slot %return.param
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: fn @F() -> %tuple.type.dc6;
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: fn @G() {
  64. // CHECK:STDOUT: !entry:
  65. // CHECK:STDOUT: %v.var: ref %struct_type.a.b.890 = var v
  66. // CHECK:STDOUT: %v: ref %struct_type.a.b.890 = bind_name v, %v.var
  67. // CHECK:STDOUT: %F.ref.loc14_61: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  68. // CHECK:STDOUT: %.loc14_74.1: ref %tuple.type.dc6 = struct_access %v.var, element0
  69. // CHECK:STDOUT: %F.call.loc14_63: init %tuple.type.dc6 = call %F.ref.loc14_61() to %.loc14_74.1
  70. // CHECK:STDOUT: %F.ref.loc14_71: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  71. // CHECK:STDOUT: %.loc14_74.2: ref %tuple.type.dc6 = struct_access %v.var, element1
  72. // CHECK:STDOUT: %F.call.loc14_73: init %tuple.type.dc6 = call %F.ref.loc14_71() to %.loc14_74.2
  73. // CHECK:STDOUT: %.loc14_74.3: %struct_type.a.b.890 = struct_literal (%F.call.loc14_63, %F.call.loc14_73)
  74. // CHECK:STDOUT: %.loc14_74.4: init %struct_type.a.b.890 = struct_init (%F.call.loc14_63, %F.call.loc14_73) to %v.var
  75. // CHECK:STDOUT: %.loc14_75: init %struct_type.a.b.890 = converted %.loc14_74.3, %.loc14_74.4
  76. // CHECK:STDOUT: assign %v.var, %.loc14_75
  77. // CHECK:STDOUT: return
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: