LCOV - code coverage report
Current view: top level - gcc/cp - cp-gimplify.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.1 % 2340 2202
Test Date: 2026-12-05 16:10:02 Functions: 100.0 % 81 81
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* C++-specific tree lowering bits; see also c-gimplify.cc and gimple.cc.
       2              : 
       3              :    Copyright (C) 2002-2026 Free Software Foundation, Inc.
       4              :    Contributed by Jason Merrill <jason@redhat.com>
       5              : 
       6              : This file is part of GCC.
       7              : 
       8              : GCC is free software; you can redistribute it and/or modify it under
       9              : the terms of the GNU General Public License as published by the Free
      10              : Software Foundation; either version 3, or (at your option) any later
      11              : version.
      12              : 
      13              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      14              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      15              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      16              : for more details.
      17              : 
      18              : You should have received a copy of the GNU General Public License
      19              : along with GCC; see the file COPYING3.  If not see
      20              : <http://www.gnu.org/licenses/>.  */
      21              : 
      22              : #include "config.h"
      23              : #include "system.h"
      24              : #include "coretypes.h"
      25              : #include "target.h"
      26              : #include "basic-block.h"
      27              : #include "cp-tree.h"
      28              : #include "gimple.h"
      29              : #include "predict.h"
      30              : #include "stor-layout.h"
      31              : #include "tree-iterator.h"
      32              : #include "gimplify.h"
      33              : #include "c-family/c-ubsan.h"
      34              : #include "stringpool.h"
      35              : #include "attribs.h"
      36              : #include "asan.h"
      37              : #include "gcc-rich-location.h"
      38              : #include "memmodel.h"
      39              : #include "tm_p.h"
      40              : #include "output.h"
      41              : #include "file-prefix-map.h"
      42              : #include "cgraph.h"
      43              : #include "omp-general.h"
      44              : #include "opts.h"
      45              : #include "gcc-urlifier.h"
      46              : #include "contracts.h" // build_contract_check ()
      47              : #include "builtins.h"
      48              : 
      49              : /* Keep track of forward references to immediate-escalating functions in
      50              :    case they become consteval.  This vector contains ADDR_EXPRs and
      51              :    PTRMEM_CSTs; it also stores FUNCTION_DECLs that had an escalating
      52              :    function call in them, to check that they can be evaluated to a constant,
      53              :    and immediate-escalating functions that may become consteval.  */
      54              : static GTY(()) hash_set<tree> *deferred_escalating_exprs;
      55              : 
      56              : static void
      57     26252634 : remember_escalating_expr (tree t)
      58              : {
      59     26252634 :   if (uses_template_parms (t))
      60              :     /* Templates don't escalate, and cp_fold_immediate can get confused by
      61              :        other template trees in the function body (c++/115986).  */
      62              :     return;
      63     26252634 :   if (!deferred_escalating_exprs)
      64        19559 :     deferred_escalating_exprs = hash_set<tree>::create_ggc (37);
      65     26252634 :   deferred_escalating_exprs->add (t);
      66              : }
      67              : 
      68              : /* Flags for cp_fold and cp_fold_r.  */
      69              : 
      70              : enum fold_flags {
      71              :   ff_none = 0,
      72              :   /* Whether we're being called from cp_fold_function.  */
      73              :   ff_genericize = 1 << 0,
      74              :   /* Whether we're folding a point where we know we're
      75              :      definitely not in a manifestly constant-evaluated
      76              :      context.  */
      77              :   ff_mce_false = 1 << 1,
      78              :   /* Whether we're only folding non-ODR usages of constants.
      79              :      This happens before saving the constexpr funcdef, so
      80              :      we should do as little other folding as possible.
      81              :      Mutually exclusive with ff_mce_false.  */
      82              :   ff_only_non_odr = 1 << 2,
      83              : };
      84              : 
      85              : using fold_flags_t = int;
      86              : 
      87     84206068 : struct cp_fold_data
      88              : {
      89              :   hash_set<tree> pset;
      90              :   fold_flags_t flags;
      91    198398107 :   cp_fold_data (fold_flags_t flags): flags (flags)
      92              :   {
      93    198398107 :     gcc_checking_assert (!(flags & ff_mce_false)
      94              :                          || !(flags & ff_only_non_odr));
      95    198398107 :   }
      96     78581687 :   mce_value mce ()
      97              :   {
      98     78581687 :     return flags & ff_mce_false ? mce_false : mce_unknown;
      99              :   }
     100              : };
     101              : 
     102              : /* Forward declarations.  */
     103              : 
     104              : static tree cp_genericize_r (tree *, int *, void *);
     105              : static tree cp_fold_r (tree *, int *, void *);
     106              : static void cp_genericize_tree (tree*, bool);
     107              : static tree cp_fold (tree, fold_flags_t);
     108              : static tree cp_fold_immediate_r (tree *, int *, void *);
     109              : 
     110              : /* Genericize a TRY_BLOCK.  */
     111              : 
     112              : static void
     113        20303 : genericize_try_block (tree *stmt_p)
     114              : {
     115        20303 :   tree body = TRY_STMTS (*stmt_p);
     116        20303 :   tree cleanup = TRY_HANDLERS (*stmt_p);
     117              : 
     118        20303 :   *stmt_p = build2 (TRY_CATCH_EXPR, void_type_node, body, cleanup);
     119        20303 : }
     120              : 
     121              : /* Genericize a HANDLER by converting to a CATCH_EXPR.  */
     122              : 
     123              : static void
     124        23479 : genericize_catch_block (tree *stmt_p)
     125              : {
     126        23479 :   tree type = HANDLER_TYPE (*stmt_p);
     127        23479 :   tree body = HANDLER_BODY (*stmt_p);
     128              : 
     129              :   /* FIXME should the caught type go in TREE_TYPE?  */
     130        23479 :   *stmt_p = build2 (CATCH_EXPR, void_type_node, type, body);
     131        23479 : }
     132              : 
     133              : /* A terser interface for building a representation of an exception
     134              :    specification.  */
     135              : 
     136              : static tree
     137         4351 : build_gimple_eh_filter_tree (tree body, tree allowed, tree failure)
     138              : {
     139         4351 :   tree t;
     140              : 
     141              :   /* FIXME should the allowed types go in TREE_TYPE?  */
     142         4351 :   t = build2 (EH_FILTER_EXPR, void_type_node, allowed, NULL_TREE);
     143         4351 :   append_to_statement_list (failure, &EH_FILTER_FAILURE (t));
     144              : 
     145         4351 :   t = build2 (TRY_CATCH_EXPR, void_type_node, NULL_TREE, t);
     146         4351 :   append_to_statement_list (body, &TREE_OPERAND (t, 0));
     147              : 
     148         4351 :   return t;
     149              : }
     150              : 
     151              : /* Genericize an EH_SPEC_BLOCK by converting it to a
     152              :    TRY_CATCH_EXPR/EH_FILTER_EXPR pair.  */
     153              : 
     154              : static void
     155         4351 : genericize_eh_spec_block (tree *stmt_p)
     156              : {
     157         4351 :   tree body = EH_SPEC_STMTS (*stmt_p);
     158         4351 :   tree allowed = EH_SPEC_RAISES (*stmt_p);
     159         4351 :   tree failure = build_call_n (call_unexpected_fn, 1, build_exc_ptr ());
     160              : 
     161         4351 :   *stmt_p = build_gimple_eh_filter_tree (body, allowed, failure);
     162         4351 :   suppress_warning (*stmt_p);
     163         4351 :   suppress_warning (TREE_OPERAND (*stmt_p, 1));
     164         4351 : }
     165              : 
     166              : /* Return the first non-compound statement in STMT.  */
     167              : 
     168              : tree
     169     15204884 : first_stmt (tree stmt)
     170              : {
     171     22920828 :   switch (TREE_CODE (stmt))
     172              :     {
     173      6100070 :     case STATEMENT_LIST:
     174      6100070 :       if (tree_statement_list_node *p = STATEMENT_LIST_HEAD (stmt))
     175      4047509 :         return first_stmt (p->stmt);
     176      2052561 :       return void_node;
     177              : 
     178      3668435 :     case BIND_EXPR:
     179      3668435 :       return first_stmt (BIND_EXPR_BODY (stmt));
     180              : 
     181              :     default:
     182              :       return stmt;
     183              :     }
     184              : }
     185              : 
     186              : /* Genericize an IF_STMT by turning it into a COND_EXPR.  */
     187              : 
     188              : static void
     189     22334239 : genericize_if_stmt (tree *stmt_p)
     190              : {
     191     22334239 :   tree stmt, cond, then_, else_;
     192     22334239 :   location_t locus = EXPR_LOCATION (*stmt_p);
     193              : 
     194     22334239 :   stmt = *stmt_p;
     195     22334239 :   cond = IF_COND (stmt);
     196     22334239 :   then_ = THEN_CLAUSE (stmt);
     197     22334239 :   else_ = ELSE_CLAUSE (stmt);
     198              : 
     199     22334239 :   if (then_ && else_)
     200              :     {
     201      7602442 :       tree ft = first_stmt (then_);
     202      7602442 :       tree fe = first_stmt (else_);
     203      7602442 :       br_predictor pr;
     204      7602442 :       if (TREE_CODE (ft) == PREDICT_EXPR
     205        43950 :           && TREE_CODE (fe) == PREDICT_EXPR
     206           48 :           && (pr = PREDICT_EXPR_PREDICTOR (ft)) == PREDICT_EXPR_PREDICTOR (fe)
     207      7602481 :           && (pr == PRED_HOT_LABEL || pr == PRED_COLD_LABEL))
     208              :         {
     209            3 :           gcc_rich_location richloc (EXPR_LOC_OR_LOC (ft, locus));
     210            3 :           richloc.add_range (EXPR_LOC_OR_LOC (fe, locus));
     211            3 :           warning_at (&richloc, OPT_Wattributes,
     212              :                       "both branches of %<if%> statement marked as %qs",
     213              :                       pr == PRED_HOT_LABEL ? "likely" : "unlikely");
     214            3 :         }
     215              :     }
     216              : 
     217     22334239 :   if (IF_STMT_VACUOUS_INIT_P (stmt))
     218              :     {
     219           58 :       gcc_checking_assert (integer_zerop (cond));
     220           58 :       gcc_checking_assert (!else_ || !TREE_SIDE_EFFECTS (else_));
     221           58 :       tree lab = create_artificial_label (UNKNOWN_LOCATION);
     222           58 :       VACUOUS_INIT_LABEL_P (lab) = 1;
     223           58 :       tree goto_expr = build_stmt (UNKNOWN_LOCATION, GOTO_EXPR, lab);
     224           58 :       tree label_expr = build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab);
     225           58 :       if (TREE_CODE (then_) == STATEMENT_LIST)
     226              :         {
     227           58 :           tree_stmt_iterator i = tsi_start (then_);
     228           58 :           tsi_link_before (&i, goto_expr, TSI_CONTINUE_LINKING);
     229           58 :           i = tsi_last (then_);
     230           58 :           tsi_link_after (&i, label_expr, TSI_CONTINUE_LINKING);
     231           58 :           stmt = then_;
     232              :         }
     233              :       else
     234              :         {
     235            0 :           stmt = NULL_TREE;
     236            0 :           append_to_statement_list (goto_expr, &stmt);
     237            0 :           append_to_statement_list (then_, &stmt);
     238            0 :           append_to_statement_list (label_expr, &stmt);
     239              :         }
     240           58 :       *stmt_p = stmt;
     241           58 :       return;
     242              :     }
     243              : 
     244     22334181 :   if (!then_)
     245         2010 :     then_ = build_empty_stmt (locus);
     246     22334181 :   if (!else_)
     247     14729838 :     else_ = build_empty_stmt (locus);
     248              : 
     249              :   /* consteval if has been verified not to have the then_/else_ blocks
     250              :      entered by gotos/case labels from elsewhere, and as then_ block
     251              :      can contain unfolded immediate function calls, we have to discard
     252              :      the then_ block regardless of whether else_ has side-effects or not.  */
     253     22334181 :   if (IF_STMT_CONSTEVAL_P (stmt))
     254              :     {
     255        79910 :       if (block_may_fallthru (then_))
     256        25761 :         stmt = build3 (COND_EXPR, void_type_node, boolean_false_node,
     257              :                        void_node, else_);
     258              :       else
     259        54149 :         stmt = else_;
     260              :     }
     261     22254271 :   else if (IF_STMT_CONSTEXPR_P (stmt))
     262      7334578 :     stmt = integer_nonzerop (cond) ? then_ : else_;
     263              :   /* ??? This optimization doesn't seem to belong here, but removing it
     264              :      causes -Wreturn-type regressions (e.g. 107310).  */
     265     17272539 :   else if (integer_nonzerop (cond) && !TREE_SIDE_EFFECTS (else_))
     266        99947 :     stmt = then_;
     267     17172592 :   else if (integer_zerop (cond) && !TREE_SIDE_EFFECTS (then_))
     268        35437 :     stmt = else_;
     269              :   else
     270     17137155 :     stmt = build3 (COND_EXPR, void_type_node, cond, then_, else_);
     271     22334181 :   protected_set_expr_location_if_unset (stmt, locus);
     272     22334181 :   *stmt_p = stmt;
     273              : }
     274              : 
     275              : /* Hook into the middle of gimplifying an OMP_FOR node.  */
     276              : 
     277              : static enum gimplify_status
     278        47996 : cp_gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
     279              : {
     280        47996 :   tree for_stmt = *expr_p;
     281        47996 :   gimple_seq seq = NULL;
     282              : 
     283              :   /* Protect ourselves from recursion.  */
     284        47996 :   if (OMP_FOR_GIMPLIFYING_P (for_stmt))
     285              :     return GS_UNHANDLED;
     286        22264 :   OMP_FOR_GIMPLIFYING_P (for_stmt) = 1;
     287              : 
     288        22264 :   gimplify_and_add (for_stmt, &seq);
     289        22264 :   gimple_seq_add_seq (pre_p, seq);
     290              : 
     291        22264 :   OMP_FOR_GIMPLIFYING_P (for_stmt) = 0;
     292              : 
     293        22264 :   return GS_ALL_DONE;
     294              : }
     295              : 
     296              : /*  Gimplify an EXPR_STMT node.  */
     297              : 
     298              : static void
     299      4097207 : gimplify_expr_stmt (tree *stmt_p)
     300              : {
     301      4097207 :   tree stmt = EXPR_STMT_EXPR (*stmt_p);
     302              : 
     303      4097207 :   if (stmt == error_mark_node)
     304              :     stmt = NULL;
     305              : 
     306              :   /* Gimplification of a statement expression will nullify the
     307              :      statement if all its side effects are moved to *PRE_P and *POST_P.
     308              : 
     309              :      In this case we will not want to emit the gimplified statement.
     310              :      However, we may still want to emit a warning, so we do that before
     311              :      gimplification.  */
     312      4093202 :   if (stmt && warn_unused_value)
     313              :     {
     314       308365 :       if (!TREE_SIDE_EFFECTS (stmt))
     315              :         {
     316            0 :           if (!IS_EMPTY_STMT (stmt)
     317         6848 :               && !VOID_TYPE_P (TREE_TYPE (stmt))
     318         6848 :               && !warning_suppressed_p (stmt, OPT_Wunused_value))
     319            0 :             warning (OPT_Wunused_value, "statement with no effect");
     320              :         }
     321              :       else
     322       301517 :         warn_if_unused_value (stmt, input_location);
     323              :     }
     324              : 
     325      4097207 :   if (stmt == NULL_TREE)
     326         4005 :     stmt = alloc_stmt_list ();
     327              : 
     328      4097207 :   *stmt_p = stmt;
     329      4097207 : }
     330              : 
     331              : /* Gimplify initialization from an AGGR_INIT_EXPR.  */
     332              : 
     333              : static void
     334     12004488 : cp_gimplify_init_expr (tree *expr_p)
     335              : {
     336     12004488 :   tree from = TREE_OPERAND (*expr_p, 1);
     337     12004488 :   tree to = TREE_OPERAND (*expr_p, 0);
     338     12004488 :   tree t;
     339              : 
     340     12004488 :   if (TREE_CODE (from) == TARGET_EXPR)
     341       213253 :     if (tree init = TARGET_EXPR_INITIAL (from))
     342              :       {
     343              :         /* Make sure that we expected to elide this temporary.  But also allow
     344              :            gimplify_modify_expr_rhs to elide temporaries of trivial type.  */
     345       213253 :         gcc_checking_assert (TARGET_EXPR_ELIDING_P (from)
     346              :                              || !TREE_ADDRESSABLE (TREE_TYPE (from)));
     347       213253 :         if (target_expr_needs_replace (from))
     348              :           {
     349              :             /* If this was changed by cp_genericize_target_expr, we need to
     350              :                walk into it to replace uses of the slot.  */
     351           96 :             replace_decl (&init, TARGET_EXPR_SLOT (from), to);
     352           96 :             *expr_p = init;
     353           96 :             return;
     354              :           }
     355              :         else
     356              :           from = init;
     357              :       }
     358              : 
     359              :   /* Look through any COMPOUND_EXPRs, since build_compound_expr pushes them
     360              :      inside the TARGET_EXPR.  */
     361     12091100 :   for (t = from; t; )
     362              :     {
     363     12091100 :       tree sub = TREE_CODE (t) == COMPOUND_EXPR ? TREE_OPERAND (t, 0) : t;
     364              : 
     365              :       /* If we are initializing from an AGGR_INIT_EXPR, drop the INIT_EXPR and
     366              :          replace the slot operand with our target.
     367              : 
     368              :          Should we add a target parm to gimplify_expr instead?  No, as in this
     369              :          case we want to replace the INIT_EXPR.  */
     370     12091100 :       if (TREE_CODE (sub) == AGGR_INIT_EXPR
     371     12091100 :           || TREE_CODE (sub) == VEC_INIT_EXPR)
     372              :         {
     373       115582 :           if (TREE_CODE (sub) == AGGR_INIT_EXPR)
     374       115582 :             AGGR_INIT_EXPR_SLOT (sub) = to;
     375              :           else
     376            0 :             VEC_INIT_EXPR_SLOT (sub) = to;
     377       115582 :           *expr_p = from;
     378              : 
     379              :           /* The initialization is now a side-effect, so the container can
     380              :              become void.  */
     381       115582 :           if (from != sub)
     382           73 :             TREE_TYPE (from) = void_type_node;
     383              :         }
     384              : 
     385              :       /* Handle aggregate NSDMI.  */
     386     12091100 :       replace_placeholders (sub, to);
     387              : 
     388     12091100 :       if (t == sub)
     389              :         break;
     390              :       else
     391        86708 :         t = TREE_OPERAND (t, 1);
     392              :     }
     393              : 
     394              : }
     395              : 
     396              : /* Gimplify a MUST_NOT_THROW_EXPR.  */
     397              : 
     398              : static enum gimplify_status
     399       576454 : gimplify_must_not_throw_expr (tree *expr_p, gimple_seq *pre_p)
     400              : {
     401       576454 :   tree stmt = *expr_p;
     402       576454 :   tree temp = voidify_wrapper_expr (stmt, NULL);
     403       576454 :   tree body = TREE_OPERAND (stmt, 0);
     404       576454 :   gimple_seq try_ = NULL;
     405       576454 :   gimple_seq catch_ = NULL;
     406       576454 :   gimple *mnt;
     407              : 
     408       576454 :   gimplify_and_add (body, &try_);
     409       576454 :   mnt = gimple_build_eh_must_not_throw (call_terminate_fn);
     410       576454 :   gimple_seq_add_stmt_without_update (&catch_, mnt);
     411       576454 :   mnt = gimple_build_try (try_, catch_, GIMPLE_TRY_CATCH);
     412              : 
     413       576454 :   gimple_seq_add_stmt_without_update (pre_p, mnt);
     414       576454 :   if (temp)
     415              :     {
     416           33 :       *expr_p = temp;
     417           33 :       return GS_OK;
     418              :     }
     419              : 
     420              :   *expr_p = NULL;
     421              :   return GS_ALL_DONE;
     422              : }
     423              : 
     424              : /* Return TRUE if an operand (OP) of a given TYPE being copied is
     425              :    really just an empty class copy.
     426              : 
     427              :    Check that the operand has a simple form so that TARGET_EXPRs and
     428              :    non-empty CONSTRUCTORs get reduced properly, and we leave the
     429              :    return slot optimization alone because it isn't a copy.  */
     430              : 
     431              : bool
     432     20095309 : simple_empty_class_p (tree type, tree op, tree_code code)
     433              : {
     434     23504716 :   if (TREE_CODE (op) == COMPOUND_EXPR)
     435       183451 :     return simple_empty_class_p (type, TREE_OPERAND (op, 1), code);
     436      4304872 :   if (SIMPLE_TARGET_EXPR_P (op)
     437     26548780 :       && TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
     438              :     /* The TARGET_EXPR is itself a simple copy, look through it.  */
     439      3225956 :     return simple_empty_class_p (type, TARGET_EXPR_INITIAL (op), code);
     440              : 
     441     20095309 :   if (TREE_CODE (op) == PARM_DECL
     442     20095309 :       && TREE_ADDRESSABLE (TREE_TYPE (op)))
     443              :     {
     444            9 :       tree fn = DECL_CONTEXT (op);
     445            9 :       if (DECL_THUNK_P (fn)
     446           12 :           || lambda_static_thunk_p (fn))
     447              :         /* In a thunk, we pass through invisible reference parms, so this isn't
     448              :            actually a copy.  */
     449              :         return false;
     450              :     }
     451              : 
     452     20095300 :   return
     453     20095300 :     (TREE_CODE (op) == EMPTY_CLASS_EXPR
     454     20095270 :      || code == MODIFY_EXPR
     455     17030370 :      || is_gimple_lvalue (op)
     456     13459460 :      || INDIRECT_REF_P (op)
     457     13032107 :      || (TREE_CODE (op) == CONSTRUCTOR
     458      2895936 :          && CONSTRUCTOR_NELTS (op) == 0)
     459     10432570 :      || (TREE_CODE (op) == CALL_EXPR
     460      2735003 :          && !CALL_EXPR_RETURN_SLOT_OPT (op)))
     461     12287753 :     && !TREE_CLOBBER_P (op)
     462     31771229 :     && is_really_empty_class (type, /*ignore_vptr*/true);
     463              : }
     464              : 
     465              : /* Returns true if evaluating E as an lvalue has side-effects;
     466              :    specifically, a volatile lvalue has TREE_SIDE_EFFECTS, but it doesn't really
     467              :    have side-effects until there is a read or write through it.  */
     468              : 
     469              : static bool
     470      2726914 : lvalue_has_side_effects (tree e)
     471              : {
     472      2726914 :   if (!TREE_SIDE_EFFECTS (e))
     473              :     return false;
     474        60590 :   while (handled_component_p (e))
     475              :     {
     476         6465 :       if (TREE_CODE (e) == ARRAY_REF
     477         6465 :           && TREE_SIDE_EFFECTS (TREE_OPERAND (e, 1)))
     478              :         return true;
     479         4627 :       e = TREE_OPERAND (e, 0);
     480              :     }
     481        54125 :   if (DECL_P (e))
     482              :     /* Just naming a variable has no side-effects.  */
     483              :     return false;
     484        37094 :   else if (INDIRECT_REF_P (e))
     485              :     /* Similarly, indirection has no side-effects.  */
     486        36957 :     return TREE_SIDE_EFFECTS (TREE_OPERAND (e, 0));
     487              :   else
     488              :     /* For anything else, trust TREE_SIDE_EFFECTS.  */
     489          137 :     return TREE_SIDE_EFFECTS (e);
     490              : }
     491              : 
     492              : /* Return true if FN is an immediate-escalating function.  */
     493              : 
     494              : bool
     495    203460105 : immediate_escalating_function_p (tree fn)
     496              : {
     497    203460105 :   if (!fn || !flag_immediate_escalation)
     498              :     return false;
     499              : 
     500    203459637 :   gcc_checking_assert (TREE_CODE (fn) == FUNCTION_DECL);
     501              : 
     502    203459637 :   if (DECL_IMMEDIATE_FUNCTION_P (fn))
     503              :     return false;
     504              : 
     505              :   /* An immediate-escalating function is
     506              :       -- the call operator of a lambda that is not declared with the consteval
     507              :          specifier  */
     508    207219668 :   if (LAMBDA_FUNCTION_P (fn))
     509              :     return true;
     510              :   /* -- a non-user-provided defaulted function that is not declared with the
     511              :         consteval specifier  */
     512    201325293 :   if (DECL_DEFAULTED_FN (fn) && !user_provided_p (fn))
     513              :     return true;
     514              :   /* -- a function that results from the instantiation of a templated entity
     515              :         defined with the constexpr specifier.  */
     516    193504258 :   return is_instantiation_of_constexpr (fn);
     517              : }
     518              : 
     519              : /* Return true if FN is an immediate-escalating function that has not been
     520              :    checked for escalating expressions..  */
     521              : 
     522              : static bool
     523    203456686 : unchecked_immediate_escalating_function_p (tree fn)
     524              : {
     525    203456686 :   return (immediate_escalating_function_p (fn)
     526    203456686 :           && !DECL_ESCALATION_CHECKED_P (fn));
     527              : }
     528              : 
     529              : /* Promote FN to an immediate function, including its clones.  */
     530              : 
     531              : void
     532         2383 : promote_function_to_consteval (tree fn)
     533              : {
     534         2383 :   SET_DECL_IMMEDIATE_FUNCTION_P (fn);
     535         2383 :   DECL_ESCALATION_CHECKED_P (fn) = true;
     536         2383 :   tree clone;
     537         4927 :   FOR_EACH_CLONE (clone, fn)
     538              :     {
     539         2544 :       SET_DECL_IMMEDIATE_FUNCTION_P (clone);
     540         2544 :       DECL_ESCALATION_CHECKED_P (clone) = true;
     541              :     }
     542         2383 : }
     543              : 
     544              : /* A wrapper around cp_fold_immediate_r.  Return a non-null tree if
     545              :    we found a non-constant immediate function, or taking the address
     546              :    of an immediate function.  */
     547              : 
     548              : tree
     549     16291427 : cp_fold_immediate (tree *tp, mce_value manifestly_const_eval,
     550              :                    tree decl /*= current_function_decl*/)
     551              : {
     552     16291427 :   if (cxx_dialect <= cxx17)
     553              :     return NULL_TREE;
     554              : 
     555     16284045 :   temp_override<tree> cfd (current_function_decl, decl);
     556              : 
     557     16284045 :   fold_flags_t flags = ff_none;
     558     16284045 :   if (manifestly_const_eval == mce_false)
     559      9558331 :     flags |= ff_mce_false;
     560              : 
     561     16284045 :   cp_fold_data data (flags);
     562     16284045 :   int save_errorcount = errorcount;
     563     16284045 :   tree r = cp_walk_tree (tp, cp_fold_immediate_r, &data, NULL);
     564     16284045 :   if (errorcount > save_errorcount)
     565           49 :     return integer_one_node;
     566              :   return r;
     567     16284045 : }
     568              : 
     569              : /* Maybe say that FN (a function decl with DECL_IMMEDIATE_FUNCTION_P set)
     570              :    was initially not an immediate function, but was promoted to one because
     571              :    its body contained an immediate-escalating expression or conversion.  */
     572              : 
     573              : static void
     574          548 : maybe_explain_promoted_consteval (location_t loc, tree fn)
     575              : {
     576          548 :   if (DECL_ESCALATION_CHECKED_P (fn))
     577              :     {
     578              :       /* See if we can figure out what made the function consteval.  */
     579          130 :       tree x = cp_fold_immediate (&DECL_SAVED_TREE (fn), mce_unknown, NULL_TREE);
     580          130 :       if (x)
     581          103 :         inform (cp_expr_loc_or_loc (x, loc),
     582              :                 "%qD was promoted to an immediate function because its "
     583              :                 "body contains an immediate-escalating expression %qE", fn, x);
     584              :       else
     585           27 :         inform (loc, "%qD was promoted to an immediate function", fn);
     586              :     }
     587          548 : }
     588              : 
     589              : /* Gimplify *EXPR_P as rvalue into an expression that can't be modified
     590              :    by expressions with side-effects in other operands.  */
     591              : 
     592              : static enum gimplify_status
     593        39050 : gimplify_to_rvalue (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
     594              :                     bool (*gimple_test_f) (tree))
     595              : {
     596        39050 :   enum gimplify_status t
     597        39050 :     = gimplify_expr (expr_p, pre_p, post_p, gimple_test_f, fb_rvalue);
     598        39050 :   if (t == GS_ERROR)
     599              :     return GS_ERROR;
     600        39047 :   else if (is_gimple_variable (*expr_p) && TREE_CODE (*expr_p) != SSA_NAME)
     601         2947 :     *expr_p = get_initialized_tmp_var (*expr_p, pre_p);
     602              :   return t;
     603              : }
     604              : 
     605              : /* Like gimplify_arg, but if ORDERED is set (which should be set if
     606              :    any of the arguments this argument is sequenced before has
     607              :    TREE_SIDE_EFFECTS set, make sure expressions with is_gimple_reg_type type
     608              :    are gimplified into SSA_NAME or a fresh temporary and for
     609              :    non-is_gimple_reg_type we don't optimize away TARGET_EXPRs.  */
     610              : 
     611              : static enum gimplify_status
     612      4332575 : cp_gimplify_arg (tree *arg_p, gimple_seq *pre_p, location_t call_location,
     613              :                  bool ordered)
     614              : {
     615      4332575 :   enum gimplify_status t;
     616      4332575 :   if (ordered
     617       431899 :       && !is_gimple_reg_type (TREE_TYPE (*arg_p))
     618      4334476 :       && TREE_CODE (*arg_p) == TARGET_EXPR)
     619              :     {
     620              :       /* gimplify_arg would strip away the TARGET_EXPR, but
     621              :          that can mean we don't copy the argument and some following
     622              :          argument with side-effect could modify it.  */
     623         1756 :       protected_set_expr_location (*arg_p, call_location);
     624         1756 :       return gimplify_expr (arg_p, pre_p, NULL, is_gimple_lvalue, fb_either);
     625              :     }
     626              :   else
     627              :     {
     628      4330819 :       t = gimplify_arg (arg_p, pre_p, call_location);
     629      4330819 :       if (t == GS_ERROR)
     630              :         return GS_ERROR;
     631      4330819 :       else if (ordered
     632       430143 :                && is_gimple_reg_type (TREE_TYPE (*arg_p))
     633       429998 :                && is_gimple_variable (*arg_p)
     634       218588 :                && TREE_CODE (*arg_p) != SSA_NAME
     635              :                /* No need to force references into register, references
     636              :                   can't be modified.  */
     637       133318 :                && !TYPE_REF_P (TREE_TYPE (*arg_p))
     638              :                /* And this can't be modified either.  */
     639      4420085 :                && *arg_p != current_class_ptr)
     640         8774 :         *arg_p = get_initialized_tmp_var (*arg_p, pre_p);
     641              :       return t;
     642              :     }
     643              : 
     644              : }
     645              : 
     646              : /* Emit a decl = {CLOBBER(bob)}; stmt before DECL_EXPR or first
     647              :    TARGET_EXPR gimplification for -flifetime-dse=2.  */
     648              : 
     649              : static void
     650      1498143 : maybe_emit_clobber_object_begin (tree decl, gimple_seq *pre_p)
     651              : {
     652      1498143 :   if (VAR_P (decl)
     653      1497544 :       && auto_var_p (decl)
     654      1462297 :       && TREE_TYPE (decl) != error_mark_node
     655      1462279 :       && DECL_NONTRIVIALLY_INITIALIZED_P (decl)
     656              :       /* Don't do it if it is fully initialized.  */
     657       905017 :       && DECL_INITIAL (decl) == NULL_TREE
     658       451836 :       && !DECL_HAS_VALUE_EXPR_P (decl)
     659       450888 :       && !OPAQUE_TYPE_P (TREE_TYPE (decl))
     660              :       /* Nor going to have decl = .DEFERRED_INIT (...); added.  */
     661      1949027 :       && (flag_auto_var_init == AUTO_INIT_UNINITIALIZED
     662        90160 :           || lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl))
     663        90160 :           || lookup_attribute ("indeterminate", DECL_ATTRIBUTES (decl))))
     664              :     {
     665       360725 :       tree eltype = strip_array_types (TREE_TYPE (decl));
     666       360725 :       if (RECORD_OR_UNION_TYPE_P (eltype)
     667       360725 :           && !is_empty_class (eltype))
     668              :         {
     669       151376 :           tree clobber
     670       151376 :             = build_clobber (TREE_TYPE (decl), CLOBBER_OBJECT_BEGIN);
     671       151376 :           gimple *g = gimple_build_assign (decl, clobber);
     672       151376 :           gimple_set_location (g, DECL_SOURCE_LOCATION (decl));
     673       151376 :           gimple_seq_add_stmt_without_update (pre_p, g);
     674              :         }
     675              :     }
     676      1498143 : }
     677              : 
     678              : /* Do C++-specific gimplification.  Args are as for gimplify_expr.  */
     679              : 
     680              : int
     681    177446134 : cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
     682              : {
     683    177446134 :   int saved_stmts_are_full_exprs_p = 0;
     684    177446134 :   location_t loc = cp_expr_loc_or_input_loc (*expr_p);
     685    177446134 :   enum tree_code code = TREE_CODE (*expr_p);
     686    177446134 :   enum gimplify_status ret;
     687              : 
     688    177446134 :   if (STATEMENT_CODE_P (code))
     689              :     {
     690      4145340 :       saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
     691      8290680 :       current_stmt_tree ()->stmts_are_full_exprs_p
     692      4145340 :         = STMT_IS_FULL_EXPR_P (*expr_p);
     693              :     }
     694              : 
     695    177446134 :   switch (code)
     696              :     {
     697       367996 :     case AGGR_INIT_EXPR:
     698       367996 :       simplify_aggr_init_expr (expr_p);
     699       367996 :       ret = GS_OK;
     700       367996 :       break;
     701              : 
     702            0 :     case VEC_INIT_EXPR:
     703            0 :       {
     704            0 :         *expr_p = expand_vec_init_expr (NULL_TREE, *expr_p,
     705              :                                         tf_warning_or_error);
     706              : 
     707            0 :         cp_fold_data data (ff_genericize | ff_mce_false);
     708            0 :         cp_walk_tree (expr_p, cp_fold_r, &data, NULL);
     709            0 :         cp_genericize_tree (expr_p, false);
     710            0 :         copy_if_shared (expr_p);
     711            0 :         ret = GS_OK;
     712            0 :       }
     713            0 :       break;
     714              : 
     715        22642 :     case THROW_EXPR:
     716              :       /* FIXME communicate throw type to back end, probably by moving
     717              :          THROW_EXPR into ../tree.def.  */
     718        22642 :       *expr_p = TREE_OPERAND (*expr_p, 0);
     719        22642 :       ret = GS_OK;
     720        22642 :       break;
     721              : 
     722       576454 :     case MUST_NOT_THROW_EXPR:
     723       576454 :       ret = gimplify_must_not_throw_expr (expr_p, pre_p);
     724       576454 :       break;
     725              : 
     726              :       /* We used to do this for MODIFY_EXPR as well, but that's unsafe; the
     727              :          LHS of an assignment might also be involved in the RHS, as in bug
     728              :          25979.  */
     729     12004488 :     case INIT_EXPR:
     730     12004488 :       cp_gimplify_init_expr (expr_p);
     731     12004488 :       if (TREE_CODE (*expr_p) != INIT_EXPR)
     732              :         return GS_OK;
     733              :       /* Fall through.  */
     734     16117220 :     case MODIFY_EXPR:
     735     11888810 :     modify_expr_case:
     736     16117220 :       {
     737              :         /* If the back end isn't clever enough to know that the lhs and rhs
     738              :            types are the same, add an explicit conversion.  */
     739     16117220 :         tree op0 = TREE_OPERAND (*expr_p, 0);
     740     16117220 :         tree op1 = TREE_OPERAND (*expr_p, 1);
     741              : 
     742     16117220 :         if (!error_operand_p (op0)
     743     16117220 :             && !error_operand_p (op1)
     744     16117201 :             && (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (op0))
     745     16114145 :                 || TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (op1)))
     746     16120285 :             && !useless_type_conversion_p (TREE_TYPE (op1), TREE_TYPE (op0)))
     747            9 :           TREE_OPERAND (*expr_p, 1) = build1 (VIEW_CONVERT_EXPR,
     748            9 :                                               TREE_TYPE (op0), op1);
     749              : 
     750     16117211 :         else if (simple_empty_class_p (TREE_TYPE (op0), op1, code))
     751              :           {
     752       218342 :             while (TREE_CODE (op1) == TARGET_EXPR)
     753              :               /* We're disconnecting the initializer from its target,
     754              :                  don't create a temporary.  */
     755         7125 :               op1 = TARGET_EXPR_INITIAL (op1);
     756              : 
     757              :             /* Remove any copies of empty classes.  Also drop volatile
     758              :                variables on the RHS to avoid infinite recursion from
     759              :                gimplify_expr trying to load the value.  */
     760       211217 :             if (TREE_SIDE_EFFECTS (op1))
     761              :               {
     762        16216 :                 if (TREE_THIS_VOLATILE (op1)
     763            0 :                     && (REFERENCE_CLASS_P (op1) || DECL_P (op1)))
     764            0 :                   op1 = build_fold_addr_expr (op1);
     765              : 
     766        16216 :                 suppress_warning (op1, OPT_Wunused_result);
     767        16216 :                 gimplify_and_add (op1, pre_p);
     768              :               }
     769       211217 :             gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
     770              :                            is_gimple_lvalue, fb_lvalue);
     771       211217 :             *expr_p = TREE_OPERAND (*expr_p, 0);
     772       211217 :             if (code == RETURN_EXPR && REFERENCE_CLASS_P (*expr_p))
     773              :               /* Avoid 'return *<retval>;'  */
     774         1267 :               *expr_p = TREE_OPERAND (*expr_p, 0);
     775              :           }
     776              :         /* P0145 says that the RHS is sequenced before the LHS.
     777              :            gimplify_modify_expr gimplifies the RHS before the LHS, but that
     778              :            isn't quite strong enough in two cases:
     779              : 
     780              :            1) gimplify.cc wants to leave a CALL_EXPR on the RHS, which would
     781              :            mean it's evaluated after the LHS.
     782              : 
     783              :            2) the value calculation of the RHS is also sequenced before the
     784              :            LHS, so for scalar assignment we need to preevaluate if the
     785              :            RHS could be affected by LHS side-effects even if it has no
     786              :            side-effects of its own.  We don't need this for classes because
     787              :            class assignment takes its RHS by reference.  */
     788     15905994 :        else if (flag_strong_eval_order > 1
     789     14576434 :                 && TREE_CODE (*expr_p) == MODIFY_EXPR
     790      2726914 :                 && lvalue_has_side_effects (op0)
     791     15944780 :                 && (TREE_CODE (op1) == CALL_EXPR
     792        31780 :                     || (SCALAR_TYPE_P (TREE_TYPE (op1))
     793        25247 :                         && !TREE_CONSTANT (op1))))
     794        21759 :          TREE_OPERAND (*expr_p, 1) = get_initialized_tmp_var (op1, pre_p);
     795              :       }
     796              :       ret = GS_OK;
     797              :       break;
     798              : 
     799       100140 :     case EMPTY_CLASS_EXPR:
     800              :       /* We create an empty CONSTRUCTOR with RECORD_TYPE.  */
     801       100140 :       *expr_p = build_constructor (TREE_TYPE (*expr_p), NULL);
     802       100140 :       ret = GS_OK;
     803       100140 :       break;
     804              : 
     805            0 :     case BASELINK:
     806            0 :       *expr_p = BASELINK_FUNCTIONS (*expr_p);
     807            0 :       ret = GS_OK;
     808            0 :       break;
     809              : 
     810        20303 :     case TRY_BLOCK:
     811        20303 :       genericize_try_block (expr_p);
     812        20303 :       ret = GS_OK;
     813        20303 :       break;
     814              : 
     815        23479 :     case HANDLER:
     816        23479 :       genericize_catch_block (expr_p);
     817        23479 :       ret = GS_OK;
     818        23479 :       break;
     819              : 
     820         4351 :     case EH_SPEC_BLOCK:
     821         4351 :       genericize_eh_spec_block (expr_p);
     822         4351 :       ret = GS_OK;
     823         4351 :       break;
     824              : 
     825            0 :     case USING_STMT:
     826            0 :       gcc_unreachable ();
     827              : 
     828            0 :     case FOR_STMT:
     829            0 :     case WHILE_STMT:
     830            0 :     case DO_STMT:
     831            0 :     case SWITCH_STMT:
     832            0 :     case CONTINUE_STMT:
     833            0 :     case BREAK_STMT:
     834            0 :       gcc_unreachable ();
     835              : 
     836        47996 :     case OMP_FOR:
     837        47996 :     case OMP_SIMD:
     838        47996 :     case OMP_DISTRIBUTE:
     839        47996 :     case OMP_LOOP:
     840        47996 :     case OMP_TASKLOOP:
     841        47996 :     case OMP_TILE:
     842        47996 :     case OMP_UNROLL:
     843        47996 :       ret = cp_gimplify_omp_for (expr_p, pre_p);
     844        47996 :       break;
     845              : 
     846      4097207 :     case EXPR_STMT:
     847      4097207 :       gimplify_expr_stmt (expr_p);
     848      4097207 :       ret = GS_OK;
     849      4097207 :       break;
     850              : 
     851            0 :     case UNARY_PLUS_EXPR:
     852            0 :       {
     853            0 :         tree arg = TREE_OPERAND (*expr_p, 0);
     854            0 :         tree type = TREE_TYPE (*expr_p);
     855            0 :         *expr_p = (TREE_TYPE (arg) != type) ? fold_convert (type, arg)
     856              :                                             : arg;
     857            0 :         ret = GS_OK;
     858              :       }
     859            0 :       break;
     860              : 
     861      8856514 :     case CALL_EXPR:
     862      8856514 :       ret = GS_OK;
     863      8856514 :       if (flag_strong_eval_order == 2
     864      8390322 :           && CALL_EXPR_FN (*expr_p)
     865      8009882 :           && !CALL_EXPR_OPERATOR_SYNTAX (*expr_p)
     866     15968549 :           && cp_get_callee_fndecl_nofold (*expr_p) == NULL_TREE)
     867              :         {
     868        39050 :           tree fnptrtype = TREE_TYPE (CALL_EXPR_FN (*expr_p));
     869        39050 :           enum gimplify_status t
     870        39050 :             = gimplify_to_rvalue (&CALL_EXPR_FN (*expr_p), pre_p, NULL,
     871              :                                   is_gimple_call_addr);
     872        39050 :           if (t == GS_ERROR)
     873              :             ret = GS_ERROR;
     874              :           /* GIMPLE considers most pointer conversion useless, but for
     875              :              calls we actually care about the exact function pointer type.  */
     876        39047 :           else if (TREE_TYPE (CALL_EXPR_FN (*expr_p)) != fnptrtype)
     877         9001 :             CALL_EXPR_FN (*expr_p)
     878        18002 :               = build1 (NOP_EXPR, fnptrtype, CALL_EXPR_FN (*expr_p));
     879              :         }
     880      8856514 :       if (!CALL_EXPR_FN (*expr_p))
     881              :         /* Internal function call.  */
     882       403220 :         switch (CALL_EXPR_IFN (*expr_p))
     883              :           {
     884           36 :           case IFN_BSWAP:
     885           36 :           case IFN_BITREVERSE:
     886           36 :             if (ret == GS_OK)
     887              :               {
     888           36 :                 location_t loc = EXPR_LOCATION (*expr_p);
     889           36 :                 internal_fn ifn = CALL_EXPR_IFN (*expr_p);
     890           36 :                 tree arg = CALL_EXPR_ARG (*expr_p, 0);
     891           36 :                 tree r = fold_build_builtin_bswapg_bitreverseg (loc, ifn,
     892              :                                                                 arg);
     893           36 :                 if (TREE_CODE (r) == CALL_EXPR
     894           27 :                     && !CALL_EXPR_FN (r)
     895           36 :                     && CALL_EXPR_IFN (r) == ifn)
     896              :                   break;
     897           36 :                 *expr_p = r;
     898           36 :                 return ret;
     899              :               }
     900              :             break;
     901          321 :           case IFN_CLMUL:
     902          321 :             if (ret == GS_OK)
     903              :               {
     904          321 :                 location_t loc = EXPR_LOCATION (*expr_p);
     905          321 :                 tree arg1 = CALL_EXPR_ARG (*expr_p, 0);
     906          321 :                 tree arg2 = CALL_EXPR_ARG (*expr_p, 1);
     907          321 :                 tree arg3 = NULL_TREE;
     908          321 :                 if (call_expr_nargs (*expr_p) == 3)
     909          105 :                   arg3 = CALL_EXPR_ARG (*expr_p, 2);
     910          321 :                 tree r = fold_build_builtin_clmulg (loc, arg1, arg2, arg3);
     911          321 :                 if (TREE_CODE (r) == CALL_EXPR
     912          174 :                     && !CALL_EXPR_FN (r)
     913          495 :                     && CALL_EXPR_IFN (r) == IFN_CLMUL)
     914              :                   break;
     915          147 :                 *expr_p = r;
     916          147 :                 return ret;
     917              :               }
     918              :             break;
     919           36 :           case IFN_BITCOMPRESS:
     920           36 :           case IFN_BITEXPAND:
     921           36 :             if (ret == GS_OK)
     922              :               {
     923           36 :                 location_t loc = EXPR_LOCATION (*expr_p);
     924           36 :                 internal_fn ifn = CALL_EXPR_IFN (*expr_p);
     925           36 :                 tree arg1 = CALL_EXPR_ARG (*expr_p, 0);
     926           36 :                 tree arg2 = CALL_EXPR_ARG (*expr_p, 1);
     927           36 :                 tree r = fold_build_builtin_bitcompressg_bitexpandg (loc, ifn,
     928              :                                                                      arg1,
     929              :                                                                      arg2);
     930           36 :                 if (TREE_CODE (r) == CALL_EXPR
     931           36 :                     && !CALL_EXPR_FN (r)
     932           72 :                     && CALL_EXPR_IFN (r) == ifn)
     933              :                   break;
     934            0 :                 *expr_p = r;
     935            0 :                 return ret;
     936              :               }
     937              :             break;
     938              :           default:
     939              :             break;
     940              :           }
     941      8453294 :       else if (CALL_EXPR_REVERSE_ARGS (*expr_p))
     942              :         {
     943              :           /* This is a call to a (compound) assignment operator that used
     944              :              the operator syntax; gimplify the RHS first.  */
     945        49144 :           gcc_assert (call_expr_nargs (*expr_p) == 2);
     946        49144 :           gcc_assert (!CALL_EXPR_ORDERED_ARGS (*expr_p));
     947        49144 :           enum gimplify_status t
     948        49144 :             = cp_gimplify_arg (&CALL_EXPR_ARG (*expr_p, 1), pre_p, loc,
     949        49144 :                                TREE_SIDE_EFFECTS (CALL_EXPR_ARG (*expr_p, 0)));
     950        49144 :           if (t == GS_ERROR)
     951              :             ret = GS_ERROR;
     952              :         }
     953      8404150 :       else if (CALL_EXPR_ORDERED_ARGS (*expr_p))
     954              :         {
     955              :           /* Leave the last argument for gimplify_call_expr, to avoid problems
     956              :              with __builtin_va_arg_pack().  */
     957       311453 :           int nargs = call_expr_nargs (*expr_p) - 1;
     958       311453 :           int last_side_effects_arg = -1;
     959       614485 :           for (int i = nargs; i > 0; --i)
     960       329982 :             if (TREE_SIDE_EFFECTS (CALL_EXPR_ARG (*expr_p, i)))
     961              :               {
     962              :                 last_side_effects_arg = i;
     963              :                 break;
     964              :               }
     965       652537 :           for (int i = 0; i < nargs; ++i)
     966              :             {
     967       341084 :               enum gimplify_status t
     968       341084 :                 = cp_gimplify_arg (&CALL_EXPR_ARG (*expr_p, i), pre_p, loc,
     969              :                                    i < last_side_effects_arg);
     970       341084 :               if (t == GS_ERROR)
     971            0 :                 ret = GS_ERROR;
     972              :             }
     973              :         }
     974      8092697 :       else if (flag_strong_eval_order
     975      8092697 :                && !CALL_EXPR_OPERATOR_SYNTAX (*expr_p))
     976              :         {
     977              :           /* If flag_strong_eval_order, evaluate the object argument first.  */
     978      7491612 :           tree fntype = TREE_TYPE (CALL_EXPR_FN (*expr_p));
     979      7491612 :           if (INDIRECT_TYPE_P (fntype))
     980      7491609 :             fntype = TREE_TYPE (fntype);
     981      7491612 :           tree decl = cp_get_callee_fndecl_nofold (*expr_p);
     982              :           /* We can't just rely on 'decl' because virtual function callees
     983              :              are expressed as OBJ_TYPE_REF.  Note that the xobj memfn check
     984              :              will also hold for calls of the form (&A::f)(a, ...) which does
     985              :              not require such sequencing, though it's allowed under
     986              :              "indeterminately sequenced".  */
     987      7491612 :           if (TREE_CODE (fntype) == METHOD_TYPE
     988      7491612 :               || (decl && DECL_LANG_SPECIFIC (decl)
     989      3536549 :                   && DECL_XOBJ_MEMBER_FUNCTION_P (decl)))
     990              :             {
     991      3942347 :               int nargs = call_expr_nargs (*expr_p);
     992      3942347 :               bool side_effects = false;
     993      5561840 :               for (int i = 1; i < nargs; ++i)
     994      2007710 :                 if (TREE_SIDE_EFFECTS (CALL_EXPR_ARG (*expr_p, i)))
     995              :                   {
     996              :                     side_effects = true;
     997              :                     break;
     998              :                   }
     999      3942347 :               enum gimplify_status t
    1000      3942347 :                 = cp_gimplify_arg (&CALL_EXPR_ARG (*expr_p, 0), pre_p, loc,
    1001              :                                    side_effects);
    1002      3942347 :               if (t == GS_ERROR)
    1003              :                 ret = GS_ERROR;
    1004              :             }
    1005              :         }
    1006      8856331 :       if (ret != GS_ERROR)
    1007              :         {
    1008      8856328 :           tree decl = cp_get_callee_fndecl_nofold (*expr_p);
    1009      8856328 :           if (!decl)
    1010              :             break;
    1011      8408597 :           if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
    1012           81 :             switch (DECL_FE_FUNCTION_CODE (decl))
    1013              :               {
    1014            0 :               case CP_BUILT_IN_IS_CONSTANT_EVALUATED:
    1015            0 :                 *expr_p = boolean_false_node;
    1016            0 :                 break;
    1017            0 :               case CP_BUILT_IN_SOURCE_LOCATION:
    1018            0 :                 *expr_p
    1019            0 :                   = fold_builtin_source_location (*expr_p);
    1020            0 :                 break;
    1021            0 :               case CP_BUILT_IN_IS_CORRESPONDING_MEMBER:
    1022            0 :                 *expr_p
    1023            0 :                   = fold_builtin_is_corresponding_member
    1024            0 :                         (EXPR_LOCATION (*expr_p), call_expr_nargs (*expr_p),
    1025              :                          &CALL_EXPR_ARG (*expr_p, 0));
    1026            0 :                 break;
    1027            0 :               case CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS:
    1028            0 :                 *expr_p
    1029            0 :                   = fold_builtin_is_pointer_inverconvertible_with_class
    1030            0 :                         (EXPR_LOCATION (*expr_p), call_expr_nargs (*expr_p),
    1031              :                          &CALL_EXPR_ARG (*expr_p, 0));
    1032            0 :                 break;
    1033            0 :               case CP_BUILT_IN_EH_PTR_ADJUST_REF:
    1034            0 :                 error_at (EXPR_LOCATION (*expr_p),
    1035              :                           "%qs used outside of constant expressions",
    1036              :                           "__builtin_eh_ptr_adjust_ref");
    1037            0 :                 *expr_p = void_node;
    1038            0 :                 break;
    1039            9 :               case CP_BUILT_IN_CURRENT_EXCEPTION:
    1040            9 :               case CP_BUILT_IN_UNCAUGHT_EXCEPTIONS:
    1041            9 :                 {
    1042            9 :                   const char *name
    1043              :                     = (DECL_FE_FUNCTION_CODE (decl)
    1044              :                        == CP_BUILT_IN_CURRENT_EXCEPTION
    1045            9 :                        ? "current_exception" : "uncaught_exceptions");
    1046            9 :                   tree newdecl = lookup_qualified_name (std_node, name);
    1047            9 :                   if (error_operand_p (newdecl))
    1048            0 :                     *expr_p = build_zero_cst (TREE_TYPE (*expr_p));
    1049            9 :                   else if (TREE_CODE (newdecl) != FUNCTION_DECL
    1050            9 :                            || !same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
    1051              :                                             TREE_TYPE (TREE_TYPE (decl)))
    1052           18 :                            || (TYPE_ARG_TYPES (TREE_TYPE (newdecl))
    1053            9 :                                != void_list_node))
    1054              :                     {
    1055            0 :                       error_at (EXPR_LOCATION (*expr_p),
    1056              :                                 "unexpected %<std::%s%> declaration",
    1057              :                                 name);
    1058            0 :                       *expr_p = build_zero_cst (TREE_TYPE (*expr_p));
    1059              :                     }
    1060              :                   else
    1061            9 :                     *expr_p = build_call_expr_loc (EXPR_LOCATION (*expr_p),
    1062              :                                                    newdecl, 0);
    1063              :                   break;
    1064              :                 }
    1065            0 :               case CP_BUILT_IN_IS_STRING_LITERAL:
    1066            0 :                 *expr_p
    1067            0 :                   = fold_builtin_is_string_literal (EXPR_LOCATION (*expr_p),
    1068            0 :                                                     call_expr_nargs (*expr_p),
    1069              :                                                     &CALL_EXPR_ARG (*expr_p,
    1070              :                                                                     0));
    1071            0 :                 break;
    1072            0 :               case CP_BUILT_IN_CONSTEXPR_DIAG:
    1073            0 :                 *expr_p = void_node;
    1074            0 :                 break;
    1075           72 :               case CP_BUILT_IN_START_LIFETIME:
    1076           72 :                 *expr_p = fold_convert (void_type_node,
    1077              :                                         CALL_EXPR_ARG (*expr_p, 0));
    1078           72 :                 break;
    1079              :               default:
    1080              :                 break;
    1081              :               }
    1082      8408516 :           else if (fndecl_built_in_p (decl, BUILT_IN_CLZG, BUILT_IN_CTZG))
    1083           33 :             ret = (enum gimplify_status) c_gimplify_expr (expr_p, pre_p,
    1084              :                                                           post_p);
    1085              :           else
    1086              :             /* All consteval functions should have been processed by now.  */
    1087      8408483 :             gcc_checking_assert (!immediate_invocation_p (decl));
    1088              :         }
    1089              :       break;
    1090              : 
    1091       699001 :     case TARGET_EXPR:
    1092              :       /* A TARGET_EXPR that expresses direct-initialization should have been
    1093              :          elided by cp_gimplify_init_expr.  */
    1094       699001 :       gcc_checking_assert (!TARGET_EXPR_DIRECT_INIT_P (*expr_p));
    1095              :       /* Likewise, but allow extra temps of trivial type so that
    1096              :          gimplify_init_ctor_preeval can materialize subobjects of a CONSTRUCTOR
    1097              :          on the rhs of an assignment, as in constexpr-aggr1.C.  */
    1098       699001 :       gcc_checking_assert (!TARGET_EXPR_ELIDING_P (*expr_p)
    1099              :                            || !TREE_ADDRESSABLE (TREE_TYPE (*expr_p)));
    1100       699001 :       if (flag_lifetime_dse > 1
    1101       698873 :           && TARGET_EXPR_INITIAL (*expr_p)
    1102      1388826 :           && VOID_TYPE_P (TREE_TYPE (TARGET_EXPR_INITIAL (*expr_p))))
    1103       254090 :         maybe_emit_clobber_object_begin (TARGET_EXPR_SLOT (*expr_p), pre_p);
    1104              :       ret = GS_UNHANDLED;
    1105              :       break;
    1106              : 
    1107            3 :     case PTRMEM_CST:
    1108            3 :       *expr_p = cplus_expand_constant (*expr_p);
    1109            3 :       if (TREE_CODE (*expr_p) == PTRMEM_CST)
    1110              :         ret = GS_ERROR;
    1111              :       else
    1112    177330273 :         ret = GS_OK;
    1113              :       break;
    1114              : 
    1115      1244281 :     case DECL_EXPR:
    1116      1244281 :       if (flag_lifetime_dse > 1)
    1117      1244053 :         maybe_emit_clobber_object_begin (DECL_EXPR_DECL (*expr_p), pre_p);
    1118              :       ret = GS_UNHANDLED;
    1119              :       break;
    1120              : 
    1121      1231689 :     case RETURN_EXPR:
    1122      1231689 :       if (TREE_OPERAND (*expr_p, 0)
    1123      1231689 :           && (TREE_CODE (TREE_OPERAND (*expr_p, 0)) == INIT_EXPR
    1124        12780 :               || TREE_CODE (TREE_OPERAND (*expr_p, 0)) == MODIFY_EXPR))
    1125              :         {
    1126      1163510 :           expr_p = &TREE_OPERAND (*expr_p, 0);
    1127              :           /* Avoid going through the INIT_EXPR case, which can
    1128              :              degrade INIT_EXPRs into AGGR_INIT_EXPRs.  */
    1129      1163510 :           goto modify_expr_case;
    1130              :         }
    1131              :       /* Fall through.  */
    1132              : 
    1133    145152869 :     default:
    1134    145152869 :       ret = (enum gimplify_status) c_gimplify_expr (expr_p, pre_p, post_p);
    1135    145152869 :       break;
    1136              :     }
    1137              : 
    1138              :   /* Restore saved state.  */
    1139    177330273 :   if (STATEMENT_CODE_P (code))
    1140      4145340 :     current_stmt_tree ()->stmts_are_full_exprs_p
    1141      4145340 :       = saved_stmts_are_full_exprs_p;
    1142              : 
    1143              :   return ret;
    1144              : }
    1145              : 
    1146              : bool
    1147   2039283311 : is_invisiref_parm (const_tree t)
    1148              : {
    1149   1911726627 :   return ((TREE_CODE (t) == PARM_DECL || TREE_CODE (t) == RESULT_DECL)
    1150   2084179048 :           && DECL_BY_REFERENCE (t));
    1151              : }
    1152              : 
    1153              : /* A stable comparison routine for use with splay trees and DECLs.  */
    1154              : 
    1155              : static int
    1156        63164 : splay_tree_compare_decl_uid (splay_tree_key xa, splay_tree_key xb)
    1157              : {
    1158        63164 :   tree a = (tree) xa;
    1159        63164 :   tree b = (tree) xb;
    1160              : 
    1161        63164 :   return DECL_UID (a) - DECL_UID (b);
    1162              : }
    1163              : 
    1164              : /* OpenMP context during genericization.  */
    1165              : 
    1166              : struct cp_genericize_omp_taskreg
    1167              : {
    1168              :   bool is_parallel;
    1169              :   bool default_shared;
    1170              :   struct cp_genericize_omp_taskreg *outer;
    1171              :   splay_tree variables;
    1172              : };
    1173              : 
    1174              : /* Return true if genericization should try to determine if
    1175              :    DECL is firstprivate or shared within task regions.  */
    1176              : 
    1177              : static bool
    1178       125444 : omp_var_to_track (tree decl)
    1179              : {
    1180       125444 :   tree type = TREE_TYPE (decl);
    1181       125444 :   if (is_invisiref_parm (decl))
    1182          537 :     type = TREE_TYPE (type);
    1183       124907 :   else if (TYPE_REF_P (type))
    1184         4317 :     type = TREE_TYPE (type);
    1185       150720 :   while (TREE_CODE (type) == ARRAY_TYPE)
    1186        25276 :     type = TREE_TYPE (type);
    1187       125444 :   if (type == error_mark_node || !CLASS_TYPE_P (type))
    1188              :     return false;
    1189        14269 :   if (VAR_P (decl) && CP_DECL_THREAD_LOCAL_P (decl))
    1190              :     return false;
    1191        14266 :   if (cxx_omp_predetermined_sharing (decl) != OMP_CLAUSE_DEFAULT_UNSPECIFIED)
    1192           57 :     return false;
    1193              :   return true;
    1194              : }
    1195              : 
    1196              : /* Note DECL use in OpenMP region OMP_CTX during genericization.  */
    1197              : 
    1198              : static void
    1199        14475 : omp_cxx_notice_variable (struct cp_genericize_omp_taskreg *omp_ctx, tree decl)
    1200              : {
    1201        14475 :   splay_tree_node n = splay_tree_lookup (omp_ctx->variables,
    1202              :                                          (splay_tree_key) decl);
    1203        14475 :   if (n == NULL)
    1204              :     {
    1205         4375 :       int flags = OMP_CLAUSE_DEFAULT_SHARED;
    1206         4375 :       if (omp_ctx->outer)
    1207         1281 :         omp_cxx_notice_variable (omp_ctx->outer, decl);
    1208         4375 :       if (!omp_ctx->default_shared)
    1209              :         {
    1210          980 :           struct cp_genericize_omp_taskreg *octx;
    1211              : 
    1212         1105 :           for (octx = omp_ctx->outer; octx; octx = octx->outer)
    1213              :             {
    1214          934 :               n = splay_tree_lookup (octx->variables, (splay_tree_key) decl);
    1215          934 :               if (n && n->value != OMP_CLAUSE_DEFAULT_SHARED)
    1216              :                 {
    1217              :                   flags = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
    1218              :                   break;
    1219              :                 }
    1220          891 :               if (octx->is_parallel)
    1221              :                 break;
    1222              :             }
    1223          980 :           if (octx == NULL
    1224          980 :               && (TREE_CODE (decl) == PARM_DECL
    1225          124 :                   || (!(TREE_STATIC (decl) || DECL_EXTERNAL (decl))
    1226           41 :                       && DECL_CONTEXT (decl) == current_function_decl)))
    1227              :             flags = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
    1228          892 :           if (flags == OMP_CLAUSE_DEFAULT_FIRSTPRIVATE)
    1229              :             {
    1230              :               /* DECL is implicitly determined firstprivate in
    1231              :                  the current task construct.  Ensure copy ctor and
    1232              :                  dtor are instantiated, because during gimplification
    1233              :                  it will be already too late.  */
    1234          131 :               tree type = TREE_TYPE (decl);
    1235          131 :               if (is_invisiref_parm (decl))
    1236            2 :                 type = TREE_TYPE (type);
    1237          129 :               else if (TYPE_REF_P (type))
    1238           56 :                 type = TREE_TYPE (type);
    1239          181 :               while (TREE_CODE (type) == ARRAY_TYPE)
    1240           50 :                 type = TREE_TYPE (type);
    1241          131 :               get_copy_ctor (type, tf_none);
    1242          131 :               get_dtor (type, tf_none);
    1243              :             }
    1244              :         }
    1245         4375 :       splay_tree_insert (omp_ctx->variables, (splay_tree_key) decl, flags);
    1246              :     }
    1247        14475 : }
    1248              : 
    1249              : /* True if any of the element initializers in CTOR are TARGET_EXPRs that are
    1250              :    not expected to elide, e.g. because unsafe_copy_elision_p is true.  */
    1251              : 
    1252              : static bool
    1253       134125 : any_non_eliding_target_exprs (tree ctor)
    1254              : {
    1255       621655 :   for (const constructor_elt &e : *CONSTRUCTOR_ELTS (ctor))
    1256              :     {
    1257       487533 :       if (TREE_CODE (e.value) == TARGET_EXPR
    1258       487533 :           && !TARGET_EXPR_ELIDING_P (e.value))
    1259              :         return true;
    1260              :     }
    1261              :   return false;
    1262              : }
    1263              : 
    1264              : /* If we might need to clean up a partially constructed object, break down the
    1265              :    CONSTRUCTOR with split_nonconstant_init.  Also expand VEC_INIT_EXPR at this
    1266              :    point.  If initializing TO with FROM is non-trivial, overwrite *REPLACE with
    1267              :    the result.  */
    1268              : 
    1269              : static void
    1270     83424178 : cp_genericize_init (tree *replace, tree from, tree to, vec<tree,va_gc>** flags)
    1271              : {
    1272     83424178 :   tree init = NULL_TREE;
    1273     83424178 :   if (TREE_CODE (from) == VEC_INIT_EXPR)
    1274         1007 :     init = expand_vec_init_expr (to, from, tf_warning_or_error, flags);
    1275     83423171 :   else if (TREE_CODE (from) == CONSTRUCTOR
    1276      4912657 :            && TREE_SIDE_EFFECTS (from)
    1277     83558636 :            && ((flag_exceptions
    1278       135378 :                 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (from)))
    1279       134125 :                || any_non_eliding_target_exprs (from)))
    1280              :     {
    1281         1343 :       to = cp_stabilize_reference (to);
    1282         1343 :       replace_placeholders (from, to);
    1283         1343 :       init = split_nonconstant_init (to, from);
    1284              :     }
    1285              : 
    1286         2350 :   if (init)
    1287              :     {
    1288         2350 :       if (*replace == from)
    1289              :         /* Make cp_gimplify_init_expr call replace_decl on this
    1290              :            TARGET_EXPR_INITIAL.  */
    1291          724 :         init = fold_convert (void_type_node, init);
    1292         2350 :       *replace = init;
    1293              :     }
    1294     83424178 : }
    1295              : 
    1296              : /* For an INIT_EXPR, replace the INIT_EXPR itself.  */
    1297              : 
    1298              : static void
    1299     62727812 : cp_genericize_init_expr (tree *stmt_p)
    1300              : {
    1301     62727812 :   iloc_sentinel ils = EXPR_LOCATION (*stmt_p);
    1302     62727812 :   tree to = TREE_OPERAND (*stmt_p, 0);
    1303     62727812 :   tree from = TREE_OPERAND (*stmt_p, 1);
    1304      6578267 :   if (SIMPLE_TARGET_EXPR_P (from)
    1305              :       /* Return gets confused if we clobber its INIT_EXPR this soon.  */
    1306     67634996 :       && TREE_CODE (to) != RESULT_DECL)
    1307       174410 :     from = TARGET_EXPR_INITIAL (from);
    1308     62727812 :   cp_genericize_init (stmt_p, from, to, nullptr);
    1309     62727812 : }
    1310              : 
    1311              : /* For a TARGET_EXPR, change the TARGET_EXPR_INITIAL.  We will need to use
    1312              :    replace_decl later when we know what we're initializing.  */
    1313              : 
    1314              : static void
    1315     20696366 : cp_genericize_target_expr (tree *stmt_p)
    1316              : {
    1317     20696366 :   iloc_sentinel ils = EXPR_LOCATION (*stmt_p);
    1318     20696366 :   tree slot = TARGET_EXPR_SLOT (*stmt_p);
    1319     20696366 :   vec<tree, va_gc> *flags = make_tree_vector ();
    1320     20696366 :   cp_genericize_init (&TARGET_EXPR_INITIAL (*stmt_p),
    1321     20696366 :                       TARGET_EXPR_INITIAL (*stmt_p), slot, &flags);
    1322     20696366 :   gcc_assert (!DECL_INITIAL (slot));
    1323     62089130 :   for (tree f : flags)
    1324              :     {
    1325              :       /* Once initialization is complete TARGET_EXPR_CLEANUP becomes active, so
    1326              :          disable any subobject cleanups.  */
    1327           32 :       tree d = build_disable_temp_cleanup (f);
    1328           32 :       auto &r = TARGET_EXPR_INITIAL (*stmt_p);
    1329           32 :       r = add_stmt_to_compound (r, d);
    1330              :     }
    1331     20696366 :   release_tree_vector (flags);
    1332     20696366 : }
    1333              : 
    1334              : /* Similar to if (target_expr_needs_replace) replace_decl, but TP is the
    1335              :    TARGET_EXPR_INITIAL, and this also updates *_SLOT.  We need this extra
    1336              :    replacement when cp_folding TARGET_EXPR to preserve the invariant that
    1337              :    AGGR_INIT_EXPR_SLOT agrees with the enclosing TARGET_EXPR_SLOT.  */
    1338              : 
    1339              : static bool
    1340          130 : maybe_replace_decl (tree *tp, tree decl, tree replacement)
    1341              : {
    1342          130 :   if (!*tp || !VOID_TYPE_P (TREE_TYPE (*tp)))
    1343              :     return false;
    1344           50 :   tree t = *tp;
    1345           50 :   while (TREE_CODE (t) == COMPOUND_EXPR)
    1346            0 :     t = TREE_OPERAND (t, 1);
    1347           50 :   if (TREE_CODE (t) == AGGR_INIT_EXPR)
    1348           50 :     replace_decl (&AGGR_INIT_EXPR_SLOT (t), decl, replacement);
    1349            0 :   else if (TREE_CODE (t) == VEC_INIT_EXPR)
    1350            0 :     replace_decl (&VEC_INIT_EXPR_SLOT (t), decl, replacement);
    1351              :   else
    1352            0 :     replace_decl (tp, decl, replacement);
    1353              :   return true;
    1354              : }
    1355              : 
    1356              : /* Genericization context.  */
    1357              : 
    1358     51443110 : struct cp_genericize_data
    1359              : {
    1360              :   hash_set<tree> *p_set;
    1361              :   auto_vec<tree> bind_expr_stack;
    1362              :   struct cp_genericize_omp_taskreg *omp_ctx;
    1363              :   tree try_block;
    1364              :   bool no_sanitize_p;
    1365              :   bool handle_invisiref_parm_p;
    1366              : };
    1367              : 
    1368              : /* Emit an error about taking the address of an immediate function.
    1369              :    EXPR is the whole expression; DECL is the immediate function.  */
    1370              : 
    1371              : static void
    1372           71 : taking_address_of_imm_fn_error (tree expr, tree decl)
    1373              : {
    1374           71 :   auto_diagnostic_group d;
    1375           71 :   const location_t loc = (TREE_CODE (expr) == PTRMEM_CST
    1376           71 :                           ? PTRMEM_CST_LOCATION (expr)
    1377           71 :                           : EXPR_LOCATION (expr));
    1378           71 :   error_at (loc, "taking address of an immediate function %qD", decl);
    1379           71 :   maybe_explain_promoted_consteval (loc, decl);
    1380           71 : }
    1381              : 
    1382              : /* Build up an INIT_EXPR to initialize the object of a constructor call that
    1383              :    has been folded to a constant value.  CALL is the CALL_EXPR for the
    1384              :    constructor call; INIT is the value.  */
    1385              : 
    1386              : static tree
    1387          503 : cp_build_init_expr_for_ctor (tree call, tree init)
    1388              : {
    1389          503 :   tree a = CALL_EXPR_ARG (call, 0);
    1390          503 :   if (is_dummy_object (a))
    1391              :     return init;
    1392          503 :   const bool return_this = targetm.cxx.cdtor_returns_this ();
    1393          503 :   const location_t loc = EXPR_LOCATION (call);
    1394          503 :   if (return_this)
    1395            0 :     a = cp_save_expr (a);
    1396          503 :   tree s = build_fold_indirect_ref_loc (loc, a);
    1397          503 :   init = cp_build_init_expr (s, init);
    1398          503 :   if (return_this)
    1399              :     {
    1400            0 :       init = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (call), init,
    1401            0 :                          fold_convert_loc (loc, TREE_TYPE (call), a));
    1402            0 :       suppress_warning (init);
    1403              :     }
    1404              :   return init;
    1405              : }
    1406              : 
    1407              : /* A walk_tree callback for cp_fold_function and cp_fully_fold_init to handle
    1408              :    immediate functions.  */
    1409              : 
    1410              : static tree
    1411   3227802577 : cp_fold_immediate_r (tree *stmt_p, int *walk_subtrees, void *data_)
    1412              : {
    1413   3227802577 :   auto data = static_cast<cp_fold_data *>(data_);
    1414   3227802577 :   tree stmt = *stmt_p;
    1415              :   /* The purpose of this is not to emit errors for mce_unknown.  */
    1416   3227802577 :   const tsubst_flags_t complain = (data->flags & ff_mce_false
    1417   3227802577 :                                    ? tf_error : tf_none);
    1418   3227802577 :   const tree_code code = TREE_CODE (stmt);
    1419              : 
    1420              :   /* No need to look into types or unevaluated operands.
    1421              :      NB: This affects cp_fold_r as well.  */
    1422   3227802577 :   if (TYPE_P (stmt)
    1423   3225384606 :       || unevaluated_p (code)
    1424              :       /* We do not use in_immediate_context here because it checks
    1425              :          more than is desirable, e.g., sk_template_parms.  */
    1426   3225037783 :       || cp_unevaluated_operand
    1427   6452840360 :       || (current_function_decl
    1428   6271155980 :           && DECL_IMMEDIATE_FUNCTION_P (current_function_decl)))
    1429              :     {
    1430      2785230 :       *walk_subtrees = 0;
    1431      2785230 :       return NULL_TREE;
    1432              :     }
    1433              : 
    1434   3225017347 :   tree decl = NULL_TREE;
    1435   3225017347 :   bool call_p = false;
    1436              : 
    1437              :   /* We are looking for &fn or fn().  */
    1438   3225017347 :   switch (code)
    1439              :     {
    1440     36726148 :     case DECL_EXPR:
    1441              :       /* Clear consteval-only DECL_EXPRs.  */
    1442     36726148 :       if (flag_reflection)
    1443              :         {
    1444       785923 :           tree d = DECL_EXPR_DECL (stmt);
    1445       785923 :           if (VAR_P (d) && consteval_only_p (d))
    1446          902 :             *stmt_p = void_node;
    1447              :         }
    1448              :       break;
    1449    155599042 :     case CALL_EXPR:
    1450    155599042 :     case AGGR_INIT_EXPR:
    1451    155599042 :       if (tree fn = cp_get_callee (stmt))
    1452    155284418 :         if (TREE_CODE (fn) != ADDR_EXPR || ADDR_EXPR_DENOTES_CALL_P (fn))
    1453    148552243 :           decl = cp_get_fndecl_from_callee (fn, /*fold*/false);
    1454              :       call_p = true;
    1455              :       break;
    1456        32965 :     case PTRMEM_CST:
    1457        32965 :       decl = PTRMEM_CST_MEMBER (stmt);
    1458        32965 :       break;
    1459    235638503 :     case ADDR_EXPR:
    1460    235638503 :       if (!ADDR_EXPR_DENOTES_CALL_P (stmt))
    1461     88787670 :         decl = TREE_OPERAND (stmt, 0);
    1462              :       break;
    1463     21865180 :     case IF_STMT:
    1464     21865180 :       if (IF_STMT_CONSTEVAL_P (stmt))
    1465              :         {
    1466        79925 :           if (!data->pset.add (stmt))
    1467        79925 :             cp_walk_tree (&ELSE_CLAUSE (stmt), cp_fold_immediate_r, data_,
    1468              :                           nullptr);
    1469        79925 :           *walk_subtrees = 0;
    1470        79925 :           return NULL_TREE;
    1471              :         }
    1472              :       /* FALLTHRU */
    1473   2796940764 :     default:
    1474   2796940764 :       if (data->pset.add (stmt))
    1475    478280753 :         *walk_subtrees = 0;
    1476              :       return NULL_TREE;
    1477              :     }
    1478              : 
    1479    237373780 :   if (!decl || TREE_CODE (decl) != FUNCTION_DECL)
    1480              :     return NULL_TREE;
    1481              : 
    1482              :   /* Fully escalate once all templates have been instantiated.  What we're
    1483              :      calling is not a consteval function but it may become one.  This
    1484              :      requires recursing; DECL may be promoted to consteval because it
    1485              :      contains an escalating expression E, but E itself may have to be
    1486              :      promoted first, etc.  */
    1487    155058090 :   if (at_eof > 1 && unchecked_immediate_escalating_function_p (decl))
    1488              :     {
    1489              :       /* Set before the actual walk to avoid endless recursion.  */
    1490      5953569 :       DECL_ESCALATION_CHECKED_P (decl) = true;
    1491              :       /* We're only looking for the first escalating expression.  Let us not
    1492              :          walk more trees than necessary, hence mce_unknown.  */
    1493      5953569 :       cp_fold_immediate (&DECL_SAVED_TREE (decl), mce_unknown, decl);
    1494              :     }
    1495              : 
    1496              :   /* [expr.const]p16 "An expression or conversion is immediate-escalating if
    1497              :      it is not initially in an immediate function context and it is either
    1498              :      -- an immediate invocation that is not a constant expression and is not
    1499              :      a subexpression of an immediate invocation."
    1500              : 
    1501              :      If we are in an immediate-escalating function, the immediate-escalating
    1502              :      expression or conversion makes it an immediate function.  So STMT does
    1503              :      not need to produce a constant expression.  */
    1504    310116180 :   if (DECL_IMMEDIATE_FUNCTION_P (decl))
    1505              :     {
    1506       470978 :       tree e = cxx_constant_value (stmt, tf_none);
    1507       470978 :       if (e == error_mark_node)
    1508              :         {
    1509              :           /* This takes care of, e.g.,
    1510              :               template <typename T>
    1511              :               constexpr int f(T t)
    1512              :               {
    1513              :                 return id(t);
    1514              :               }
    1515              :             where id (consteval) causes f<int> to be promoted.  */
    1516         2961 :           if (immediate_escalating_function_p (current_function_decl))
    1517         2313 :             promote_function_to_consteval (current_function_decl);
    1518          648 :           else if (complain & tf_error)
    1519              :             {
    1520          536 :               if (call_p)
    1521              :                 {
    1522          477 :                   auto_diagnostic_group d;
    1523          477 :                   location_t loc = cp_expr_loc_or_input_loc (stmt);
    1524          477 :                   error_at (loc, "call to consteval function %qE is "
    1525              :                             "not a constant expression", stmt);
    1526              :                   /* Explain why it's not a constant expression.  */
    1527          477 :                   cxx_constant_value (stmt, complain);
    1528          477 :                   *stmt_p = error_mark_node;
    1529          477 :                   maybe_explain_promoted_consteval (loc, decl);
    1530          477 :                 }
    1531           59 :               else if (!data->pset.add (stmt))
    1532              :                 {
    1533           59 :                   taking_address_of_imm_fn_error (stmt, decl);
    1534           59 :                   *stmt_p = build_zero_cst (TREE_TYPE (stmt));
    1535              :                 }
    1536              :               /* If we're giving hard errors, continue the walk rather than
    1537              :                  bailing out after the first error.  */
    1538              :               return NULL_TREE;
    1539              :             }
    1540         2425 :           *walk_subtrees = 0;
    1541         2425 :           return stmt;
    1542              :         }
    1543              : 
    1544              :       /* We've evaluated the consteval function call.  */
    1545       468017 :       if (call_p)
    1546              :         {
    1547       564641 :           if (code == CALL_EXPR && DECL_CONSTRUCTOR_P (decl))
    1548            0 :             *stmt_p = cp_build_init_expr_for_ctor (stmt, e);
    1549              :           else
    1550       468017 :             *stmt_p = e;
    1551              :         }
    1552              :     }
    1553              :   /* We've encountered a function call that may turn out to be consteval
    1554              :      later.  Store its caller so that we can ensure that the call is
    1555              :      a constant expression.  */
    1556    154587112 :   else if (unchecked_immediate_escalating_function_p (decl))
    1557              :     {
    1558              :       /* Make sure we're not inserting new elements while walking
    1559              :          the deferred_escalating_exprs hash table; if we are, it's
    1560              :          likely that a function wasn't properly marked checked for
    1561              :          i-e expressions.  */
    1562     26253021 :       gcc_checking_assert (at_eof <= 1);
    1563     26253021 :       if (current_function_decl)
    1564     26252491 :         remember_escalating_expr (current_function_decl);
    1565              :       /* auto p = &f<int>; in the global scope won't be ensconced in
    1566              :          a function we could store for later at this point.  (If there's
    1567              :          no c_f_d at this point and we're dealing with a call, we should
    1568              :          see the call when cp_fold_function __static_i_and_d.)  */
    1569          530 :       else if (!call_p)
    1570          143 :         remember_escalating_expr (stmt);
    1571              :     }
    1572              : 
    1573              :   return NULL_TREE;
    1574              : }
    1575              : 
    1576              : /* A walk_tree helper to replace constant-initialized references in an
    1577              :    OMP_CLAUSE with the the declaration that they refer to.  Such refs
    1578              :    will have been folded out in the body by cp_fold_non_odr_use_1 and
    1579              :    so we need to follow suit to prevent confusion.  */
    1580              : 
    1581              : static tree
    1582       100191 : cp_fold_omp_clause_refs_r (tree *expr_p, int *walk_subtrees, void */*data*/)
    1583              : {
    1584       100191 :   tree expr = *expr_p;
    1585              : 
    1586       100191 :   if (TYPE_P (expr))
    1587              :     {
    1588            0 :       *walk_subtrees = 0;
    1589            0 :       return NULL_TREE;
    1590              :     }
    1591              : 
    1592       100191 :   if (DECL_P (expr))
    1593              :     {
    1594        55788 :       *walk_subtrees = 0;
    1595              : 
    1596        55788 :       if (decl_constant_var_p (expr)
    1597        55788 :           && TYPE_REF_P (TREE_TYPE (expr)))
    1598              :         {
    1599          548 :           tree init = maybe_constant_value (expr);
    1600          548 :           if (TREE_CONSTANT (init))
    1601          548 :             *expr_p = tree_strip_nop_conversions (init);
    1602              :         }
    1603              :     }
    1604              : 
    1605              :   return NULL_TREE;
    1606              : }
    1607              : 
    1608              : /* Perform any pre-gimplification folding of C++ front end trees to
    1609              :    GENERIC.
    1610              :    Note:  The folding of non-omp cases is something to move into
    1611              :      the middle-end.  As for now we have most foldings only on GENERIC
    1612              :      in fold-const, we need to perform this before transformation to
    1613              :      GIMPLE-form.
    1614              : 
    1615              :    ??? This is algorithmically weird because walk_tree works in pre-order, so
    1616              :    we see outer expressions before inner expressions.  This isn't as much of an
    1617              :    issue because cp_fold recurses into subexpressions in many cases, but then
    1618              :    walk_tree walks back into those subexpressions again.  We avoid the
    1619              :    resulting complexity problem by caching the result of cp_fold, but it's
    1620              :    inelegant.  */
    1621              : 
    1622              : static tree
    1623   4436514306 : cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_)
    1624              : {
    1625   4436514306 :   cp_fold_data *data = (cp_fold_data*)data_;
    1626   4436514306 :   tree stmt = *stmt_p;
    1627   4436514306 :   enum tree_code code = TREE_CODE (stmt);
    1628              : 
    1629   4436514306 :   *stmt_p = stmt = cp_fold (*stmt_p, data->flags);
    1630              : 
    1631   4436514306 :   if (data->pset.add (stmt))
    1632              :     {
    1633              :       /* Don't walk subtrees of stmts we've already walked once, otherwise
    1634              :          we can have exponential complexity with e.g. lots of nested
    1635              :          SAVE_EXPRs or TARGET_EXPRs.  cp_fold uses a cache and will return
    1636              :          always the same tree, which the first time cp_fold_r has been
    1637              :          called on it had the subtrees walked.  */
    1638    632346907 :       *walk_subtrees = 0;
    1639    632346907 :       return NULL_TREE;
    1640              :     }
    1641              : 
    1642   3804167399 :   code = TREE_CODE (stmt);
    1643   3804167399 :   switch (code)
    1644              :     {
    1645        54173 :       tree x;
    1646        54173 :       int i, n;
    1647        54173 :     case OMP_FOR:
    1648        54173 :     case OMP_SIMD:
    1649        54173 :     case OMP_DISTRIBUTE:
    1650        54173 :     case OMP_LOOP:
    1651        54173 :     case OMP_TASKLOOP:
    1652        54173 :     case OMP_TILE:
    1653        54173 :     case OMP_UNROLL:
    1654        54173 :     case OACC_LOOP:
    1655        54173 :       cp_walk_tree (&OMP_FOR_BODY (stmt), cp_fold_r, data, NULL);
    1656        54173 :       cp_walk_tree (&OMP_FOR_CLAUSES (stmt), cp_fold_r, data, NULL);
    1657        54173 :       cp_walk_tree (&OMP_FOR_INIT (stmt), cp_fold_r, data, NULL);
    1658        54173 :       x = OMP_FOR_COND (stmt);
    1659        54173 :       if (x && TREE_CODE_CLASS (TREE_CODE (x)) == tcc_comparison)
    1660              :         {
    1661            0 :           cp_walk_tree (&TREE_OPERAND (x, 0), cp_fold_r, data, NULL);
    1662            0 :           cp_walk_tree (&TREE_OPERAND (x, 1), cp_fold_r, data, NULL);
    1663              :         }
    1664        39307 :       else if (x && TREE_CODE (x) == TREE_VEC)
    1665              :         {
    1666        39307 :           n = TREE_VEC_LENGTH (x);
    1667        90906 :           for (i = 0; i < n; i++)
    1668              :             {
    1669        51599 :               tree o = TREE_VEC_ELT (x, i);
    1670        51599 :               if (o && TREE_CODE_CLASS (TREE_CODE (o)) == tcc_comparison)
    1671        49773 :                 cp_walk_tree (&TREE_OPERAND (o, 1), cp_fold_r, data, NULL);
    1672              :             }
    1673              :         }
    1674        54173 :       x = OMP_FOR_INCR (stmt);
    1675        54173 :       if (x && TREE_CODE (x) == TREE_VEC)
    1676              :         {
    1677        39307 :           n = TREE_VEC_LENGTH (x);
    1678        90906 :           for (i = 0; i < n; i++)
    1679              :             {
    1680        51599 :               tree o = TREE_VEC_ELT (x, i);
    1681        51599 :               if (o && TREE_CODE (o) == MODIFY_EXPR)
    1682        12186 :                 o = TREE_OPERAND (o, 1);
    1683        49773 :               if (o && (TREE_CODE (o) == PLUS_EXPR || TREE_CODE (o) == MINUS_EXPR
    1684        40493 :                         || TREE_CODE (o) == POINTER_PLUS_EXPR))
    1685              :                 {
    1686        12186 :                   cp_walk_tree (&TREE_OPERAND (o, 0), cp_fold_r, data, NULL);
    1687        12186 :                   cp_walk_tree (&TREE_OPERAND (o, 1), cp_fold_r, data, NULL);
    1688              :                 }
    1689              :             }
    1690              :         }
    1691        54173 :       cp_walk_tree (&OMP_FOR_PRE_BODY (stmt), cp_fold_r, data, NULL);
    1692        54173 :       *walk_subtrees = 0;
    1693        54173 :       return NULL_TREE;
    1694              : 
    1695       174050 :     case OMP_CLAUSE:
    1696       174050 :       if ((data->flags & ff_only_non_odr)
    1697        87036 :           && omp_clause_num_ops[OMP_CLAUSE_CODE (stmt)] >= 1
    1698        73272 :           && OMP_CLAUSE_CODE (stmt) >= OMP_CLAUSE_PRIVATE
    1699        73272 :           && OMP_CLAUSE_CODE (stmt) <= OMP_CLAUSE__SCANTEMP_
    1700       222755 :           && OMP_CLAUSE_DECL (stmt))
    1701              :         {
    1702        47523 :           tree *decl = &OMP_CLAUSE_DECL (stmt);
    1703        47523 :           cp_walk_tree (decl, cp_fold_omp_clause_refs_r, NULL, NULL);
    1704        47523 :           if (TREE_CODE (*decl) == ADDR_EXPR
    1705        47523 :               && DECL_P (TREE_OPERAND (*decl, 0)))
    1706          164 :             *decl = TREE_OPERAND (*decl, 0);
    1707        47523 :           data->pset.add (*decl);
    1708              :         }
    1709              :       break;
    1710              : 
    1711     45963495 :     case IF_STMT:
    1712     45963495 :       if (IF_STMT_CONSTEVAL_P (stmt))
    1713              :         {
    1714              :           /* Don't walk THEN_CLAUSE (stmt) for consteval if.  IF_COND is always
    1715              :              boolean_false_node.  */
    1716       159850 :           cp_walk_tree (&ELSE_CLAUSE (stmt), cp_fold_r, data, NULL);
    1717       159850 :           cp_walk_tree (&IF_SCOPE (stmt), cp_fold_r, data, NULL);
    1718       159850 :           *walk_subtrees = 0;
    1719       159850 :           return NULL_TREE;
    1720              :         }
    1721              :       break;
    1722              : 
    1723              :       /* cp_genericize_{init,target}_expr are only for genericize time; they're
    1724              :          here rather than in cp_genericize to avoid problems with the invisible
    1725              :          reference transition.  */
    1726    126576868 :     case INIT_EXPR:
    1727    126576868 :       if (!flag_no_inline
    1728    119412600 :           && (data->flags & ff_genericize))
    1729              :         {
    1730     59183998 :           tree to = TREE_OPERAND (*stmt_p, 0);
    1731     59183998 :           tree &from = TREE_OPERAND (*stmt_p, 1);
    1732     59183998 :           tree folded = maybe_constant_init (from, to, data->mce ());
    1733     59183998 :           if (folded != from && TREE_CONSTANT (folded))
    1734      1619427 :             from = folded;
    1735              :         }
    1736              : 
    1737    126576868 :       if (data->flags & ff_genericize)
    1738     62727812 :         cp_genericize_init_expr (stmt_p);
    1739              :       break;
    1740              : 
    1741     44188584 :     case TARGET_EXPR:
    1742     44188584 :       if (!flag_no_inline
    1743     41534683 :           && (data->flags & ff_genericize))
    1744     19397689 :         if (tree &init = TARGET_EXPR_INITIAL (stmt))
    1745              :           {
    1746     19397689 :             tree folded = maybe_constant_init (init, TARGET_EXPR_SLOT (stmt),
    1747              :                                                data->mce ());
    1748     19397689 :             if (folded != init && TREE_CONSTANT (folded))
    1749      1207403 :               init = folded;
    1750              :           }
    1751              : 
    1752              :       /* This needs to happen between the constexpr evaluation (which wants
    1753              :          pre-generic trees) and fold (which wants the cp_genericize_init
    1754              :          transformations).  */
    1755     44188584 :       if (data->flags & ff_genericize)
    1756     20696366 :         cp_genericize_target_expr (stmt_p);
    1757              : 
    1758     44188584 :       if (tree &init = TARGET_EXPR_INITIAL (stmt))
    1759              :         {
    1760     44188584 :           cp_walk_tree (&init, cp_fold_r, data, NULL);
    1761     44188584 :           cp_walk_tree (&TARGET_EXPR_CLEANUP (stmt), cp_fold_r, data, NULL);
    1762     44188584 :           *walk_subtrees = 0;
    1763              :           /* Folding might replace e.g. a COND_EXPR with a TARGET_EXPR; in
    1764              :              that case, strip it in favor of this one.  */
    1765     44188584 :           if (TREE_CODE (init) == TARGET_EXPR)
    1766              :             {
    1767          130 :               tree sub = TARGET_EXPR_INITIAL (init);
    1768          130 :               maybe_replace_decl (&sub, TARGET_EXPR_SLOT (init),
    1769          130 :                                   TARGET_EXPR_SLOT (stmt));
    1770          130 :               init = sub;
    1771              :             }
    1772              :         }
    1773              :       break;
    1774              : 
    1775    129805170 :     case CONVERT_EXPR:
    1776              :       /* convert_to_void used to fold these away to void_node.  Do it now;
    1777              :          other code (e.g., trees_out) depends on these being expunged.  We
    1778              :          do it here before maybe_save_constexpr_fundef copies function
    1779              :          bodies.  */
    1780    129805170 :       if ((data->flags & (ff_only_non_odr | ff_genericize))
    1781    129678973 :           && VOID_TYPE_P (TREE_TYPE (stmt))
    1782    220768590 :           && !TREE_SIDE_EFFECTS (stmt))
    1783              :        {
    1784              :          /* Since we're discarding it, it's our last chance to check for
    1785              :             out-of-consteval expressions.  */
    1786       385117 :          check_out_of_consteval_use (stmt);
    1787       385117 :          *stmt_p = void_node;
    1788       385117 :          *walk_subtrees = 0;
    1789       385117 :          return NULL_TREE;
    1790              :        }
    1791              :       break;
    1792              : 
    1793              :     default:
    1794              :       break;
    1795              :     }
    1796              : 
    1797              :   return NULL_TREE;
    1798              : }
    1799              : 
    1800              : /* Fold ALL the trees!  FIXME we should be able to remove this, but
    1801              :    apparently that still causes optimization regressions.  */
    1802              : 
    1803              : void
    1804     67922023 : cp_fold_function (tree fndecl)
    1805              : {
    1806              :   /* By now all manifestly-constant-evaluated expressions will have
    1807              :      been constant-evaluated already if possible, so we can safely
    1808              :      pass ff_mce_false.  */
    1809     67922023 :   cp_fold_data data (ff_genericize | ff_mce_false);
    1810              :   /* Do cp_fold_immediate_r in separate whole IL walk instead of during
    1811              :      cp_fold_r, as otherwise expressions using results of immediate functions
    1812              :      might not be folded as cp_fold is called on those before cp_fold_r is
    1813              :      called on their argument.  */
    1814     67922023 :   if (cxx_dialect >= cxx20)
    1815              :     {
    1816     65970220 :       cp_walk_tree (&DECL_SAVED_TREE (fndecl), cp_fold_immediate_r,
    1817              :                     &data, NULL);
    1818     65970220 :       data.pset.empty ();
    1819              :     }
    1820     67922023 :   cp_walk_tree (&DECL_SAVED_TREE (fndecl), cp_fold_r, &data, NULL);
    1821              : 
    1822              :   /* This is merely an optimization: if FNDECL has no i-e expressions,
    1823              :      we'll not save c_f_d, and we can safely say that FNDECL will not
    1824              :      be promoted to consteval.  */
    1825     67922023 :   if (deferred_escalating_exprs
    1826     67922023 :       && !deferred_escalating_exprs->contains (current_function_decl))
    1827     50656733 :     DECL_ESCALATION_CHECKED_P (fndecl) = true;
    1828     67922023 : }
    1829              : 
    1830              : /* Fold any non-ODR usages of constant variables in FNDECL.  This occurs
    1831              :    before saving the constexpr fundef, so do as little other folding
    1832              :    as possible.  */
    1833              : 
    1834              : void
    1835     68967044 : cp_fold_function_non_odr_use (tree fndecl)
    1836              : {
    1837     68967044 :   cp_fold_data data (ff_only_non_odr);
    1838     68967044 :   cp_walk_tree (&DECL_SAVED_TREE (fndecl), cp_fold_r, &data, NULL);
    1839     68967044 : }
    1840              : 
    1841              : /* We've stashed immediate-escalating functions.  Now see if they indeed
    1842              :    ought to be promoted to consteval.  */
    1843              : 
    1844              : void
    1845       100997 : process_and_check_pending_immediate_escalating_fns ()
    1846              : {
    1847              :   /* This will be null for -fno-immediate-escalation.  */
    1848       100997 :   if (!deferred_escalating_exprs)
    1849              :     return;
    1850              : 
    1851     14009285 :   for (auto e : *deferred_escalating_exprs)
    1852     13989734 :     if (TREE_CODE (e) == FUNCTION_DECL && !DECL_ESCALATION_CHECKED_P (e))
    1853      9545594 :       cp_fold_immediate (&DECL_SAVED_TREE (e), mce_false, e);
    1854              : 
    1855              :   /* We've escalated every function that could have been promoted to
    1856              :      consteval.  Check that we are not taking the address of a consteval
    1857              :      function.  */
    1858     14009285 :   for (auto e : *deferred_escalating_exprs)
    1859              :     {
    1860     13989734 :       if (TREE_CODE (e) == FUNCTION_DECL)
    1861     13989591 :         continue;
    1862          143 :       tree decl = (TREE_CODE (e) == PTRMEM_CST
    1863          143 :                    ? PTRMEM_CST_MEMBER (e)
    1864          143 :                    : TREE_OPERAND (e, 0));
    1865          286 :       if (DECL_IMMEDIATE_FUNCTION_P (decl))
    1866           12 :         taking_address_of_imm_fn_error (e, decl);
    1867              :     }
    1868              : 
    1869        19551 :   deferred_escalating_exprs = nullptr;
    1870              : }
    1871              : 
    1872              : /* Turn SPACESHIP_EXPR EXPR into GENERIC.  */
    1873              : 
    1874       235198 : static tree genericize_spaceship (tree expr)
    1875              : {
    1876       235198 :   iloc_sentinel s (cp_expr_location (expr));
    1877       235198 :   tree type = TREE_TYPE (expr);
    1878       235198 :   tree op0 = TREE_OPERAND (expr, 0);
    1879       235198 :   tree op1 = TREE_OPERAND (expr, 1);
    1880       235198 :   return genericize_spaceship (input_location, type, op0, op1);
    1881       235198 : }
    1882              : 
    1883              : /* If EXPR involves an anonymous VLA type, prepend a DECL_EXPR for that type
    1884              :    to trigger gimplify_type_sizes; otherwise a cast to pointer-to-VLA confuses
    1885              :    the middle-end (c++/88256).  If EXPR is a DECL, use add_stmt and return
    1886              :    NULL_TREE; otherwise return a COMPOUND_STMT of the DECL_EXPR and EXPR.  */
    1887              : 
    1888              : tree
    1889    142623770 : predeclare_vla (tree expr)
    1890              : {
    1891    142623770 :   tree type = TREE_TYPE (expr);
    1892    142623770 :   if (type == error_mark_node)
    1893              :     return expr;
    1894    142623632 :   if (is_typedef_decl (expr))
    1895    142623632 :     type = DECL_ORIGINAL_TYPE (expr);
    1896              : 
    1897              :   /* We need to strip pointers for gimplify_type_sizes.  */
    1898    142623632 :   tree vla = type;
    1899    217421923 :   while (POINTER_TYPE_P (vla))
    1900              :     {
    1901     77315875 :       if (TYPE_NAME (vla))
    1902              :         return expr;
    1903     74798291 :       vla = TREE_TYPE (vla);
    1904              :     }
    1905     72859631 :   if (vla == type || TYPE_NAME (vla)
    1906    140676508 :       || !variably_modified_type_p (vla, NULL_TREE))
    1907              :     return expr;
    1908              : 
    1909          216 :   tree decl = build_decl (input_location, TYPE_DECL, NULL_TREE, vla);
    1910          216 :   DECL_ARTIFICIAL (decl) = 1;
    1911          216 :   TYPE_NAME (vla) = decl;
    1912          216 :   tree dexp = build_stmt (input_location, DECL_EXPR, decl);
    1913          216 :   if (DECL_P (expr))
    1914              :     {
    1915            5 :       add_stmt (dexp);
    1916            5 :       return NULL_TREE;
    1917              :     }
    1918              :   else
    1919              :     {
    1920          211 :       expr = build2 (COMPOUND_EXPR, type, dexp, expr);
    1921          211 :       return expr;
    1922              :     }
    1923              : }
    1924              : 
    1925              : /* Perform any pre-gimplification lowering of C++ front end trees to
    1926              :    GENERIC.  */
    1927              : 
    1928              : static tree
    1929   1850519079 : cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data)
    1930              : {
    1931   1872854380 :   tree stmt = *stmt_p;
    1932   1872854380 :   struct cp_genericize_data *wtd = (struct cp_genericize_data *) data;
    1933   1872854380 :   hash_set<tree> *p_set = wtd->p_set;
    1934              : 
    1935              :   /* If in an OpenMP context, note var uses.  */
    1936   1872854380 :   if (UNLIKELY (wtd->omp_ctx != NULL)
    1937       625515 :       && (VAR_P (stmt)
    1938              :           || TREE_CODE (stmt) == PARM_DECL
    1939              :           || TREE_CODE (stmt) == RESULT_DECL)
    1940   1872967619 :       && omp_var_to_track (stmt))
    1941        12691 :     omp_cxx_notice_variable (wtd->omp_ctx, stmt);
    1942              : 
    1943              :   /* Don't dereference parms in a thunk, pass the references through. */
    1944     75488195 :   if ((TREE_CODE (stmt) == CALL_EXPR && call_from_lambda_thunk_p (stmt))
    1945   1948274305 :       || (TREE_CODE (stmt) == AGGR_INIT_EXPR && AGGR_INIT_FROM_THUNK_P (stmt)))
    1946              :     {
    1947        68484 :       *walk_subtrees = 0;
    1948        68484 :       return NULL;
    1949              :     }
    1950              : 
    1951              :   /* Dereference invisible reference parms.  */
    1952   1872785896 :   if (wtd->handle_invisiref_parm_p && is_invisiref_parm (stmt))
    1953              :     {
    1954      1302765 :       *stmt_p = convert_from_reference (stmt);
    1955      1302765 :       p_set->add (*stmt_p);
    1956      1302765 :       *walk_subtrees = 0;
    1957      1302765 :       return NULL;
    1958              :     }
    1959              : 
    1960              :   /* Map block scope extern declarations to visible declarations with the
    1961              :      same name and type in outer scopes if any.  */
    1962   1871483131 :   if (VAR_OR_FUNCTION_DECL_P (stmt) && DECL_LOCAL_DECL_P (stmt))
    1963        21717 :     if (tree alias = DECL_LOCAL_DECL_ALIAS (stmt))
    1964              :       {
    1965        21717 :         if (alias != error_mark_node)
    1966              :           {
    1967        21714 :             *stmt_p = alias;
    1968        21714 :             TREE_USED (alias) |= TREE_USED (stmt);
    1969              :           }
    1970        21717 :         *walk_subtrees = 0;
    1971        21717 :         return NULL;
    1972              :       }
    1973              : 
    1974   1871461414 :   if (TREE_CODE (stmt) == INTEGER_CST
    1975    215093680 :       && TYPE_REF_P (TREE_TYPE (stmt))
    1976          168 :       && (flag_sanitize & (SANITIZE_NULL | SANITIZE_ALIGNMENT))
    1977   1871461415 :       && !wtd->no_sanitize_p)
    1978              :     {
    1979            1 :       ubsan_maybe_instrument_reference (stmt_p);
    1980            1 :       if (*stmt_p != stmt)
    1981              :         {
    1982            1 :           *walk_subtrees = 0;
    1983            1 :           return NULL_TREE;
    1984              :         }
    1985              :     }
    1986              : 
    1987              :   /* Other than invisiref parms, don't walk the same tree twice.  */
    1988   1871461413 :   if (p_set->contains (stmt))
    1989              :     {
    1990    372739191 :       *walk_subtrees = 0;
    1991    372739191 :       return NULL_TREE;
    1992              :     }
    1993              : 
    1994   1498722222 :   if ((TREE_CODE (stmt) == VAR_DECL
    1995              :        || TREE_CODE (stmt) == PARM_DECL
    1996              :        || TREE_CODE (stmt) == RESULT_DECL)
    1997    160234870 :       && DECL_HAS_VALUE_EXPR_P (stmt))
    1998              :     {
    1999       857898 :       tree ve = DECL_VALUE_EXPR (stmt);
    2000       857898 :       cp_walk_tree (&ve, cp_genericize_r, data, NULL);
    2001       857898 :       SET_DECL_VALUE_EXPR (stmt, ve);
    2002              :     }
    2003              : 
    2004   1498722222 :   switch (TREE_CODE (stmt))
    2005              :     {
    2006    121172674 :     case ADDR_EXPR:
    2007    121172674 :       if (is_invisiref_parm (TREE_OPERAND (stmt, 0)))
    2008              :         {
    2009              :           /* If in an OpenMP context, note var uses.  */
    2010       563272 :           if (UNLIKELY (wtd->omp_ctx != NULL)
    2011       563272 :               && omp_var_to_track (TREE_OPERAND (stmt, 0)))
    2012          412 :             omp_cxx_notice_variable (wtd->omp_ctx, TREE_OPERAND (stmt, 0));
    2013       563272 :           *stmt_p = fold_convert (TREE_TYPE (stmt), TREE_OPERAND (stmt, 0));
    2014       563272 :           *walk_subtrees = 0;
    2015              :         }
    2016    121172674 :       check_out_of_consteval_use (stmt);
    2017    121172674 :       break;
    2018              : 
    2019     44893859 :     case RETURN_EXPR:
    2020     44893859 :       if (TREE_OPERAND (stmt, 0))
    2021              :         {
    2022     44195501 :           if (error_operand_p (TREE_OPERAND (stmt, 0))
    2023     44195501 :               && warn_return_type)
    2024              :             /* Suppress -Wreturn-type for this function.  */
    2025           15 :             suppress_warning (current_function_decl, OPT_Wreturn_type);
    2026              : 
    2027     44195501 :           if (is_invisiref_parm (TREE_OPERAND (stmt, 0)))
    2028              :             /* Don't dereference an invisiref RESULT_DECL inside a
    2029              :                RETURN_EXPR.  */
    2030          680 :             *walk_subtrees = 0;
    2031     44195501 :           if (RETURN_EXPR_LOCAL_ADDR_P (stmt))
    2032              :             {
    2033              :               /* Don't return the address of a local variable.  */
    2034          175 :               tree *p = &TREE_OPERAND (stmt, 0);
    2035          350 :               while (TREE_CODE (*p) == COMPOUND_EXPR)
    2036            0 :                 p = &TREE_OPERAND (*p, 0);
    2037          175 :               if (TREE_CODE (*p) == INIT_EXPR)
    2038              :                 {
    2039          175 :                   tree op = TREE_OPERAND (*p, 1);
    2040          175 :                   tree new_op = build2 (COMPOUND_EXPR, TREE_TYPE (op), op,
    2041          175 :                                         build_zero_cst (TREE_TYPE (op)));
    2042          175 :                   TREE_OPERAND (*p, 1) = new_op;
    2043              :                 }
    2044              :             }
    2045              :         }
    2046              :       break;
    2047              : 
    2048        86923 :     case OMP_CLAUSE:
    2049        86923 :       switch (OMP_CLAUSE_CODE (stmt))
    2050              :         {
    2051         2686 :         case OMP_CLAUSE_LASTPRIVATE:
    2052              :           /* Don't dereference an invisiref in OpenMP clauses.  */
    2053         2686 :           if (is_invisiref_parm (OMP_CLAUSE_DECL (stmt)))
    2054              :             {
    2055           53 :               *walk_subtrees = 0;
    2056           53 :               if (OMP_CLAUSE_LASTPRIVATE_STMT (stmt))
    2057           48 :                 cp_walk_tree (&OMP_CLAUSE_LASTPRIVATE_STMT (stmt),
    2058              :                               cp_genericize_r, data, NULL);
    2059              :             }
    2060              :           break;
    2061         2124 :         case OMP_CLAUSE_PRIVATE:
    2062              :           /* Don't dereference an invisiref in OpenMP clauses.  */
    2063         2124 :           if (is_invisiref_parm (OMP_CLAUSE_DECL (stmt)))
    2064            8 :             *walk_subtrees = 0;
    2065         2116 :           else if (wtd->omp_ctx != NULL)
    2066              :             {
    2067              :               /* Private clause doesn't cause any references to the
    2068              :                  var in outer contexts, avoid calling
    2069              :                  omp_cxx_notice_variable for it.  */
    2070          596 :               struct cp_genericize_omp_taskreg *old = wtd->omp_ctx;
    2071          596 :               wtd->omp_ctx = NULL;
    2072          596 :               cp_walk_tree (&OMP_CLAUSE_DECL (stmt), cp_genericize_r,
    2073              :                             data, NULL);
    2074          596 :               wtd->omp_ctx = old;
    2075          596 :               *walk_subtrees = 0;
    2076              :             }
    2077              :           break;
    2078         6346 :         case OMP_CLAUSE_SHARED:
    2079         6346 :         case OMP_CLAUSE_FIRSTPRIVATE:
    2080         6346 :         case OMP_CLAUSE_COPYIN:
    2081         6346 :         case OMP_CLAUSE_COPYPRIVATE:
    2082         6346 :         case OMP_CLAUSE_INCLUSIVE:
    2083         6346 :         case OMP_CLAUSE_EXCLUSIVE:
    2084              :           /* Don't dereference an invisiref in OpenMP clauses.  */
    2085         6346 :           if (is_invisiref_parm (OMP_CLAUSE_DECL (stmt)))
    2086           87 :             *walk_subtrees = 0;
    2087              :           break;
    2088         8964 :         case OMP_CLAUSE_REDUCTION:
    2089         8964 :         case OMP_CLAUSE_IN_REDUCTION:
    2090         8964 :         case OMP_CLAUSE_TASK_REDUCTION:
    2091              :           /* Don't dereference an invisiref in reduction clause's
    2092              :              OMP_CLAUSE_DECL either.  OMP_CLAUSE_REDUCTION_{INIT,MERGE}
    2093              :              still needs to be genericized.  */
    2094         8964 :           if (is_invisiref_parm (OMP_CLAUSE_DECL (stmt)))
    2095              :             {
    2096           38 :               *walk_subtrees = 0;
    2097           38 :               if (OMP_CLAUSE_REDUCTION_INIT (stmt))
    2098           38 :                 cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (stmt),
    2099              :                               cp_genericize_r, data, NULL);
    2100           38 :               if (OMP_CLAUSE_REDUCTION_MERGE (stmt))
    2101           38 :                 cp_walk_tree (&OMP_CLAUSE_REDUCTION_MERGE (stmt),
    2102              :                               cp_genericize_r, data, NULL);
    2103              :             }
    2104              :           break;
    2105              :         default:
    2106              :           break;
    2107              :         }
    2108              :       break;
    2109              : 
    2110              :     /* Due to the way voidify_wrapper_expr is written, we don't get a chance
    2111              :        to lower this construct before scanning it, so we need to lower these
    2112              :        before doing anything else.  */
    2113      5819315 :     case CLEANUP_STMT:
    2114      5819315 :       *stmt_p = build2_loc (EXPR_LOCATION (stmt),
    2115      5819315 :                             CLEANUP_EH_ONLY (stmt) ? TRY_CATCH_EXPR
    2116              :                                                    : TRY_FINALLY_EXPR,
    2117              :                             void_type_node,
    2118      5819315 :                             CLEANUP_BODY (stmt),
    2119      5819315 :                             CLEANUP_EXPR (stmt));
    2120      5819315 :       break;
    2121              : 
    2122     22334239 :     case IF_STMT:
    2123     22334239 :       genericize_if_stmt (stmt_p);
    2124              :       /* *stmt_p has changed, tail recurse to handle it again.  */
    2125     22334239 :       return cp_genericize_r (stmt_p, walk_subtrees, data);
    2126              : 
    2127              :     /* COND_EXPR might have incompatible types in branches if one or both
    2128              :        arms are bitfields.  Fix it up now.  */
    2129     19811448 :     case COND_EXPR:
    2130     19811448 :       {
    2131     19811448 :         tree type_left
    2132     19811448 :           = (TREE_OPERAND (stmt, 1)
    2133     19811448 :              ? is_bitfield_expr_with_lowered_type (TREE_OPERAND (stmt, 1))
    2134              :              : NULL_TREE);
    2135     19811448 :         tree type_right
    2136     19811448 :           = (TREE_OPERAND (stmt, 2)
    2137     19811448 :              ? is_bitfield_expr_with_lowered_type (TREE_OPERAND (stmt, 2))
    2138              :              : NULL_TREE);
    2139     19811448 :         if (type_left
    2140     19811451 :             && !useless_type_conversion_p (TREE_TYPE (stmt),
    2141            3 :                                            TREE_TYPE (TREE_OPERAND (stmt, 1))))
    2142              :           {
    2143            0 :             TREE_OPERAND (stmt, 1)
    2144            0 :               = fold_convert (type_left, TREE_OPERAND (stmt, 1));
    2145            0 :             gcc_assert (useless_type_conversion_p (TREE_TYPE (stmt),
    2146              :                                                    type_left));
    2147              :           }
    2148     19811448 :         if (type_right
    2149     19811448 :             && !useless_type_conversion_p (TREE_TYPE (stmt),
    2150            0 :                                            TREE_TYPE (TREE_OPERAND (stmt, 2))))
    2151              :           {
    2152            0 :             TREE_OPERAND (stmt, 2)
    2153            0 :               = fold_convert (type_right, TREE_OPERAND (stmt, 2));
    2154            0 :             gcc_assert (useless_type_conversion_p (TREE_TYPE (stmt),
    2155              :                                                    type_right));
    2156              :           }
    2157              :       }
    2158              :       break;
    2159              : 
    2160     26084922 :     case BIND_EXPR:
    2161     26084922 :       if (UNLIKELY (wtd->omp_ctx != NULL))
    2162              :         {
    2163        28851 :           tree decl;
    2164        35827 :           for (decl = BIND_EXPR_VARS (stmt); decl; decl = DECL_CHAIN (decl))
    2165         6976 :             if (VAR_P (decl)
    2166         6928 :                 && !DECL_EXTERNAL (decl)
    2167        13904 :                 && omp_var_to_track (decl))
    2168              :               {
    2169          586 :                 splay_tree_node n
    2170          586 :                   = splay_tree_lookup (wtd->omp_ctx->variables,
    2171              :                                        (splay_tree_key) decl);
    2172          586 :                 if (n == NULL)
    2173          586 :                   splay_tree_insert (wtd->omp_ctx->variables,
    2174              :                                      (splay_tree_key) decl,
    2175          586 :                                      TREE_STATIC (decl)
    2176              :                                      ? OMP_CLAUSE_DEFAULT_SHARED
    2177              :                                      : OMP_CLAUSE_DEFAULT_PRIVATE);
    2178              :               }
    2179              :         }
    2180     26084922 :       if (flag_reflection)
    2181              :         /* Adjust consteval-only vars in BIND_EXPR_VARS so that REFLECT_EXPR
    2182              :            doesn't leak into the ME.  */
    2183      1192411 :         for (tree *p = &BIND_EXPR_VARS (stmt); *p; )
    2184              :           {
    2185       574560 :             if (VAR_P (*p))
    2186              :               {
    2187              :                 /* First, adjust null reflections.  */
    2188       491516 :                 if (DECL_INITIAL (*p))
    2189       235913 :                   rewrite_null_reflection (DECL_INITIAL (*p));
    2190              :                 /* If the variable is still consteval-only, remove it.  */
    2191       491516 :                 if (consteval_only_p (*p))
    2192              :                   {
    2193          902 :                     if (BIND_EXPR_BLOCK (stmt)
    2194          902 :                         && *p == BLOCK_VARS (BIND_EXPR_BLOCK (stmt)))
    2195          428 :                       BLOCK_VARS (BIND_EXPR_BLOCK (stmt)) = DECL_CHAIN (*p);
    2196          902 :                     *p = DECL_CHAIN (*p);
    2197          902 :                     continue;
    2198              :                   }
    2199              :               }
    2200       573658 :             p = &DECL_CHAIN (*p);
    2201              :           }
    2202     26084922 :       if (sanitize_flags_p (SANITIZE_NULL | SANITIZE_ALIGNMENT | SANITIZE_VPTR))
    2203              :         {
    2204              :           /* The point here is to not sanitize static initializers.  */
    2205         3572 :           bool no_sanitize_p = wtd->no_sanitize_p;
    2206         3572 :           wtd->no_sanitize_p = true;
    2207         3572 :           for (tree decl = BIND_EXPR_VARS (stmt);
    2208         7022 :                decl;
    2209         3450 :                decl = DECL_CHAIN (decl))
    2210         3450 :             if (VAR_P (decl)
    2211         3033 :                 && TREE_STATIC (decl)
    2212         3524 :                 && DECL_INITIAL (decl))
    2213           12 :               cp_walk_tree (&DECL_INITIAL (decl), cp_genericize_r, data, NULL);
    2214         3572 :           wtd->no_sanitize_p = no_sanitize_p;
    2215              :         }
    2216     26084922 :       wtd->bind_expr_stack.safe_push (stmt);
    2217     26084922 :       cp_walk_tree (&BIND_EXPR_BODY (stmt),
    2218              :                     cp_genericize_r, data, NULL);
    2219     26084922 :       wtd->bind_expr_stack.pop ();
    2220     26084922 :       break;
    2221              : 
    2222         1062 :     case ASSERTION_STMT:
    2223         1062 :     case PRECONDITION_STMT:
    2224         1062 :     case POSTCONDITION_STMT:
    2225         1062 :       if (tree check = build_contract_check (stmt))
    2226              :         {
    2227         1062 :           *stmt_p = check;
    2228         1062 :           return cp_genericize_r (stmt_p, walk_subtrees, data);
    2229              :         }
    2230              :       /* If we didn't build a check, replace it with void_node so we don't
    2231              :          leak contracts into GENERIC.  */
    2232            0 :       *stmt_p = void_node;
    2233            0 :       *walk_subtrees = 0;
    2234            0 :       break;
    2235              : 
    2236        18457 :     case USING_STMT:
    2237        18457 :       {
    2238        18457 :         tree block = NULL_TREE;
    2239              : 
    2240              :         /* Get the innermost inclosing GIMPLE_BIND that has a non NULL
    2241              :            BLOCK, and append an IMPORTED_DECL to its
    2242              :            BLOCK_VARS chained list.  */
    2243        18457 :         if (wtd->bind_expr_stack.exists ())
    2244              :           {
    2245        18457 :             int i;
    2246        18457 :             for (i = wtd->bind_expr_stack.length () - 1; i >= 0; i--)
    2247        18457 :               if ((block = BIND_EXPR_BLOCK (wtd->bind_expr_stack[i])))
    2248              :                 break;
    2249              :           }
    2250        18457 :         if (block)
    2251              :           {
    2252        18457 :             tree decl = TREE_OPERAND (stmt, 0);
    2253        18457 :             gcc_assert (decl);
    2254              : 
    2255        18457 :             if (undeduced_auto_decl (decl))
    2256              :               /* Omit from the GENERIC, the back-end can't handle it.  */;
    2257              :             else
    2258              :               {
    2259        18454 :                 tree using_directive = make_node (IMPORTED_DECL);
    2260        18454 :                 TREE_TYPE (using_directive) = void_type_node;
    2261        18454 :                 DECL_CONTEXT (using_directive) = current_function_decl;
    2262        36908 :                 DECL_SOURCE_LOCATION (using_directive)
    2263        18454 :                   = cp_expr_loc_or_input_loc (stmt);
    2264              : 
    2265        18454 :                 IMPORTED_DECL_ASSOCIATED_DECL (using_directive) = decl;
    2266        18454 :                 DECL_CHAIN (using_directive) = BLOCK_VARS (block);
    2267        18454 :                 BLOCK_VARS (block) = using_directive;
    2268              :               }
    2269              :           }
    2270              :         /* The USING_STMT won't appear in GENERIC.  */
    2271        18457 :         *stmt_p = build1 (NOP_EXPR, void_type_node, integer_zero_node);
    2272        18457 :         *walk_subtrees = 0;
    2273              :       }
    2274        18457 :       break;
    2275              : 
    2276     25819009 :     case DECL_EXPR:
    2277     25819009 :       if (TREE_CODE (DECL_EXPR_DECL (stmt)) == USING_DECL)
    2278              :         {
    2279              :           /* Using decls inside DECL_EXPRs are just dropped on the floor.  */
    2280        20734 :           *stmt_p = build1 (NOP_EXPR, void_type_node, integer_zero_node);
    2281        20734 :           *walk_subtrees = 0;
    2282              :         }
    2283              :       else
    2284              :         {
    2285     25798275 :           tree d = DECL_EXPR_DECL (stmt);
    2286     25798275 :           if (VAR_P (d))
    2287     51594991 :             gcc_assert (CP_DECL_THREAD_LOCAL_P (d) == DECL_THREAD_LOCAL_P (d));
    2288              :         }
    2289              :       break;
    2290              : 
    2291        12071 :     case OMP_PARALLEL:
    2292        12071 :     case OMP_TASK:
    2293        12071 :     case OMP_TASKLOOP:
    2294        12071 :       {
    2295        12071 :         struct cp_genericize_omp_taskreg omp_ctx;
    2296        12071 :         tree c, decl;
    2297        12071 :         splay_tree_node n;
    2298              : 
    2299        12071 :         *walk_subtrees = 0;
    2300        12071 :         cp_walk_tree (&OMP_CLAUSES (stmt), cp_genericize_r, data, NULL);
    2301        12071 :         omp_ctx.is_parallel = TREE_CODE (stmt) == OMP_PARALLEL;
    2302        12071 :         omp_ctx.default_shared = omp_ctx.is_parallel;
    2303        12071 :         omp_ctx.outer = wtd->omp_ctx;
    2304        12071 :         omp_ctx.variables = splay_tree_new (splay_tree_compare_decl_uid, 0, 0);
    2305        12071 :         wtd->omp_ctx = &omp_ctx;
    2306        28386 :         for (c = OMP_CLAUSES (stmt); c; c = OMP_CLAUSE_CHAIN (c))
    2307        16315 :           switch (OMP_CLAUSE_CODE (c))
    2308              :             {
    2309         4865 :             case OMP_CLAUSE_SHARED:
    2310         4865 :             case OMP_CLAUSE_PRIVATE:
    2311         4865 :             case OMP_CLAUSE_FIRSTPRIVATE:
    2312         4865 :             case OMP_CLAUSE_LASTPRIVATE:
    2313         4865 :               decl = OMP_CLAUSE_DECL (c);
    2314         4865 :               if (decl == error_mark_node || !omp_var_to_track (decl))
    2315              :                 break;
    2316          520 :               n = splay_tree_lookup (omp_ctx.variables, (splay_tree_key) decl);
    2317          520 :               if (n != NULL)
    2318              :                 break;
    2319         1022 :               splay_tree_insert (omp_ctx.variables, (splay_tree_key) decl,
    2320          511 :                                  OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
    2321              :                                  ? OMP_CLAUSE_DEFAULT_SHARED
    2322              :                                  : OMP_CLAUSE_DEFAULT_PRIVATE);
    2323          511 :               if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_PRIVATE && omp_ctx.outer)
    2324           91 :                 omp_cxx_notice_variable (omp_ctx.outer, decl);
    2325              :               break;
    2326         1651 :             case OMP_CLAUSE_DEFAULT:
    2327         1651 :               if (OMP_CLAUSE_DEFAULT_KIND (c) == OMP_CLAUSE_DEFAULT_SHARED)
    2328          731 :                 omp_ctx.default_shared = true;
    2329              :             default:
    2330              :               break;
    2331              :             }
    2332        12071 :         if (TREE_CODE (stmt) == OMP_TASKLOOP)
    2333         1001 :           c_genericize_control_stmt (stmt_p, walk_subtrees, data,
    2334              :                                      cp_genericize_r, cp_walk_subtrees);
    2335              :         else
    2336        11070 :           cp_walk_tree (&OMP_BODY (stmt), cp_genericize_r, data, NULL);
    2337        12071 :         wtd->omp_ctx = omp_ctx.outer;
    2338        12071 :         splay_tree_delete (omp_ctx.variables);
    2339              :       }
    2340        12071 :       break;
    2341              : 
    2342         7428 :     case OMP_TARGET:
    2343         7428 :       cfun->has_omp_target = true;
    2344         7428 :       break;
    2345              : 
    2346       141364 :     case TRY_BLOCK:
    2347       141364 :       {
    2348       141364 :         *walk_subtrees = 0;
    2349       141364 :         tree try_block = wtd->try_block;
    2350       141364 :         wtd->try_block = stmt;
    2351       141364 :         cp_walk_tree (&TRY_STMTS (stmt), cp_genericize_r, data, NULL);
    2352       141364 :         wtd->try_block = try_block;
    2353       141364 :         cp_walk_tree (&TRY_HANDLERS (stmt), cp_genericize_r, data, NULL);
    2354              :       }
    2355       141364 :       break;
    2356              : 
    2357     25439658 :     case MUST_NOT_THROW_EXPR:
    2358              :       /* MUST_NOT_THROW_COND might be something else with TM.  */
    2359     25439658 :       if (MUST_NOT_THROW_COND (stmt) == NULL_TREE)
    2360              :         {
    2361     25439640 :           *walk_subtrees = 0;
    2362     25439640 :           tree try_block = wtd->try_block;
    2363     25439640 :           wtd->try_block = stmt;
    2364     25439640 :           cp_walk_tree (&TREE_OPERAND (stmt, 0), cp_genericize_r, data, NULL);
    2365     25439640 :           wtd->try_block = try_block;
    2366              :         }
    2367              :       break;
    2368              : 
    2369       147432 :     case THROW_EXPR:
    2370       147432 :       {
    2371       147432 :         location_t loc = location_of (stmt);
    2372       147432 :         if (warning_suppressed_p (stmt /* What warning? */))
    2373              :           /* Never mind.  */;
    2374        48015 :         else if (wtd->try_block)
    2375              :           {
    2376        11147 :             if (TREE_CODE (wtd->try_block) == MUST_NOT_THROW_EXPR)
    2377              :               {
    2378           18 :                 auto_diagnostic_group d;
    2379           31 :                 if (warning_at (loc, OPT_Wterminate,
    2380              :                                 "%<throw%> will always call %<terminate%>")
    2381           10 :                     && cxx_dialect >= cxx11
    2382           36 :                     && DECL_DESTRUCTOR_P (current_function_decl))
    2383            5 :                   inform (loc, "in C++11 destructors default to %<noexcept%>");
    2384           18 :               }
    2385              :           }
    2386              :         else
    2387              :           {
    2388          103 :             if (warn_cxx11_compat && cxx_dialect < cxx11
    2389          206 :                 && DECL_DESTRUCTOR_P (current_function_decl)
    2390            1 :                 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))
    2391              :                     == NULL_TREE)
    2392        36869 :                 && (get_defaulted_eh_spec (current_function_decl)
    2393            1 :                     == empty_except_spec))
    2394            1 :               warning_at (loc, OPT_Wc__11_compat,
    2395              :                           "in C++11 this %<throw%> will call %<terminate%> "
    2396              :                           "because destructors default to %<noexcept%>");
    2397              :           }
    2398              :       }
    2399              :       break;
    2400              : 
    2401     42235991 :     case CONVERT_EXPR:
    2402     42235991 :       gcc_checking_assert (!AGGREGATE_TYPE_P (TREE_TYPE (stmt)));
    2403     42235991 :       gcc_assert (!CONVERT_EXPR_VBASE_PATH (stmt));
    2404              :       break;
    2405              : 
    2406       235198 :     case SPACESHIP_EXPR:
    2407       235198 :       *stmt_p = genericize_spaceship (*stmt_p);
    2408       235198 :       break;
    2409              : 
    2410        31780 :     case PTRMEM_CST:
    2411              :       /* By the time we get here we're handing off to the back end, so we don't
    2412              :          need or want to preserve PTRMEM_CST anymore.  */
    2413        31780 :       *stmt_p = cplus_expand_constant (stmt);
    2414        31780 :       *walk_subtrees = 0;
    2415        31780 :       break;
    2416              : 
    2417       278420 :     case MEM_REF:
    2418              :       /* For MEM_REF, make sure not to sanitize the second operand even
    2419              :          if it has reference type.  It is just an offset with a type
    2420              :          holding other information.  There is no other processing we
    2421              :          need to do for INTEGER_CSTs, so just ignore the second argument
    2422              :          unconditionally.  */
    2423       278420 :       cp_walk_tree (&TREE_OPERAND (stmt, 0), cp_genericize_r, data, NULL);
    2424       278420 :       *walk_subtrees = 0;
    2425       278420 :       break;
    2426              : 
    2427     41294787 :     case INDIRECT_REF:
    2428              :       /* A pointer to a class might point to a base subobject, which is
    2429              :          only guaranteed the alignment of the class as a base (the ABI
    2430              :          "nvalign").  That is less than TYPE_ALIGN if a virtual base needs
    2431              :          more alignment than the rest of the class, so don't let the middle
    2432              :          end assume more (PR c++/103303).  */
    2433     41294787 :       {
    2434     41294787 :         tree type = TREE_TYPE (stmt);
    2435     30028806 :         if (CLASS_TYPE_P (type)
    2436     29836381 :             && COMPLETE_TYPE_P (type)
    2437     29275679 :             && CLASSTYPE_AS_BASE (type)
    2438     29275679 :             && CLASSTYPE_ALIGN (type) < TYPE_ALIGN (type)
    2439           95 :             && resolves_to_fixed_type_p (stmt) <= 0
    2440              :             /* Respect an alignment the user specified on a variant.  */
    2441     41294876 :             && TYPE_ALIGN (type) == TYPE_ALIGN (TYPE_MAIN_VARIANT (type)))
    2442           89 :           TREE_TYPE (stmt) = build_aligned_type (type, CLASSTYPE_ALIGN (type));
    2443              :       }
    2444              :       break;
    2445              : 
    2446    119107766 :     case NOP_EXPR:
    2447    119107766 :       *stmt_p = predeclare_vla (*stmt_p);
    2448              : 
    2449              :       /* Warn of new allocations that are not big enough for the target
    2450              :          type.  Don't warn for calls from new expressions, new TYPE[0]
    2451              :          is fine and new expansion should arrange for the right size
    2452              :          to be provided.  */
    2453    119107766 :       if (warn_alloc_size
    2454      1086154 :           && TREE_CODE (TREE_OPERAND (stmt, 0)) == CALL_EXPR
    2455        64812 :           && !CALL_FROM_NEW_OR_DELETE_P (TREE_OPERAND (stmt, 0))
    2456    119172027 :           && POINTER_TYPE_P (TREE_TYPE (stmt)))
    2457              :         {
    2458        23096 :           if (tree fndecl = get_callee_fndecl (TREE_OPERAND (stmt, 0)))
    2459        23082 :             if (DECL_IS_MALLOC (fndecl))
    2460              :               {
    2461          629 :                 tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
    2462          629 :                 tree alloc_size = lookup_attribute ("alloc_size", attrs);
    2463          629 :                 if (alloc_size)
    2464          627 :                   warn_for_alloc_size (EXPR_LOCATION (stmt),
    2465          627 :                                        TREE_TYPE (TREE_TYPE (stmt)),
    2466          627 :                                        TREE_OPERAND (stmt, 0), alloc_size);
    2467              :               }
    2468              :         }
    2469              : 
    2470    119107766 :       if (!wtd->no_sanitize_p
    2471    119107761 :           && sanitize_flags_p (SANITIZE_NULL | SANITIZE_ALIGNMENT)
    2472    119123766 :           && TYPE_REF_P (TREE_TYPE (stmt)))
    2473         2506 :         ubsan_maybe_instrument_reference (stmt_p);
    2474              :       break;
    2475              : 
    2476     75415533 :     case CALL_EXPR:
    2477     75415533 :       if (!wtd->no_sanitize_p
    2478     75415533 :           && sanitize_flags_p ((SANITIZE_NULL
    2479              :                                 | SANITIZE_ALIGNMENT | SANITIZE_VPTR)))
    2480              :         {
    2481        16148 :           tree fn = CALL_EXPR_FN (stmt);
    2482        16148 :           if (fn != NULL_TREE
    2483        10017 :               && !error_operand_p (fn)
    2484        10017 :               && INDIRECT_TYPE_P (TREE_TYPE (fn))
    2485        26165 :               && TREE_CODE (TREE_TYPE (TREE_TYPE (fn))) == METHOD_TYPE)
    2486              :             {
    2487         5675 :               bool is_ctor
    2488         5675 :                 = TREE_CODE (fn) == ADDR_EXPR
    2489         5552 :                   && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
    2490        16779 :                   && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0));
    2491         5675 :               if (sanitize_flags_p (SANITIZE_NULL | SANITIZE_ALIGNMENT))
    2492         5064 :                 ubsan_maybe_instrument_member_call (stmt, is_ctor);
    2493         5675 :               if (sanitize_flags_p (SANITIZE_VPTR) && !is_ctor)
    2494         4830 :                 cp_ubsan_maybe_instrument_member_call (stmt);
    2495              :             }
    2496        10473 :           else if (fn == NULL_TREE
    2497         6131 :                    && CALL_EXPR_IFN (stmt) == IFN_UBSAN_NULL
    2498         5024 :                    && TREE_CODE (CALL_EXPR_ARG (stmt, 0)) == INTEGER_CST
    2499        10479 :                    && TYPE_REF_P (TREE_TYPE (CALL_EXPR_ARG (stmt, 0))))
    2500            6 :             *walk_subtrees = 0;
    2501              :         }
    2502              :       /* Fall through.  */
    2503     80241540 :     case AGGR_INIT_EXPR:
    2504              :       /* For calls to a multi-versioned function, overload resolution
    2505              :          returns the function with the highest target priority, that is,
    2506              :          the version that will checked for dispatching first.  If this
    2507              :          version is inlinable, a direct call to this version can be made
    2508              :          otherwise the call should go through the dispatcher.
    2509              :          This is done at multiple_target.cc for target_version semantics.  */
    2510     80241540 :       {
    2511     80241540 :         tree fn = cp_get_callee_fndecl_nofold (stmt);
    2512     80241540 :         if (TARGET_HAS_FMV_TARGET_ATTRIBUTE
    2513              :             && fn
    2514     79080952 :             && DECL_FUNCTION_VERSIONED (fn)
    2515     80241675 :             && (current_function_decl == NULL
    2516          135 :                 || !targetm.target_option.can_inline_p
    2517          135 :                       (current_function_decl, fn)))
    2518          123 :           if (tree dis = get_function_version_dispatcher (fn))
    2519              :             {
    2520          123 :               mark_versions_used (dis);
    2521          123 :               dis = build_address (dis);
    2522          123 :               if (TREE_CODE (stmt) == CALL_EXPR)
    2523          120 :                 CALL_EXPR_FN (stmt) = dis;
    2524              :               else
    2525            3 :                 AGGR_INIT_EXPR_FN (stmt) = dis;
    2526              :             }
    2527              :       }
    2528              :       break;
    2529              : 
    2530     19462847 :     case TARGET_EXPR:
    2531     19462847 :       if (TARGET_EXPR_INITIAL (stmt)
    2532     19462847 :           && TREE_CODE (TARGET_EXPR_INITIAL (stmt)) == CONSTRUCTOR
    2533     21892309 :           && CONSTRUCTOR_PLACEHOLDER_BOUNDARY (TARGET_EXPR_INITIAL (stmt)))
    2534          169 :         TARGET_EXPR_NO_ELIDE (stmt) = 1;
    2535              :       break;
    2536              : 
    2537          642 :     case TEMPLATE_ID_EXPR:
    2538          642 :       gcc_assert (concept_check_p (stmt));
    2539              :       /* Emit the value of the concept check.  */
    2540          642 :       *stmt_p = evaluate_concept_check (stmt);
    2541          642 :       walk_subtrees = 0;
    2542          642 :       break;
    2543              : 
    2544         4541 :     case OMP_DISTRIBUTE:
    2545              :       /* Need to explicitly instantiate copy ctors on class iterators of
    2546              :          composite distribute parallel for.  */
    2547         4541 :       if (OMP_FOR_INIT (*stmt_p) == NULL_TREE)
    2548              :         {
    2549         4042 :           tree *data[4] = { NULL, NULL, NULL, NULL };
    2550         4042 :           tree inner = walk_tree (&OMP_FOR_BODY (*stmt_p),
    2551              :                                   find_combined_omp_for, data, NULL);
    2552         4042 :           if (inner != NULL_TREE
    2553         4008 :               && TREE_CODE (inner) == OMP_FOR)
    2554              :             {
    2555         4554 :               for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (inner)); i++)
    2556         2859 :                 if (TREE_VEC_ELT (OMP_FOR_INIT (inner), i)
    2557         2843 :                     && OMP_FOR_ORIG_DECLS (inner)
    2558         2843 :                     && TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner),
    2559              :                                   i)) == TREE_LIST
    2560         2883 :                     && TREE_PURPOSE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner),
    2561              :                                      i)))
    2562              :                   {
    2563           12 :                     tree orig = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner), i);
    2564              :                     /* Class iterators aren't allowed on OMP_SIMD, so the only
    2565              :                        case we need to solve is distribute parallel for.  */
    2566           12 :                     gcc_assert (TREE_CODE (inner) == OMP_FOR
    2567              :                                 && data[1]);
    2568           12 :                     tree orig_decl = TREE_PURPOSE (orig);
    2569           12 :                     tree c, cl = NULL_TREE;
    2570           12 :                     for (c = OMP_FOR_CLAUSES (inner);
    2571           16 :                          c; c = OMP_CLAUSE_CHAIN (c))
    2572           12 :                       if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
    2573            5 :                            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
    2574           13 :                           && OMP_CLAUSE_DECL (c) == orig_decl)
    2575              :                         {
    2576              :                           cl = c;
    2577              :                           break;
    2578              :                         }
    2579           12 :                     if (cl == NULL_TREE)
    2580              :                       {
    2581            4 :                         for (c = OMP_PARALLEL_CLAUSES (*data[1]);
    2582            4 :                              c; c = OMP_CLAUSE_CHAIN (c))
    2583            1 :                           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
    2584            1 :                               && OMP_CLAUSE_DECL (c) == orig_decl)
    2585              :                             {
    2586              :                               cl = c;
    2587              :                               break;
    2588              :                             }
    2589              :                       }
    2590            4 :                     if (cl)
    2591              :                       {
    2592            9 :                         orig_decl = require_complete_type (orig_decl);
    2593            9 :                         tree inner_type = TREE_TYPE (orig_decl);
    2594            9 :                         if (orig_decl == error_mark_node)
    2595            0 :                           continue;
    2596            9 :                         if (TYPE_REF_P (TREE_TYPE (orig_decl)))
    2597            0 :                           inner_type = TREE_TYPE (inner_type);
    2598              : 
    2599            9 :                         while (TREE_CODE (inner_type) == ARRAY_TYPE)
    2600            0 :                           inner_type = TREE_TYPE (inner_type);
    2601            9 :                         get_copy_ctor (inner_type, tf_warning_or_error);
    2602              :                       }
    2603              :                 }
    2604              :             }
    2605              :         }
    2606              :       /* FALLTHRU */
    2607              : 
    2608      5040475 :     case FOR_STMT:
    2609      5040475 :     case WHILE_STMT:
    2610      5040475 :     case DO_STMT:
    2611      5040475 :     case SWITCH_STMT:
    2612      5040475 :     case CONTINUE_STMT:
    2613      5040475 :     case BREAK_STMT:
    2614      5040475 :     case OMP_FOR:
    2615      5040475 :     case OMP_SIMD:
    2616      5040475 :     case OMP_LOOP:
    2617      5040475 :     case OMP_TILE:
    2618      5040475 :     case OMP_UNROLL:
    2619      5040475 :     case OACC_LOOP:
    2620              :       /* These cases are handled by shared code.  */
    2621      5040475 :       c_genericize_control_stmt (stmt_p, walk_subtrees, data,
    2622              :                                  cp_genericize_r, cp_walk_subtrees);
    2623      5040475 :       break;
    2624              : 
    2625     69892893 :     case STATEMENT_LIST:
    2626              :       /* As above, handled by shared code.  */
    2627     69892893 :       c_genericize_control_stmt (stmt_p, walk_subtrees, data,
    2628              :                                  cp_genericize_r, cp_walk_subtrees);
    2629              :       /* If a statement list is freed as part of genericisation it will be
    2630              :          pushed onto the top of a statement list cache stack.  A subsequent
    2631              :          action can cause a new statement list to be required - and the one
    2632              :          just pushed will be returned.  If that is marked as visited, it can
    2633              :          prevent a tail recursion from processing the 'new' statement list,
    2634              :          so we do not mark statement lists as visited.  */
    2635     69892893 :       return NULL_TREE;
    2636        76345 :       break;
    2637              : 
    2638        76345 :     case BIT_CAST_EXPR:
    2639        76345 :       *stmt_p = build1_loc (EXPR_LOCATION (stmt), VIEW_CONVERT_EXPR,
    2640        76345 :                             TREE_TYPE (stmt), TREE_OPERAND (stmt, 0));
    2641        76345 :       break;
    2642              : 
    2643     22009365 :     case MODIFY_EXPR:
    2644              :       /* Mark stores to parts of complex automatic non-addressable
    2645              :          variables as DECL_NOT_GIMPLE_REG_P for -O0.  This can't be
    2646              :          done during gimplification.  See PR119120.  */
    2647     22009365 :       if ((TREE_CODE (TREE_OPERAND (stmt, 0)) == REALPART_EXPR
    2648     21981121 :            || TREE_CODE (TREE_OPERAND (stmt, 0)) == IMAGPART_EXPR)
    2649        56499 :           && !optimize
    2650          564 :           && DECL_P (TREE_OPERAND (TREE_OPERAND (stmt, 0), 0))
    2651     22009459 :           && is_gimple_reg (TREE_OPERAND (TREE_OPERAND (stmt, 0), 0)))
    2652           50 :         DECL_NOT_GIMPLE_REG_P (TREE_OPERAND (TREE_OPERAND (stmt, 0), 0)) = 1;
    2653              :       break;
    2654              : 
    2655          151 :     case REFLECT_EXPR:
    2656              :       /* Only the null reflection may reach the ME.  */
    2657          151 :       check_out_of_consteval_use (stmt);
    2658          151 :       *stmt_p = build_int_cst (meta_info_type_node, 0);
    2659          151 :       break;
    2660              : 
    2661    807024161 :     default:
    2662    807024161 :       if (IS_TYPE_OR_DECL_P (stmt))
    2663    264101197 :         *walk_subtrees = 0;
    2664              :       break;
    2665              :     }
    2666              : 
    2667   1406494028 :   p_set->add (*stmt_p);
    2668              : 
    2669   1406494028 :   return NULL;
    2670              : }
    2671              : 
    2672              : /* Lower C++ front end trees to GENERIC in T_P.  */
    2673              : 
    2674              : static void
    2675     51443110 : cp_genericize_tree (tree* t_p, bool handle_invisiref_parm_p)
    2676              : {
    2677     51443110 :   struct cp_genericize_data wtd;
    2678              : 
    2679     51443110 :   wtd.p_set = new hash_set<tree>;
    2680     51443110 :   wtd.bind_expr_stack.create (0);
    2681     51443110 :   wtd.omp_ctx = NULL;
    2682     51443110 :   wtd.try_block = NULL_TREE;
    2683     51443110 :   wtd.no_sanitize_p = false;
    2684     51443110 :   wtd.handle_invisiref_parm_p = handle_invisiref_parm_p;
    2685     51443110 :   cp_walk_tree (t_p, cp_genericize_r, &wtd, NULL);
    2686    102886220 :   delete wtd.p_set;
    2687     51443110 :   if (sanitize_flags_p (SANITIZE_VPTR))
    2688         5808 :     cp_ubsan_instrument_member_accesses (t_p);
    2689     51443110 : }
    2690              : 
    2691              : /* If a function that should end with a return in non-void
    2692              :    function doesn't obviously end with return, add ubsan
    2693              :    instrumentation code to verify it at runtime.  If -fsanitize=return
    2694              :    is not enabled, instrument __builtin_unreachable.  */
    2695              : 
    2696              : static void
    2697     51443110 : cp_maybe_instrument_return (tree fndecl)
    2698              : {
    2699     51443110 :   if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fndecl)))
    2700     73835104 :       || DECL_CONSTRUCTOR_P (fndecl)
    2701     36917552 :       || DECL_DESTRUCTOR_P (fndecl)
    2702     88360662 :       || !targetm.warn_func_return (fndecl))
    2703              :     return;
    2704              : 
    2705     36917540 :   if (!sanitize_flags_p (SANITIZE_RETURN, fndecl)
    2706              :       /* Don't add __builtin_unreachable () if not optimizing, it will not
    2707              :          improve any optimizations in that case, just break UB code.
    2708              :          Don't add it if -fsanitize=unreachable -fno-sanitize=return either,
    2709              :          UBSan covers this with ubsan_instrument_return above where sufficient
    2710              :          information is provided, while the __builtin_unreachable () below
    2711              :          if return sanitization is disabled will just result in hard to
    2712              :          understand runtime error without location.  */
    2713     36917540 :       && ((!optimize && !flag_unreachable_traps)
    2714     36913606 :           || sanitize_flags_p (SANITIZE_UNREACHABLE, fndecl)))
    2715              :     return;
    2716              : 
    2717     36917510 :   tree t = DECL_SAVED_TREE (fndecl);
    2718     63830844 :   while (t)
    2719              :     {
    2720     63830844 :       switch (TREE_CODE (t))
    2721              :         {
    2722      4928097 :         case BIND_EXPR:
    2723      4928097 :           t = BIND_EXPR_BODY (t);
    2724      4928097 :           continue;
    2725      9076729 :         case TRY_FINALLY_EXPR:
    2726      9076729 :         case CLEANUP_POINT_EXPR:
    2727      9076729 :           t = TREE_OPERAND (t, 0);
    2728      9076729 :           continue;
    2729     12911315 :         case STATEMENT_LIST:
    2730     12911315 :           {
    2731     12911315 :             tree_stmt_iterator i = tsi_last (t);
    2732     12915006 :             while (!tsi_end_p (i))
    2733              :               {
    2734     12912199 :                 tree p = tsi_stmt (i);
    2735     12912199 :                 if (TREE_CODE (p) != DEBUG_BEGIN_STMT)
    2736              :                   break;
    2737         3691 :                 tsi_prev (&i);
    2738              :               }
    2739     12911315 :             if (!tsi_end_p (i))
    2740              :               {
    2741     12908508 :                 t = tsi_stmt (i);
    2742     12908508 :                 continue;
    2743              :               }
    2744              :           }
    2745         2807 :           break;
    2746              :         case RETURN_EXPR:
    2747              :           return;
    2748              :         default:
    2749              :           break;
    2750     14004826 :         }
    2751              :       break;
    2752              :     }
    2753     20279030 :   if (t == NULL_TREE)
    2754              :     return;
    2755     20279030 :   tree *p = &DECL_SAVED_TREE (fndecl);
    2756     20279030 :   if (TREE_CODE (*p) == BIND_EXPR)
    2757       927944 :     p = &BIND_EXPR_BODY (*p);
    2758              : 
    2759     20279030 :   location_t loc = DECL_SOURCE_LOCATION (fndecl);
    2760     20279030 :   if (sanitize_flags_p (SANITIZE_RETURN, fndecl))
    2761         1807 :     t = ubsan_instrument_return (loc);
    2762              :   else
    2763     20277223 :     t = build_builtin_unreachable (BUILTINS_LOCATION);
    2764              : 
    2765     20279030 :   append_to_statement_list (t, p);
    2766              : }
    2767              : 
    2768              : void
    2769     67921533 : cp_genericize (tree fndecl)
    2770              : {
    2771     67921533 :   tree t;
    2772              : 
    2773              :   /* Fix up the types of parms passed by invisible reference.  */
    2774    179851941 :   for (t = DECL_ARGUMENTS (fndecl); t; t = DECL_CHAIN (t))
    2775    111930408 :     if (TREE_ADDRESSABLE (TREE_TYPE (t)))
    2776              :       {
    2777              :         /* If a function's arguments are copied to create a thunk,
    2778              :            then DECL_BY_REFERENCE will be set -- but the type of the
    2779              :            argument will be a pointer type, so we will never get
    2780              :            here.  */
    2781       132467 :         gcc_assert (!DECL_BY_REFERENCE (t));
    2782       132467 :         gcc_assert (DECL_ARG_TYPE (t) != TREE_TYPE (t));
    2783       132467 :         TREE_TYPE (t) = DECL_ARG_TYPE (t);
    2784       132467 :         DECL_BY_REFERENCE (t) = 1;
    2785       132467 :         TREE_ADDRESSABLE (t) = 0;
    2786       132467 :         relayout_decl (t);
    2787              :       }
    2788              : 
    2789              :   /* Do the same for the return value.  */
    2790     67921533 :   if (TREE_ADDRESSABLE (TREE_TYPE (DECL_RESULT (fndecl))))
    2791              :     {
    2792      1153228 :       t = DECL_RESULT (fndecl);
    2793      1153228 :       TREE_TYPE (t) = build_reference_type (TREE_TYPE (t));
    2794      1153228 :       DECL_BY_REFERENCE (t) = 1;
    2795      1153228 :       TREE_ADDRESSABLE (t) = 0;
    2796      1153228 :       relayout_decl (t);
    2797      1153228 :       if (DECL_NAME (t))
    2798              :         {
    2799              :           /* Adjust DECL_VALUE_EXPR of the original var.  */
    2800       128354 :           tree outer = outer_curly_brace_block (current_function_decl);
    2801       128354 :           tree var;
    2802              : 
    2803       128354 :           if (outer)
    2804       300344 :             for (var = BLOCK_VARS (outer); var; var = DECL_CHAIN (var))
    2805       299616 :               if (VAR_P (var)
    2806       289531 :                   && DECL_NAME (t) == DECL_NAME (var)
    2807       127626 :                   && DECL_HAS_VALUE_EXPR_P (var)
    2808       427242 :                   && DECL_VALUE_EXPR (var) == t)
    2809              :                 {
    2810       127626 :                   tree val = convert_from_reference (t);
    2811       127626 :                   SET_DECL_VALUE_EXPR (var, val);
    2812       127626 :                   break;
    2813              :                 }
    2814              :         }
    2815              :     }
    2816              : 
    2817              :   /* If we're a clone, the body is already GIMPLE.  */
    2818     67921533 :   if (DECL_CLONED_FUNCTION_P (fndecl))
    2819     16478423 :     return;
    2820              : 
    2821              :   /* Allow cp_genericize calls to be nested.  */
    2822     51443110 :   bc_state_t save_state;
    2823     51443110 :   save_bc_state (&save_state);
    2824              : 
    2825              :   /* We do want to see every occurrence of the parms, so we can't just use
    2826              :      walk_tree's hash functionality.  */
    2827     51443110 :   cp_genericize_tree (&DECL_SAVED_TREE (fndecl), true);
    2828              : 
    2829     51443110 :   cp_maybe_instrument_return (fndecl);
    2830              : 
    2831              :   /* Do everything else.  */
    2832     51443110 :   c_genericize (fndecl);
    2833     51443110 :   restore_bc_state (&save_state);
    2834              : }
    2835              : 
    2836              : /* Build code to apply FN to each member of ARG1 and ARG2.  FN may be
    2837              :    NULL if there is in fact nothing to do.  ARG2 may be null if FN
    2838              :    actually only takes one argument.  */
    2839              : 
    2840              : static tree
    2841         3722 : cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
    2842              : {
    2843         3722 :   tree defparm, parm, t;
    2844         3722 :   int i = 0;
    2845         3722 :   int nargs;
    2846         3722 :   tree *argarray;
    2847              : 
    2848         3722 :   if (fn == NULL)
    2849              :     return NULL;
    2850              : 
    2851         2848 :   nargs = list_length (DECL_ARGUMENTS (fn));
    2852         2848 :   argarray = XALLOCAVEC (tree, nargs);
    2853              : 
    2854         2848 :   defparm = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)));
    2855         2848 :   if (arg2)
    2856          944 :     defparm = TREE_CHAIN (defparm);
    2857              : 
    2858         2848 :   bool is_method = TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE;
    2859         2848 :   if (TREE_CODE (TREE_TYPE (arg1)) == ARRAY_TYPE)
    2860              :     {
    2861           27 :       tree inner_type = TREE_TYPE (arg1);
    2862           27 :       tree start1, end1, p1;
    2863           27 :       tree start2 = NULL, p2 = NULL;
    2864           27 :       tree ret = NULL, lab;
    2865              : 
    2866           27 :       start1 = arg1;
    2867           27 :       start2 = arg2;
    2868           27 :       do
    2869              :         {
    2870           27 :           inner_type = TREE_TYPE (inner_type);
    2871           27 :           start1 = build4 (ARRAY_REF, inner_type, start1,
    2872              :                            size_zero_node, NULL, NULL);
    2873           27 :           if (arg2)
    2874            9 :             start2 = build4 (ARRAY_REF, inner_type, start2,
    2875              :                              size_zero_node, NULL, NULL);
    2876              :         }
    2877           27 :       while (TREE_CODE (inner_type) == ARRAY_TYPE);
    2878           27 :       start1 = build_fold_addr_expr_loc (input_location, start1);
    2879           27 :       if (arg2)
    2880            9 :         start2 = build_fold_addr_expr_loc (input_location, start2);
    2881              : 
    2882           27 :       end1 = TYPE_SIZE_UNIT (TREE_TYPE (arg1));
    2883           27 :       end1 = fold_build_pointer_plus (start1, end1);
    2884              : 
    2885           27 :       p1 = create_tmp_var (TREE_TYPE (start1));
    2886           27 :       t = build2 (MODIFY_EXPR, TREE_TYPE (p1), p1, start1);
    2887           27 :       append_to_statement_list (t, &ret);
    2888              : 
    2889           27 :       if (arg2)
    2890              :         {
    2891            9 :           p2 = create_tmp_var (TREE_TYPE (start2));
    2892            9 :           t = build2 (MODIFY_EXPR, TREE_TYPE (p2), p2, start2);
    2893            9 :           append_to_statement_list (t, &ret);
    2894              :         }
    2895              : 
    2896           27 :       lab = create_artificial_label (input_location);
    2897           27 :       t = build1 (LABEL_EXPR, void_type_node, lab);
    2898           27 :       append_to_statement_list (t, &ret);
    2899              : 
    2900           27 :       argarray[i++] = p1;
    2901           27 :       if (arg2)
    2902            9 :         argarray[i++] = p2;
    2903              :       /* Handle default arguments.  */
    2904           27 :       for (parm = defparm; parm && parm != void_list_node;
    2905            0 :            parm = TREE_CHAIN (parm), i++)
    2906            0 :         argarray[i] = convert_default_arg (TREE_VALUE (parm),
    2907            0 :                                            TREE_PURPOSE (parm), fn,
    2908              :                                            i - is_method, tf_warning_or_error);
    2909           27 :       t = build_call_a (fn, i, argarray);
    2910           27 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (t)))
    2911            0 :         t = build_cplus_new (TREE_TYPE (t), t, tf_warning_or_error);
    2912           27 :       t = fold_convert (void_type_node, t);
    2913           27 :       t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    2914           27 :       append_to_statement_list (t, &ret);
    2915              : 
    2916           27 :       t = fold_build_pointer_plus (p1, TYPE_SIZE_UNIT (inner_type));
    2917           27 :       t = build2 (MODIFY_EXPR, TREE_TYPE (p1), p1, t);
    2918           27 :       append_to_statement_list (t, &ret);
    2919              : 
    2920           27 :       if (arg2)
    2921              :         {
    2922            9 :           t = fold_build_pointer_plus (p2, TYPE_SIZE_UNIT (inner_type));
    2923            9 :           t = build2 (MODIFY_EXPR, TREE_TYPE (p2), p2, t);
    2924            9 :           append_to_statement_list (t, &ret);
    2925              :         }
    2926              : 
    2927           27 :       t = build2 (NE_EXPR, boolean_type_node, p1, end1);
    2928           27 :       t = build3 (COND_EXPR, void_type_node, t, build_and_jump (&lab), NULL);
    2929           27 :       append_to_statement_list (t, &ret);
    2930              : 
    2931           27 :       return ret;
    2932              :     }
    2933              :   else
    2934              :     {
    2935         2821 :       argarray[i++] = build_fold_addr_expr_loc (input_location, arg1);
    2936         2821 :       if (arg2)
    2937          935 :         argarray[i++] = build_fold_addr_expr_loc (input_location, arg2);
    2938              :       /* Handle default arguments.  */
    2939         2826 :       for (parm = defparm; parm && parm != void_list_node;
    2940            5 :            parm = TREE_CHAIN (parm), i++)
    2941           10 :         argarray[i] = convert_default_arg (TREE_VALUE (parm),
    2942            5 :                                            TREE_PURPOSE (parm), fn,
    2943              :                                            i - is_method, tf_warning_or_error);
    2944         2821 :       t = build_call_a (fn, i, argarray);
    2945         2821 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (t)))
    2946            1 :         t = build_cplus_new (TREE_TYPE (t), t, tf_warning_or_error);
    2947         2821 :       t = fold_convert (void_type_node, t);
    2948         2821 :       return fold_build_cleanup_point_expr (TREE_TYPE (t), t);
    2949              :     }
    2950              : }
    2951              : 
    2952              : /* Return code to initialize DECL with its default constructor, or
    2953              :    NULL if there's nothing to do.  */
    2954              : 
    2955              : tree
    2956        46055 : cxx_omp_clause_default_ctor (tree clause, tree decl, tree /*outer*/)
    2957              : {
    2958        46055 :   tree info = CP_OMP_CLAUSE_INFO (clause);
    2959        46055 :   tree ret = NULL;
    2960              : 
    2961        46055 :   if (info)
    2962         1433 :     ret = cxx_omp_clause_apply_fn (TREE_VEC_ELT (info, 0), decl, NULL);
    2963              : 
    2964        46055 :   return ret;
    2965              : }
    2966              : 
    2967              : /* Return code to initialize DST with a copy constructor from SRC.  */
    2968              : 
    2969              : tree
    2970        12627 : cxx_omp_clause_copy_ctor (tree clause, tree dst, tree src)
    2971              : {
    2972        12627 :   tree info = CP_OMP_CLAUSE_INFO (clause);
    2973        12627 :   tree ret = NULL;
    2974              : 
    2975        12627 :   if (info)
    2976          284 :     ret = cxx_omp_clause_apply_fn (TREE_VEC_ELT (info, 0), dst, src);
    2977          284 :   if (ret == NULL)
    2978        12409 :     ret = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
    2979              : 
    2980        12627 :   return ret;
    2981              : }
    2982              : 
    2983              : /* Similarly, except use an assignment operator instead.  */
    2984              : 
    2985              : tree
    2986        13163 : cxx_omp_clause_assign_op (tree clause, tree dst, tree src)
    2987              : {
    2988        13163 :   tree info = CP_OMP_CLAUSE_INFO (clause);
    2989        13163 :   tree ret = NULL;
    2990              : 
    2991        13163 :   if (info)
    2992          748 :     ret = cxx_omp_clause_apply_fn (TREE_VEC_ELT (info, 2), dst, src);
    2993          748 :   if (ret == NULL)
    2994        12437 :     ret = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
    2995              : 
    2996        13163 :   return ret;
    2997              : }
    2998              : 
    2999              : /* Return code to destroy DECL.  */
    3000              : 
    3001              : tree
    3002        67921 : cxx_omp_clause_dtor (tree clause, tree decl)
    3003              : {
    3004        67921 :   tree info = CP_OMP_CLAUSE_INFO (clause);
    3005        67921 :   tree ret = NULL;
    3006              : 
    3007        67921 :   if (info)
    3008         1257 :     ret = cxx_omp_clause_apply_fn (TREE_VEC_ELT (info, 1), decl, NULL);
    3009              : 
    3010        67921 :   return ret;
    3011              : }
    3012              : 
    3013              : /* True if OpenMP should privatize what this DECL points to rather
    3014              :    than the DECL itself.  */
    3015              : 
    3016              : bool
    3017      1014384 : cxx_omp_privatize_by_reference (const_tree decl)
    3018              : {
    3019      1014384 :   return (TYPE_REF_P (TREE_TYPE (decl))
    3020      1014384 :           || is_invisiref_parm (decl));
    3021              : }
    3022              : 
    3023              : /* Return true if DECL is const qualified var having no mutable member.  */
    3024              : bool
    3025        15936 : cxx_omp_const_qual_no_mutable (tree decl)
    3026              : {
    3027        15936 :   tree type = TREE_TYPE (decl);
    3028        15936 :   if (TYPE_REF_P (type))
    3029              :     {
    3030          897 :       if (!is_invisiref_parm (decl))
    3031              :         return false;
    3032            0 :       type = TREE_TYPE (type);
    3033              : 
    3034            0 :       if (TREE_CODE (decl) == RESULT_DECL && DECL_NAME (decl))
    3035              :         {
    3036              :           /* NVR doesn't preserve const qualification of the
    3037              :              variable's type.  */
    3038            0 :           tree outer = outer_curly_brace_block (current_function_decl);
    3039            0 :           tree var;
    3040              : 
    3041            0 :           if (outer)
    3042            0 :             for (var = BLOCK_VARS (outer); var; var = DECL_CHAIN (var))
    3043            0 :               if (VAR_P (var)
    3044            0 :                   && DECL_NAME (decl) == DECL_NAME (var)
    3045            0 :                   && (TYPE_MAIN_VARIANT (type)
    3046            0 :                       == TYPE_MAIN_VARIANT (TREE_TYPE (var))))
    3047              :                 {
    3048            0 :                   if (TYPE_READONLY (TREE_TYPE (var)))
    3049            0 :                     type = TREE_TYPE (var);
    3050              :                   break;
    3051              :                 }
    3052              :         }
    3053              :     }
    3054              : 
    3055        15039 :   if (type == error_mark_node)
    3056              :     return false;
    3057              : 
    3058              :   /* Variables with const-qualified type having no mutable member
    3059              :      are predetermined shared.  */
    3060        15024 :   if (TYPE_READONLY (type) && !cp_has_mutable_p (type))
    3061           69 :     return true;
    3062              : 
    3063              :   return false;
    3064              : }
    3065              : 
    3066              : /* OMP_CLAUSE_DEFAULT_UNSPECIFIED unless OpenMP sharing attribute
    3067              :    of DECL is predetermined.  */
    3068              : 
    3069              : enum omp_clause_default_kind
    3070        57452 : cxx_omp_predetermined_sharing_1 (tree decl)
    3071              : {
    3072              :   /* Static data members are predetermined shared.  */
    3073        57452 :   if (TREE_STATIC (decl))
    3074              :     {
    3075        15850 :       tree ctx = CP_DECL_CONTEXT (decl);
    3076        15850 :       if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
    3077              :         return OMP_CLAUSE_DEFAULT_SHARED;
    3078              : 
    3079        15744 :       if (c_omp_predefined_variable (decl))
    3080              :         return OMP_CLAUSE_DEFAULT_SHARED;
    3081              :     }
    3082              : 
    3083              :   /* this may not be specified in data-sharing clauses, still we need
    3084              :      to predetermined it firstprivate.  */
    3085        57301 :   if (decl == current_class_ptr)
    3086          113 :     return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
    3087              : 
    3088              :   return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
    3089              : }
    3090              : 
    3091              : /* Likewise, but also include the artificial vars.  We don't want to
    3092              :    disallow the artificial vars being mentioned in explicit clauses,
    3093              :    as we use artificial vars e.g. for loop constructs with random
    3094              :    access iterators other than pointers, but during gimplification
    3095              :    we want to treat them as predetermined.  */
    3096              : 
    3097              : enum omp_clause_default_kind
    3098        36029 : cxx_omp_predetermined_sharing (tree decl)
    3099              : {
    3100        36029 :   enum omp_clause_default_kind ret = cxx_omp_predetermined_sharing_1 (decl);
    3101        36029 :   if (ret != OMP_CLAUSE_DEFAULT_UNSPECIFIED)
    3102              :     return ret;
    3103              : 
    3104              :   /* Predetermine artificial variables holding integral values, those
    3105              :      are usually result of gimplify_one_sizepos or SAVE_EXPR
    3106              :      gimplification.  */
    3107        35812 :   if (VAR_P (decl)
    3108        23773 :       && DECL_ARTIFICIAL (decl)
    3109         7289 :       && INTEGRAL_TYPE_P (TREE_TYPE (decl))
    3110        36420 :       && !(DECL_LANG_SPECIFIC (decl)
    3111            2 :            && DECL_OMP_PRIVATIZED_MEMBER (decl)))
    3112              :     return OMP_CLAUSE_DEFAULT_SHARED;
    3113              : 
    3114              :   /* Similarly for typeinfo symbols.  */
    3115        35206 :   if (VAR_P (decl) && DECL_ARTIFICIAL (decl) && DECL_TINFO_P (decl))
    3116           60 :     return OMP_CLAUSE_DEFAULT_SHARED;
    3117              : 
    3118              :   return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
    3119              : }
    3120              : 
    3121              : enum omp_clause_defaultmap_kind
    3122        17693 : cxx_omp_predetermined_mapping (tree decl)
    3123              : {
    3124              :   /* Predetermine artificial variables holding integral values, those
    3125              :      are usually result of gimplify_one_sizepos or SAVE_EXPR
    3126              :      gimplification.  */
    3127        17693 :   if (VAR_P (decl)
    3128         1701 :       && DECL_ARTIFICIAL (decl)
    3129          142 :       && INTEGRAL_TYPE_P (TREE_TYPE (decl))
    3130        17759 :       && !(DECL_LANG_SPECIFIC (decl)
    3131            6 :            && DECL_OMP_PRIVATIZED_MEMBER (decl)))
    3132              :     return OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE;
    3133              : 
    3134        17627 :   if (c_omp_predefined_variable (decl))
    3135           12 :     return OMP_CLAUSE_DEFAULTMAP_TO;
    3136              : 
    3137              :   return OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED;
    3138              : }
    3139              : 
    3140              : /* Finalize an implicitly determined clause.  */
    3141              : 
    3142              : void
    3143        67078 : cxx_omp_finish_clause (tree c, gimple_seq *, bool /* openacc */)
    3144              : {
    3145        67078 :   tree decl, inner_type;
    3146        67078 :   bool make_shared = false;
    3147              : 
    3148        67078 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
    3149        59526 :       && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_PRIVATE
    3150        98562 :       && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LASTPRIVATE
    3151         4944 :           || !OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)))
    3152              :     return;
    3153              : 
    3154        35609 :   decl = OMP_CLAUSE_DECL (c);
    3155        35609 :   decl = require_complete_type (decl);
    3156        35609 :   inner_type = TREE_TYPE (decl);
    3157        35609 :   if (decl == error_mark_node)
    3158        35609 :     make_shared = true;
    3159        35609 :   else if (TYPE_REF_P (TREE_TYPE (decl)))
    3160           86 :     inner_type = TREE_TYPE (inner_type);
    3161              : 
    3162              :   /* We're interested in the base element, not arrays.  */
    3163        35879 :   while (TREE_CODE (inner_type) == ARRAY_TYPE)
    3164          270 :     inner_type = TREE_TYPE (inner_type);
    3165              : 
    3166              :   /* Check for special function availability by building a call to one.
    3167              :      Save the results, because later we won't be in the right context
    3168              :      for making these queries.  */
    3169        35609 :   bool first = OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE;
    3170        35609 :   bool last = OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE;
    3171        35609 :   if (!make_shared
    3172        35609 :       && CLASS_TYPE_P (inner_type)
    3173        35833 :       && cxx_omp_create_clause_info (c, inner_type, !first, first, last,
    3174              :                                      true))
    3175              :     make_shared = true;
    3176              : 
    3177        35603 :   if (make_shared)
    3178              :     {
    3179            6 :       OMP_CLAUSE_CODE (c) = OMP_CLAUSE_SHARED;
    3180            6 :       OMP_CLAUSE_SHARED_FIRSTPRIVATE (c) = 0;
    3181            6 :       OMP_CLAUSE_SHARED_READONLY (c) = 0;
    3182              :     }
    3183              : }
    3184              : 
    3185              : tree
    3186           38 : cxx_omp_finish_mapper_clauses (tree clauses)
    3187              : {
    3188           38 :   return finish_omp_clauses (clauses, C_ORT_OMP);
    3189              : }
    3190              : 
    3191              : /* Return true if DECL's DECL_VALUE_EXPR (if any) should be
    3192              :    disregarded in OpenMP construct, because it is going to be
    3193              :    remapped during OpenMP lowering.  SHARED is true if DECL
    3194              :    is going to be shared, false if it is going to be privatized.  */
    3195              : 
    3196              : bool
    3197       694010 : cxx_omp_disregard_value_expr (tree decl, bool shared)
    3198              : {
    3199       694010 :   if (shared)
    3200              :     return false;
    3201       419809 :   if (VAR_P (decl)
    3202       396862 :       && DECL_HAS_VALUE_EXPR_P (decl)
    3203        10124 :       && DECL_ARTIFICIAL (decl)
    3204         9094 :       && DECL_LANG_SPECIFIC (decl)
    3205       427760 :       && DECL_OMP_PRIVATIZED_MEMBER (decl))
    3206              :     return true;
    3207       414396 :   if (VAR_P (decl) && DECL_CONTEXT (decl) && is_capture_proxy (decl))
    3208              :     return true;
    3209              :   return false;
    3210              : }
    3211              : 
    3212              : /* Fold any non-ODR-usages of a constant variable in expression X.  */
    3213              : 
    3214              : static tree
    3215    585604368 : cp_fold_non_odr_use_1 (tree x)
    3216              : {
    3217    585604368 :   tree var = x;
    3218    883116848 :   while (!VAR_P (var))
    3219    807736176 :     switch (TREE_CODE (var))
    3220              :       {
    3221    285426845 :       case ARRAY_REF:
    3222    285426845 :       case BIT_FIELD_REF:
    3223    285426845 :       case COMPONENT_REF:
    3224    285426845 :       case VIEW_CONVERT_EXPR:
    3225    285426845 :       CASE_CONVERT:
    3226    285426845 :         var = TREE_OPERAND (var, 0);
    3227    285426845 :         break;
    3228              : 
    3229     28628784 :       case INDIRECT_REF:
    3230     28628784 :         if (REFERENCE_REF_P (var))
    3231     12085635 :           var = TREE_OPERAND (var, 0);
    3232              :         else
    3233              :           return x;
    3234     12085635 :         break;
    3235              : 
    3236              :       default:
    3237              :         return x;
    3238              :       }
    3239              : 
    3240     75380672 :   if (TREE_THIS_VOLATILE (var)
    3241     75380672 :       || !decl_constant_var_p (var))
    3242              :     return x;
    3243              : 
    3244              :   /* We mustn't fold std::hardware_destructive_interference_size here
    3245              :      so that maybe_warn_about_constant_value can complain if it's used
    3246              :      in a manifestly constant-evaluated context.  */
    3247      5814150 :   if (decl_in_std_namespace_p (var)
    3248      2774206 :       && DECL_NAME (var)
    3249      8588356 :       && id_equal (DECL_NAME (var), "hardware_destructive_interference_size"))
    3250              :     return x;
    3251              : 
    3252      5814150 :   tree t = maybe_constant_value (x);
    3253      5814150 :   return TREE_CONSTANT (t) ? t : x;
    3254              : }
    3255              : 
    3256              : /* Fold expression X which is used as an rvalue if RVAL is true.  */
    3257              : 
    3258              : static tree
    3259   2587369377 : cp_fold_maybe_rvalue (tree x, bool rval, fold_flags_t flags)
    3260              : {
    3261   2608280711 :   while (true)
    3262              :     {
    3263   2597825044 :       if (rval && (flags & ff_only_non_odr))
    3264    568785171 :         x = cp_fold_non_odr_use_1 (x);
    3265   2597825044 :       x = cp_fold (x, flags);
    3266   2597825044 :       if (rval)
    3267              :         {
    3268   1735369020 :           x = mark_rvalue_use (x);
    3269   1735369020 :           if (!(flags & ff_only_non_odr)
    3270   1735369020 :               && DECL_P (x) && !TYPE_REF_P (TREE_TYPE (x)))
    3271              :             {
    3272    261058547 :               tree v = decl_constant_value (x);
    3273    261058547 :               if (v != x && v != error_mark_node)
    3274              :                 {
    3275     10455667 :                   x = v;
    3276     10455667 :                   continue;
    3277              :                 }
    3278              :             }
    3279              :         }
    3280   2587369377 :       break;
    3281     10455667 :     }
    3282   2587369377 :   return x;
    3283              : }
    3284              : 
    3285              : tree
    3286     76485976 : cp_fold_maybe_rvalue (tree x, bool rval)
    3287              : {
    3288     76485976 :   return cp_fold_maybe_rvalue (x, rval, ff_none);
    3289              : }
    3290              : 
    3291              : /* Fold expression X which is used as an rvalue.  */
    3292              : 
    3293              : static tree
    3294    274559277 : cp_fold_rvalue (tree x, fold_flags_t flags)
    3295              : {
    3296     10209622 :   return cp_fold_maybe_rvalue (x, true, flags);
    3297              : }
    3298              : 
    3299              : tree
    3300      2161355 : cp_fold_rvalue (tree x)
    3301              : {
    3302      2161355 :   return cp_fold_rvalue (x, ff_none);
    3303              : }
    3304              : 
    3305              : /* Fold any non-ODR used constants in an expression X which
    3306              :    is used as an rvalue if RVAL is true.  */
    3307              : 
    3308              : tree
    3309       736471 : cp_fold_non_odr_use (tree x, bool rval)
    3310              : {
    3311       736471 :   return cp_fold_maybe_rvalue (x, rval, ff_only_non_odr);
    3312              : }
    3313              : 
    3314              : /* Perform folding on expression X.  */
    3315              : 
    3316              : static tree
    3317    288004495 : cp_fully_fold (tree x, mce_value manifestly_const_eval)
    3318              : {
    3319    288004495 :   if (processing_template_decl)
    3320              :     return x;
    3321              :   /* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't
    3322              :      have to call both.  */
    3323    262188300 :   if (cxx_dialect >= cxx11)
    3324              :     {
    3325    261140728 :       x = maybe_constant_value (x, /*decl=*/NULL_TREE, manifestly_const_eval);
    3326              :       /* Sometimes we are given a CONSTRUCTOR but the call above wraps it into
    3327              :          a TARGET_EXPR; undo that here.  */
    3328    261140728 :       if (TREE_CODE (x) == TARGET_EXPR)
    3329       681153 :         x = TARGET_EXPR_INITIAL (x);
    3330    260459575 :       else if (TREE_CODE (x) == VIEW_CONVERT_EXPR
    3331     27728147 :                && TREE_CODE (TREE_OPERAND (x, 0)) == CONSTRUCTOR
    3332    260459764 :                && TREE_TYPE (TREE_OPERAND (x, 0)) == TREE_TYPE (x))
    3333          189 :         x = TREE_OPERAND (x, 0);
    3334              :     }
    3335    262188300 :   fold_flags_t flags = ff_none;
    3336    262188300 :   if (manifestly_const_eval == mce_false)
    3337     45224995 :     flags |= ff_mce_false;
    3338    262188300 :   return cp_fold_rvalue (x, flags);
    3339              : }
    3340              : 
    3341              : tree
    3342    242779500 : cp_fully_fold (tree x)
    3343              : {
    3344    242779500 :   return cp_fully_fold (x, mce_unknown);
    3345              : }
    3346              : 
    3347              : /* Likewise, but also fold recursively, which cp_fully_fold doesn't perform
    3348              :    in some cases.  */
    3349              : 
    3350              : tree
    3351     47589423 : cp_fully_fold_init (tree x)
    3352              : {
    3353     47589423 :   if (processing_template_decl)
    3354      2364428 :     return x;
    3355     45224995 :   x = cp_fully_fold (x, mce_false);
    3356     45224995 :   cp_fold_data data (ff_mce_false);
    3357     45224995 :   if (cxx_dialect >= cxx20)
    3358              :     {
    3359     44591001 :       cp_walk_tree (&x, cp_fold_immediate_r, &data, NULL);
    3360     44591001 :       data.pset.empty ();
    3361              :     }
    3362     45224995 :   cp_walk_tree (&x, cp_fold_r, &data, NULL);
    3363     45224995 :   return x;
    3364     45224995 : }
    3365              : 
    3366              : /* c-common interface to cp_fold.  If IN_INIT, this is in a static initializer
    3367              :    and certain changes are made to the folding done.  Or should be (FIXME).  We
    3368              :    never touch maybe_const, as it is only used for the C front-end
    3369              :    C_MAYBE_CONST_EXPR.  */
    3370              : 
    3371              : tree
    3372     76485976 : c_fully_fold (tree x, bool /*in_init*/, bool */*maybe_const*/, bool lval)
    3373              : {
    3374     76485976 :   return cp_fold_maybe_rvalue (x, !lval);
    3375              : }
    3376              : 
    3377              : static GTY((deletable)) hash_map<tree, tree> *fold_caches[3];
    3378              : 
    3379              : /* Subroutine of cp_fold.  Returns which fold cache to use according
    3380              :    to the given flags.  We need multiple caches since the result of
    3381              :    folding may depend on which flags are used.  */
    3382              : 
    3383              : static hash_map<tree, tree> *&
    3384   4785433214 : get_fold_cache (fold_flags_t flags)
    3385              : {
    3386            0 :   if (flags & ff_mce_false)
    3387   2154221637 :     return fold_caches[2];
    3388   2631211577 :   else if (flags & ff_only_non_odr)
    3389   2266050199 :     return fold_caches[1];
    3390              :   else
    3391    365161378 :     return fold_caches[0];
    3392              : }
    3393              : 
    3394              : /* Dispose of the whole FOLD_CACHE.  */
    3395              : 
    3396              : void
    3397     40663383 : clear_fold_cache (void)
    3398              : {
    3399    162653532 :   for (auto& fold_cache : fold_caches)
    3400    121990149 :     if (fold_cache != NULL)
    3401    146057675 :       fold_cache->empty ();
    3402     40663383 : }
    3403              : 
    3404              : /*  This function tries to fold an expression X.
    3405              :     To avoid combinatorial explosion, folding results are kept in fold_cache.
    3406              :     If X is invalid, we don't fold at all.
    3407              :     For performance reasons we don't cache expressions representing a
    3408              :     declaration or constant.
    3409              :     Function returns X or its folded variant.  */
    3410              : 
    3411              : static tree
    3412   7792046395 : cp_fold (tree x, fold_flags_t flags)
    3413              : {
    3414   7792046395 :   tree op0, op1, op2, op3;
    3415   7792046395 :   tree org_x = x, r = NULL_TREE;
    3416   7792046395 :   enum tree_code code;
    3417   7792046395 :   location_t loc;
    3418   7792046395 :   bool rval_ops = true;
    3419              : 
    3420   7792046395 :   if (!x || x == error_mark_node)
    3421              :     return x;
    3422              : 
    3423   7785542122 :   if (EXPR_P (x) && (!TREE_TYPE (x) || TREE_TYPE (x) == error_mark_node))
    3424              :     return x;
    3425              : 
    3426              :   /* Don't bother to cache DECLs or constants.  */
    3427   7785241236 :   if (DECL_P (x) || CONSTANT_CLASS_P (x))
    3428              :     return x;
    3429              : 
    3430   4785433214 :   auto& fold_cache = get_fold_cache (flags);
    3431   4785433214 :   if (fold_cache == NULL)
    3432       518778 :     fold_cache = hash_map<tree, tree>::create_ggc (101);
    3433              : 
    3434   4785433214 :   if (tree *cached = fold_cache->get (x))
    3435              :     {
    3436              :       /* unshare_expr doesn't recurse into SAVE_EXPRs.  If SAVE_EXPR's
    3437              :          argument has been folded into a tree invariant, make sure it is
    3438              :          unshared.  See PR112727.  */
    3439   1098412058 :       if (TREE_CODE (x) == SAVE_EXPR && *cached != x)
    3440           89 :         return unshare_expr (*cached);
    3441   1098411969 :       return *cached;
    3442              :     }
    3443              : 
    3444   3687021156 :   uid_sensitive_constexpr_evaluation_checker c;
    3445              : 
    3446   3687021156 :   code = TREE_CODE (x);
    3447   3687021156 :   switch (code)
    3448              :     {
    3449    209623038 :     case CLEANUP_POINT_EXPR:
    3450              :       /* Strip CLEANUP_POINT_EXPR if the expression doesn't have side
    3451              :          effects.  */
    3452    209623038 :       r = cp_fold (TREE_OPERAND (x, 0), flags);
    3453    209623038 :       if (!TREE_SIDE_EFFECTS (r) && !(flags & ff_only_non_odr))
    3454      2380274 :         x = r;
    3455              :       break;
    3456              : 
    3457      1695983 :     case SIZEOF_EXPR:
    3458      1695983 :       x = fold_sizeof_expr (x);
    3459      1695983 :       break;
    3460              : 
    3461    328702207 :     case VIEW_CONVERT_EXPR:
    3462    328702207 :       rval_ops = false;
    3463              :       /* FALLTHRU */
    3464   1011648064 :     case NON_LVALUE_EXPR:
    3465   1011648064 :     CASE_CONVERT:
    3466              : 
    3467   1011648064 :       if (VOID_TYPE_P (TREE_TYPE (x)))
    3468              :         {
    3469              :           /* This is just to make sure we don't end up with casts to
    3470              :              void from error_mark_node.  If we just return x, then
    3471              :              cp_fold_r might fold the operand into error_mark_node and
    3472              :              leave the conversion in the IR.  STRIP_USELESS_TYPE_CONVERSION
    3473              :              during gimplification doesn't like such casts.
    3474              :              Don't create a new tree if op0 != TREE_OPERAND (x, 0), the
    3475              :              folding of the operand should be in the caches and if in cp_fold_r
    3476              :              it will modify it in place.  */
    3477     92817160 :           op0 = cp_fold (TREE_OPERAND (x, 0), flags);
    3478     92817160 :           if (op0 == error_mark_node)
    3479          119 :             x = error_mark_node;
    3480              :           break;
    3481              :         }
    3482              : 
    3483    918830904 :       loc = EXPR_LOCATION (x);
    3484    918830904 :       op0 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 0), rval_ops, flags);
    3485              : 
    3486    918830904 :       if (op0 == error_mark_node)
    3487            3 :         x = error_mark_node;
    3488    918830901 :       else if (flags & ff_only_non_odr)
    3489              :         {
    3490    341877547 :           if (op0 != TREE_OPERAND (x, 0))
    3491      2084687 :             x = build1_loc (loc, code, TREE_TYPE (x), op0);
    3492    341877547 :           if (code == NOP_EXPR)
    3493    174419467 :             REINTERPRET_CAST_P (x) = REINTERPRET_CAST_P (org_x);
    3494              :         }
    3495    576953354 :       else if (code == CONVERT_EXPR
    3496     45625399 :           && SCALAR_TYPE_P (TREE_TYPE (x))
    3497    622577653 :           && op0 != void_node)
    3498              :         /* During parsing we used convert_to_*_nofold; re-convert now using the
    3499              :            folding variants, since fold() doesn't do those transformations.  */
    3500     41231486 :         x = fold (convert (TREE_TYPE (x), op0));
    3501    535721868 :       else if (op0 != TREE_OPERAND (x, 0))
    3502    142438389 :         x = fold_build1_loc (loc, code, TREE_TYPE (x), op0);
    3503              :       else
    3504    393283479 :         x = fold (x);
    3505              : 
    3506              :       /* Conversion of an out-of-range value has implementation-defined
    3507              :          behavior; the language considers it different from arithmetic
    3508              :          overflow, which is undefined.  */
    3509    918830904 :       if (TREE_CODE (op0) == INTEGER_CST
    3510    918830904 :           && TREE_OVERFLOW_P (x) && !TREE_OVERFLOW_P (op0))
    3511           44 :         TREE_OVERFLOW (x) = false;
    3512              : 
    3513              :       break;
    3514              : 
    3515          261 :     case EXCESS_PRECISION_EXPR:
    3516          261 :       op0 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 0), rval_ops, flags);
    3517          261 :       if (op0 == error_mark_node)
    3518            0 :         x = error_mark_node;
    3519          261 :       else if (flags & ff_only_non_odr)
    3520              :         {
    3521           67 :           if (op0 != TREE_OPERAND (x, 0))
    3522            0 :             x = build1_loc (EXPR_LOCATION (x), code, TREE_TYPE (x), op0);
    3523              :         }
    3524              :       else
    3525          194 :         x = fold_convert_loc (EXPR_LOCATION (x), TREE_TYPE (x), op0);
    3526              :       break;
    3527              : 
    3528    126478336 :     case INDIRECT_REF:
    3529              :       /* We don't need the decltype(auto) obfuscation anymore.  */
    3530    126478336 :       if (REF_PARENTHESIZED_P (x))
    3531              :         {
    3532          855 :           tree p = maybe_undo_parenthesized_ref (x);
    3533          855 :           if (p != x)
    3534            0 :             return cp_fold (p, flags);
    3535              :         }
    3536              :       /* When folding non-ODR usages of constants, we also want to
    3537              :          remove any constant-initialized references, even when
    3538              :          used as lvalues.  */
    3539    126478336 :       if ((flags & ff_only_non_odr) && REFERENCE_REF_P (x))
    3540              :         {
    3541     16819197 :           op0 = cp_fold_non_odr_use_1 (TREE_OPERAND (x, 0));
    3542     16819197 :           if (op0 != TREE_OPERAND (x, 0))
    3543         1575 :             return convert_from_reference (cp_fold (op0, flags));
    3544              :         }
    3545    126476761 :       goto unary;
    3546              : 
    3547    316850661 :     case ADDR_EXPR:
    3548    316850661 :       loc = EXPR_LOCATION (x);
    3549    316850661 :       op0 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 0), false, flags);
    3550              : 
    3551              :       /* Cope with user tricks that amount to offsetof.  */
    3552    316850661 :       if (op0 != error_mark_node
    3553    316850661 :           && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (op0))
    3554    434903424 :           && !(flags & ff_only_non_odr))
    3555              :         {
    3556     65497430 :           tree val = get_base_address (op0);
    3557     65497430 :           if (val
    3558     65497430 :               && INDIRECT_REF_P (val)
    3559     25398683 :               && COMPLETE_TYPE_P (TREE_TYPE (val))
    3560     90896023 :               && TREE_CONSTANT (TREE_OPERAND (val, 0)))
    3561              :             {
    3562          261 :               val = TREE_OPERAND (val, 0);
    3563          261 :               STRIP_NOPS (val);
    3564          261 :               val = maybe_constant_value (val);
    3565          261 :               if (TREE_CODE (val) == INTEGER_CST)
    3566          127 :                 return fold_offsetof (op0, TREE_TYPE (x));
    3567              :             }
    3568              :         }
    3569    316850534 :       goto finish_unary;
    3570              : 
    3571              :     case REALPART_EXPR:
    3572              :     case IMAGPART_EXPR:
    3573    169308387 :       rval_ops = false;
    3574              :       /* FALLTHRU */
    3575    169308387 :     case CONJ_EXPR:
    3576    169308387 :     case FIX_TRUNC_EXPR:
    3577    169308387 :     case FLOAT_EXPR:
    3578    169308387 :     case NEGATE_EXPR:
    3579    169308387 :     case ABS_EXPR:
    3580    169308387 :     case ABSU_EXPR:
    3581    169308387 :     case BIT_NOT_EXPR:
    3582    169308387 :     case TRUTH_NOT_EXPR:
    3583    169308387 :     case FIXED_CONVERT_EXPR:
    3584    169308387 :     unary:
    3585              : 
    3586    169308387 :       loc = EXPR_LOCATION (x);
    3587    169308387 :       op0 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 0), rval_ops, flags);
    3588              : 
    3589    486158921 :     finish_unary:
    3590    486158921 :       if (op0 == error_mark_node)
    3591            3 :         x = error_mark_node;
    3592    486158918 :       else if (op0 != TREE_OPERAND (x, 0))
    3593              :         {
    3594     31525895 :           if (flags & ff_only_non_odr)
    3595       419852 :             x = build1_loc (loc, code, TREE_TYPE (x), op0);
    3596              :           else
    3597     31106043 :             x = fold_build1_loc (loc, code, TREE_TYPE (x), op0);
    3598     31525895 :           if (code == INDIRECT_REF
    3599      9623421 :               && (INDIRECT_REF_P (x) || TREE_CODE (x) == MEM_REF))
    3600              :             {
    3601      9623216 :               TREE_READONLY (x) = TREE_READONLY (org_x);
    3602      9623216 :               TREE_SIDE_EFFECTS (x) = TREE_SIDE_EFFECTS (org_x);
    3603      9623216 :               TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x);
    3604              :             }
    3605              :         }
    3606    454633023 :       else if (!(flags & ff_only_non_odr))
    3607    224728564 :         x = fold (x);
    3608              : 
    3609    486158921 :       gcc_assert (TREE_CODE (x) != COND_EXPR
    3610              :                   || !VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))));
    3611              :       break;
    3612              : 
    3613       318076 :     case UNARY_PLUS_EXPR:
    3614       318076 :       op0 = cp_fold_rvalue (TREE_OPERAND (x, 0), flags);
    3615       318076 :       if (op0 == error_mark_node)
    3616            0 :         x = error_mark_node;
    3617       318076 :       else if (flags & ff_only_non_odr)
    3618              :         {
    3619       125740 :           if (op0 != TREE_OPERAND (x, 0))
    3620           12 :             x = build1_loc (EXPR_LOCATION (x), code, TREE_TYPE (x), op0);
    3621              :         }
    3622              :       else
    3623       192336 :         x = fold_convert (TREE_TYPE (x), op0);
    3624              :       break;
    3625              : 
    3626    199966891 :     case POSTDECREMENT_EXPR:
    3627    199966891 :     case POSTINCREMENT_EXPR:
    3628    199966891 :     case INIT_EXPR:
    3629    199966891 :     case PREDECREMENT_EXPR:
    3630    199966891 :     case PREINCREMENT_EXPR:
    3631    199966891 :     case COMPOUND_EXPR:
    3632    199966891 :     case MODIFY_EXPR:
    3633    199966891 :       rval_ops = false;
    3634              :       /* FALLTHRU */
    3635    415298720 :     case POINTER_PLUS_EXPR:
    3636    415298720 :     case PLUS_EXPR:
    3637    415298720 :     case POINTER_DIFF_EXPR:
    3638    415298720 :     case MINUS_EXPR:
    3639    415298720 :     case MULT_EXPR:
    3640    415298720 :     case TRUNC_DIV_EXPR:
    3641    415298720 :     case CEIL_DIV_EXPR:
    3642    415298720 :     case FLOOR_DIV_EXPR:
    3643    415298720 :     case ROUND_DIV_EXPR:
    3644    415298720 :     case TRUNC_MOD_EXPR:
    3645    415298720 :     case CEIL_MOD_EXPR:
    3646    415298720 :     case ROUND_MOD_EXPR:
    3647    415298720 :     case RDIV_EXPR:
    3648    415298720 :     case EXACT_DIV_EXPR:
    3649    415298720 :     case MIN_EXPR:
    3650    415298720 :     case MAX_EXPR:
    3651    415298720 :     case LSHIFT_EXPR:
    3652    415298720 :     case RSHIFT_EXPR:
    3653    415298720 :     case LROTATE_EXPR:
    3654    415298720 :     case RROTATE_EXPR:
    3655    415298720 :     case BIT_AND_EXPR:
    3656    415298720 :     case BIT_IOR_EXPR:
    3657    415298720 :     case BIT_XOR_EXPR:
    3658    415298720 :     case TRUTH_AND_EXPR:
    3659    415298720 :     case TRUTH_ANDIF_EXPR:
    3660    415298720 :     case TRUTH_OR_EXPR:
    3661    415298720 :     case TRUTH_ORIF_EXPR:
    3662    415298720 :     case TRUTH_XOR_EXPR:
    3663    415298720 :     case LT_EXPR: case LE_EXPR:
    3664    415298720 :     case GT_EXPR: case GE_EXPR:
    3665    415298720 :     case EQ_EXPR: case NE_EXPR:
    3666    415298720 :     case UNORDERED_EXPR: case ORDERED_EXPR:
    3667    415298720 :     case UNLT_EXPR: case UNLE_EXPR:
    3668    415298720 :     case UNGT_EXPR: case UNGE_EXPR:
    3669    415298720 :     case UNEQ_EXPR: case LTGT_EXPR:
    3670    415298720 :     case RANGE_EXPR: case COMPLEX_EXPR:
    3671              : 
    3672    415298720 :       loc = EXPR_LOCATION (x);
    3673    415298720 :       op0 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 0), rval_ops, flags);
    3674    415298720 :       bool clear_decl_read;
    3675    415298720 :       clear_decl_read = false;
    3676    415298720 :       if (code == MODIFY_EXPR
    3677     52260571 :           && (VAR_P (op0) || TREE_CODE (op0) == PARM_DECL)
    3678    430016028 :           && !DECL_READ_P (op0))
    3679              :         clear_decl_read = true;
    3680    415298720 :       op1 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 1),
    3681              :                                   code != COMPOUND_EXPR, flags);
    3682    415298720 :       if (clear_decl_read)
    3683       768970 :         DECL_READ_P (op0) = 0;
    3684              : 
    3685    415298720 :       if (flags & ff_only_non_odr)
    3686              :         {
    3687    180797572 :           if (op0 == error_mark_node || op1 == error_mark_node)
    3688           24 :             x = error_mark_node;
    3689    180797548 :           else if (op0 != TREE_OPERAND (x, 0) || op1 != TREE_OPERAND (x, 1))
    3690              :             {
    3691      7983009 :               if (code == INIT_EXPR && op1 != TREE_OPERAND (x, 1))
    3692      2503051 :                 set_target_expr_eliding (op1);
    3693      7983009 :               x = build2_loc (loc, code, TREE_TYPE (x), op0, op1);
    3694              :             }
    3695              :           break;
    3696              :         }
    3697              : 
    3698              :       /* decltype(nullptr) has only one value, so optimize away all comparisons
    3699              :          with that type right away, keeping them in the IL causes troubles for
    3700              :          various optimizations.  */
    3701    234501148 :       if (COMPARISON_CLASS_P (org_x)
    3702     38893342 :           && TREE_CODE (TREE_TYPE (op0)) == NULLPTR_TYPE
    3703    234501175 :           && TREE_CODE (TREE_TYPE (op1)) == NULLPTR_TYPE)
    3704              :         {
    3705           27 :           switch (code)
    3706              :             {
    3707           12 :             case EQ_EXPR:
    3708           12 :               x = constant_boolean_node (true, TREE_TYPE (x));
    3709           12 :               break;
    3710           15 :             case NE_EXPR:
    3711           15 :               x = constant_boolean_node (false, TREE_TYPE (x));
    3712           15 :               break;
    3713            0 :             default:
    3714            0 :               gcc_unreachable ();
    3715              :             }
    3716           27 :           return omit_two_operands_loc (loc, TREE_TYPE (x), x,
    3717           27 :                                         op0, op1);
    3718              :         }
    3719              : 
    3720    234501121 :       if (op0 == error_mark_node || op1 == error_mark_node)
    3721          105 :         x = error_mark_node;
    3722    234501016 :       else if (op0 != TREE_OPERAND (x, 0) || op1 != TREE_OPERAND (x, 1))
    3723    161226782 :         x = fold_build2_loc (loc, code, TREE_TYPE (x), op0, op1);
    3724              :       else
    3725     73274234 :         x = fold (x);
    3726              : 
    3727              :       /* This is only needed for -Wnonnull-compare and only if
    3728              :          TREE_NO_WARNING (org_x), but to avoid that option affecting code
    3729              :          generation, we do it always.  */
    3730    234501121 :       if (COMPARISON_CLASS_P (org_x))
    3731              :         {
    3732     38893315 :           if (x == error_mark_node || TREE_CODE (x) == INTEGER_CST)
    3733              :             ;
    3734     37778416 :           else if (COMPARISON_CLASS_P (x))
    3735              :             {
    3736     36761301 :               if (warn_nonnull_compare
    3737     36761301 :                   && warning_suppressed_p (org_x, OPT_Wnonnull_compare))
    3738       122805 :                 suppress_warning (x, OPT_Wnonnull_compare);
    3739              :             }
    3740              :           /* Otherwise give up on optimizing these, let GIMPLE folders
    3741              :              optimize those later on.  */
    3742      1017115 :           else if (op0 != TREE_OPERAND (org_x, 0)
    3743      1017115 :                    || op1 != TREE_OPERAND (org_x, 1))
    3744              :             {
    3745      1015052 :               x = build2_loc (loc, code, TREE_TYPE (org_x), op0, op1);
    3746      1015052 :               if (warn_nonnull_compare
    3747      1015052 :                   && warning_suppressed_p (org_x, OPT_Wnonnull_compare))
    3748           16 :                 suppress_warning (x, OPT_Wnonnull_compare);
    3749              :             }
    3750              :           else
    3751         2063 :             x = org_x;
    3752              :         }
    3753              : 
    3754              :       break;
    3755              : 
    3756      9891546 :     case VEC_COND_EXPR:
    3757      9891546 :     case COND_EXPR:
    3758      9891546 :       loc = EXPR_LOCATION (x);
    3759      9891546 :       op0 = cp_fold_rvalue (TREE_OPERAND (x, 0), flags);
    3760      9891546 :       op1 = cp_fold (TREE_OPERAND (x, 1), flags);
    3761      9891546 :       op2 = cp_fold (TREE_OPERAND (x, 2), flags);
    3762              : 
    3763      9891546 :       if (flags & ff_only_non_odr)
    3764              :         {
    3765      4163780 :           if (op0 == error_mark_node
    3766      4163774 :               || op1 == error_mark_node
    3767      4163774 :               || op2 == error_mark_node)
    3768            6 :             x = error_mark_node;
    3769      4163774 :           else if (op0 != TREE_OPERAND (x, 0)
    3770      4086432 :                    || op1 != TREE_OPERAND (x, 1)
    3771      8026551 :                    || op2 != TREE_OPERAND (x, 2))
    3772       315925 :             x = build3_loc (loc, code, TREE_TYPE (x), op0, op1, op2);
    3773              :           break;
    3774              :         }
    3775              : 
    3776      5727766 :       if (TREE_CODE (TREE_TYPE (x)) == BOOLEAN_TYPE)
    3777              :         {
    3778        20937 :           warning_sentinel s (warn_int_in_bool_context);
    3779        20937 :           if (!VOID_TYPE_P (TREE_TYPE (op1)))
    3780        20937 :             op1 = cp_truthvalue_conversion (op1, tf_warning_or_error);
    3781        20937 :           if (!VOID_TYPE_P (TREE_TYPE (op2)))
    3782        20916 :             op2 = cp_truthvalue_conversion (op2, tf_warning_or_error);
    3783        20937 :         }
    3784      5706829 :       else if (VOID_TYPE_P (TREE_TYPE (x)))
    3785              :         {
    3786      1868671 :           if (TREE_CODE (op0) == INTEGER_CST)
    3787              :             {
    3788              :               /* If the condition is constant, fold can fold away
    3789              :                  the COND_EXPR.  If some statement-level uses of COND_EXPR
    3790              :                  have one of the branches NULL, avoid folding crash.  */
    3791       342020 :               if (!op1)
    3792            0 :                 op1 = build_empty_stmt (loc);
    3793       342020 :               if (!op2)
    3794           12 :                 op2 = build_empty_stmt (loc);
    3795              :             }
    3796              :           else
    3797              :             {
    3798              :               /* Otherwise, don't bother folding a void condition, since
    3799              :                  it can't produce a constant value.  */
    3800      1526651 :               if (op0 != TREE_OPERAND (x, 0)
    3801      1435125 :                   || op1 != TREE_OPERAND (x, 1)
    3802      2597281 :                   || op2 != TREE_OPERAND (x, 2))
    3803       458267 :                 x = build3_loc (loc, code, TREE_TYPE (x), op0, op1, op2);
    3804              :               break;
    3805              :             }
    3806              :         }
    3807              : 
    3808              :       /* If either op1 or op2 or both are bit-fields, promote them now,
    3809              :          as middle-end folding doesn't expect COND_EXPR with inconsistent
    3810              :          types.  At this point we shouldn't care whether COND_EXPR or what
    3811              :          it folds into is an lvalue or rvalue, after all middle-end
    3812              :          folding doesn't differentiate that either.  */
    3813      4201115 :       if (op1 && is_bitfield_expr_with_lowered_type (op1))
    3814           78 :         op1 = fold_convert_loc (loc, TREE_TYPE (x), op1);
    3815      4201115 :       if (op2 && is_bitfield_expr_with_lowered_type (op2))
    3816           46 :         op2 = fold_convert_loc (loc, TREE_TYPE (x), op2);
    3817              : 
    3818      4201115 :       if (op0 == error_mark_node
    3819      4201115 :           || op1 == error_mark_node
    3820      4201101 :           || op2 == error_mark_node)
    3821           62 :         x = error_mark_node;
    3822      4201053 :       else if (op0 != TREE_OPERAND (x, 0)
    3823      1705375 :                || op1 != TREE_OPERAND (x, 1)
    3824      5536460 :                || op2 != TREE_OPERAND (x, 2))
    3825      2972878 :         x = fold_build3_loc (loc, code, TREE_TYPE (x), op0, op1, op2);
    3826              :       else
    3827      1228175 :         x = fold (x);
    3828              : 
    3829              :       break;
    3830              : 
    3831    230136773 :     case CALL_EXPR:
    3832    230136773 :       {
    3833    230136773 :         tree callee = get_callee_fndecl (x);
    3834              : 
    3835              :         /* "Inline" calls to std::move/forward and other cast-like functions
    3836              :            by simply folding them into a corresponding cast to their return
    3837              :            type.  This is cheaper than relying on the middle end to do so, and
    3838              :            also means we avoid generating useless debug info for them at all.
    3839              : 
    3840              :            At this point the argument has already been converted into a
    3841              :            reference, so it suffices to use a NOP_EXPR to express the
    3842              :            cast.  */
    3843    230136773 :         if ((OPTION_SET_P (flag_fold_simple_inlines)
    3844    230136773 :              ? flag_fold_simple_inlines
    3845    230136458 :              : !flag_no_inline)
    3846    217458072 :             && !(flags & ff_only_non_odr)
    3847    125647392 :             && call_expr_nargs (x) == 1
    3848     66229035 :             && decl_in_std_namespace_p (callee)
    3849     42314297 :             && DECL_NAME (callee) != NULL_TREE
    3850    272451070 :             && (id_equal (DECL_NAME (callee), "move")
    3851     41000938 :                 || id_equal (DECL_NAME (callee), "forward")
    3852     39391208 :                 || id_equal (DECL_NAME (callee), "forward_like")
    3853     39391062 :                 || id_equal (DECL_NAME (callee), "addressof")
    3854              :                 /* This addressof equivalent is used heavily in libstdc++.  */
    3855     39060674 :                 || id_equal (DECL_NAME (callee), "__addressof")
    3856     38676276 :                 || id_equal (DECL_NAME (callee), "to_underlying")
    3857     38676270 :                 || id_equal (DECL_NAME (callee), "as_const")))
    3858              :           {
    3859      3640630 :             r = CALL_EXPR_ARG (x, 0);
    3860              :             /* These type-checks must be performed here, because invalid
    3861              :                definitions of these functions could fail to ensure those and
    3862              :                build_nop could misbehave.  See PR122185.  */
    3863      3640630 :             if (id_equal (DECL_NAME (callee), "to_underlying")
    3864      3640630 :                 ? TREE_CODE (TREE_TYPE (r)) == ENUMERAL_TYPE
    3865            6 :                   && INTEGRAL_TYPE_P (TREE_TYPE (x))
    3866      6566462 :                 : INDIRECT_TYPE_P (TREE_TYPE (x))
    3867      6566450 :                   && INDIRECT_TYPE_P (TREE_TYPE (r)))
    3868              :               {
    3869      3640615 :                 r = build_nop (TREE_TYPE (x), r);
    3870      3640615 :                 x = cp_fold (r, flags);
    3871              :               }
    3872              :             break;
    3873              :           }
    3874              : 
    3875    226496143 :         int sv = optimize, nw = sv;
    3876              : 
    3877              :         /* Some built-in function calls will be evaluated at compile-time in
    3878              :            fold ().  Set optimize to 1 when folding __builtin_constant_p inside
    3879              :            a constexpr function so that fold_builtin_1 doesn't fold it to 0.  */
    3880    224094970 :         if (callee && fndecl_built_in_p (callee) && !optimize
    3881      2154955 :             && DECL_IS_BUILTIN_CONSTANT_P (callee)
    3882        50752 :             && current_function_decl
    3883    226546879 :             && DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    3884              :           nw = 1;
    3885              : 
    3886    224094970 :         if (callee && !(flags & ff_only_non_odr)
    3887    354332992 :             && fndecl_built_in_p (callee, BUILT_IN_FRONTEND))
    3888              :           {
    3889        60587 :             iloc_sentinel ils (EXPR_LOCATION (x));
    3890        60587 :             switch (DECL_FE_FUNCTION_CODE (callee))
    3891              :               {
    3892        53698 :               case CP_BUILT_IN_IS_CONSTANT_EVALUATED:
    3893              :                 /* Defer folding __builtin_is_constant_evaluated unless
    3894              :                    we know this isn't a manifestly constant-evaluated
    3895              :                    context.  */
    3896        53698 :                 if (flags & ff_mce_false)
    3897        27230 :                   x = boolean_false_node;
    3898              :                 break;
    3899            3 :               case CP_BUILT_IN_SOURCE_LOCATION:
    3900            3 :                 x = fold_builtin_source_location (x);
    3901            3 :                 break;
    3902          456 :               case CP_BUILT_IN_IS_CORRESPONDING_MEMBER:
    3903          912 :                 x = fold_builtin_is_corresponding_member
    3904          456 :                         (EXPR_LOCATION (x), call_expr_nargs (x),
    3905              :                          &CALL_EXPR_ARG (x, 0));
    3906          456 :                 break;
    3907          400 :               case CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS:
    3908          800 :                 x = fold_builtin_is_pointer_inverconvertible_with_class
    3909          400 :                         (EXPR_LOCATION (x), call_expr_nargs (x),
    3910              :                          &CALL_EXPR_ARG (x, 0));
    3911          400 :                 break;
    3912              :               default:
    3913              :                 break;
    3914              :               }
    3915        60587 :             break;
    3916        60587 :           }
    3917              : 
    3918    226435556 :         bool changed = false;
    3919    226435556 :         int m = call_expr_nargs (x);
    3920    558441537 :         for (int i = 0; i < m; i++)
    3921              :           {
    3922    332005981 :             r = cp_fold (CALL_EXPR_ARG (x, i), flags);
    3923    332005981 :             if (r != CALL_EXPR_ARG (x, i))
    3924              :               {
    3925    109184514 :                 if (r == error_mark_node)
    3926              :                   {
    3927            0 :                     x = error_mark_node;
    3928            0 :                     break;
    3929              :                   }
    3930    109184514 :                 if (!changed)
    3931     69618525 :                   x = copy_node (x);
    3932    109184514 :                 CALL_EXPR_ARG (x, i) = r;
    3933    109184514 :                 changed = true;
    3934              :               }
    3935              :           }
    3936              :         /* Don't fold away the function entirely if we're just folding
    3937              :            non-ODR-used variables.  */
    3938    226435556 :         if (x == error_mark_node || (flags & ff_only_non_odr))
    3939              :           break;
    3940              : 
    3941    129163154 :         optimize = nw;
    3942    129163154 :         r = fold (x);
    3943    129163154 :         optimize = sv;
    3944              : 
    3945    129163154 :         if (TREE_CODE (r) != CALL_EXPR)
    3946              :           {
    3947      2948518 :             x = cp_fold (r, flags);
    3948      2948518 :             break;
    3949              :           }
    3950              : 
    3951    126214636 :         optimize = nw;
    3952              : 
    3953              :         /* Invoke maybe_constant_value for functions declared
    3954              :            constexpr and not called with AGGR_INIT_EXPRs.
    3955              :            TODO:
    3956              :            Do constexpr expansion of expressions where the call itself is not
    3957              :            constant, but the call followed by an INDIRECT_REF is.  */
    3958    124827744 :         if (callee && DECL_DECLARED_CONSTEXPR_P (callee)
    3959              :             && !(flags & ff_only_non_odr)
    3960    188620947 :             && (!flag_no_inline
    3961      3790053 :                 || lookup_attribute ("always_inline",
    3962      3790053 :                                      DECL_ATTRIBUTES (callee))))
    3963              :           {
    3964     59459522 :             mce_value manifestly_const_eval = mce_unknown;
    3965     59459522 :             if (flags & ff_mce_false)
    3966              :               /* Allow folding __builtin_is_constant_evaluated to false during
    3967              :                  constexpr evaluation of this call.  */
    3968     46118275 :               manifestly_const_eval = mce_false;
    3969     59459522 :             r = maybe_constant_value (x, /*decl=*/NULL_TREE,
    3970              :                                       manifestly_const_eval);
    3971              :           }
    3972    126214636 :         optimize = sv;
    3973              : 
    3974    126214636 :         if (TREE_CODE (r) != CALL_EXPR)
    3975              :           {
    3976      9035442 :             if (DECL_CONSTRUCTOR_P (callee))
    3977          503 :               r = cp_build_init_expr_for_ctor (x, r);
    3978      4517721 :             x = r;
    3979      4517721 :             break;
    3980              :           }
    3981              : 
    3982              :         break;
    3983              :       }
    3984              : 
    3985     24418613 :     case CONSTRUCTOR:
    3986     24418613 :       {
    3987     24418613 :         unsigned i;
    3988     24418613 :         constructor_elt *p;
    3989     24418613 :         vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (x);
    3990     24418613 :         vec<constructor_elt, va_gc> *nelts = NULL;
    3991    116523411 :         FOR_EACH_VEC_SAFE_ELT (elts, i, p)
    3992              :           {
    3993     80957191 :             tree op = cp_fold (p->value, flags);
    3994     80957191 :             if (op == error_mark_node)
    3995              :               {
    3996            0 :                 x = error_mark_node;
    3997            0 :                 vec_free (nelts);
    3998              :                 break;
    3999              :               }
    4000     80957191 :             else if (op != p->value)
    4001              :               {
    4002      1252531 :                 if (nelts == NULL)
    4003       805052 :                   nelts = elts->copy ();
    4004      1252531 :                 (*nelts)[i].value = op;
    4005              :               }
    4006              :           }
    4007     24418613 :         if (nelts)
    4008              :           {
    4009       805052 :             x = build_constructor (TREE_TYPE (x), nelts);
    4010       805052 :             CONSTRUCTOR_PLACEHOLDER_BOUNDARY (x)
    4011       805052 :               = CONSTRUCTOR_PLACEHOLDER_BOUNDARY (org_x);
    4012       805052 :             CONSTRUCTOR_MUTABLE_POISON (x)
    4013      1610104 :               = CONSTRUCTOR_MUTABLE_POISON (org_x);
    4014              :           }
    4015     24418613 :         if (VECTOR_TYPE_P (TREE_TYPE (x)))
    4016        78770 :           x = fold (x);
    4017              :         break;
    4018              :       }
    4019       834824 :     case TREE_VEC:
    4020       834824 :       {
    4021       834824 :         bool changed = false;
    4022       834824 :         int n = TREE_VEC_LENGTH (x);
    4023              : 
    4024      2102190 :         for (int i = 0; i < n; i++)
    4025              :           {
    4026      1267366 :             tree op = cp_fold (TREE_VEC_ELT (x, i), flags);
    4027      1267366 :             if (op != TREE_VEC_ELT (x, i))
    4028              :               {
    4029          876 :                 if (!changed)
    4030          833 :                   x = copy_node (x);
    4031          876 :                 TREE_VEC_ELT (x, i) = op;
    4032          876 :                 changed = true;
    4033              :               }
    4034              :           }
    4035              :       }
    4036              : 
    4037              :       break;
    4038              : 
    4039      3238106 :     case ARRAY_REF:
    4040      3238106 :     case ARRAY_RANGE_REF:
    4041              : 
    4042      3238106 :       loc = EXPR_LOCATION (x);
    4043      3238106 :       op0 = cp_fold (TREE_OPERAND (x, 0), flags);
    4044      3238106 :       op1 = cp_fold (TREE_OPERAND (x, 1), flags);
    4045      3238106 :       op2 = cp_fold (TREE_OPERAND (x, 2), flags);
    4046      3238106 :       op3 = cp_fold (TREE_OPERAND (x, 3), flags);
    4047              : 
    4048      3238106 :       if (op0 == error_mark_node
    4049      3238106 :           || op1 == error_mark_node
    4050      3238106 :           || op2 == error_mark_node
    4051      3238106 :           || op3 == error_mark_node)
    4052            0 :         x = error_mark_node;
    4053      3238106 :       else if (op0 != TREE_OPERAND (x, 0)
    4054      2226289 :           || op1 != TREE_OPERAND (x, 1)
    4055      1728451 :           || op2 != TREE_OPERAND (x, 2)
    4056      4966557 :           || op3 != TREE_OPERAND (x, 3))
    4057              :         {
    4058      1509655 :           x = build4_loc (loc, code, TREE_TYPE (x), op0, op1, op2, op3);
    4059      1509655 :           TREE_READONLY (x) = TREE_READONLY (org_x);
    4060      1509655 :           TREE_SIDE_EFFECTS (x) = TREE_SIDE_EFFECTS (org_x);
    4061      1509655 :           TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x);
    4062              :         }
    4063              : 
    4064      3238106 :       if (!(flags & ff_only_non_odr))
    4065      1884751 :         x = fold (x);
    4066              :       break;
    4067              : 
    4068      1710085 :     case SAVE_EXPR:
    4069              :       /* A SAVE_EXPR might contain e.g. (0 * i) + (0 * j), which, after
    4070              :          folding, evaluates to an invariant.  In that case no need to wrap
    4071              :          this folded tree with a SAVE_EXPR.  */
    4072      1710085 :       r = cp_fold (TREE_OPERAND (x, 0), flags);
    4073      1710085 :       if (tree_invariant_p (r))
    4074           61 :         x = r;
    4075              :       break;
    4076              : 
    4077           16 :     case REQUIRES_EXPR:
    4078           16 :       x = evaluate_requires_expr (x);
    4079           16 :       break;
    4080              : 
    4081              :     default:
    4082              :       return org_x;
    4083              :     }
    4084              : 
    4085   2394972999 :   if (EXPR_P (x) && TREE_CODE (x) == code)
    4086              :     {
    4087   1992097633 :       TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x);
    4088   1992097633 :       copy_warning (x, org_x);
    4089              :     }
    4090              : 
    4091   2394972999 :   if (!c.evaluation_restricted_p ())
    4092              :     {
    4093   2394928015 :       fold_cache->put (org_x, x);
    4094              :       /* Prevent that we try to fold an already folded result again.  */
    4095   2394928015 :       if (x != org_x)
    4096    751790573 :         fold_cache->put (x, x);
    4097              :     }
    4098              : 
    4099              :   return x;
    4100              : }
    4101              : 
    4102              : /* Look up "hot", "cold", "likely" or "unlikely" in attribute list LIST.  */
    4103              : 
    4104              : tree
    4105    310993323 : lookup_hotness_attribute (tree list)
    4106              : {
    4107    311100937 :   for (; list; list = TREE_CHAIN (list))
    4108              :     {
    4109      2020013 :       tree name = get_attribute_name (list);
    4110      2020013 :       if ((is_attribute_p ("hot", name)
    4111      2020013 :            || is_attribute_p ("cold", name)
    4112      2020010 :            || is_attribute_p ("likely", name)
    4113      1390309 :            || is_attribute_p ("unlikely", name))
    4114      3932421 :           && is_attribute_namespace_p ("", list))
    4115              :         break;
    4116              :     }
    4117    310993323 :   return list;
    4118              : }
    4119              : 
    4120              : /* Remove "hot", "cold", "likely" and "unlikely" attributes from LIST.  */
    4121              : 
    4122              : static tree
    4123      1912390 : remove_hotness_attribute (tree list)
    4124              : {
    4125      3824798 :   for (tree *p = &list; *p; )
    4126              :     {
    4127      1912408 :       tree l = *p;
    4128      1912408 :       tree name = get_attribute_name (l);
    4129      1912408 :       if ((is_attribute_p ("hot", name)
    4130      1912408 :            || is_attribute_p ("cold", name)
    4131      1912405 :            || is_attribute_p ("likely", name)
    4132      1282704 :            || is_attribute_p ("unlikely", name))
    4133      3824816 :           && is_attribute_namespace_p ("", l))
    4134              :         {
    4135      1912399 :           *p = TREE_CHAIN (l);
    4136      1912399 :           continue;
    4137              :         }
    4138            9 :       p = &TREE_CHAIN (l);
    4139              :     }
    4140      1912390 :   return list;
    4141              : }
    4142              : 
    4143              : /* If [[likely]] or [[unlikely]] appear on this statement, turn it into a
    4144              :    PREDICT_EXPR.  */
    4145              : 
    4146              : tree
    4147    309080951 : process_stmt_hotness_attribute (tree std_attrs, location_t attrs_loc)
    4148              : {
    4149    309080951 :   if (std_attrs == error_mark_node)
    4150              :     return std_attrs;
    4151    309080933 :   if (tree attr = lookup_hotness_attribute (std_attrs))
    4152              :     {
    4153      1912390 :       tree name = get_attribute_name (attr);
    4154      1912390 :       bool hot = (is_attribute_p ("hot", name)
    4155      1912390 :                   || is_attribute_p ("likely", name));
    4156      1912390 :       tree pred = build_predict_expr (hot ? PRED_HOT_LABEL : PRED_COLD_LABEL,
    4157              :                                       hot ? TAKEN : NOT_TAKEN);
    4158      1912390 :       SET_EXPR_LOCATION (pred, attrs_loc);
    4159      1912390 :       add_stmt (pred);
    4160      1912390 :       if (tree other = lookup_hotness_attribute (TREE_CHAIN (attr)))
    4161              :         {
    4162            9 :           auto_urlify_attributes sentinel;
    4163            9 :           warning (OPT_Wattributes, "ignoring attribute %qE after earlier %qE",
    4164              :                    get_attribute_name (other), name);
    4165            9 :         }
    4166      1912390 :       std_attrs = remove_hotness_attribute (std_attrs);
    4167              :     }
    4168              :   return std_attrs;
    4169              : }
    4170              : 
    4171              : /* Build IFN_ASSUME internal call for assume condition ARG.  */
    4172              : 
    4173              : tree
    4174        11795 : build_assume_call (location_t loc, tree arg)
    4175              : {
    4176        11795 :   if (!processing_template_decl)
    4177        11694 :     arg = fold_build_cleanup_point_expr (TREE_TYPE (arg), arg);
    4178        11795 :   return build_call_expr_internal_loc (loc, IFN_ASSUME, void_type_node,
    4179        11795 :                                        1, arg);
    4180              : }
    4181              : 
    4182              : /* If [[assume (cond)]] appears on this statement, handle it.  */
    4183              : 
    4184              : tree
    4185    243338440 : process_stmt_assume_attribute (tree std_attrs, tree statement,
    4186              :                                location_t attrs_loc)
    4187              : {
    4188    243338440 :   if (std_attrs == error_mark_node)
    4189              :     return std_attrs;
    4190    243338422 :   tree attr = lookup_attribute ("gnu", "assume", std_attrs);
    4191    243338422 :   if (!attr)
    4192              :     return std_attrs;
    4193              :   /* The next token after the assume attribute is not ';'.  */
    4194        11711 :   if (statement)
    4195              :     {
    4196           12 :       warning_at (attrs_loc, OPT_Wattributes,
    4197              :                   "%<assume%> attribute not followed by %<;%>");
    4198           12 :       attr = NULL_TREE;
    4199              :     }
    4200        23446 :   for (; attr; attr = lookup_attribute ("gnu", "assume", TREE_CHAIN (attr)))
    4201              :     {
    4202        11735 :       tree args = TREE_VALUE (attr);
    4203        11735 :       if (args && PACK_EXPANSION_P (args))
    4204              :         {
    4205            6 :           auto_diagnostic_group d;
    4206            6 :           error_at (attrs_loc, "pack expansion of %qE attribute",
    4207              :                     get_attribute_name (attr));
    4208            6 :           if (cxx_dialect >= cxx17)
    4209            4 :             inform (attrs_loc, "use fold expression in the attribute "
    4210              :                                "argument instead");
    4211            6 :           continue;
    4212            6 :         }
    4213        11729 :       int nargs = list_length (args);
    4214        11729 :       if (nargs != 1)
    4215              :         {
    4216           42 :           auto_diagnostic_group d;
    4217           42 :           error_at (attrs_loc, "wrong number of arguments specified for "
    4218              :                                "%qE attribute", get_attribute_name (attr));
    4219           42 :           inform (attrs_loc, "expected %i, found %i", 1, nargs);
    4220           42 :         }
    4221              :       else
    4222              :         {
    4223        11687 :           tree arg = TREE_VALUE (args);
    4224        11687 :           if (!type_dependent_expression_p (arg))
    4225        11586 :             arg = contextual_conv_bool (arg, tf_warning_or_error);
    4226        11687 :           if (error_operand_p (arg))
    4227           18 :             continue;
    4228        11669 :           finish_expr_stmt (build_assume_call (attrs_loc, arg));
    4229              :         }
    4230              :     }
    4231        11711 :   return remove_attribute ("gnu", "assume", std_attrs);
    4232              : }
    4233              : 
    4234              : /* Return the type std::source_location::__impl after performing
    4235              :    verification on it.  */
    4236              : 
    4237              : tree
    4238        10313 : get_source_location_impl_type ()
    4239              : {
    4240        10313 :   tree name = get_identifier ("source_location");
    4241        10313 :   tree decl = lookup_qualified_name (std_node, name);
    4242        10313 :   if (TREE_CODE (decl) != TYPE_DECL)
    4243              :     {
    4244            6 :       auto_diagnostic_group d;
    4245            6 :       if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
    4246            3 :         qualified_name_lookup_error (std_node, name, decl, input_location);
    4247              :       else
    4248            3 :         error ("%qD is not a type", decl);
    4249            6 :       return error_mark_node;
    4250            6 :     }
    4251        10307 :   name = get_identifier ("__impl");
    4252        10307 :   tree type = TREE_TYPE (decl);
    4253        10307 :   decl = lookup_qualified_name (type, name);
    4254        10307 :   if (TREE_CODE (decl) != TYPE_DECL)
    4255              :     {
    4256            9 :       auto_diagnostic_group d;
    4257            9 :       if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
    4258            6 :         qualified_name_lookup_error (type, name, decl, input_location);
    4259              :       else
    4260            3 :         error ("%qD is not a type", decl);
    4261            9 :       return error_mark_node;
    4262            9 :     }
    4263        10298 :   type = TREE_TYPE (decl);
    4264        10298 :   if (TREE_CODE (type) != RECORD_TYPE)
    4265              :     {
    4266            3 :       error ("%qD is not a class type", decl);
    4267            3 :       return error_mark_node;
    4268              :     }
    4269              : 
    4270        10295 :   int cnt = 0;
    4271        10295 :   for (tree field = TYPE_FIELDS (type);
    4272        51436 :        (field = next_aggregate_field (field)) != NULL_TREE;
    4273        41141 :        field = DECL_CHAIN (field))
    4274              :     {
    4275        41150 :       if (DECL_NAME (field) != NULL_TREE)
    4276              :         {
    4277        41150 :           const char *n = IDENTIFIER_POINTER (DECL_NAME (field));
    4278        41150 :           if (strcmp (n, "_M_file_name") == 0
    4279        30858 :               || strcmp (n, "_M_function_name") == 0)
    4280              :             {
    4281        20581 :               if (TREE_TYPE (field) != const_string_type_node)
    4282              :                 {
    4283            3 :                   error ("%qD does not have %<const char *%> type", field);
    4284            3 :                   return error_mark_node;
    4285              :                 }
    4286        20578 :               cnt++;
    4287        20578 :               continue;
    4288              :             }
    4289        20569 :           else if (strcmp (n, "_M_line") == 0 || strcmp (n, "_M_column") == 0)
    4290              :             {
    4291        20566 :               if (TREE_CODE (TREE_TYPE (field)) != INTEGER_TYPE)
    4292              :                 {
    4293            3 :                   error ("%qD does not have integral type", field);
    4294            3 :                   return error_mark_node;
    4295              :                 }
    4296        20563 :               cnt++;
    4297        20563 :               continue;
    4298              :             }
    4299              :         }
    4300              :       cnt = 0;
    4301              :       break;
    4302              :     }
    4303        10289 :   if (cnt != 4)
    4304              :     {
    4305            9 :       error ("%<std::source_location::__impl%> does not contain only "
    4306              :              "non-static data members %<_M_file_name%>, "
    4307              :              "%<_M_function_name%>, %<_M_line%> and %<_M_column%>");
    4308            9 :       return error_mark_node;
    4309              :     }
    4310        10280 :   return build_qualified_type (type, TYPE_QUAL_CONST);
    4311              : }
    4312              : 
    4313              : /* Type for source_location_table hash_set.  */
    4314              : struct GTY((for_user)) source_location_table_entry {
    4315              :   location_t loc;
    4316              :   unsigned uid;
    4317              :   tree var;
    4318              : };
    4319              : 
    4320              : /* Traits class for function start hash maps below.  */
    4321              : 
    4322              : struct source_location_table_entry_hash
    4323              :   : ggc_remove <source_location_table_entry>
    4324              : {
    4325              :   typedef source_location_table_entry value_type;
    4326              :   typedef source_location_table_entry compare_type;
    4327              : 
    4328              :   static hashval_t
    4329        59540 :   hash (const source_location_table_entry &ref)
    4330              :   {
    4331        59540 :     inchash::hash hstate (0);
    4332        59540 :     hstate.add_int (ref.loc);
    4333        59540 :     hstate.add_int (ref.uid);
    4334        59540 :     return hstate.end ();
    4335              :   }
    4336              : 
    4337              :   static bool
    4338        51427 :   equal (const source_location_table_entry &ref1,
    4339              :          const source_location_table_entry &ref2)
    4340              :   {
    4341        51427 :     return ref1.loc == ref2.loc && ref1.uid == ref2.uid;
    4342              :   }
    4343              : 
    4344              :   static void
    4345              :   mark_deleted (source_location_table_entry &ref)
    4346              :   {
    4347              :     ref.loc = UNKNOWN_LOCATION;
    4348              :     ref.uid = -1U;
    4349              :     ref.var = NULL_TREE;
    4350              :   }
    4351              : 
    4352              :   static const bool empty_zero_p = true;
    4353              : 
    4354              :   static void
    4355            0 :   mark_empty (source_location_table_entry &ref)
    4356              :   {
    4357            0 :     ref.loc = UNKNOWN_LOCATION;
    4358            0 :     ref.uid = 0;
    4359            0 :     ref.var = NULL_TREE;
    4360              :   }
    4361              : 
    4362              :   static bool
    4363        83278 :   is_deleted (const source_location_table_entry &ref)
    4364              :   {
    4365        83278 :     return (ref.loc == UNKNOWN_LOCATION
    4366            0 :             && ref.uid == -1U
    4367        83278 :             && ref.var == NULL_TREE);
    4368              :   }
    4369              : 
    4370              :   static bool
    4371       318198 :   is_empty (const source_location_table_entry &ref)
    4372              :   {
    4373       318198 :     return (ref.loc == UNKNOWN_LOCATION
    4374       142902 :             && ref.uid == 0
    4375       461100 :             && ref.var == NULL_TREE);
    4376              :   }
    4377              : 
    4378              :   static void
    4379            3 :   pch_nx (source_location_table_entry &p)
    4380              :   {
    4381            3 :     extern void gt_pch_nx (source_location_table_entry &);
    4382            3 :     gt_pch_nx (p);
    4383              :   }
    4384              : 
    4385              :   static void
    4386            3 :   pch_nx (source_location_table_entry &p, gt_pointer_operator op, void *cookie)
    4387              :   {
    4388            3 :     extern void gt_pch_nx (source_location_table_entry *, gt_pointer_operator,
    4389              :                            void *);
    4390            3 :     gt_pch_nx (&p, op, cookie);
    4391              :   }
    4392              : };
    4393              : 
    4394              : static GTY(()) hash_table <source_location_table_entry_hash>
    4395              :   *source_location_table;
    4396              : 
    4397              : /* Build a std::source_location::__impl from a location_t.  */
    4398              : 
    4399              : tree
    4400        12178 : build_source_location_impl (location_t loc, tree fndecl,
    4401              :                             tree source_location_impl)
    4402              : {
    4403        12178 :   if (source_location_table == NULL)
    4404          400 :     source_location_table
    4405          400 :       = hash_table <source_location_table_entry_hash>::create_ggc (64);
    4406        12178 :   const line_map_ordinary *map;
    4407        12178 :   source_location_table_entry entry;
    4408        12178 :   entry.loc
    4409        12178 :     = linemap_resolve_location (line_table, loc, LRK_MACRO_EXPANSION_POINT,
    4410              :                                 &map);
    4411        12178 :   entry.uid = fndecl ? DECL_UID (fndecl) : -1;
    4412        12178 :   entry.var = error_mark_node;
    4413        12178 :   source_location_table_entry *entryp
    4414        12178 :     = source_location_table->find_slot (entry, INSERT);
    4415              : 
    4416        12178 :   if (entryp->var)
    4417              :     return entryp->var;
    4418              : 
    4419         8993 :   tree var = build_decl (loc, VAR_DECL, generate_internal_label ("Lsrc_loc"),
    4420              :                          source_location_impl);
    4421         8993 :   TREE_STATIC (var) = 1;
    4422         8993 :   TREE_PUBLIC (var) = 0;
    4423         8993 :   DECL_ARTIFICIAL (var) = 1;
    4424         8993 :   DECL_IGNORED_P (var) = 1;
    4425         8993 :   DECL_EXTERNAL (var) = 0;
    4426         8993 :   DECL_DECLARED_CONSTEXPR_P (var) = 1;
    4427         8993 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var) = 1;
    4428         8993 :   layout_decl (var, 0);
    4429              : 
    4430         8993 :   vec<constructor_elt, va_gc> *v = NULL;
    4431         8993 :   vec_alloc (v, 4);
    4432         8993 :   for (tree field = TYPE_FIELDS (source_location_impl);
    4433        44965 :         (field = next_aggregate_field (field)) != NULL_TREE;
    4434        35972 :         field = DECL_CHAIN (field))
    4435              :     {
    4436        35972 :       const char *n = IDENTIFIER_POINTER (DECL_NAME (field));
    4437        35972 :       tree val = NULL_TREE;
    4438        35972 :       if (strcmp (n, "_M_file_name") == 0)
    4439              :         {
    4440         8993 :           if (const char *fname = LOCATION_FILE (loc))
    4441              :             {
    4442         8993 :               fname = remap_macro_filename (fname);
    4443         8993 :               val = build_string_literal (fname);
    4444              :             }
    4445              :           else
    4446            0 :             val = build_string_literal ("");
    4447              :         }
    4448        26979 :       else if (strcmp (n, "_M_function_name") == 0)
    4449              :         {
    4450         8993 :           const char *name = "";
    4451              : 
    4452         8993 :           if (fndecl)
    4453              :             {
    4454              :               /* If this is a coroutine, we should get the name of the user
    4455              :                  function rather than the actor we generate.  */
    4456         8594 :               if (tree ramp = DECL_RAMP_FN (fndecl))
    4457           12 :                 name = cxx_printable_name (ramp, 2);
    4458              :               else
    4459         8582 :                 name = cxx_printable_name (fndecl, 2);
    4460              :             }
    4461              : 
    4462         8993 :           val = build_string_literal (name);
    4463              :         }
    4464        17986 :       else if (strcmp (n, "_M_line") == 0)
    4465         8993 :         val = build_int_cst (TREE_TYPE (field), LOCATION_LINE (loc));
    4466         8993 :       else if (strcmp (n, "_M_column") == 0)
    4467         8993 :         val = build_int_cst (TREE_TYPE (field), LOCATION_COLUMN (loc));
    4468              :       else
    4469            0 :         gcc_unreachable ();
    4470        35972 :       CONSTRUCTOR_APPEND_ELT (v, field, val);
    4471              :     }
    4472              : 
    4473         8993 :   tree ctor = build_constructor (source_location_impl, v);
    4474         8993 :   TREE_CONSTANT (ctor) = 1;
    4475         8993 :   TREE_STATIC (ctor) = 1;
    4476         8993 :   DECL_INITIAL (var) = ctor;
    4477         8993 :   varpool_node::finalize_decl (var);
    4478         8993 :   *entryp = entry;
    4479         8993 :   entryp->var = var;
    4480         8993 :   return var;
    4481              : }
    4482              : 
    4483              : /* Fold the __builtin_source_location () call T.  */
    4484              : 
    4485              : tree
    4486        11120 : fold_builtin_source_location (const_tree t)
    4487              : {
    4488        11120 :   gcc_assert (TREE_CODE (t) == CALL_EXPR);
    4489              :   /* TREE_TYPE (t) is const std::source_location::__impl*  */
    4490        11120 :   tree source_location_impl = TREE_TYPE (TREE_TYPE (t));
    4491        11120 :   if (source_location_impl == error_mark_node)
    4492            0 :     return build_zero_cst (const_ptr_type_node);
    4493        11120 :   gcc_assert (CLASS_TYPE_P (source_location_impl)
    4494              :               && id_equal (TYPE_IDENTIFIER (source_location_impl), "__impl"));
    4495              : 
    4496        11120 :   location_t loc = EXPR_LOCATION (t);
    4497        11120 :   tree var = build_source_location_impl (loc, current_function_decl,
    4498              :                                          source_location_impl);
    4499        11120 :   return build_fold_addr_expr_with_type_loc (loc, var, TREE_TYPE (t));
    4500              : }
    4501              : 
    4502              : #include "gt-cp-cp-gimplify.h"
        

Generated by: LCOV version 2.6-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.