assign_var.carbon 7.1 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/assign_var.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/assign_var.carbon
  10. var a: (i32, i32, i32) = (1, 2, 3);
  11. var b: [i32; 3] = a;
  12. // CHECK:STDOUT: --- assign_var.carbon
  13. // CHECK:STDOUT:
  14. // CHECK:STDOUT: constants {
  15. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  16. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  17. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  18. // CHECK:STDOUT: %.2: type = tuple_type (type, type, type) [template]
  19. // CHECK:STDOUT: %.3: type = tuple_type (i32, i32, i32) [template]
  20. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  21. // CHECK:STDOUT: %.5: i32 = int_literal 1 [template]
  22. // CHECK:STDOUT: %.6: i32 = int_literal 2 [template]
  23. // CHECK:STDOUT: %.7: i32 = int_literal 3 [template]
  24. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.5, %.6, %.7) [template]
  25. // CHECK:STDOUT: %.8: type = array_type %.7, i32 [template]
  26. // CHECK:STDOUT: %.9: type = ptr_type %.8 [template]
  27. // CHECK:STDOUT: %.10: i32 = int_literal 0 [template]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: imports {
  31. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  32. // CHECK:STDOUT: .Int32 = %import_ref
  33. // CHECK:STDOUT: import Core//prelude
  34. // CHECK:STDOUT: import Core//prelude/operators
  35. // CHECK:STDOUT: import Core//prelude/types
  36. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  37. // CHECK:STDOUT: import Core//prelude/operators/as
  38. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  39. // CHECK:STDOUT: import Core//prelude/operators/comparison
  40. // CHECK:STDOUT: import Core//prelude/types/bool
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+9, loaded [template = constants.%Int32]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .Core = imports.%Core
  48. // CHECK:STDOUT: .a = %a
  49. // CHECK:STDOUT: .b = %b
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %Core.import = import Core
  52. // CHECK:STDOUT: %int.make_type_32.loc11_9: init type = call constants.%Int32() [template = i32]
  53. // CHECK:STDOUT: %int.make_type_32.loc11_14: init type = call constants.%Int32() [template = i32]
  54. // CHECK:STDOUT: %int.make_type_32.loc11_19: init type = call constants.%Int32() [template = i32]
  55. // CHECK:STDOUT: %.loc11_22.1: %.2 = tuple_literal (%int.make_type_32.loc11_9, %int.make_type_32.loc11_14, %int.make_type_32.loc11_19)
  56. // CHECK:STDOUT: %.loc11_22.2: type = value_of_initializer %int.make_type_32.loc11_9 [template = i32]
  57. // CHECK:STDOUT: %.loc11_22.3: type = converted %int.make_type_32.loc11_9, %.loc11_22.2 [template = i32]
  58. // CHECK:STDOUT: %.loc11_22.4: type = value_of_initializer %int.make_type_32.loc11_14 [template = i32]
  59. // CHECK:STDOUT: %.loc11_22.5: type = converted %int.make_type_32.loc11_14, %.loc11_22.4 [template = i32]
  60. // CHECK:STDOUT: %.loc11_22.6: type = value_of_initializer %int.make_type_32.loc11_19 [template = i32]
  61. // CHECK:STDOUT: %.loc11_22.7: type = converted %int.make_type_32.loc11_19, %.loc11_22.6 [template = i32]
  62. // CHECK:STDOUT: %.loc11_22.8: type = converted %.loc11_22.1, constants.%.3 [template = constants.%.3]
  63. // CHECK:STDOUT: %a.var: ref %.3 = var a
  64. // CHECK:STDOUT: %a: ref %.3 = bind_name a, %a.var
  65. // CHECK:STDOUT: %int.make_type_32.loc12: init type = call constants.%Int32() [template = i32]
  66. // CHECK:STDOUT: %.loc12_14: i32 = int_literal 3 [template = constants.%.7]
  67. // CHECK:STDOUT: %.loc12_9.1: type = value_of_initializer %int.make_type_32.loc12 [template = i32]
  68. // CHECK:STDOUT: %.loc12_9.2: type = converted %int.make_type_32.loc12, %.loc12_9.1 [template = i32]
  69. // CHECK:STDOUT: %.loc12_15: type = array_type %.loc12_14, i32 [template = constants.%.8]
  70. // CHECK:STDOUT: %b.var: ref %.8 = var b
  71. // CHECK:STDOUT: %b: ref %.8 = bind_name b, %b.var
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @__global_init() {
  77. // CHECK:STDOUT: !entry:
  78. // CHECK:STDOUT: %.loc11_27: i32 = int_literal 1 [template = constants.%.5]
  79. // CHECK:STDOUT: %.loc11_30: i32 = int_literal 2 [template = constants.%.6]
  80. // CHECK:STDOUT: %.loc11_33: i32 = int_literal 3 [template = constants.%.7]
  81. // CHECK:STDOUT: %.loc11_34.1: %.3 = tuple_literal (%.loc11_27, %.loc11_30, %.loc11_33)
  82. // CHECK:STDOUT: %.loc11_34.2: ref i32 = tuple_access file.%a.var, element0
  83. // CHECK:STDOUT: %.loc11_34.3: init i32 = initialize_from %.loc11_27 to %.loc11_34.2 [template = constants.%.5]
  84. // CHECK:STDOUT: %.loc11_34.4: ref i32 = tuple_access file.%a.var, element1
  85. // CHECK:STDOUT: %.loc11_34.5: init i32 = initialize_from %.loc11_30 to %.loc11_34.4 [template = constants.%.6]
  86. // CHECK:STDOUT: %.loc11_34.6: ref i32 = tuple_access file.%a.var, element2
  87. // CHECK:STDOUT: %.loc11_34.7: init i32 = initialize_from %.loc11_33 to %.loc11_34.6 [template = constants.%.7]
  88. // CHECK:STDOUT: %.loc11_34.8: init %.3 = tuple_init (%.loc11_34.3, %.loc11_34.5, %.loc11_34.7) to file.%a.var [template = constants.%tuple]
  89. // CHECK:STDOUT: %.loc11_35: init %.3 = converted %.loc11_34.1, %.loc11_34.8 [template = constants.%tuple]
  90. // CHECK:STDOUT: assign file.%a.var, %.loc11_35
  91. // CHECK:STDOUT: %a.ref: ref %.3 = name_ref a, file.%a
  92. // CHECK:STDOUT: %.loc12_19.1: ref i32 = tuple_access %a.ref, element0
  93. // CHECK:STDOUT: %.loc12_19.2: i32 = bind_value %.loc12_19.1
  94. // CHECK:STDOUT: %.loc12_19.3: i32 = int_literal 0 [template = constants.%.10]
  95. // CHECK:STDOUT: %.loc12_19.4: ref i32 = array_index file.%b.var, %.loc12_19.3
  96. // CHECK:STDOUT: %.loc12_19.5: init i32 = initialize_from %.loc12_19.2 to %.loc12_19.4
  97. // CHECK:STDOUT: %.loc12_19.6: ref i32 = tuple_access %a.ref, element1
  98. // CHECK:STDOUT: %.loc12_19.7: i32 = bind_value %.loc12_19.6
  99. // CHECK:STDOUT: %.loc12_19.8: i32 = int_literal 1 [template = constants.%.5]
  100. // CHECK:STDOUT: %.loc12_19.9: ref i32 = array_index file.%b.var, %.loc12_19.8
  101. // CHECK:STDOUT: %.loc12_19.10: init i32 = initialize_from %.loc12_19.7 to %.loc12_19.9
  102. // CHECK:STDOUT: %.loc12_19.11: ref i32 = tuple_access %a.ref, element2
  103. // CHECK:STDOUT: %.loc12_19.12: i32 = bind_value %.loc12_19.11
  104. // CHECK:STDOUT: %.loc12_19.13: i32 = int_literal 2 [template = constants.%.6]
  105. // CHECK:STDOUT: %.loc12_19.14: ref i32 = array_index file.%b.var, %.loc12_19.13
  106. // CHECK:STDOUT: %.loc12_19.15: init i32 = initialize_from %.loc12_19.12 to %.loc12_19.14
  107. // CHECK:STDOUT: %.loc12_19.16: init %.8 = array_init (%.loc12_19.5, %.loc12_19.10, %.loc12_19.15) to file.%b.var
  108. // CHECK:STDOUT: %.loc12_20: init %.8 = converted %a.ref, %.loc12_19.16
  109. // CHECK:STDOUT: assign file.%b.var, %.loc12_20
  110. // CHECK:STDOUT: return
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: