diff options
author | lrh2000 <lrh2000@pku.edu.cn> | 2021-04-10 22:53:32 +0800 |
---|---|---|
committer | lrh2000 <lrh2000@pku.edu.cn> | 2021-04-18 10:21:37 +0800 |
commit | 3aeb9f47187f9b7ad55e32bcd273556823f383c6 (patch) | |
tree | c42044bbf0bac300b37cfb2e786fdc5c06a29838 /gcc/rust/backend | |
parent | c5fdf8cc544f9647e2cf28a2da431bfa1faacd15 (diff) | |
download | gcc-3aeb9f47187f9b7ad55e32bcd273556823f383c6.zip gcc-3aeb9f47187f9b7ad55e32bcd273556823f383c6.tar.gz gcc-3aeb9f47187f9b7ad55e32bcd273556823f383c6.tar.bz2 |
Introduce limited support for the never type
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 5 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-tyty.h | 5 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile.cc | 8 |
3 files changed, 13 insertions, 5 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 8866575..2024a6f 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -503,6 +503,11 @@ public: translated = compiled_type; } + void visit (TyTy::NeverType &) override + { + translated = ctx->get_backend ()->void_type (); + } + private: TyTyResolveCompile (Context *ctx) : ctx (ctx), translated (nullptr) {} diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h index 28db289..ba98ac0 100644 --- a/gcc/rust/backend/rust-compile-tyty.h +++ b/gcc/rust/backend/rust-compile-tyty.h @@ -222,6 +222,11 @@ public: = backend->named_type ("str", raw_str, Linemap::predeclared_location ()); } + void visit (TyTy::NeverType &) override + { + translated = backend->void_type (); + } + private: TyTyCompile (::Backend *backend) : backend (backend), translated (nullptr), diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index d0e0c66..9375dd0 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -256,7 +256,7 @@ CompileBlock::visit (HIR::BlockExpr &expr) } } - if (expr.has_expr () && expr.tail_expr_reachable ()) + if (expr.has_expr ()) { // the previous passes will ensure this is a valid return // dead code elimination should remove any bad trailing expressions @@ -410,17 +410,15 @@ HIRCompileBase::compile_function_body ( } } - if (function_body->has_expr () && function_body->tail_expr_reachable ()) + if (function_body->has_expr ()) { // the previous passes will ensure this is a valid return // dead code elimination should remove any bad trailing expressions Bexpression *compiled_expr = CompileExpr::Compile (function_body->expr.get (), ctx); - if (has_return_type) + if (has_return_type && compiled_expr) { - rust_assert (compiled_expr != nullptr); - std::vector<Bexpression *> retstmts; retstmts.push_back (compiled_expr); |