From: Philip Herron Date: Thu, 31 Aug 2023 10:33:27 +0000 (+0100) Subject: gccrs: Fix move_val_init X-Git-Tag: basepoints/gcc-15~2185 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b79f6432799f983470a5d19f4e91b45531166e90;p=thirdparty%2Fgcc.git 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 #1895 gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (move_val_init_handler): mark as side-effects Signed-off-by: Philip Herron --- diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 5b41a3f6b051..f2650c98c150 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -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(); rust_assert (fntype->get_num_substitutions () == 1); auto ¶m_mapping = fntype->get_substs ().at (0); @@ -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