aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-05-05 16:54:28 +0100
committerPhilip Herron <philip.herron@embecosm.com>2023-05-05 18:15:06 +0000
commitcae5140e9b5a74e09f3dd95a5ffe664f1eefc14c (patch)
tree2cdf2ca51d8426cb63d886eea6cd80c325fe2885
parentbd91c5696e72038cab4ff6e8fc7be1f30200cd2a (diff)
downloadgcc-cae5140e9b5a74e09f3dd95a5ffe664f1eefc14c.zip
gcc-cae5140e9b5a74e09f3dd95a5ffe664f1eefc14c.tar.gz
gcc-cae5140e9b5a74e09f3dd95a5ffe664f1eefc14c.tar.bz2
gccrs: Add missing compile locals for constants and statics
When we have a block expression for cosntants or statics we need to ensure we compile the locals for the implicit function we generate in GIMPLE before feeding it directly into the constant folder to evaluate the data. Fixes #2178 gcc/rust/ChangeLog: * backend/rust-compile-base.cc: add missing compile_locals call gcc/testsuite/ChangeLog: * rust/compile/issue-2178.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
-rw-r--r--gcc/rust/backend/rust-compile-base.cc11
-rw-r--r--gcc/testsuite/rust/compile/issue-2178.rs10
2 files changed, 19 insertions, 2 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 9650d1a..11154e8 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -666,8 +666,8 @@ HIRCompileBase::compile_constant_item (
= ctx->get_backend ()->function (compiled_fn_type, ident, "", 0, locus);
TREE_READONLY (fndecl) = 1;
+ std::vector<Bvariable *> locals;
tree enclosing_scope = NULL_TREE;
-
Location start_location = const_value_expr->get_locus ();
Location end_location = const_value_expr->get_locus ();
if (is_block_expr)
@@ -676,9 +676,16 @@ HIRCompileBase::compile_constant_item (
= static_cast<HIR::BlockExpr *> (const_value_expr);
start_location = function_body->get_locus ();
end_location = function_body->get_end_locus ();
+
+ Resolver::Rib *rib = nullptr;
+ bool ok = ctx->get_resolver ()->find_name_rib (
+ function_body->get_mappings ().get_nodeid (), &rib);
+ rust_assert (ok);
+
+ locals = compile_locals_for_block (ctx, *rib, fndecl);
}
- tree code_block = ctx->get_backend ()->block (fndecl, enclosing_scope, {},
+ tree code_block = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
start_location, end_location);
ctx->push_block (code_block);
diff --git a/gcc/testsuite/rust/compile/issue-2178.rs b/gcc/testsuite/rust/compile/issue-2178.rs
new file mode 100644
index 0000000..faa2228
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2178.rs
@@ -0,0 +1,10 @@
+const A: usize = {
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let x = 23;
+ x
+};
+
+static B: usize = {
+ let x = 23;
+ x
+};