aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.cc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-03-29 16:14:04 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:28:39 +0100
commitfc2ba3b929aa6457a37604567c01bd97b92ecab1 (patch)
tree5325f499bb52f315b93ca8e1d35e7e57eb0eeee9 /gcc/rust/backend/rust-compile-expr.cc
parent7b2d86cad18998e6e14b6fa74d4a984438ab4b72 (diff)
downloadgcc-fc2ba3b929aa6457a37604567c01bd97b92ecab1.zip
gcc-fc2ba3b929aa6457a37604567c01bd97b92ecab1.tar.gz
gcc-fc2ba3b929aa6457a37604567c01bd97b92ecab1.tar.bz2
gccrs: fix ICE when closure body is not a block
Fixes: #2052 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::generate_closure_function): when its not a block we dont have any ribs to generate locals from gcc/testsuite/ChangeLog: * rust/execute/torture/issue-2052.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc23
1 files changed, 14 insertions, 9 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 962135b..e3b012c 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -2880,20 +2880,25 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
// lookup locals
HIR::Expr *function_body = expr.get_expr ().get ();
- auto body_mappings = function_body->get_mappings ();
- Resolver::Rib *rib = nullptr;
- bool ok
- = ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (), &rib);
- rust_assert (ok);
+ bool is_block_expr
+ = function_body->get_expression_type () == HIR::Expr::ExprType::Block;
+
+ std::vector<Bvariable *> locals = {};
+ if (is_block_expr)
+ {
+ auto body_mappings = function_body->get_mappings ();
+ Resolver::Rib *rib = nullptr;
+ bool ok
+ = ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (),
+ &rib);
+ rust_assert (ok);
- std::vector<Bvariable *> locals
- = compile_locals_for_block (ctx, *rib, fndecl);
+ locals = compile_locals_for_block (ctx, *rib, fndecl);
+ }
tree enclosing_scope = NULL_TREE;
Location start_location = function_body->get_locus ();
Location end_location = function_body->get_locus ();
- bool is_block_expr
- = function_body->get_expression_type () == HIR::Expr::ExprType::Block;
if (is_block_expr)
{
HIR::BlockExpr *body = static_cast<HIR::BlockExpr *> (function_body);