fail_out_of_bound_non_literal.carbon 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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; 3] = (1, 2, 3);
  7. // CHECK:STDERR: fail_out_of_bound_non_literal.carbon:[[@LINE+3]]:16: ERROR: Array index `3` is past the end of type `[i32; 3]`.
  8. // CHECK:STDERR: var b: i32 = a[{.index = 3}.index];
  9. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  10. var b: i32 = a[{.index = 3}.index];
  11. // CHECK:STDOUT: --- fail_out_of_bound_non_literal.carbon
  12. // CHECK:STDOUT:
  13. // CHECK:STDOUT: constants {
  14. // CHECK:STDOUT: %.1: i32 = int_literal 3 [template]
  15. // CHECK:STDOUT: %.2: type = array_type %.1, i32 [template]
  16. // CHECK:STDOUT: %.3: type = ptr_type [i32; 3] [template]
  17. // CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
  18. // CHECK:STDOUT: %.5: i32 = int_literal 2 [template]
  19. // CHECK:STDOUT: %.6: type = tuple_type (i32, i32, i32) [template]
  20. // CHECK:STDOUT: %.7: i32 = int_literal 0 [template]
  21. // CHECK:STDOUT: %.8: [i32; 3] = tuple_value (%.4, %.5, %.1) [template]
  22. // CHECK:STDOUT: %.9: type = struct_type {.index: i32} [template]
  23. // CHECK:STDOUT: %.10: {.index: i32} = struct_value (%.1) [template]
  24. // CHECK:STDOUT: }
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: file {
  27. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  28. // CHECK:STDOUT: .a = %a
  29. // CHECK:STDOUT: .b = %b
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT: %.loc7_14: i32 = int_literal 3 [template = constants.%.1]
  32. // CHECK:STDOUT: %.loc7_15: type = array_type %.loc7_14, i32 [template = constants.%.2]
  33. // CHECK:STDOUT: %a.var: ref [i32; 3] = var a
  34. // CHECK:STDOUT: %a: ref [i32; 3] = bind_name a, %a.var
  35. // CHECK:STDOUT: %b.var: ref i32 = var b
  36. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: fn @__global_init() {
  40. // CHECK:STDOUT: !entry:
  41. // CHECK:STDOUT: %.loc7_20: i32 = int_literal 1 [template = constants.%.4]
  42. // CHECK:STDOUT: %.loc7_23: i32 = int_literal 2 [template = constants.%.5]
  43. // CHECK:STDOUT: %.loc7_26: i32 = int_literal 3 [template = constants.%.1]
  44. // CHECK:STDOUT: %.loc7_27.1: (i32, i32, i32) = tuple_literal (%.loc7_20, %.loc7_23, %.loc7_26)
  45. // CHECK:STDOUT: %.loc7_27.2: i32 = int_literal 0 [template = constants.%.7]
  46. // CHECK:STDOUT: %.loc7_27.3: ref i32 = array_index file.%a.var, %.loc7_27.2
  47. // CHECK:STDOUT: %.loc7_27.4: init i32 = initialize_from %.loc7_20 to %.loc7_27.3 [template = constants.%.4]
  48. // CHECK:STDOUT: %.loc7_27.5: i32 = int_literal 1 [template = constants.%.4]
  49. // CHECK:STDOUT: %.loc7_27.6: ref i32 = array_index file.%a.var, %.loc7_27.5
  50. // CHECK:STDOUT: %.loc7_27.7: init i32 = initialize_from %.loc7_23 to %.loc7_27.6 [template = constants.%.5]
  51. // CHECK:STDOUT: %.loc7_27.8: i32 = int_literal 2 [template = constants.%.5]
  52. // CHECK:STDOUT: %.loc7_27.9: ref i32 = array_index file.%a.var, %.loc7_27.8
  53. // CHECK:STDOUT: %.loc7_27.10: init i32 = initialize_from %.loc7_26 to %.loc7_27.9 [template = constants.%.1]
  54. // CHECK:STDOUT: %.loc7_27.11: init [i32; 3] = array_init (%.loc7_27.4, %.loc7_27.7, %.loc7_27.10) to file.%a.var [template = constants.%.8]
  55. // CHECK:STDOUT: %.loc7_27.12: init [i32; 3] = converted %.loc7_27.1, %.loc7_27.11 [template = constants.%.8]
  56. // CHECK:STDOUT: assign file.%a.var, %.loc7_27.12
  57. // CHECK:STDOUT: %a.ref: ref [i32; 3] = name_ref a, file.%a
  58. // CHECK:STDOUT: %.loc11_26: i32 = int_literal 3 [template = constants.%.1]
  59. // CHECK:STDOUT: %.loc11_27.1: {.index: i32} = struct_literal (%.loc11_26)
  60. // CHECK:STDOUT: %.loc11_27.2: {.index: i32} = struct_value (%.loc11_26) [template = constants.%.10]
  61. // CHECK:STDOUT: %.loc11_27.3: {.index: i32} = converted %.loc11_27.1, %.loc11_27.2 [template = constants.%.10]
  62. // CHECK:STDOUT: %.loc11_28: i32 = struct_access %.loc11_27.3, element0 [template = constants.%.1]
  63. // CHECK:STDOUT: %.loc11_34.1: ref i32 = array_index %a.ref, %.loc11_28 [template = <error>]
  64. // CHECK:STDOUT: %.loc11_34.2: i32 = bind_value %.loc11_34.1
  65. // CHECK:STDOUT: assign file.%b.var, %.loc11_34.2
  66. // CHECK:STDOUT: return
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: