[gcc/devel/rust/master] Merge #1452
Thomas Schwinge
tschwinge@gcc.gnu.org
Thu Aug 11 19:19:16 GMT 2022
https://gcc.gnu.org/g:7027e5c21ae6b8cb1ea2222e55960f1587071d14
commit 7027e5c21ae6b8cb1ea2222e55960f1587071d14
Merge: 7c3766ccfce 71b5bc8705c
Author: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Date: Wed Aug 10 10:35:07 2022 +0000
Merge #1452
1452: transmute: Fix behavior by always performing the raw copy r=CohenArthur a=CohenArthur
This desugars calls to transmute the following way:
`transmute::<T1, T2>(value)`
->
`*((T2 *) &value)`
This always ends up being optimized into a simple copy for small types
and a memcpy for larger types.
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diff:
gcc/rust/backend/rust-compile-intrinsic.cc | 36 ++++++------------------
gcc/testsuite/rust/execute/torture/transmute1.rs | 23 +++++++++++++++
2 files changed, 32 insertions(+), 27 deletions(-)
diff --cc gcc/rust/backend/rust-compile-intrinsic.cc
index a68ccc56a13,75e8c99158b..67e38c3261c
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@@ -309,36 -381,24 +309,18 @@@ transmute_handler (Context *ctx, TyTy::
(unsigned long) target_size);
}
- tree enclosing_scope = NULL_TREE;
- Location start_location = Location ();
- Location end_location = Location ();
-
- tree code_block = ctx->get_backend ()->block (fndecl, enclosing_scope, {},
- start_location, end_location);
- ctx->push_block (code_block);
+ enter_intrinsic_block (ctx, fndecl);
// BUILTIN transmute FN BODY BEGIN
- tree result_type_tree = TREE_TYPE (DECL_RESULT (fndecl));
- tree result_expr = error_mark_node;
- if (AGGREGATE_TYPE_P (TREE_TYPE (convert_me_expr)))
- {
- // Return *(orig_type*)&decl. */
- // tree t = build_fold_addr_expr_loc (location.gcc_location (), this->t_);
- // t = fold_build1_loc (location.gcc_location (), NOP_EXPR,
- // build_pointer_type (this->orig_type_), t);
- // return build_fold_indirect_ref_loc (location.gcc_location (), t);
-
- // result_expr = fold_build1_loc (Location ().gcc_location (),
- // CONVERT_EXPR,
- // result_type_tree, convert_me_expr);
-
- tree t = build_fold_addr_expr_loc (Location ().gcc_location (),
- convert_me_expr);
- t = fold_build1_loc (Location ().gcc_location (), NOP_EXPR,
- build_pointer_type (target_type_expr), t);
- result_expr
- = build_fold_indirect_ref_loc (Location ().gcc_location (), t);
- }
- else
- {
- result_expr = ctx->get_backend ()->convert_expression (result_type_tree,
- convert_me_expr,
- Location ());
- }
+
+ // Return *((orig_type*)&decl) */
+
+ tree t
+ = build_fold_addr_expr_loc (Location ().gcc_location (), convert_me_expr);
+ t = fold_build1_loc (Location ().gcc_location (), NOP_EXPR,
+ build_pointer_type (target_type_expr), t);
+ tree result_expr
+ = build_fold_indirect_ref_loc (Location ().gcc_location (), t);
auto return_statement
= ctx->get_backend ()->return_statement (fndecl, {result_expr},
More information about the Gcc-cvs
mailing list