fail_bound_overflow.carbon 2.6 KB

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