fail_array_large_index.carbon 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_large_index.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_large_index.carbon
  10. var a: [i32; 1] = (12,);
  11. // CHECK:STDERR: fail_array_large_index.carbon:[[@LINE+4]]:16: error: array index `1` is past the end of type `[i32; 1]` [ArrayIndexOutOfBounds]
  12. // CHECK:STDERR: var b: i32 = a[1];
  13. // CHECK:STDERR: ^
  14. // CHECK:STDERR:
  15. var b: i32 = a[1];
  16. // CHECK:STDERR: fail_array_large_index.carbon:[[@LINE+3]]:16: error: array index `2147483647` is past the end of type `[i32; 1]` [ArrayIndexOutOfBounds]
  17. // CHECK:STDERR: var c: i32 = a[0x7FFF_FFFF];
  18. // CHECK:STDERR: ^~~~~~~~~~~
  19. var c: i32 = a[0x7FFF_FFFF];
  20. // CHECK:STDOUT: --- fail_array_large_index.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  24. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  25. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [template]
  26. // CHECK:STDOUT: %array_type: type = array_type %int_1.5b8, %i32 [template]
  27. // CHECK:STDOUT: %int_12.6a3: Core.IntLiteral = int_value 12 [template]
  28. // CHECK:STDOUT: %tuple.type: type = tuple_type (Core.IntLiteral) [template]
  29. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template]
  30. // CHECK:STDOUT: %Convert.type.cd1: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  31. // CHECK:STDOUT: %impl_witness.5b0: <witness> = impl_witness (imports.%import_ref.723), @impl.1(%int_32) [template]
  32. // CHECK:STDOUT: %Convert.type.466: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  33. // CHECK:STDOUT: %Convert.925: %Convert.type.466 = struct_value () [template]
  34. // CHECK:STDOUT: %Convert.bound.8aa: <bound method> = bound_method %int_12.6a3, %Convert.925 [template]
  35. // CHECK:STDOUT: %Convert.specific_fn.545: <specific function> = specific_function %Convert.bound.8aa, @Convert.2(%int_32) [template]
  36. // CHECK:STDOUT: %int_12.43d: %i32 = int_value 12 [template]
  37. // CHECK:STDOUT: %array: %array_type = tuple_value (%int_12.43d) [template]
  38. // CHECK:STDOUT: %Convert.bound.afd: <bound method> = bound_method %int_1.5b8, %Convert.925 [template]
  39. // CHECK:STDOUT: %Convert.specific_fn.b73: <specific function> = specific_function %Convert.bound.afd, @Convert.2(%int_32) [template]
  40. // CHECK:STDOUT: %int_1.c60: %i32 = int_value 1 [template]
  41. // CHECK:STDOUT: %int_2147483647.d89: Core.IntLiteral = int_value 2147483647 [template]
  42. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2147483647.d89, %Convert.925 [template]
  43. // CHECK:STDOUT: %Convert.specific_fn.a96: <specific function> = specific_function %Convert.bound.ef9, @Convert.2(%int_32) [template]
  44. // CHECK:STDOUT: %int_2147483647.2ba: %i32 = int_value 2147483647 [template]
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: imports {
  48. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  49. // CHECK:STDOUT: .Int = %import_ref.187
  50. // CHECK:STDOUT: .ImplicitAs = %import_ref.a69
  51. // CHECK:STDOUT: import Core//prelude
  52. // CHECK:STDOUT: import Core//prelude/...
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  58. // CHECK:STDOUT: .Core = imports.%Core
  59. // CHECK:STDOUT: .a = %a
  60. // CHECK:STDOUT: .b = %b
  61. // CHECK:STDOUT: .c = %c
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %Core.import = import Core
  64. // CHECK:STDOUT: %a.var: ref %array_type = var a
  65. // CHECK:STDOUT: %a: ref %array_type = bind_name a, %a.var
  66. // CHECK:STDOUT: %b.var: ref %i32 = var b
  67. // CHECK:STDOUT: %b: ref %i32 = bind_name b, %b.var
  68. // CHECK:STDOUT: %c.var: ref %i32 = var c
  69. // CHECK:STDOUT: %c: ref %i32 = bind_name c, %c.var
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: fn @__global_init() {
  73. // CHECK:STDOUT: !entry:
  74. // CHECK:STDOUT: %int_12: Core.IntLiteral = int_value 12 [template = constants.%int_12.6a3]
  75. // CHECK:STDOUT: %.loc11_23.1: %tuple.type = tuple_literal (%int_12)
  76. // CHECK:STDOUT: %impl.elem0.loc11: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  77. // CHECK:STDOUT: %Convert.bound.loc11: <bound method> = bound_method %int_12, %impl.elem0.loc11 [template = constants.%Convert.bound.8aa]
  78. // CHECK:STDOUT: %Convert.specific_fn.loc11: <specific function> = specific_function %Convert.bound.loc11, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.545]
  79. // CHECK:STDOUT: %int.convert_checked.loc11: init %i32 = call %Convert.specific_fn.loc11(%int_12) [template = constants.%int_12.43d]
  80. // CHECK:STDOUT: %.loc11_23.2: init %i32 = converted %int_12, %int.convert_checked.loc11 [template = constants.%int_12.43d]
  81. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  82. // CHECK:STDOUT: %.loc11_23.3: ref %i32 = array_index file.%a.var, %int_0
  83. // CHECK:STDOUT: %.loc11_23.4: init %i32 = initialize_from %.loc11_23.2 to %.loc11_23.3 [template = constants.%int_12.43d]
  84. // CHECK:STDOUT: %.loc11_23.5: init %array_type = array_init (%.loc11_23.4) to file.%a.var [template = constants.%array]
  85. // CHECK:STDOUT: %.loc11_24: init %array_type = converted %.loc11_23.1, %.loc11_23.5 [template = constants.%array]
  86. // CHECK:STDOUT: assign file.%a.var, %.loc11_24
  87. // CHECK:STDOUT: %a.ref.loc17: ref %array_type = name_ref a, file.%a
  88. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  89. // CHECK:STDOUT: %int_32.loc17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  90. // CHECK:STDOUT: %i32.loc17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  91. // CHECK:STDOUT: %impl.elem0.loc17: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  92. // CHECK:STDOUT: %Convert.bound.loc17: <bound method> = bound_method %int_1, %impl.elem0.loc17 [template = constants.%Convert.bound.afd]
  93. // CHECK:STDOUT: %Convert.specific_fn.loc17: <specific function> = specific_function %Convert.bound.loc17, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.b73]
  94. // CHECK:STDOUT: %int.convert_checked.loc17: init %i32 = call %Convert.specific_fn.loc17(%int_1) [template = constants.%int_1.c60]
  95. // CHECK:STDOUT: %.loc17_16.1: %i32 = value_of_initializer %int.convert_checked.loc17 [template = constants.%int_1.c60]
  96. // CHECK:STDOUT: %.loc17_16.2: %i32 = converted %int_1, %.loc17_16.1 [template = constants.%int_1.c60]
  97. // CHECK:STDOUT: %.loc17_17.1: ref %i32 = array_index %a.ref.loc17, %.loc17_16.2 [template = <error>]
  98. // CHECK:STDOUT: %.loc17_17.2: %i32 = bind_value %.loc17_17.1
  99. // CHECK:STDOUT: assign file.%b.var, %.loc17_17.2
  100. // CHECK:STDOUT: %a.ref.loc22: ref %array_type = name_ref a, file.%a
  101. // CHECK:STDOUT: %int_2147483647: Core.IntLiteral = int_value 2147483647 [template = constants.%int_2147483647.d89]
  102. // CHECK:STDOUT: %int_32.loc22: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  103. // CHECK:STDOUT: %i32.loc22: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  104. // CHECK:STDOUT: %impl.elem0.loc22: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  105. // CHECK:STDOUT: %Convert.bound.loc22: <bound method> = bound_method %int_2147483647, %impl.elem0.loc22 [template = constants.%Convert.bound.ef9]
  106. // CHECK:STDOUT: %Convert.specific_fn.loc22: <specific function> = specific_function %Convert.bound.loc22, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.a96]
  107. // CHECK:STDOUT: %int.convert_checked.loc22: init %i32 = call %Convert.specific_fn.loc22(%int_2147483647) [template = constants.%int_2147483647.2ba]
  108. // CHECK:STDOUT: %.loc22_16.1: %i32 = value_of_initializer %int.convert_checked.loc22 [template = constants.%int_2147483647.2ba]
  109. // CHECK:STDOUT: %.loc22_16.2: %i32 = converted %int_2147483647, %.loc22_16.1 [template = constants.%int_2147483647.2ba]
  110. // CHECK:STDOUT: %.loc22_27.1: ref %i32 = array_index %a.ref.loc22, %.loc22_16.2 [template = <error>]
  111. // CHECK:STDOUT: %.loc22_27.2: %i32 = bind_value %.loc22_27.1
  112. // CHECK:STDOUT: assign file.%c.var, %.loc22_27.2
  113. // CHECK:STDOUT: return
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: