ssub.carbon 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. // EXTRA-ARGS: --no-dump-sem-ir
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/int/ssub.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/int/ssub.carbon
  12. // --- int_sub.carbon
  13. fn Sub(a: i32, b: i32) -> i32 = "int.ssub";
  14. var arr: [i32; Sub(3, 2)];
  15. let arr_p: [i32; 1]* = &arr;
  16. fn RuntimeCallIsValid(a: i32, b: i32) -> i32 {
  17. return Sub(a, b);
  18. }
  19. // --- fail_overflow.carbon
  20. package FailOverflow;
  21. fn Sub(a: i32, b: i32) -> i32 = "int.ssub";
  22. let a: i32 = Sub(0, 0x7FFFFFFF);
  23. let b: i32 = Sub(Sub(0, 0x7FFFFFFF), 1);
  24. // CHECK:STDERR: fail_overflow.carbon:[[@LINE+4]]:14: error: integer overflow in calculation `-2147483647 - 2` [CompileTimeIntegerOverflow]
  25. // CHECK:STDERR: let c: i32 = Sub(Sub(0, 0x7FFFFFFF), 2);
  26. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~
  27. // CHECK:STDERR:
  28. let c: i32 = Sub(Sub(0, 0x7FFFFFFF), 2);