https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124084
--- Comment #1 from kugan at gcc dot gnu.org ---
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index 437797fef0c..a03dd6346ff 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -3568,14 +3568,19 @@ build_new_1 (vec<tree, va_gc> **placement, tree type,
tree nelts,
/* Clobber the object now that the constructor won't do it in
start_preparsed_function. This is most important for activating an array
- in a union (c++/121068), but should also help the optimizers. */
+ in a union (c++/121068), but should also help the optimizers.
+ Don't emit clobber for placement new of primitive types, as they don't
+ initialize (no constructor runs). Otherwise MEM=CLOBBER(bob) in GIMPLE
+ is treated as a store and a preceding memset is considered dead and
+ removed (wrong code). */
const bool do_clobber
= (flag_lifetime_dse > 1
&& !processing_template_decl
&& !is_empty_type (elt_type)
&& !integer_zerop (TYPE_SIZE (type))
&& (!outer_nelts || !integer_zerop (cst_outer_nelts))
- && (!*init || CLASS_TYPE_P (elt_type)));
+ && (!*init || CLASS_TYPE_P (elt_type))
+ && !(std_placement && !CLASS_TYPE_P (elt_type)));
/* In the simple case, we can stop now. */
pointer_type = build_pointer_type (type);
Is a potential fix