fail_array_large_index.carbon 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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]`
  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]`
  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: %Int32.type: type = fn_type @Int32 [template]
  24. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  25. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  26. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  27. // CHECK:STDOUT: %.3: type = array_type %.2, i32 [template]
  28. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  29. // CHECK:STDOUT: %.5: i32 = int_literal 12 [template]
  30. // CHECK:STDOUT: %.6: type = tuple_type (i32) [template]
  31. // CHECK:STDOUT: %.7: i32 = int_literal 0 [template]
  32. // CHECK:STDOUT: %array: %.3 = tuple_value (%.5) [template]
  33. // CHECK:STDOUT: %.8: i32 = int_literal 2147483647 [template]
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: imports {
  37. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  38. // CHECK:STDOUT: .Int32 = %import_ref
  39. // CHECK:STDOUT: import Core//prelude
  40. // CHECK:STDOUT: import Core//prelude/operators
  41. // CHECK:STDOUT: import Core//prelude/types
  42. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  43. // CHECK:STDOUT: import Core//prelude/operators/as
  44. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  45. // CHECK:STDOUT: import Core//prelude/operators/comparison
  46. // CHECK:STDOUT: import Core//prelude/types/bool
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+9, loaded [template = constants.%Int32]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  53. // CHECK:STDOUT: .Core = imports.%Core
  54. // CHECK:STDOUT: .a = %a
  55. // CHECK:STDOUT: .b = %b
  56. // CHECK:STDOUT: .c = %c
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Core.import = import Core
  59. // CHECK:STDOUT: %int.make_type_32.loc11: init type = call constants.%Int32() [template = i32]
  60. // CHECK:STDOUT: %.loc11_14: i32 = int_literal 1 [template = constants.%.2]
  61. // CHECK:STDOUT: %.loc11_9.1: type = value_of_initializer %int.make_type_32.loc11 [template = i32]
  62. // CHECK:STDOUT: %.loc11_9.2: type = converted %int.make_type_32.loc11, %.loc11_9.1 [template = i32]
  63. // CHECK:STDOUT: %.loc11_15: type = array_type %.loc11_14, i32 [template = constants.%.3]
  64. // CHECK:STDOUT: %a.var: ref %.3 = var a
  65. // CHECK:STDOUT: %a: ref %.3 = bind_name a, %a.var
  66. // CHECK:STDOUT: %int.make_type_32.loc17: init type = call constants.%Int32() [template = i32]
  67. // CHECK:STDOUT: %.loc17_8.1: type = value_of_initializer %int.make_type_32.loc17 [template = i32]
  68. // CHECK:STDOUT: %.loc17_8.2: type = converted %int.make_type_32.loc17, %.loc17_8.1 [template = i32]
  69. // CHECK:STDOUT: %b.var: ref i32 = var b
  70. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  71. // CHECK:STDOUT: %int.make_type_32.loc22: init type = call constants.%Int32() [template = i32]
  72. // CHECK:STDOUT: %.loc22_8.1: type = value_of_initializer %int.make_type_32.loc22 [template = i32]
  73. // CHECK:STDOUT: %.loc22_8.2: type = converted %int.make_type_32.loc22, %.loc22_8.1 [template = i32]
  74. // CHECK:STDOUT: %c.var: ref i32 = var c
  75. // CHECK:STDOUT: %c: ref i32 = bind_name c, %c.var
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @__global_init() {
  81. // CHECK:STDOUT: !entry:
  82. // CHECK:STDOUT: %.loc11_20: i32 = int_literal 12 [template = constants.%.5]
  83. // CHECK:STDOUT: %.loc11_23.1: %.6 = tuple_literal (%.loc11_20)
  84. // CHECK:STDOUT: %.loc11_23.2: i32 = int_literal 0 [template = constants.%.7]
  85. // CHECK:STDOUT: %.loc11_23.3: ref i32 = array_index file.%a.var, %.loc11_23.2
  86. // CHECK:STDOUT: %.loc11_23.4: init i32 = initialize_from %.loc11_20 to %.loc11_23.3 [template = constants.%.5]
  87. // CHECK:STDOUT: %.loc11_23.5: init %.3 = array_init (%.loc11_23.4) to file.%a.var [template = constants.%array]
  88. // CHECK:STDOUT: %.loc11_24: init %.3 = converted %.loc11_23.1, %.loc11_23.5 [template = constants.%array]
  89. // CHECK:STDOUT: assign file.%a.var, %.loc11_24
  90. // CHECK:STDOUT: %a.ref.loc17: ref %.3 = name_ref a, file.%a
  91. // CHECK:STDOUT: %.loc17_16: i32 = int_literal 1 [template = constants.%.2]
  92. // CHECK:STDOUT: %.loc17_17.1: ref i32 = array_index %a.ref.loc17, %.loc17_16 [template = <error>]
  93. // CHECK:STDOUT: %.loc17_17.2: i32 = bind_value %.loc17_17.1
  94. // CHECK:STDOUT: assign file.%b.var, %.loc17_17.2
  95. // CHECK:STDOUT: %a.ref.loc22: ref %.3 = name_ref a, file.%a
  96. // CHECK:STDOUT: %.loc22_16: i32 = int_literal 2147483647 [template = constants.%.8]
  97. // CHECK:STDOUT: %.loc22_27.1: ref i32 = array_index %a.ref.loc22, %.loc22_16 [template = <error>]
  98. // CHECK:STDOUT: %.loc22_27.2: i32 = bind_value %.loc22_27.1
  99. // CHECK:STDOUT: assign file.%c.var, %.loc22_27.2
  100. // CHECK:STDOUT: return
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: