aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-02-10 14:38:10 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-02-10 18:10:57 +0000
commitf10e695fc508c472c77e968e644f710806f82f54 (patch)
tree1628784a0b83981ea01f024e5989832edf447a1a /gcc/rust/backend/rust-compile-expr.h
parentae273ffac99cb75d832a11a83fd63291bb74cbdc (diff)
downloadgcc-f10e695fc508c472c77e968e644f710806f82f54.zip
gcc-f10e695fc508c472c77e968e644f710806f82f54.tar.gz
gcc-f10e695fc508c472c77e968e644f710806f82f54.tar.bz2
Return expressions can be empty which us unit-type
The parser has the same bug as in #225 for break expressions. This tidies up the type resolver and GENERIC translation to handle the case where there is no return expression as well. Fixes #226
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 92cb392..0c8d25a 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -84,14 +84,18 @@ public:
void visit (HIR::ReturnExpr &expr)
{
- Bexpression *compiled_expr
- = CompileExpr::Compile (expr.return_expr.get (), ctx);
- rust_assert (compiled_expr != nullptr);
-
auto fncontext = ctx->peek_fn ();
std::vector<Bexpression *> retstmts;
- retstmts.push_back (compiled_expr);
+ if (expr.has_return_expr ())
+ {
+ Bexpression *compiled_expr
+ = CompileExpr::Compile (expr.return_expr.get (), ctx);
+ rust_assert (compiled_expr != nullptr);
+
+ retstmts.push_back (compiled_expr);
+ }
+
auto s = ctx->get_backend ()->return_statement (fncontext.fndecl, retstmts,
expr.get_locus ());
ctx->add_statement (s);