fail_numeric_literal_overflow.carbon 5.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/basics/fail_numeric_literal_overflow.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/basics/fail_numeric_literal_overflow.carbon
  10. // CHECK:STDERR: fail_numeric_literal_overflow.carbon:[[@LINE+4]]:14: ERROR: Integer literal with value 39999999999999999993 does not fit in i32.
  11. // CHECK:STDERR: let a: i32 = 39999999999999999993;
  12. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
  13. // CHECK:STDERR:
  14. let a: i32 = 39999999999999999993;
  15. // CHECK:STDERR: fail_numeric_literal_overflow.carbon:[[@LINE+4]]:14: ERROR: Integer literal with value 2147483648 does not fit in i32.
  16. // CHECK:STDERR: let b: i32 = 2_147_483_648;
  17. // CHECK:STDERR: ^~~~~~~~~~~~~
  18. // CHECK:STDERR:
  19. let b: i32 = 2_147_483_648;
  20. // CHECK:STDERR: fail_numeric_literal_overflow.carbon:[[@LINE+4]]:14: ERROR: Integer literal with value 2147483648 does not fit in i32.
  21. // CHECK:STDERR: let c: i32 = 0x8000_0000;
  22. // CHECK:STDERR: ^~~~~~~~~~~
  23. // CHECK:STDERR:
  24. let c: i32 = 0x8000_0000;
  25. // CHECK:STDERR: fail_numeric_literal_overflow.carbon:[[@LINE+4]]:14: ERROR: Real mantissa with value 399999999999999999930 does not fit in i64.
  26. // CHECK:STDERR: let d: f64 = 39999999999999999993.0e3;
  27. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~
  28. // CHECK:STDERR:
  29. let d: f64 = 39999999999999999993.0e3;
  30. // CHECK:STDERR: fail_numeric_literal_overflow.carbon:[[@LINE+3]]:14: ERROR: Real exponent with value 39999999999999999992 does not fit in i64.
  31. // CHECK:STDERR: let e: f64 = 5.0e39999999999999999993;
  32. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~
  33. let e: f64 = 5.0e39999999999999999993;
  34. // CHECK:STDOUT: --- fail_numeric_literal_overflow.carbon
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: constants {
  37. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  38. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  39. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  40. // CHECK:STDOUT: %.2: i32 = int_literal 64 [template]
  41. // CHECK:STDOUT: %Float.type: type = fn_type @Float [template]
  42. // CHECK:STDOUT: %Float: %Float.type = struct_value () [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .Core = %Core
  48. // CHECK:STDOUT: .a = @__global_init.%a
  49. // CHECK:STDOUT: .b = @__global_init.%b
  50. // CHECK:STDOUT: .c = @__global_init.%c
  51. // CHECK:STDOUT: .d = @__global_init.%d
  52. // CHECK:STDOUT: .e = @__global_init.%e
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  55. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  56. // CHECK:STDOUT: %int.make_type_32.loc15: init type = call constants.%Int32() [template = i32]
  57. // CHECK:STDOUT: %.loc15_8.1: type = value_of_initializer %int.make_type_32.loc15 [template = i32]
  58. // CHECK:STDOUT: %.loc15_8.2: type = converted %int.make_type_32.loc15, %.loc15_8.1 [template = i32]
  59. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  60. // CHECK:STDOUT: %int.make_type_32.loc21: init type = call constants.%Int32() [template = i32]
  61. // CHECK:STDOUT: %.loc21_8.1: type = value_of_initializer %int.make_type_32.loc21 [template = i32]
  62. // CHECK:STDOUT: %.loc21_8.2: type = converted %int.make_type_32.loc21, %.loc21_8.1 [template = i32]
  63. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  64. // CHECK:STDOUT: %int.make_type_32.loc27: init type = call constants.%Int32() [template = i32]
  65. // CHECK:STDOUT: %.loc27_8.1: type = value_of_initializer %int.make_type_32.loc27 [template = i32]
  66. // CHECK:STDOUT: %.loc27_8.2: type = converted %int.make_type_32.loc27, %.loc27_8.1 [template = i32]
  67. // CHECK:STDOUT: %.loc33_8.1: i32 = int_literal 64 [template = constants.%.2]
  68. // CHECK:STDOUT: %import_ref.4: %Float.type = import_ref ir3, inst+31, loaded [template = constants.%Float]
  69. // CHECK:STDOUT: %float.make_type.loc33: init type = call constants.%Float(%.loc33_8.1) [template = f64]
  70. // CHECK:STDOUT: %.loc33_8.2: type = value_of_initializer %float.make_type.loc33 [template = f64]
  71. // CHECK:STDOUT: %.loc33_8.3: type = converted %float.make_type.loc33, %.loc33_8.2 [template = f64]
  72. // CHECK:STDOUT: %.loc38_8.1: i32 = int_literal 64 [template = constants.%.2]
  73. // CHECK:STDOUT: %import_ref.5: %Float.type = import_ref ir3, inst+31, loaded [template = constants.%Float]
  74. // CHECK:STDOUT: %float.make_type.loc38: init type = call constants.%Float(%.loc38_8.1) [template = f64]
  75. // CHECK:STDOUT: %.loc38_8.2: type = value_of_initializer %float.make_type.loc38 [template = f64]
  76. // CHECK:STDOUT: %.loc38_8.3: type = converted %float.make_type.loc38, %.loc38_8.2 [template = f64]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @Float(%size: i32) -> type = "float.make_type";
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @__global_init() {
  84. // CHECK:STDOUT: !entry:
  85. // CHECK:STDOUT: %a: i32 = bind_name a, <error>
  86. // CHECK:STDOUT: %b: i32 = bind_name b, <error>
  87. // CHECK:STDOUT: %c: i32 = bind_name c, <error>
  88. // CHECK:STDOUT: %d: f64 = bind_name d, <error>
  89. // CHECK:STDOUT: %e: f64 = bind_name e, <error>
  90. // CHECK:STDOUT: return
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: