Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions gcc/rust/backend/rust-compile-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,17 @@ CompileExpr::array_copied_expr (location_t expr_locus,
unsigned HOST_WIDE_INT len
= wi::ext (max - min + 1, precision, sign).to_uhwi ();

unsigned int res;
if (__builtin_umul_overflow (TREE_INT_CST_ELT (TYPE_SIZE_UNIT (array_type),
0),
len, &res))
{
rust_error_at (expr_locus, ErrorCode::E0080,
"the type %qs is too big for the current architecture",
array_tyty.as_string ().c_str ());
return error_mark_node;
}

// In a const context we must initialize the entire array, which entails
// allocating for each element. If the user wants a huge array, we will OOM
// and die horribly.
Expand Down
5 changes: 5 additions & 0 deletions gcc/testsuite/rust/compile/issue-3962.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
static FOO2: () = {
let x = [47; (1 << 47) - 1];
// { dg-error "the type ..i32; 140737488355327.. is too big for the current architecture" "" { target x86_64-*-* } .-1 }

Check failure on line 3 in gcc/testsuite/rust/compile/issue-3962.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-32bit

Test failure (FAIL)

at line 3 (test for errors, line 2)
// { dg-error "left shift count >= width of type" "" { target i?86-*-* } .-2 }
};
Loading