fail_bound_overflow.carbon 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/array/fail_bound_overflow.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/fail_bound_overflow.carbon
  10. // TODO: Once we preserve the full value of integer literals in SemIR, check
  11. // that we reject the array bound being too large.
  12. // CHECK:STDERR: fail_bound_overflow.carbon:[[@LINE+4]]:14: ERROR: Integer literal with value 39999999999999999993 does not fit in i32.
  13. // CHECK:STDERR: var a: [i32; 39999999999999999993];
  14. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
  15. // CHECK:STDERR:
  16. var a: [i32; 39999999999999999993];
  17. // CHECK:STDERR: fail_bound_overflow.carbon:[[@LINE+7]]:9: ERROR: Cannot implicitly convert from `i32` to `type`.
  18. // CHECK:STDERR: var b: [1; 39999999999999999993];
  19. // CHECK:STDERR: ^
  20. // CHECK:STDERR:
  21. // CHECK:STDERR: fail_bound_overflow.carbon:[[@LINE+3]]:12: ERROR: Integer literal with value 39999999999999999993 does not fit in i32.
  22. // CHECK:STDERR: var b: [1; 39999999999999999993];
  23. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
  24. var b: [1; 39999999999999999993];
  25. // CHECK:STDOUT: --- fail_bound_overflow.carbon
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: constants {
  28. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  29. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  30. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  31. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: imports {
  35. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref ir3, inst+4, loaded [template = constants.%Int32]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .Core = %Core
  41. // CHECK:STDOUT: .a = %a
  42. // CHECK:STDOUT: .b = %b
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %Core.import = import Core
  45. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {}
  46. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  47. // CHECK:STDOUT: %.loc18_9.1: type = value_of_initializer %int.make_type_32 [template = i32]
  48. // CHECK:STDOUT: %.loc18_9.2: type = converted %int.make_type_32, %.loc18_9.1 [template = i32]
  49. // CHECK:STDOUT: %.loc18_34: type = array_type <error>, i32 [template = <error>]
  50. // CHECK:STDOUT: %a.var: ref <error> = var a
  51. // CHECK:STDOUT: %a: ref <error> = bind_name a, %a.var
  52. // CHECK:STDOUT: %.loc27_9: i32 = int_literal 1 [template = constants.%.2]
  53. // CHECK:STDOUT: %.loc27_32: type = array_type <error>, <error> [template = <error>]
  54. // CHECK:STDOUT: %b.var: ref <error> = var b
  55. // CHECK:STDOUT: %b: ref <error> = bind_name b, %b.var
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  59. // CHECK:STDOUT: