array_in_place.carbon 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/array/array_in_place.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/array_in_place.carbon
  10. fn F() -> (i32, i32, i32);
  11. fn G() {
  12. var v: [(i32, i32, i32); 2] = (F(), F());
  13. }
  14. // CHECK:STDOUT: --- array_in_place.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 = tuple_type (type, type, type) [template]
  21. // CHECK:STDOUT: %.3: type = tuple_type (i32, i32, i32) [template]
  22. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  23. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  24. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  25. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  26. // CHECK:STDOUT: %.4: i32 = int_value 2 [template]
  27. // CHECK:STDOUT: %.5: type = array_type %.4, %.3 [template]
  28. // CHECK:STDOUT: %.6: type = ptr_type %.3 [template]
  29. // CHECK:STDOUT: %.7: type = ptr_type %.5 [template]
  30. // CHECK:STDOUT: %.8: type = tuple_type (%.3, %.3) [template]
  31. // CHECK:STDOUT: %.9: i32 = int_value 0 [template]
  32. // CHECK:STDOUT: %.10: i32 = int_value 1 [template]
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: imports {
  36. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  37. // CHECK:STDOUT: .Int32 = %import_ref
  38. // CHECK:STDOUT: import Core//prelude
  39. // CHECK:STDOUT: import Core//prelude/...
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  46. // CHECK:STDOUT: .Core = imports.%Core
  47. // CHECK:STDOUT: .F = %F.decl
  48. // CHECK:STDOUT: .G = %G.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Core.import = import Core
  51. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  52. // CHECK:STDOUT: %return.patt: %.3 = return_slot_pattern
  53. // CHECK:STDOUT: %return.param_patt: %.3 = out_param_pattern %return.patt, runtime_param0
  54. // CHECK:STDOUT: } {
  55. // CHECK:STDOUT: %int.make_type_32.loc11_12: init type = call constants.%Int32() [template = i32]
  56. // CHECK:STDOUT: %int.make_type_32.loc11_17: init type = call constants.%Int32() [template = i32]
  57. // CHECK:STDOUT: %int.make_type_32.loc11_22: init type = call constants.%Int32() [template = i32]
  58. // CHECK:STDOUT: %.loc11_25.1: %.2 = tuple_literal (%int.make_type_32.loc11_12, %int.make_type_32.loc11_17, %int.make_type_32.loc11_22)
  59. // CHECK:STDOUT: %.loc11_25.2: type = value_of_initializer %int.make_type_32.loc11_12 [template = i32]
  60. // CHECK:STDOUT: %.loc11_25.3: type = converted %int.make_type_32.loc11_12, %.loc11_25.2 [template = i32]
  61. // CHECK:STDOUT: %.loc11_25.4: type = value_of_initializer %int.make_type_32.loc11_17 [template = i32]
  62. // CHECK:STDOUT: %.loc11_25.5: type = converted %int.make_type_32.loc11_17, %.loc11_25.4 [template = i32]
  63. // CHECK:STDOUT: %.loc11_25.6: type = value_of_initializer %int.make_type_32.loc11_22 [template = i32]
  64. // CHECK:STDOUT: %.loc11_25.7: type = converted %int.make_type_32.loc11_22, %.loc11_25.6 [template = i32]
  65. // CHECK:STDOUT: %.loc11_25.8: type = converted %.loc11_25.1, constants.%.3 [template = constants.%.3]
  66. // CHECK:STDOUT: %return.param: ref %.3 = out_param runtime_param0
  67. // CHECK:STDOUT: %return: ref %.3 = return_slot %return.param
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @F() -> %.3;
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @G() {
  77. // CHECK:STDOUT: !entry:
  78. // CHECK:STDOUT: %int.make_type_32.loc14_12: init type = call constants.%Int32() [template = i32]
  79. // CHECK:STDOUT: %int.make_type_32.loc14_17: init type = call constants.%Int32() [template = i32]
  80. // CHECK:STDOUT: %int.make_type_32.loc14_22: init type = call constants.%Int32() [template = i32]
  81. // CHECK:STDOUT: %.loc14_25.1: %.2 = tuple_literal (%int.make_type_32.loc14_12, %int.make_type_32.loc14_17, %int.make_type_32.loc14_22)
  82. // CHECK:STDOUT: %.loc14_28: i32 = int_value 2 [template = constants.%.4]
  83. // CHECK:STDOUT: %.loc14_25.2: type = value_of_initializer %int.make_type_32.loc14_12 [template = i32]
  84. // CHECK:STDOUT: %.loc14_25.3: type = converted %int.make_type_32.loc14_12, %.loc14_25.2 [template = i32]
  85. // CHECK:STDOUT: %.loc14_25.4: type = value_of_initializer %int.make_type_32.loc14_17 [template = i32]
  86. // CHECK:STDOUT: %.loc14_25.5: type = converted %int.make_type_32.loc14_17, %.loc14_25.4 [template = i32]
  87. // CHECK:STDOUT: %.loc14_25.6: type = value_of_initializer %int.make_type_32.loc14_22 [template = i32]
  88. // CHECK:STDOUT: %.loc14_25.7: type = converted %int.make_type_32.loc14_22, %.loc14_25.6 [template = i32]
  89. // CHECK:STDOUT: %.loc14_25.8: type = converted %.loc14_25.1, constants.%.3 [template = constants.%.3]
  90. // CHECK:STDOUT: %.loc14_29: type = array_type %.loc14_28, %.3 [template = constants.%.5]
  91. // CHECK:STDOUT: %v.var: ref %.5 = var v
  92. // CHECK:STDOUT: %v: ref %.5 = bind_name v, %v.var
  93. // CHECK:STDOUT: %F.ref.loc14_34: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  94. // CHECK:STDOUT: %.loc14_42.3: ref %.3 = splice_block %.loc14_42.2 {
  95. // CHECK:STDOUT: %.loc14_42.1: i32 = int_value 0 [template = constants.%.9]
  96. // CHECK:STDOUT: %.loc14_42.2: ref %.3 = array_index %v.var, %.loc14_42.1
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %F.call.loc14_35: init %.3 = call %F.ref.loc14_34() to %.loc14_42.3
  99. // CHECK:STDOUT: %F.ref.loc14_39: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  100. // CHECK:STDOUT: %.loc14_42.6: ref %.3 = splice_block %.loc14_42.5 {
  101. // CHECK:STDOUT: %.loc14_42.4: i32 = int_value 1 [template = constants.%.10]
  102. // CHECK:STDOUT: %.loc14_42.5: ref %.3 = array_index %v.var, %.loc14_42.4
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %F.call.loc14_40: init %.3 = call %F.ref.loc14_39() to %.loc14_42.6
  105. // CHECK:STDOUT: %.loc14_42.7: %.8 = tuple_literal (%F.call.loc14_35, %F.call.loc14_40)
  106. // CHECK:STDOUT: %.loc14_42.8: init %.5 = array_init (%F.call.loc14_35, %F.call.loc14_40) to %v.var
  107. // CHECK:STDOUT: %.loc14_43: init %.5 = converted %.loc14_42.7, %.loc14_42.8
  108. // CHECK:STDOUT: assign %v.var, %.loc14_43
  109. // CHECK:STDOUT: return
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: