From 4b82481d850a35765919cf5c91e7e063d9bceb29 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 14 Jul 2022 14:09:06 +0100 Subject: Support aggregate types in transmute In some testcases in libcore transmute is used on aggregate types like array's. The convert expression code assumes simple integer's. This this patch uses a gimple convert_expr to try and convert this type. This might change to a generic memcpy at somepoint but lets try this first and see how it works. --- gcc/rust/backend/rust-compile-intrinsic.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 57a952f..65eddfa 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -542,9 +542,19 @@ transmute_intrinsic_handler (Context *ctx, TyTy::BaseType *fntype_tyty) // BUILTIN transmute FN BODY BEGIN tree result_type_tree = TREE_TYPE (DECL_RESULT (fndecl)); - tree result_expr - = ctx->get_backend ()->convert_expression (result_type_tree, - convert_me_expr, Location ()); + tree result_expr = error_mark_node; + if (AGGREGATE_TYPE_P (TREE_TYPE (convert_me_expr))) + { + result_expr = fold_build1_loc (Location ().gcc_location (), CONVERT_EXPR, + result_type_tree, convert_me_expr); + } + else + { + result_expr = ctx->get_backend ()->convert_expression (result_type_tree, + convert_me_expr, + Location ()); + } + auto return_statement = ctx->get_backend ()->return_statement (fndecl, {result_expr}, Location ()); -- cgit v1.1 From 1347d23e09845b854ce50f8f857c062e04a89b60 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 14 Jul 2022 14:08:26 +0100 Subject: Implement AST dump for ArithmeticOrLogicalExpr to fix unreachable --- gcc/rust/ast/rust-ast-dump.cc | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index a06dd72..f4bff44 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -173,8 +173,40 @@ Dump::visit (ArithmeticOrLogicalExpr &expr) stream << "+"; break; - default: - gcc_unreachable (); + case ArithmeticOrLogicalOperator::SUBTRACT: + stream << "-"; + break; + + case ArithmeticOrLogicalOperator::MULTIPLY: + stream << "*"; + break; + + case ArithmeticOrLogicalOperator::DIVIDE: + stream << "/"; + break; + + case ArithmeticOrLogicalOperator::MODULUS: + stream << "%"; + break; + + case ArithmeticOrLogicalOperator::BITWISE_AND: + stream << "&"; + break; + + case ArithmeticOrLogicalOperator::BITWISE_OR: + stream << "|"; + break; + + case ArithmeticOrLogicalOperator::BITWISE_XOR: + stream << "^"; + break; + + case ArithmeticOrLogicalOperator::LEFT_SHIFT: + stream << "<<"; + break; + + case ArithmeticOrLogicalOperator::RIGHT_SHIFT: + stream << ">>"; break; } -- cgit v1.1 From 2ff776d36416adbade8161eeda4ee478a288af87 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 14 Jul 2022 15:06:22 +0100 Subject: Support ast dump of generic parameters on functions --- gcc/rust/ast/rust-ast-dump.cc | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index a06dd72..9af8fa8 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -48,7 +48,11 @@ void Dump::go (AST::Crate &crate) { for (auto &item : crate.items) - item->accept_vis (*this); + { + stream << indentation; + item->accept_vis (*this); + stream << "\n"; + } } void @@ -401,8 +405,12 @@ Dump::visit (AsyncBlockExpr &expr) void Dump::visit (TypeParam ¶m) { - // Is it possible to have a null type here? - param.get_type ()->accept_vis (*this); + stream << param.get_type_representation (); + if (param.has_type ()) + { + stream << ": "; + param.get_type ()->accept_vis (*this); + } } void @@ -473,8 +481,24 @@ Dump::visit (UseDeclaration &use_decl) void Dump::visit (Function &function) { - stream << indentation << "fn " << function.get_function_name () << '('; + stream << "fn " << function.get_function_name (); + + if (function.has_generics ()) + { + stream << "<"; + for (size_t i = 0; i < function.get_generic_params ().size (); i++) + { + auto ¶m = function.get_generic_params ().at (i); + param->accept_vis (*this); + + bool has_next = (i + 1) < function.get_generic_params ().size (); + if (has_next) + stream << ", "; + } + stream << ">"; + } + stream << '('; auto ¶ms = function.get_function_params (); if (params.size () >= 1) { -- cgit v1.1