mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-22 01:56:53 +00:00
In line with the proposal in #4682, this changes the array syntax to be array(T, N). `array` is a builtin keyword which must be followed by parens containing two expressions and a separating comma. The array type expression is still fully builtin, it does not forward to a Core.Array library type yet. It merely adds the `ArrayType` instruction, as was done with the previous syntax. Followup work will change the instruction to reference to Core.Array, once the library type exists and can be used directly. --------- Co-authored-by: zygoloid <richard@metafoo.co.uk>
65 lines
2.2 KiB
Plaintext
65 lines
2.2 KiB
Plaintext
// 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/smod.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/int/smod.carbon
|
|
|
|
// --- int_div.carbon
|
|
|
|
fn Mod(a: i32, b: i32) -> i32 = "int.smod";
|
|
|
|
var arr: array(i32, Mod(5, 3));
|
|
let arr_p: array(i32, 2)* = &arr;
|
|
|
|
fn RuntimeCallIsValid(a: i32, b: i32) -> i32 {
|
|
return Mod(a, b);
|
|
}
|
|
|
|
// --- fail_overflow.carbon
|
|
|
|
package FailOverflow;
|
|
|
|
fn Mod(a: i32, b: i32) -> i32 = "int.smod";
|
|
fn Sub(a: i32, b: i32) -> i32 = "int.ssub";
|
|
fn Negate(a: i32) -> i32 = "int.snegate";
|
|
|
|
// -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 overflows, so -0x8000_0000 % -1 is disallowed, even though
|
|
// its result is representable.
|
|
// CHECK:STDERR: fail_overflow.carbon:[[@LINE+4]]:14: error: integer overflow in calculation `-2147483648 % -1` [CompileTimeIntegerOverflow]
|
|
// CHECK:STDERR: let c: i32 = Mod(Sub(Negate(0x7FFF_FFFF), 1), Negate(1));
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
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.smod";
|
|
|
|
// 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);
|