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 @@ -2029,6 +2029,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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like there is a regression here on running on 32 bit platforms. So this __builtin wont work.

Its definetlyy worth checking this in C/C++ on compiler explorer and if they make the same error and work back from that error message.

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
4 changes: 4 additions & 0 deletions gcc/testsuite/rust/compile/issue-3962.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
static FOO2: () = {
let x = [47; (1 << 47) - 1];
// { dg-error "the type ..i32; 140737488355327.. is too big for the current architecture" "" { target *-*-* } .-1 }

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

View workflow job for this annotation

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

Test failure (FAIL)

at line 3 (test for errors, line 2)

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)
};
Loading