aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-constexpr.cc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-05-05 19:06:37 +0100
committerPhilip Herron <philip.herron@embecosm.com>2023-05-08 14:53:18 +0000
commitea597e73da52a4292986b5267fc535006ae4c343 (patch)
tree668fe7aa980f82a6094528255e7c85ebfcfd16c9 /gcc/rust/backend/rust-constexpr.cc
parenta252a9c12d7cc6cb160a57b271d2c8e8840b7f55 (diff)
downloadgcc-ea597e73da52a4292986b5267fc535006ae4c343.zip
gcc-ea597e73da52a4292986b5267fc535006ae4c343.tar.gz
gcc-ea597e73da52a4292986b5267fc535006ae4c343.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.cc1
1 files changed, 0 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc
index 4e581a3..34443cd 100644
--- a/gcc/rust/backend/rust-constexpr.cc
+++ b/gcc/rust/backend/rust-constexpr.cc
@@ -2248,7 +2248,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)