On Thu, 15 May 2025 at 18:32, Ville Voutilainen
<ville.voutilai...@gmail.com> wrote:
>
> On Thu, 15 May 2025 at 18:19, Jason Merrill <ja...@redhat.com> wrote:
>
> > > @@ -3347,8 +3347,6 @@ cp_fold (tree x, fold_flags_t flags)
> > >               || id_equal (DECL_NAME (callee), "as_const")))
> > >         {
> > >           r = CALL_EXPR_ARG (x, 0);
> > > -         if (!same_type_p (TREE_TYPE (x), TREE_TYPE (r)))
> > > -           r = build_nop (TREE_TYPE (x), r);
> >
> > This is removing the conversion entirely; I'm rather surprised it didn't
> > break anything.  I thought you were thinking to make the build_nop
> > unconditional.
>
> Oops. Yes, that makes more sense. I am confused how that build_nop
> actually works, but it indeed should
> convert r to x, and not be completely nuked. Re-doing...

So, let's try this again. As discussed privately, the difference of
whether that build_nop is there is hard to the point of
unknown-how-to test-trigger, but this patch makes more sense.

Tested on Linux-PPC64 (gcc112). Ok for trunk?

  Further simplify the stdlib inline folding

   gcc/cp/ChangeLog:
           * cp-gimplify.cc (cp_fold): Do the conversion
unconditionally, even for same-type cases.

   gcc/ChangeLog:
           * doc/invoke.texi: Add to_underlying to -ffold-simple-inlines.
diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index eab55504b05..f7bd453bc5e 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -3347,8 +3347,7 @@ cp_fold (tree x, fold_flags_t flags)
 		|| id_equal (DECL_NAME (callee), "as_const")))
 	  {
 	    r = CALL_EXPR_ARG (x, 0);
-	    if (!same_type_p (TREE_TYPE (x), TREE_TYPE (r)))
-	      r = build_nop (TREE_TYPE (x), r);
+	    r = build_nop (TREE_TYPE (x), r);
 	    x = cp_fold (r, flags);
 	    break;
 	  }
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index ee7180110e1..83c63ce6ae5 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -3348,7 +3348,8 @@ aliases, the default is @option{-fno-extern-tls-init}.
 @item -ffold-simple-inlines
 @itemx -fno-fold-simple-inlines
 Permit the C++ frontend to fold calls to @code{std::move}, @code{std::forward},
-@code{std::addressof} and @code{std::as_const}.  In contrast to inlining, this
+@code{std::addressof}, @code{std::to_underlying}
+and @code{std::as_const}.  In contrast to inlining, this
 means no debug information will be generated for such calls.  Since these
 functions are rarely interesting to debug, this flag is enabled by default
 unless @option{-fno-inline} is active.

Reply via email to