diff --git a/toolchain/check/handle_array.cpp b/toolchain/check/handle_array.cpp index c1d9f815139e..25dd3f1cf548 100644 --- a/toolchain/check/handle_array.cpp +++ b/toolchain/check/handle_array.cpp @@ -37,7 +37,7 @@ auto HandleArrayExpression(Context& context, Parse::Node parse_node) -> bool { if (bound_node.kind() == SemIR::NodeKind::IntegerLiteral) { auto bound_value = context.semantics_ir().GetIntegerLiteral( bound_node.GetAsIntegerLiteral()); - if (!bound_value.isNegative()) { + if (!bound_value.isNegative() && bound_value.getBitWidth() <= 64) { context.AddNodeAndPush( parse_node, SemIR::Node::ArrayType::Make( diff --git a/toolchain/check/testdata/array/fail_bound_overflow.carbon b/toolchain/check/testdata/array/fail_bound_overflow.carbon new file mode 100644 index 000000000000..17a9937548da --- /dev/null +++ b/toolchain/check/testdata/array/fail_bound_overflow.carbon @@ -0,0 +1,48 @@ +// 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 +// +// AUTOUPDATE + +// CHECK:STDERR: fail_bound_overflow.carbon:[[@LINE+3]]:32: Invalid array expression. +// CHECK:STDERR: var a: [1; 39999999999999999993]; +// CHECK:STDERR: ^ +var a: [1; 39999999999999999993]; + +// CHECK:STDOUT: cross_reference_irs_size: 1 +// CHECK:STDOUT: functions: [ +// CHECK:STDOUT: ] +// CHECK:STDOUT: integer_literals: [ +// CHECK:STDOUT: 1, +// CHECK:STDOUT: 39999999999999999993, +// CHECK:STDOUT: ] +// CHECK:STDOUT: real_literals: [ +// CHECK:STDOUT: ] +// CHECK:STDOUT: strings: [ +// CHECK:STDOUT: a, +// CHECK:STDOUT: ] +// CHECK:STDOUT: types: [ +// CHECK:STDOUT: nodeIntegerType, +// CHECK:STDOUT: ] +// CHECK:STDOUT: type_blocks: [ +// CHECK:STDOUT: ] +// CHECK:STDOUT: nodes: [ +// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int0, type: type0}, +// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int1, type: type0}, +// CHECK:STDOUT: {kind: VarStorage, arg0: str0, type: typeError}, +// CHECK:STDOUT: ] +// CHECK:STDOUT: node_blocks: [ +// CHECK:STDOUT: [ +// CHECK:STDOUT: ], +// CHECK:STDOUT: [ +// CHECK:STDOUT: node+0, +// CHECK:STDOUT: node+1, +// CHECK:STDOUT: node+2, +// CHECK:STDOUT: ], +// CHECK:STDOUT: ] +// CHECK:STDOUT: +// CHECK:STDOUT: package { +// CHECK:STDOUT: %.loc10_9: i32 = int_literal 1 +// CHECK:STDOUT: %.loc10_12: i32 = int_literal 39999999999999999993 +// CHECK:STDOUT: %a: ref = var "a" +// CHECK:STDOUT: }