diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-05-05 19:06:37 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:37:15 +0100 |
commit | cf046027a23df64ed46ade5ae4a5c9d77ea191ab (patch) | |
tree | ab8bacf59c17455cdc4c6844c367d4cb4220d2aa /gcc/rust/backend/rust-constexpr.cc | |
parent | c6f1b887e8f52ba6252ad83e03cbea41af326f6e (diff) | |
download | gcc-cf046027a23df64ed46ade5ae4a5c9d77ea191ab.zip gcc-cf046027a23df64ed46ade5ae4a5c9d77ea191ab.tar.gz gcc-cf046027a23df64ed46ade5ae4a5c9d77ea191ab.tar.bz2 |
gccrs: Redo how we handle unit types for the final time
We had a very inconsistant way for dealing with unit-types in gccrs we
tried to optimize the case for a function returning unit type to be clever
and not emit any return value for unit types. Then for other cases we would
use an empty constructor for an empty tuple and in others use a zero
percsion integer. This was all just confusing and made the IR less
conformant to Rust. In this patch I change all of this to use an empty
tuple type for all cases so we pass around {} which maps over to Rust and
gets optimized away in the middle end anyway.
In the patch we also remove old gccgo code which optimizes away zero
size types to void_type_node which is why my original attempt at doing this
two years ago failed.
Fixes #2188
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::compile_function_body): use unit_expression
(HIRCompileBase::unit_expression): new helper
* backend/rust-compile-base.h: update prototype
* backend/rust-compile-block.cc (CompileBlock::visit): use unit_expression
* backend/rust-compile-expr.cc (CompileExpr::visit): likewise
(CompileExpr::generate_closure_function): likewise
* backend/rust-compile-implitem.cc (CompileTraitItem::visit): cleanup
* backend/rust-compile-item.cc (CompileItem::visit): likewise
* backend/rust-compile-pattern.cc (CompilePatternLet::visit): likewise
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): likewise
* backend/rust-compile-type.cc (TyTyResolveCompile::get_unit_type): new helper
(TyTyResolveCompile::visit): use new unit_type helper
* backend/rust-compile-type.h: likewise
* rust-backend.h: simplify the return_expression
* rust-gcc.cc (Gcc_backend::function_type): likewise
(Gcc_backend::return_statement): likewise
* backend/rust-constexpr.cc (eval_constant_expression): remove bad assertion
gcc/testsuite/ChangeLog:
* rust/compile/issue-2188.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/backend/rust-constexpr.cc')
-rw-r--r-- | gcc/rust/backend/rust-constexpr.cc | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index a7ae416..3fd1b96 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -2247,7 +2247,6 @@ eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval, /* Don't VERIFY_CONSTANT here. */ if (*non_constant_p) return t; - gcc_checking_assert (TREE_CODE (op) != CONSTRUCTOR); /* This function does more aggressive folding than fold itself. */ r = build_fold_addr_expr_with_type (op, TREE_TYPE (t)); if (TREE_CODE (r) == ADDR_EXPR && TREE_OPERAND (r, 0) == oldop) |