Skip to content

Commit b79f643

Browse files
philbertyCohenArthur
authored andcommitted
gccrs: Fix move_val_init
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]>
1 parent 7519a5f commit b79f643

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

gcc/rust/backend/rust-compile-intrinsic.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,10 @@ move_val_init_handler (Context *ctx, TyTy::FnType *fntype)
10821082

10831083
auto fndecl = compile_intrinsic_function (ctx, fntype);
10841084

1085+
// Most intrinsic functions are pure - not `move_val_init`
1086+
TREE_READONLY (fndecl) = 0;
1087+
TREE_SIDE_EFFECTS (fndecl) = 1;
1088+
10851089
// get the template parameter type tree fn size_of<T>();
10861090
rust_assert (fntype->get_num_substitutions () == 1);
10871091
auto &param_mapping = fntype->get_substs ().at (0);
@@ -1113,8 +1117,6 @@ move_val_init_handler (Context *ctx, TyTy::FnType *fntype)
11131117
src = build_fold_addr_expr_loc (BUILTINS_LOCATION, src);
11141118
tree memset_call = build_call_expr_loc (BUILTINS_LOCATION, memcpy_builtin, 3,
11151119
dst, src, size);
1116-
TREE_READONLY (memset_call) = 0;
1117-
TREE_SIDE_EFFECTS (memset_call) = 1;
11181120

11191121
ctx->add_statement (memset_call);
11201122
// BUILTIN size_of FN BODY END

0 commit comments

Comments
 (0)