aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-item.cc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-04-08 08:30:30 +0000
committerGitHub <noreply@github.com>2022-04-08 08:30:30 +0000
commitda3d59db1f13fb08aa9bd394b36379068315477c (patch)
tree96e6621e8cb28606efa91c030d2b9de4c77339f6 /gcc/rust/backend/rust-compile-item.cc
parentb829e7c0a21c94672d09732e4a791e0471f41c13 (diff)
parent5559bdc86635b2ff6cbaa60e933a7989ff212e1f (diff)
downloadgcc-da3d59db1f13fb08aa9bd394b36379068315477c.zip
gcc-da3d59db1f13fb08aa9bd394b36379068315477c.tar.gz
gcc-da3d59db1f13fb08aa9bd394b36379068315477c.tar.bz2
Merge #1087
1087: Use loop to initialize repeat arrays r=philberty a=dafaust This PR changes how we compile initializers for arrays of repeating elements. I use the same approach outlined in the comments of the linked issue, with some tweaks. It is very similar to how the D language front-end compiles, the new function `Gcc_backend::array_initializer` is heavily inspired by the D front-end's `build_array_set` This fixes the issue where the compiler tries to allocate a vec containing all elements of the array to be constructed, and therefore explodes on huge constructions (e.g. `let x = [0u8; 4 * 1024 * 1024 * 1024 * 1024]`) However, we can only initialize non-const arrays in this way. For arrays in const contexts we must initialize them at compile time, and therefore continue using the old method. Fixes: #1068 Co-authored-by: David Faust <david.faust@oracle.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-item.cc')
-rw-r--r--gcc/rust/backend/rust-compile-item.cc2
1 files changed, 2 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc
index 21cbb1c..80b7ceb 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -92,9 +92,11 @@ CompileItem::visit (HIR::ConstantItem &constant)
rust_assert (ok);
HIR::Expr *const_value_expr = constant.get_expr ();
+ ctx->push_const_context ();
tree const_expr
= compile_constant_item (ctx, resolved_type, canonical_path,
const_value_expr, constant.get_locus ());
+ ctx->pop_const_context ();
ctx->push_const (const_expr);
ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);