fail_array_out_of_bound_access.carbon 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. var a: [i32; 1] = (12,);
  7. // CHECK:STDERR: fail_array_out_of_bound_access.carbon:[[@LINE+3]]:16: ERROR: Array index `1` is past the end of type `[i32; 1]`.
  8. // CHECK:STDERR: var b: i32 = a[1];
  9. // CHECK:STDERR: ^
  10. var b: i32 = a[1];
  11. // CHECK:STDOUT: --- fail_array_out_of_bound_access.carbon
  12. // CHECK:STDOUT:
  13. // CHECK:STDOUT: constants {
  14. // CHECK:STDOUT: %.1: i32 = int_literal 1 [template]
  15. // CHECK:STDOUT: %.2: type = array_type %.1, i32 [template]
  16. // CHECK:STDOUT: %.3: type = ptr_type [i32; 1] [template]
  17. // CHECK:STDOUT: %.4: i32 = int_literal 12 [template]
  18. // CHECK:STDOUT: %.5: type = tuple_type (i32) [template]
  19. // CHECK:STDOUT: %.6: i32 = int_literal 0 [template]
  20. // CHECK:STDOUT: %.7: [i32; 1] = tuple_value (%.4) [template]
  21. // CHECK:STDOUT: }
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: file {
  24. // CHECK:STDOUT: package: <namespace> = namespace {.a = %a, .b = %b} [template]
  25. // CHECK:STDOUT: %.loc7_14: i32 = int_literal 1 [template = constants.%.1]
  26. // CHECK:STDOUT: %.loc7_15: type = array_type %.loc7_14, i32 [template = constants.%.2]
  27. // CHECK:STDOUT: %a.var: ref [i32; 1] = var a
  28. // CHECK:STDOUT: %a: ref [i32; 1] = bind_name a, %a.var
  29. // CHECK:STDOUT: %b.var: ref i32 = var b
  30. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: fn @__global_init() {
  34. // CHECK:STDOUT: !entry:
  35. // CHECK:STDOUT: %.loc7_20: i32 = int_literal 12 [template = constants.%.4]
  36. // CHECK:STDOUT: %.loc7_23.1: (i32,) = tuple_literal (%.loc7_20)
  37. // CHECK:STDOUT: %.loc7_23.2: i32 = int_literal 0 [template = constants.%.6]
  38. // CHECK:STDOUT: %.loc7_23.3: ref i32 = array_index file.%a.var, %.loc7_23.2
  39. // CHECK:STDOUT: %.loc7_23.4: init i32 = initialize_from %.loc7_20 to %.loc7_23.3 [template = constants.%.4]
  40. // CHECK:STDOUT: %.loc7_23.5: init [i32; 1] = array_init (%.loc7_23.4) to file.%a.var [template = constants.%.7]
  41. // CHECK:STDOUT: %.loc7_23.6: init [i32; 1] = converted %.loc7_23.1, %.loc7_23.5 [template = constants.%.7]
  42. // CHECK:STDOUT: assign file.%a.var, %.loc7_23.6
  43. // CHECK:STDOUT: %a.ref: ref [i32; 1] = name_ref a, file.%a
  44. // CHECK:STDOUT: %.loc11_16: i32 = int_literal 1 [template = constants.%.1]
  45. // CHECK:STDOUT: %.loc11_17.1: ref i32 = array_index %a.ref, %.loc11_16 [template = <error>]
  46. // CHECK:STDOUT: %.loc11_17.2: i32 = bind_value %.loc11_17.1
  47. // CHECK:STDOUT: assign file.%b.var, %.loc11_17.2
  48. // CHECK:STDOUT: return
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: