index_not_literal.carbon 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/index_not_literal.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/index_not_literal.carbon
  10. var a: [i32; 3] = (1, 2, 3);
  11. var b: i32 = a[{.index = 2}.index];
  12. // CHECK:STDOUT: --- index_not_literal.carbon
  13. // CHECK:STDOUT:
  14. // CHECK:STDOUT: constants {
  15. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  16. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  17. // CHECK:STDOUT: %.1: i32 = int_value 3 [template]
  18. // CHECK:STDOUT: %.2: type = array_type %.1, i32 [template]
  19. // CHECK:STDOUT: %.4: i32 = int_value 1 [template]
  20. // CHECK:STDOUT: %.5: i32 = int_value 2 [template]
  21. // CHECK:STDOUT: %tuple.type: type = tuple_type (i32, i32, i32) [template]
  22. // CHECK:STDOUT: %.6: i32 = int_value 0 [template]
  23. // CHECK:STDOUT: %array: %.2 = tuple_value (%.4, %.5, %.1) [template]
  24. // CHECK:STDOUT: %.7: type = struct_type {.index: i32} [template]
  25. // CHECK:STDOUT: %struct: %.7 = struct_value (%.5) [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: imports {
  29. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  30. // CHECK:STDOUT: .Int32 = %import_ref
  31. // CHECK:STDOUT: import Core//prelude
  32. // CHECK:STDOUT: import Core//prelude/...
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: file {
  37. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  38. // CHECK:STDOUT: .Core = imports.%Core
  39. // CHECK:STDOUT: .a = %a
  40. // CHECK:STDOUT: .b = %b
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %Core.import = import Core
  43. // CHECK:STDOUT: %int.make_type_32.loc11: init type = call constants.%Int32() [template = i32]
  44. // CHECK:STDOUT: %.loc11_14: i32 = int_value 3 [template = constants.%.1]
  45. // CHECK:STDOUT: %.loc11_9.1: type = value_of_initializer %int.make_type_32.loc11 [template = i32]
  46. // CHECK:STDOUT: %.loc11_9.2: type = converted %int.make_type_32.loc11, %.loc11_9.1 [template = i32]
  47. // CHECK:STDOUT: %.loc11_15: type = array_type %.loc11_14, i32 [template = constants.%.2]
  48. // CHECK:STDOUT: %a.var: ref %.2 = var a
  49. // CHECK:STDOUT: %a: ref %.2 = bind_name a, %a.var
  50. // CHECK:STDOUT: %int.make_type_32.loc12: init type = call constants.%Int32() [template = i32]
  51. // CHECK:STDOUT: %.loc12_8.1: type = value_of_initializer %int.make_type_32.loc12 [template = i32]
  52. // CHECK:STDOUT: %.loc12_8.2: type = converted %int.make_type_32.loc12, %.loc12_8.1 [template = i32]
  53. // CHECK:STDOUT: %b.var: ref i32 = var b
  54. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: fn @__global_init() {
  58. // CHECK:STDOUT: !entry:
  59. // CHECK:STDOUT: %.loc11_20: i32 = int_value 1 [template = constants.%.4]
  60. // CHECK:STDOUT: %.loc11_23: i32 = int_value 2 [template = constants.%.5]
  61. // CHECK:STDOUT: %.loc11_26: i32 = int_value 3 [template = constants.%.1]
  62. // CHECK:STDOUT: %.loc11_27.1: %tuple.type = tuple_literal (%.loc11_20, %.loc11_23, %.loc11_26)
  63. // CHECK:STDOUT: %.loc11_27.2: i32 = int_value 0 [template = constants.%.6]
  64. // CHECK:STDOUT: %.loc11_27.3: ref i32 = array_index file.%a.var, %.loc11_27.2
  65. // CHECK:STDOUT: %.loc11_27.4: init i32 = initialize_from %.loc11_20 to %.loc11_27.3 [template = constants.%.4]
  66. // CHECK:STDOUT: %.loc11_27.5: i32 = int_value 1 [template = constants.%.4]
  67. // CHECK:STDOUT: %.loc11_27.6: ref i32 = array_index file.%a.var, %.loc11_27.5
  68. // CHECK:STDOUT: %.loc11_27.7: init i32 = initialize_from %.loc11_23 to %.loc11_27.6 [template = constants.%.5]
  69. // CHECK:STDOUT: %.loc11_27.8: i32 = int_value 2 [template = constants.%.5]
  70. // CHECK:STDOUT: %.loc11_27.9: ref i32 = array_index file.%a.var, %.loc11_27.8
  71. // CHECK:STDOUT: %.loc11_27.10: init i32 = initialize_from %.loc11_26 to %.loc11_27.9 [template = constants.%.1]
  72. // CHECK:STDOUT: %.loc11_27.11: init %.2 = array_init (%.loc11_27.4, %.loc11_27.7, %.loc11_27.10) to file.%a.var [template = constants.%array]
  73. // CHECK:STDOUT: %.loc11_28: init %.2 = converted %.loc11_27.1, %.loc11_27.11 [template = constants.%array]
  74. // CHECK:STDOUT: assign file.%a.var, %.loc11_28
  75. // CHECK:STDOUT: %a.ref: ref %.2 = name_ref a, file.%a
  76. // CHECK:STDOUT: %.loc12_26: i32 = int_value 2 [template = constants.%.5]
  77. // CHECK:STDOUT: %.loc12_27.1: %.7 = struct_literal (%.loc12_26)
  78. // CHECK:STDOUT: %struct: %.7 = struct_value (%.loc12_26) [template = constants.%struct]
  79. // CHECK:STDOUT: %.loc12_27.2: %.7 = converted %.loc12_27.1, %struct [template = constants.%struct]
  80. // CHECK:STDOUT: %.loc12_28: i32 = struct_access %.loc12_27.2, element0 [template = constants.%.5]
  81. // CHECK:STDOUT: %.loc12_34.1: ref i32 = array_index %a.ref, %.loc12_28
  82. // CHECK:STDOUT: %.loc12_34.2: i32 = bind_value %.loc12_34.1
  83. // CHECK:STDOUT: assign file.%b.var, %.loc12_34.2
  84. // CHECK:STDOUT: return
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: