On 9/20/24 12:40 AM, Jakub Jelinek wrote:
On Fri, Sep 20, 2024 at 06:18:15PM -0400, Marek Polacek wrote:
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -1473,6 +1473,20 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_)
that case, strip it in favor of this one. */
if (tree &init = TARGET_EXPR_INITIAL (stmt))
{
+ tree fn;
+ if ((data->flags & ff_genericize)
+ /* Give the user an option to opt out. */
+ && !((fn = current_function_decl)
+ && lookup_attribute ("noinline",
+ DECL_ATTRIBUTES (fn))))
+ {
+ tree folded = maybe_constant_init (init, TARGET_EXPR_SLOT (stmt));
+ if (folded != init && TREE_CONSTANT (folded))
+ {
+ init = folded;
+ break;
+ }
+ }
The CALL_EXPR case in cp_fold uses !flag_no_inline instead, that makes more
sense to me.
Because checking "noinline" attribute (which means don't inline this
function) on current_function_decl rather than on functions being "inlined"
(the constexpr functions being non-manifestly constant evaluated) is just
weird.
If we really wanted, we could honor "noinline" during constant evaluation
on the CALL_EXPR/AGGR_INIT_EXPR fndecls, but dunno if whenever doing the
non-manifestly constant evaluated cases or just in special cases like these
two (CALL_EXPR in cp_fold, this in cp_fold_r).
Checking noinline in non-manifestly constant-evaluated cases might make
sense.
But I suspect there isn't even a call in pr78687; the only thing I can
see that maybe_constant could do anything with is the option_2()
value-init, and that should just be a TARGET_EXPR around a CONSTRUCTOR
already. Mysterious.
Jason