]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Mark uninit-intrinsic as side-effects
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 31 Aug 2023 10:33:12 +0000 (11:33 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:00:34 +0000 (19:00 +0100)
Ensure the uninit intrinsic does not get optimized away

Addresses #1895

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (uninit_handler): Update fndecl attributes

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-intrinsic.cc

index cbf6c0bb2b86f7415fc3d88f430491139d52b130..5b41a3f6b0512a51c59cb8786ff09d8e1c8b5201 100644 (file)
@@ -1017,6 +1017,10 @@ uninit_handler (Context *ctx, TyTy::FnType *fntype)
 
   auto fndecl = compile_intrinsic_function (ctx, fntype);
 
+  // Most intrinsic functions are pure - not `uninit_handler`
+  TREE_READONLY (fndecl) = 0;
+  TREE_SIDE_EFFECTS (fndecl) = 1;
+
   // get the template parameter type tree fn uninit<T>();
   rust_assert (fntype->get_num_substitutions () == 1);
   auto &param_mapping = fntype->get_substs ().at (0);
@@ -1055,9 +1059,6 @@ uninit_handler (Context *ctx, TyTy::FnType *fntype)
 
   tree memset_call = build_call_expr_loc (BUILTINS_LOCATION, memset_builtin, 3,
                                          dst_addr, constant_byte, size_expr);
-  TREE_READONLY (memset_call) = 0;
-  TREE_SIDE_EFFECTS (memset_call) = 1;
-
   ctx->add_statement (memset_call);
 
   auto return_statement