aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-08-04 20:25:59 +0100
committerPhilip Herron <philip.herron@embecosm.com>2022-08-04 20:36:46 +0100
commit7022b9dd107e534896d8383f6bc4ce70b4726cc9 (patch)
treed42eca280664839dae014a2a6feac37870f2b921 /gcc/rust
parentc788a806195f326a595cd15b96c59e7584927f1a (diff)
downloadgcc-7022b9dd107e534896d8383f6bc4ce70b4726cc9.zip
gcc-7022b9dd107e534896d8383f6bc4ce70b4726cc9.tar.gz
gcc-7022b9dd107e534896d8383f6bc4ce70b4726cc9.tar.bz2
Fix bad transmute for aggregate types
This changes the CONVERT_EXPR to use the same *(foo*)&bar style cast from the c front-end to handle the case of: int a[1]; int b = (int)a; Which is converted into: int b = *(int*)&a; which the constant folders can turn directly into int b = a[0]; Fixes #1432
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/backend/rust-compile-intrinsic.cc18
1 files changed, 16 insertions, 2 deletions
diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc
index 65eddfa..88d7923 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -545,8 +545,22 @@ transmute_intrinsic_handler (Context *ctx, TyTy::BaseType *fntype_tyty)
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);
+ // 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
{