diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-08-09 13:50:39 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-08-10 12:36:26 +0200 |
commit | 71b5bc8705c789fa61ad0d7858441da861213356 (patch) | |
tree | f26b5cbc8647efb7b14ea260b251fa4d275a2bcb /gcc/rust | |
parent | 349b0f8ed4564fff88fc28bab0733657f2621780 (diff) | |
download | gcc-71b5bc8705c789fa61ad0d7858441da861213356.zip gcc-71b5bc8705c789fa61ad0d7858441da861213356.tar.gz gcc-71b5bc8705c789fa61ad0d7858441da861213356.tar.bz2 |
transmute: Fix behavior by always performing the raw copy
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: philberty <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/backend/rust-compile-intrinsic.cc | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index ebf1ed6..75e8c99 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -390,33 +390,15 @@ transmute_intrinsic_handler (Context *ctx, TyTy::BaseType *fntype_tyty) ctx->push_block (code_block); // 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}, |