canonicalize_index.carbon 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/canonicalize_index.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/canonicalize_index.carbon
  10. fn Add(a: i32, b: i32) -> i32 = "int.sadd";
  11. var a: [i32; Add(1, 2)] = (1, 2, 3);
  12. let b: [i32; 3]* = &a;
  13. // CHECK:STDOUT: --- canonicalize_index.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: %Add.type: type = fn_type @Add [template]
  20. // CHECK:STDOUT: %Add: %Add.type = struct_value () [template]
  21. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  22. // CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
  23. // CHECK:STDOUT: %.4: i32 = int_literal 3 [template]
  24. // CHECK:STDOUT: %.5: type = array_type %.4, i32 [template]
  25. // CHECK:STDOUT: %.6: type = ptr_type %.5 [template]
  26. // CHECK:STDOUT: %.7: type = tuple_type (i32, i32, i32) [template]
  27. // CHECK:STDOUT: %.8: i32 = int_literal 0 [template]
  28. // CHECK:STDOUT: %array: %.5 = tuple_value (%.2, %.3, %.4) [template]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: imports {
  32. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  33. // CHECK:STDOUT: .Int32 = %import_ref
  34. // CHECK:STDOUT: import Core//prelude
  35. // CHECK:STDOUT: import Core//prelude/operators
  36. // CHECK:STDOUT: import Core//prelude/types
  37. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  38. // CHECK:STDOUT: import Core//prelude/operators/as
  39. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  40. // CHECK:STDOUT: import Core//prelude/operators/comparison
  41. // CHECK:STDOUT: import Core//prelude/types/bool
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: file {
  47. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  48. // CHECK:STDOUT: .Core = imports.%Core
  49. // CHECK:STDOUT: .Add = %Add.decl
  50. // CHECK:STDOUT: .a = %a
  51. // CHECK:STDOUT: .b = @__global_init.%b
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.import = import Core
  54. // CHECK:STDOUT: %Add.decl: %Add.type = fn_decl @Add [template = constants.%Add] {
  55. // CHECK:STDOUT: %a.patt: i32 = binding_pattern a
  56. // CHECK:STDOUT: %a.param_patt: i32 = param_pattern %a.patt, runtime_param0
  57. // CHECK:STDOUT: %b.patt: i32 = binding_pattern b
  58. // CHECK:STDOUT: %b.param_patt: i32 = param_pattern %b.patt, runtime_param1
  59. // CHECK:STDOUT: } {
  60. // CHECK:STDOUT: %int.make_type_32.loc11_11: init type = call constants.%Int32() [template = i32]
  61. // CHECK:STDOUT: %.loc11_11.1: type = value_of_initializer %int.make_type_32.loc11_11 [template = i32]
  62. // CHECK:STDOUT: %.loc11_11.2: type = converted %int.make_type_32.loc11_11, %.loc11_11.1 [template = i32]
  63. // CHECK:STDOUT: %int.make_type_32.loc11_19: init type = call constants.%Int32() [template = i32]
  64. // CHECK:STDOUT: %.loc11_19.1: type = value_of_initializer %int.make_type_32.loc11_19 [template = i32]
  65. // CHECK:STDOUT: %.loc11_19.2: type = converted %int.make_type_32.loc11_19, %.loc11_19.1 [template = i32]
  66. // CHECK:STDOUT: %int.make_type_32.loc11_27: init type = call constants.%Int32() [template = i32]
  67. // CHECK:STDOUT: %.loc11_27.1: type = value_of_initializer %int.make_type_32.loc11_27 [template = i32]
  68. // CHECK:STDOUT: %.loc11_27.2: type = converted %int.make_type_32.loc11_27, %.loc11_27.1 [template = i32]
  69. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  70. // CHECK:STDOUT: %param.loc11_8: i32 = param runtime_param0
  71. // CHECK:STDOUT: %a: i32 = bind_name a, %param.loc11_8
  72. // CHECK:STDOUT: %param.loc11_16: i32 = param runtime_param1
  73. // CHECK:STDOUT: %b: i32 = bind_name b, %param.loc11_16
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  76. // CHECK:STDOUT: %Add.ref: %Add.type = name_ref Add, %Add.decl [template = constants.%Add]
  77. // CHECK:STDOUT: %.loc13_18: i32 = int_literal 1 [template = constants.%.2]
  78. // CHECK:STDOUT: %.loc13_21: i32 = int_literal 2 [template = constants.%.3]
  79. // CHECK:STDOUT: %int.sadd: init i32 = call %Add.ref(%.loc13_18, %.loc13_21) [template = constants.%.4]
  80. // CHECK:STDOUT: %.loc13_9.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  81. // CHECK:STDOUT: %.loc13_9.2: type = converted %int.make_type_32.loc13, %.loc13_9.1 [template = i32]
  82. // CHECK:STDOUT: %.loc13_23: type = array_type %int.sadd, i32 [template = constants.%.5]
  83. // CHECK:STDOUT: %a.var: ref %.5 = var a
  84. // CHECK:STDOUT: %a: ref %.5 = bind_name a, %a.var
  85. // CHECK:STDOUT: %int.make_type_32.loc14: init type = call constants.%Int32() [template = i32]
  86. // CHECK:STDOUT: %.loc14_14: i32 = int_literal 3 [template = constants.%.4]
  87. // CHECK:STDOUT: %.loc14_9.1: type = value_of_initializer %int.make_type_32.loc14 [template = i32]
  88. // CHECK:STDOUT: %.loc14_9.2: type = converted %int.make_type_32.loc14, %.loc14_9.1 [template = i32]
  89. // CHECK:STDOUT: %.loc14_15: type = array_type %.loc14_14, i32 [template = constants.%.5]
  90. // CHECK:STDOUT: %.loc14_16: type = ptr_type %.5 [template = constants.%.6]
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: fn @Add(%a.param_patt: i32, %b.param_patt: i32) -> i32 = "int.sadd";
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn @__global_init() {
  98. // CHECK:STDOUT: !entry:
  99. // CHECK:STDOUT: %.loc13_28: i32 = int_literal 1 [template = constants.%.2]
  100. // CHECK:STDOUT: %.loc13_31: i32 = int_literal 2 [template = constants.%.3]
  101. // CHECK:STDOUT: %.loc13_34: i32 = int_literal 3 [template = constants.%.4]
  102. // CHECK:STDOUT: %.loc13_35.1: %.7 = tuple_literal (%.loc13_28, %.loc13_31, %.loc13_34)
  103. // CHECK:STDOUT: %.loc13_35.2: i32 = int_literal 0 [template = constants.%.8]
  104. // CHECK:STDOUT: %.loc13_35.3: ref i32 = array_index file.%a.var, %.loc13_35.2
  105. // CHECK:STDOUT: %.loc13_35.4: init i32 = initialize_from %.loc13_28 to %.loc13_35.3 [template = constants.%.2]
  106. // CHECK:STDOUT: %.loc13_35.5: i32 = int_literal 1 [template = constants.%.2]
  107. // CHECK:STDOUT: %.loc13_35.6: ref i32 = array_index file.%a.var, %.loc13_35.5
  108. // CHECK:STDOUT: %.loc13_35.7: init i32 = initialize_from %.loc13_31 to %.loc13_35.6 [template = constants.%.3]
  109. // CHECK:STDOUT: %.loc13_35.8: i32 = int_literal 2 [template = constants.%.3]
  110. // CHECK:STDOUT: %.loc13_35.9: ref i32 = array_index file.%a.var, %.loc13_35.8
  111. // CHECK:STDOUT: %.loc13_35.10: init i32 = initialize_from %.loc13_34 to %.loc13_35.9 [template = constants.%.4]
  112. // CHECK:STDOUT: %.loc13_35.11: init %.5 = array_init (%.loc13_35.4, %.loc13_35.7, %.loc13_35.10) to file.%a.var [template = constants.%array]
  113. // CHECK:STDOUT: %.loc13_36: init %.5 = converted %.loc13_35.1, %.loc13_35.11 [template = constants.%array]
  114. // CHECK:STDOUT: assign file.%a.var, %.loc13_36
  115. // CHECK:STDOUT: %a.ref: ref %.5 = name_ref a, file.%a
  116. // CHECK:STDOUT: %.loc14: %.6 = addr_of %a.ref
  117. // CHECK:STDOUT: %b: %.6 = bind_name b, %.loc14
  118. // CHECK:STDOUT: return
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: