https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123557

--- Comment #6 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
The following patch seems to fix things and passes regtest but I'm not sure if
it's actually correct; should 'set_target_expr_eliding' only be set if this is
folding an INIT_EXPR?


diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index df86c390332..d427117db11 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -3030,7 +3030,11 @@ cp_fold_non_odr_use_1 (tree x)
     return x;

   tree t = maybe_constant_value (x);
-  return TREE_CONSTANT (t) ? t : x;
+  if (!TREE_CONSTANT (t))
+    return x;
+
+  set_target_expr_eliding (t);
+  return t;
 }

 /* Fold expression X which is used as an rvalue if RVAL is true.  */

Reply via email to