| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
- // Exceptions. See /LICENSE for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- // EXTRA-ARGS: --no-dump-sem-ir
- //
- // AUTOUPDATE
- // TIP: To test this file alone, run:
- // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/int/umod.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/int/umod.carbon
- // --- int_div.carbon
- fn Mod(a: i32, b: i32) -> i32 = "int.umod";
- var arr: [i32; Mod(5, 3)];
- let arr_p: [i32; 2]* = &arr;
- fn RuntimeCallIsValid(a: i32, b: i32) -> i32 {
- return Mod(a, b);
- }
- // --- overflow.carbon
- package Overflow;
- fn Mod(a: i32, b: i32) -> i32 = "int.umod";
- fn Sub(a: i32, b: i32) -> i32 = "int.usub";
- fn Negate(a: i32) -> i32 = "int.unegate";
- // -0x7FFF_FFFF % -1 is OK.
- let a: i32 = Mod(Negate(0x7FFF_FFFF), Negate(1));
- // -0x8000_0000 % 1 is OK.
- let b: i32 = Mod(Sub(Negate(0x7FFF_FFFF), 1), 1);
- // -0x8000_0000 / -1 is OK.
- let c: i32 = Mod(Sub(Negate(0x7FFF_FFFF), 1), Negate(1));
- // --- fail_div_by_zero.carbon
- package FailDivByZero;
- fn Mod(a: i32, b: i32) -> i32 = "int.umod";
- // Remainder of division by zero is not defined.
- // CHECK:STDERR: fail_div_by_zero.carbon:[[@LINE+4]]:14: error: division by zero [CompileTimeDivisionByZero]
- // CHECK:STDERR: let a: i32 = Mod(1, 0);
- // CHECK:STDERR: ^~~~~~~~~
- // CHECK:STDERR:
- let a: i32 = Mod(1, 0);
- // CHECK:STDERR: fail_div_by_zero.carbon:[[@LINE+4]]:14: error: division by zero [CompileTimeDivisionByZero]
- // CHECK:STDERR: let b: i32 = Mod(0, 0);
- // CHECK:STDERR: ^~~~~~~~~
- // CHECK:STDERR:
- let b: i32 = Mod(0, 0);
|