@@ -83,6 +83,8 @@ static tree
83
83
op_with_overflow_inner (Context *ctx, TyTy::FnType *fntype, tree_code op);
84
84
static tree
85
85
uninit_handler (Context *ctx, TyTy::FnType *fntype);
86
+ static tree
87
+ move_val_init_handler (Context *ctx, TyTy::FnType *fntype);
86
88
87
89
enum class Prefetch
88
90
{
@@ -205,6 +207,7 @@ static const std::map<std::string,
205
207
{" unchecked_shl" , unchecked_op_handler (LSHIFT_EXPR)},
206
208
{" unchecked_shr" , unchecked_op_handler (RSHIFT_EXPR)},
207
209
{" uninit" , uninit_handler},
210
+ {" move_val_init" , move_val_init_handler},
208
211
};
209
212
210
213
Intrinsics::Intrinsics (Context *ctx) : ctx (ctx) {}
@@ -1001,7 +1004,7 @@ uninit_handler (Context *ctx, TyTy::FnType *fntype)
1001
1004
1002
1005
auto fndecl = compile_intrinsic_function (ctx, fntype);
1003
1006
1004
- // get the template parameter type tree fn size_of <T>();
1007
+ // get the template parameter type tree fn uninit <T>();
1005
1008
rust_assert (fntype->get_num_substitutions () == 1 );
1006
1009
auto ¶m_mapping = fntype->get_substs ().at (0 );
1007
1010
const TyTy::ParamType *param_tyty = param_mapping.get_param_ty ();
@@ -1042,5 +1045,56 @@ uninit_handler (Context *ctx, TyTy::FnType *fntype)
1042
1045
return fndecl;
1043
1046
}
1044
1047
1048
+ static tree
1049
+ move_val_init_handler (Context *ctx, TyTy::FnType *fntype)
1050
+ {
1051
+ rust_assert (fntype->get_params ().size () == 2 );
1052
+
1053
+ tree lookup = NULL_TREE;
1054
+ if (check_for_cached_intrinsic (ctx, fntype, &lookup))
1055
+ return lookup;
1056
+
1057
+ auto fndecl = compile_intrinsic_function (ctx, fntype);
1058
+
1059
+ // get the template parameter type tree fn size_of<T>();
1060
+ rust_assert (fntype->get_num_substitutions () == 1 );
1061
+ auto ¶m_mapping = fntype->get_substs ().at (0 );
1062
+ const TyTy::ParamType *param_tyty = param_mapping.get_param_ty ();
1063
+ TyTy::BaseType *resolved_tyty = param_tyty->resolve ();
1064
+ tree template_parameter_type
1065
+ = TyTyResolveCompile::compile (ctx, resolved_tyty);
1066
+
1067
+ std::vector<Bvariable *> param_vars;
1068
+ compile_fn_params (ctx, fntype, fndecl, ¶m_vars);
1069
+
1070
+ if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
1071
+ return error_mark_node;
1072
+
1073
+ enter_intrinsic_block (ctx, fndecl);
1074
+
1075
+ // BUILTIN size_of FN BODY BEGIN
1076
+
1077
+ tree dst = ctx->get_backend ()->var_expression (param_vars[0 ], Location ());
1078
+ tree src = ctx->get_backend ()->var_expression (param_vars[1 ], Location ());
1079
+ tree size = TYPE_SIZE_UNIT (template_parameter_type);
1080
+
1081
+ tree memcpy_builtin = error_mark_node;
1082
+ BuiltinsContext::get ().lookup_simple_builtin (" memcpy" , &memcpy_builtin);
1083
+ rust_assert (memcpy_builtin != error_mark_node);
1084
+
1085
+ src = build_fold_addr_expr_loc (BUILTINS_LOCATION, src);
1086
+ tree memset_call = build_call_expr_loc (BUILTINS_LOCATION, memcpy_builtin, 3 ,
1087
+ dst, src, size);
1088
+ TREE_READONLY (memset_call) = 0 ;
1089
+ TREE_SIDE_EFFECTS (memset_call) = 1 ;
1090
+
1091
+ ctx->add_statement (memset_call);
1092
+ // BUILTIN size_of FN BODY END
1093
+
1094
+ finalize_intrinsic_block (ctx, fndecl);
1095
+
1096
+ return fndecl;
1097
+ }
1098
+
1045
1099
} // namespace Compile
1046
1100
} // namespace Rust
0 commit comments