base.carbon 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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/base.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/base.carbon
  10. var a: [i32; 1] = (1,);
  11. var b: [f64; 2] = (11.1, 2.2,);
  12. var c: [(); 5] = ((), (), (), (), (),);
  13. // CHECK:STDOUT: --- base.carbon
  14. // CHECK:STDOUT:
  15. // CHECK:STDOUT: constants {
  16. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  17. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  18. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  19. // CHECK:STDOUT: %.2: i32 = int_value 1 [template]
  20. // CHECK:STDOUT: %.3: type = array_type %.2, i32 [template]
  21. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  22. // CHECK:STDOUT: %.5: type = tuple_type (i32) [template]
  23. // CHECK:STDOUT: %.6: i32 = int_value 0 [template]
  24. // CHECK:STDOUT: %array.1: %.3 = tuple_value (%.2) [template]
  25. // CHECK:STDOUT: %.7: Core.IntLiteral = int_value 64 [template]
  26. // CHECK:STDOUT: %Float.type: type = fn_type @Float [template]
  27. // CHECK:STDOUT: %Float: %Float.type = struct_value () [template]
  28. // CHECK:STDOUT: %.8: i32 = int_value 2 [template]
  29. // CHECK:STDOUT: %.9: type = array_type %.8, f64 [template]
  30. // CHECK:STDOUT: %.10: type = ptr_type %.9 [template]
  31. // CHECK:STDOUT: %.11: f64 = float_literal 11.100000000000001 [template]
  32. // CHECK:STDOUT: %.12: f64 = float_literal 2.2000000000000002 [template]
  33. // CHECK:STDOUT: %.13: type = tuple_type (f64, f64) [template]
  34. // CHECK:STDOUT: %array.2: %.9 = tuple_value (%.11, %.12) [template]
  35. // CHECK:STDOUT: %.14: i32 = int_value 5 [template]
  36. // CHECK:STDOUT: %.15: type = array_type %.14, %.1 [template]
  37. // CHECK:STDOUT: %.16: type = ptr_type %.15 [template]
  38. // CHECK:STDOUT: %.17: type = tuple_type (%.1, %.1, %.1, %.1, %.1) [template]
  39. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  40. // CHECK:STDOUT: %.18: i32 = int_value 3 [template]
  41. // CHECK:STDOUT: %.19: i32 = int_value 4 [template]
  42. // CHECK:STDOUT: %array.3: %.15 = tuple_value (%tuple, %tuple, %tuple, %tuple, %tuple) [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: imports {
  46. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  47. // CHECK:STDOUT: .Int32 = %import_ref.1
  48. // CHECK:STDOUT: .Float = %import_ref.2
  49. // CHECK:STDOUT: import Core//prelude
  50. // CHECK:STDOUT: import Core//prelude/...
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  53. // CHECK:STDOUT: %import_ref.2: %Float.type = import_ref Core//prelude/types, inst+60, loaded [template = constants.%Float]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  58. // CHECK:STDOUT: .Core = imports.%Core
  59. // CHECK:STDOUT: .a = %a
  60. // CHECK:STDOUT: .b = %b
  61. // CHECK:STDOUT: .c = %c
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %Core.import = import Core
  64. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  65. // CHECK:STDOUT: %.loc11_14: i32 = int_value 1 [template = constants.%.2]
  66. // CHECK:STDOUT: %.loc11_9.1: type = value_of_initializer %int.make_type_32 [template = i32]
  67. // CHECK:STDOUT: %.loc11_9.2: type = converted %int.make_type_32, %.loc11_9.1 [template = i32]
  68. // CHECK:STDOUT: %.loc11_15: type = array_type %.loc11_14, i32 [template = constants.%.3]
  69. // CHECK:STDOUT: %a.var: ref %.3 = var a
  70. // CHECK:STDOUT: %a: ref %.3 = bind_name a, %a.var
  71. // CHECK:STDOUT: %.loc12_9.1: Core.IntLiteral = int_value 64 [template = constants.%.7]
  72. // CHECK:STDOUT: %float.make_type: init type = call constants.%Float(%.loc12_9.1) [template = f64]
  73. // CHECK:STDOUT: %.loc12_14: i32 = int_value 2 [template = constants.%.8]
  74. // CHECK:STDOUT: %.loc12_9.2: type = value_of_initializer %float.make_type [template = f64]
  75. // CHECK:STDOUT: %.loc12_9.3: type = converted %float.make_type, %.loc12_9.2 [template = f64]
  76. // CHECK:STDOUT: %.loc12_15: type = array_type %.loc12_14, f64 [template = constants.%.9]
  77. // CHECK:STDOUT: %b.var: ref %.9 = var b
  78. // CHECK:STDOUT: %b: ref %.9 = bind_name b, %b.var
  79. // CHECK:STDOUT: %.loc13_10.1: %.1 = tuple_literal ()
  80. // CHECK:STDOUT: %.loc13_13: i32 = int_value 5 [template = constants.%.14]
  81. // CHECK:STDOUT: %.loc13_10.2: type = converted %.loc13_10.1, constants.%.1 [template = constants.%.1]
  82. // CHECK:STDOUT: %.loc13_14: type = array_type %.loc13_13, %.1 [template = constants.%.15]
  83. // CHECK:STDOUT: %c.var: ref %.15 = var c
  84. // CHECK:STDOUT: %c: ref %.15 = bind_name c, %c.var
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: fn @Float(%size.param_patt: Core.IntLiteral) -> type = "float.make_type";
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @__global_init() {
  92. // CHECK:STDOUT: !entry:
  93. // CHECK:STDOUT: %.loc11_20: i32 = int_value 1 [template = constants.%.2]
  94. // CHECK:STDOUT: %.loc11_22.1: %.5 = tuple_literal (%.loc11_20)
  95. // CHECK:STDOUT: %.loc11_22.2: i32 = int_value 0 [template = constants.%.6]
  96. // CHECK:STDOUT: %.loc11_22.3: ref i32 = array_index file.%a.var, %.loc11_22.2
  97. // CHECK:STDOUT: %.loc11_22.4: init i32 = initialize_from %.loc11_20 to %.loc11_22.3 [template = constants.%.2]
  98. // CHECK:STDOUT: %.loc11_22.5: init %.3 = array_init (%.loc11_22.4) to file.%a.var [template = constants.%array.1]
  99. // CHECK:STDOUT: %.loc11_23: init %.3 = converted %.loc11_22.1, %.loc11_22.5 [template = constants.%array.1]
  100. // CHECK:STDOUT: assign file.%a.var, %.loc11_23
  101. // CHECK:STDOUT: %.loc12_20: f64 = float_literal 11.100000000000001 [template = constants.%.11]
  102. // CHECK:STDOUT: %.loc12_26: f64 = float_literal 2.2000000000000002 [template = constants.%.12]
  103. // CHECK:STDOUT: %.loc12_30.1: %.13 = tuple_literal (%.loc12_20, %.loc12_26)
  104. // CHECK:STDOUT: %.loc12_30.2: i32 = int_value 0 [template = constants.%.6]
  105. // CHECK:STDOUT: %.loc12_30.3: ref f64 = array_index file.%b.var, %.loc12_30.2
  106. // CHECK:STDOUT: %.loc12_30.4: init f64 = initialize_from %.loc12_20 to %.loc12_30.3 [template = constants.%.11]
  107. // CHECK:STDOUT: %.loc12_30.5: i32 = int_value 1 [template = constants.%.2]
  108. // CHECK:STDOUT: %.loc12_30.6: ref f64 = array_index file.%b.var, %.loc12_30.5
  109. // CHECK:STDOUT: %.loc12_30.7: init f64 = initialize_from %.loc12_26 to %.loc12_30.6 [template = constants.%.12]
  110. // CHECK:STDOUT: %.loc12_30.8: init %.9 = array_init (%.loc12_30.4, %.loc12_30.7) to file.%b.var [template = constants.%array.2]
  111. // CHECK:STDOUT: %.loc12_31: init %.9 = converted %.loc12_30.1, %.loc12_30.8 [template = constants.%array.2]
  112. // CHECK:STDOUT: assign file.%b.var, %.loc12_31
  113. // CHECK:STDOUT: %.loc13_20.1: %.1 = tuple_literal ()
  114. // CHECK:STDOUT: %.loc13_24.1: %.1 = tuple_literal ()
  115. // CHECK:STDOUT: %.loc13_28.1: %.1 = tuple_literal ()
  116. // CHECK:STDOUT: %.loc13_32.1: %.1 = tuple_literal ()
  117. // CHECK:STDOUT: %.loc13_36.1: %.1 = tuple_literal ()
  118. // CHECK:STDOUT: %.loc13_38.1: %.17 = tuple_literal (%.loc13_20.1, %.loc13_24.1, %.loc13_28.1, %.loc13_32.1, %.loc13_36.1)
  119. // CHECK:STDOUT: %.loc13_38.2: i32 = int_value 0 [template = constants.%.6]
  120. // CHECK:STDOUT: %.loc13_38.3: ref %.1 = array_index file.%c.var, %.loc13_38.2
  121. // CHECK:STDOUT: %.loc13_20.2: init %.1 = tuple_init () to %.loc13_38.3 [template = constants.%tuple]
  122. // CHECK:STDOUT: %.loc13_38.4: init %.1 = converted %.loc13_20.1, %.loc13_20.2 [template = constants.%tuple]
  123. // CHECK:STDOUT: %.loc13_38.5: i32 = int_value 1 [template = constants.%.2]
  124. // CHECK:STDOUT: %.loc13_38.6: ref %.1 = array_index file.%c.var, %.loc13_38.5
  125. // CHECK:STDOUT: %.loc13_24.2: init %.1 = tuple_init () to %.loc13_38.6 [template = constants.%tuple]
  126. // CHECK:STDOUT: %.loc13_38.7: init %.1 = converted %.loc13_24.1, %.loc13_24.2 [template = constants.%tuple]
  127. // CHECK:STDOUT: %.loc13_38.8: i32 = int_value 2 [template = constants.%.8]
  128. // CHECK:STDOUT: %.loc13_38.9: ref %.1 = array_index file.%c.var, %.loc13_38.8
  129. // CHECK:STDOUT: %.loc13_28.2: init %.1 = tuple_init () to %.loc13_38.9 [template = constants.%tuple]
  130. // CHECK:STDOUT: %.loc13_38.10: init %.1 = converted %.loc13_28.1, %.loc13_28.2 [template = constants.%tuple]
  131. // CHECK:STDOUT: %.loc13_38.11: i32 = int_value 3 [template = constants.%.18]
  132. // CHECK:STDOUT: %.loc13_38.12: ref %.1 = array_index file.%c.var, %.loc13_38.11
  133. // CHECK:STDOUT: %.loc13_32.2: init %.1 = tuple_init () to %.loc13_38.12 [template = constants.%tuple]
  134. // CHECK:STDOUT: %.loc13_38.13: init %.1 = converted %.loc13_32.1, %.loc13_32.2 [template = constants.%tuple]
  135. // CHECK:STDOUT: %.loc13_38.14: i32 = int_value 4 [template = constants.%.19]
  136. // CHECK:STDOUT: %.loc13_38.15: ref %.1 = array_index file.%c.var, %.loc13_38.14
  137. // CHECK:STDOUT: %.loc13_36.2: init %.1 = tuple_init () to %.loc13_38.15 [template = constants.%tuple]
  138. // CHECK:STDOUT: %.loc13_38.16: init %.1 = converted %.loc13_36.1, %.loc13_36.2 [template = constants.%tuple]
  139. // CHECK:STDOUT: %.loc13_38.17: init %.15 = array_init (%.loc13_38.4, %.loc13_38.7, %.loc13_38.10, %.loc13_38.13, %.loc13_38.16) to file.%c.var [template = constants.%array.3]
  140. // CHECK:STDOUT: %.loc13_39: init %.15 = converted %.loc13_38.1, %.loc13_38.17 [template = constants.%array.3]
  141. // CHECK:STDOUT: assign file.%c.var, %.loc13_39
  142. // CHECK:STDOUT: return
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT: