fail_array_out_of_bound_access.carbon 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/index/fail_array_out_of_bound_access.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/index/fail_array_out_of_bound_access.carbon
  10. var a: [i32; 1] = (12,);
  11. // CHECK:STDERR: fail_array_out_of_bound_access.carbon:[[@LINE+3]]:16: ERROR: Array index `1` is past the end of type `[i32; 1]`.
  12. // CHECK:STDERR: var b: i32 = a[1];
  13. // CHECK:STDERR: ^
  14. var b: i32 = a[1];
  15. // CHECK:STDOUT: --- fail_array_out_of_bound_access.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  19. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  20. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  21. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  22. // CHECK:STDOUT: %.3: type = array_type %.2, i32 [template]
  23. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  24. // CHECK:STDOUT: %.5: i32 = int_literal 12 [template]
  25. // CHECK:STDOUT: %.6: type = tuple_type (i32) [template]
  26. // CHECK:STDOUT: %.7: i32 = int_literal 0 [template]
  27. // CHECK:STDOUT: %array: %.3 = tuple_value (%.5) [template]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: file {
  31. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  32. // CHECK:STDOUT: .Core = %Core
  33. // CHECK:STDOUT: .a = %a
  34. // CHECK:STDOUT: .b = %b
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  37. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  38. // CHECK:STDOUT: %int.make_type_32.loc11: init type = call constants.%Int32() [template = i32]
  39. // CHECK:STDOUT: %.loc11_14: i32 = int_literal 1 [template = constants.%.2]
  40. // CHECK:STDOUT: %.loc11_9.1: type = value_of_initializer %int.make_type_32.loc11 [template = i32]
  41. // CHECK:STDOUT: %.loc11_9.2: type = converted %int.make_type_32.loc11, %.loc11_9.1 [template = i32]
  42. // CHECK:STDOUT: %.loc11_15: type = array_type %.loc11_14, i32 [template = constants.%.3]
  43. // CHECK:STDOUT: %a.var: ref %.3 = var a
  44. // CHECK:STDOUT: %a: ref %.3 = bind_name a, %a.var
  45. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  46. // CHECK:STDOUT: %int.make_type_32.loc15: init type = call constants.%Int32() [template = i32]
  47. // CHECK:STDOUT: %.loc15_8.1: type = value_of_initializer %int.make_type_32.loc15 [template = i32]
  48. // CHECK:STDOUT: %.loc15_8.2: type = converted %int.make_type_32.loc15, %.loc15_8.1 [template = i32]
  49. // CHECK:STDOUT: %b.var: ref i32 = var b
  50. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @__global_init() {
  56. // CHECK:STDOUT: !entry:
  57. // CHECK:STDOUT: %.loc11_20: i32 = int_literal 12 [template = constants.%.5]
  58. // CHECK:STDOUT: %.loc11_23.1: %.6 = tuple_literal (%.loc11_20)
  59. // CHECK:STDOUT: %.loc11_23.2: i32 = int_literal 0 [template = constants.%.7]
  60. // CHECK:STDOUT: %.loc11_23.3: ref i32 = array_index file.%a.var, %.loc11_23.2
  61. // CHECK:STDOUT: %.loc11_23.4: init i32 = initialize_from %.loc11_20 to %.loc11_23.3 [template = constants.%.5]
  62. // CHECK:STDOUT: %.loc11_23.5: init %.3 = array_init (%.loc11_23.4) to file.%a.var [template = constants.%array]
  63. // CHECK:STDOUT: %.loc11_24: init %.3 = converted %.loc11_23.1, %.loc11_23.5 [template = constants.%array]
  64. // CHECK:STDOUT: assign file.%a.var, %.loc11_24
  65. // CHECK:STDOUT: %a.ref: ref %.3 = name_ref a, file.%a
  66. // CHECK:STDOUT: %.loc15_16: i32 = int_literal 1 [template = constants.%.2]
  67. // CHECK:STDOUT: %.loc15_17.1: ref i32 = array_index %a.ref, %.loc15_16 [template = <error>]
  68. // CHECK:STDOUT: %.loc15_17.2: i32 = bind_value %.loc15_17.1
  69. // CHECK:STDOUT: assign file.%b.var, %.loc15_17.2
  70. // CHECK:STDOUT: return
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: