Skip to content

Commit

Permalink
gccrs: Fix move_val_init
Browse files Browse the repository at this point in the history
The intrinsic move_val_init was being optimized away even at -O0 because
the function looked "pure" but this adds in the attributes to enforce that
this function has side-effects to override that bad assumption by the
middle-end.

Addresses Rust-GCC#1895

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (move_val_init_handler): mark as side-effects

Signed-off-by: Philip Herron <[email protected]>
  • Loading branch information
philberty authored and CohenArthur committed Jan 16, 2024
1 parent 7519a5f commit b79f643
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gcc/rust/backend/rust-compile-intrinsic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,10 @@ move_val_init_handler (Context *ctx, TyTy::FnType *fntype)

auto fndecl = compile_intrinsic_function (ctx, fntype);

// Most intrinsic functions are pure - not `move_val_init`
TREE_READONLY (fndecl) = 0;
TREE_SIDE_EFFECTS (fndecl) = 1;

// get the template parameter type tree fn size_of<T>();
rust_assert (fntype->get_num_substitutions () == 1);
auto &param_mapping = fntype->get_substs ().at (0);
Expand Down Expand Up @@ -1113,8 +1117,6 @@ move_val_init_handler (Context *ctx, TyTy::FnType *fntype)
src = build_fold_addr_expr_loc (BUILTINS_LOCATION, src);
tree memset_call = build_call_expr_loc (BUILTINS_LOCATION, memcpy_builtin, 3,
dst, src, size);
TREE_READONLY (memset_call) = 0;
TREE_SIDE_EFFECTS (memset_call) = 1;

ctx->add_statement (memset_call);
// BUILTIN size_of FN BODY END
Expand Down

0 comments on commit b79f643

Please sign in to comment.