canonicalize_index.carbon 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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: %Int32: %Int32.type = struct_value () [template]
  18. // CHECK:STDOUT: %Add.type: type = fn_type @Add [template]
  19. // CHECK:STDOUT: %Add: %Add.type = struct_value () [template]
  20. // CHECK:STDOUT: %.1: i32 = int_value 1 [template]
  21. // CHECK:STDOUT: %.2: i32 = int_value 2 [template]
  22. // CHECK:STDOUT: %.3: i32 = int_value 3 [template]
  23. // CHECK:STDOUT: %.4: type = array_type %.3, i32 [template]
  24. // CHECK:STDOUT: %.5: type = ptr_type %.4 [template]
  25. // CHECK:STDOUT: %tuple.type: type = tuple_type (i32, i32, i32) [template]
  26. // CHECK:STDOUT: %.6: i32 = int_value 0 [template]
  27. // CHECK:STDOUT: %array: %.4 = tuple_value (%.1, %.2, %.3) [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/...
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .Core = imports.%Core
  41. // CHECK:STDOUT: .Add = %Add.decl
  42. // CHECK:STDOUT: .a = %a
  43. // CHECK:STDOUT: .b = @__global_init.%b
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %Core.import = import Core
  46. // CHECK:STDOUT: %Add.decl: %Add.type = fn_decl @Add [template = constants.%Add] {
  47. // CHECK:STDOUT: %a.patt: i32 = binding_pattern a
  48. // CHECK:STDOUT: %a.param_patt: i32 = value_param_pattern %a.patt, runtime_param0
  49. // CHECK:STDOUT: %b.patt: i32 = binding_pattern b
  50. // CHECK:STDOUT: %b.param_patt: i32 = value_param_pattern %b.patt, runtime_param1
  51. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  52. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param2
  53. // CHECK:STDOUT: } {
  54. // CHECK:STDOUT: %int.make_type_32.loc11_11: init type = call constants.%Int32() [template = i32]
  55. // CHECK:STDOUT: %.loc11_11.1: type = value_of_initializer %int.make_type_32.loc11_11 [template = i32]
  56. // CHECK:STDOUT: %.loc11_11.2: type = converted %int.make_type_32.loc11_11, %.loc11_11.1 [template = i32]
  57. // CHECK:STDOUT: %int.make_type_32.loc11_19: init type = call constants.%Int32() [template = i32]
  58. // CHECK:STDOUT: %.loc11_19.1: type = value_of_initializer %int.make_type_32.loc11_19 [template = i32]
  59. // CHECK:STDOUT: %.loc11_19.2: type = converted %int.make_type_32.loc11_19, %.loc11_19.1 [template = i32]
  60. // CHECK:STDOUT: %int.make_type_32.loc11_27: init type = call constants.%Int32() [template = i32]
  61. // CHECK:STDOUT: %.loc11_27.1: type = value_of_initializer %int.make_type_32.loc11_27 [template = i32]
  62. // CHECK:STDOUT: %.loc11_27.2: type = converted %int.make_type_32.loc11_27, %.loc11_27.1 [template = i32]
  63. // CHECK:STDOUT: %a.param: i32 = value_param runtime_param0
  64. // CHECK:STDOUT: %a: i32 = bind_name a, %a.param
  65. // CHECK:STDOUT: %b.param: i32 = value_param runtime_param1
  66. // CHECK:STDOUT: %b: i32 = bind_name b, %b.param
  67. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param2
  68. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  71. // CHECK:STDOUT: %Add.ref: %Add.type = name_ref Add, %Add.decl [template = constants.%Add]
  72. // CHECK:STDOUT: %.loc13_18: i32 = int_value 1 [template = constants.%.1]
  73. // CHECK:STDOUT: %.loc13_21: i32 = int_value 2 [template = constants.%.2]
  74. // CHECK:STDOUT: %int.sadd: init i32 = call %Add.ref(%.loc13_18, %.loc13_21) [template = constants.%.3]
  75. // CHECK:STDOUT: %.loc13_9.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  76. // CHECK:STDOUT: %.loc13_9.2: type = converted %int.make_type_32.loc13, %.loc13_9.1 [template = i32]
  77. // CHECK:STDOUT: %.loc13_23: type = array_type %int.sadd, i32 [template = constants.%.4]
  78. // CHECK:STDOUT: %a.var: ref %.4 = var a
  79. // CHECK:STDOUT: %a: ref %.4 = bind_name a, %a.var
  80. // CHECK:STDOUT: %int.make_type_32.loc14: init type = call constants.%Int32() [template = i32]
  81. // CHECK:STDOUT: %.loc14_14: i32 = int_value 3 [template = constants.%.3]
  82. // CHECK:STDOUT: %.loc14_9.1: type = value_of_initializer %int.make_type_32.loc14 [template = i32]
  83. // CHECK:STDOUT: %.loc14_9.2: type = converted %int.make_type_32.loc14, %.loc14_9.1 [template = i32]
  84. // CHECK:STDOUT: %.loc14_15: type = array_type %.loc14_14, i32 [template = constants.%.4]
  85. // CHECK:STDOUT: %.loc14_16: type = ptr_type %.4 [template = constants.%.5]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: fn @Add(%a.param_patt: i32, %b.param_patt: i32) -> i32 = "int.sadd";
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: fn @__global_init() {
  91. // CHECK:STDOUT: !entry:
  92. // CHECK:STDOUT: %.loc13_28: i32 = int_value 1 [template = constants.%.1]
  93. // CHECK:STDOUT: %.loc13_31: i32 = int_value 2 [template = constants.%.2]
  94. // CHECK:STDOUT: %.loc13_34: i32 = int_value 3 [template = constants.%.3]
  95. // CHECK:STDOUT: %.loc13_35.1: %tuple.type = tuple_literal (%.loc13_28, %.loc13_31, %.loc13_34)
  96. // CHECK:STDOUT: %.loc13_35.2: i32 = int_value 0 [template = constants.%.6]
  97. // CHECK:STDOUT: %.loc13_35.3: ref i32 = array_index file.%a.var, %.loc13_35.2
  98. // CHECK:STDOUT: %.loc13_35.4: init i32 = initialize_from %.loc13_28 to %.loc13_35.3 [template = constants.%.1]
  99. // CHECK:STDOUT: %.loc13_35.5: i32 = int_value 1 [template = constants.%.1]
  100. // CHECK:STDOUT: %.loc13_35.6: ref i32 = array_index file.%a.var, %.loc13_35.5
  101. // CHECK:STDOUT: %.loc13_35.7: init i32 = initialize_from %.loc13_31 to %.loc13_35.6 [template = constants.%.2]
  102. // CHECK:STDOUT: %.loc13_35.8: i32 = int_value 2 [template = constants.%.2]
  103. // CHECK:STDOUT: %.loc13_35.9: ref i32 = array_index file.%a.var, %.loc13_35.8
  104. // CHECK:STDOUT: %.loc13_35.10: init i32 = initialize_from %.loc13_34 to %.loc13_35.9 [template = constants.%.3]
  105. // CHECK:STDOUT: %.loc13_35.11: init %.4 = array_init (%.loc13_35.4, %.loc13_35.7, %.loc13_35.10) to file.%a.var [template = constants.%array]
  106. // CHECK:STDOUT: %.loc13_36: init %.4 = converted %.loc13_35.1, %.loc13_35.11 [template = constants.%array]
  107. // CHECK:STDOUT: assign file.%a.var, %.loc13_36
  108. // CHECK:STDOUT: %a.ref: ref %.4 = name_ref a, file.%a
  109. // CHECK:STDOUT: %.loc14: %.5 = addr_of %a.ref
  110. // CHECK:STDOUT: %b: %.5 = bind_name b, %.loc14
  111. // CHECK:STDOUT: return
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: