]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix move_val_init
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 31 Aug 2023 10:33:27 +0000 (11:33 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:04:30 +0000 (19:04 +0100)
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 <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-intrinsic.cc

index 5b41a3f6b0512a51c59cb8786ff09d8e1c8b5201..f2650c98c15032020ee8bbaa11621597c2863bf6 100644 (file)
@@ -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);
@@ -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