LCOV - code coverage report
Current view: top level - gcc/cp - constexpr.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.1 % 6305 5868
Test Date: 2026-05-30 15:37:04 Functions: 99.5 % 196 195
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Perform -*- C++ -*- constant expression evaluation, including calls to
       2              :    constexpr functions.  These routines are used both during actual parsing
       3              :    and during the instantiation of template functions.
       4              : 
       5              :    Copyright (C) 1998-2026 Free Software Foundation, Inc.
       6              : 
       7              :    This file is part of GCC.
       8              : 
       9              :    GCC is free software; you can redistribute it and/or modify it
      10              :    under the terms of the GNU General Public License as published by
      11              :    the Free Software Foundation; either version 3, or (at your option)
      12              :    any later version.
      13              : 
      14              :    GCC is distributed in the hope that it will be useful, but
      15              :    WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17              :    General Public License for more details.
      18              : 
      19              : You should have received a copy of the GNU General Public License
      20              : along with GCC; see the file COPYING3.  If not see
      21              : <http://www.gnu.org/licenses/>.  */
      22              : 
      23              : #include "config.h"
      24              : #include "system.h"
      25              : #include "coretypes.h"
      26              : #include "cp-tree.h"
      27              : #include "varasm.h"
      28              : #include "c-family/c-objc.h"
      29              : #include "tree-iterator.h"
      30              : #include "gimplify.h"
      31              : #include "builtins.h"
      32              : #include "tree-inline.h"
      33              : #include "ubsan.h"
      34              : #include "timevar.h"
      35              : #include "fold-const-call.h"
      36              : #include "stor-layout.h"
      37              : #include "cgraph.h"
      38              : #include "opts.h"
      39              : #include "stringpool.h"
      40              : #include "attribs.h"
      41              : #include "fold-const.h"
      42              : #include "intl.h"
      43              : #include "toplev.h"
      44              : #include "contracts.h"
      45              : 
      46              : static bool verify_constant (tree, bool, bool *, bool *);
      47              : #define VERIFY_CONSTANT(X)                                              \
      48              : do {                                                                    \
      49              :   if (verify_constant ((X), ctx->quiet, non_constant_p, overflow_p)) \
      50              :     return t;                                                           \
      51              :  } while (0)
      52              : 
      53              : static HOST_WIDE_INT find_array_ctor_elt (tree ary, tree dindex,
      54              :                                           bool insert = false);
      55              : static int array_index_cmp (tree key, tree index);
      56              : 
      57              : /* Returns true iff FUN is an instantiation of a constexpr function
      58              :    template or a defaulted constexpr function.  */
      59              : 
      60              : bool
      61    180517066 : is_instantiation_of_constexpr (tree fun)
      62              : {
      63    251101387 :   return ((DECL_TEMPLOID_INSTANTIATION (fun)
      64    110353265 :            && DECL_DECLARED_CONSTEXPR_P (DECL_TI_TEMPLATE (fun)))
      65    270966106 :           || (DECL_DEFAULTED_FN (fun)
      66            0 :               && DECL_DECLARED_CONSTEXPR_P (fun)));
      67              : }
      68              : 
      69              : /* Return true if T is a literal type.   */
      70              : 
      71              : bool
      72    166923863 : literal_type_p (tree t)
      73              : {
      74    163799338 :   if (SCALAR_TYPE_P (t)
      75     75412367 :       || VECTOR_TYPE_P (t)
      76     75391842 :       || TYPE_REF_P (t)
      77    229228145 :       || (VOID_TYPE_P (t) && cxx_dialect >= cxx14))
      78              :     return true;
      79     57873150 :   if (CLASS_TYPE_P (t))
      80              :     {
      81     56424446 :       t = complete_type (t);
      82     56424446 :       gcc_assert (COMPLETE_TYPE_P (t) || errorcount);
      83     56424446 :       return CLASSTYPE_LITERAL_P (t);
      84              :     }
      85      1448704 :   if (TREE_CODE (t) == ARRAY_TYPE)
      86      1448502 :     return literal_type_p (strip_array_types (t));
      87              :   return false;
      88              : }
      89              : 
      90              : /* If DECL is a variable declared `constexpr', require its type
      91              :    be literal.  Return error_mark_node if we give an error, the
      92              :    DECL otherwise.  */
      93              : 
      94              : tree
      95    321255269 : ensure_literal_type_for_constexpr_object (tree decl)
      96              : {
      97    321255269 :   tree type = TREE_TYPE (decl);
      98    321255269 :   if (VAR_P (decl)
      99    120753987 :       && (DECL_DECLARED_CONSTEXPR_P (decl)
     100     84872535 :           || var_in_constexpr_fn (decl))
     101    374716636 :       && !processing_template_decl)
     102              :     {
     103     34714004 :       tree stype = strip_array_types (type);
     104     34714004 :       if (CLASS_TYPE_P (stype) && !COMPLETE_TYPE_P (complete_type (stype)))
     105              :         /* Don't complain here, we'll complain about incompleteness
     106              :            when we try to initialize the variable.  */;
     107     34713998 :       else if (!literal_type_p (type))
     108              :         {
     109        24269 :           if (DECL_DECLARED_CONSTEXPR_P (decl))
     110              :             {
     111           53 :               auto_diagnostic_group d;
     112           53 :               error_at (DECL_SOURCE_LOCATION (decl),
     113              :                         "the type %qT of %<constexpr%> variable %qD "
     114              :                         "is not literal", type, decl);
     115           53 :               explain_non_literal_class (type);
     116           53 :               decl = error_mark_node;
     117           53 :             }
     118        24216 :           else if (cxx_dialect < cxx23)
     119              :             {
     120        18287 :               if (!is_instantiation_of_constexpr (current_function_decl))
     121              :                 {
     122            8 :                   auto_diagnostic_group d;
     123            8 :                   error_at (DECL_SOURCE_LOCATION (decl),
     124              :                             "variable %qD of non-literal type %qT in "
     125              :                             "%<constexpr%> function only available with "
     126              :                             "%<-std=c++23%> or %<-std=gnu++23%>", decl, type);
     127            8 :                   explain_non_literal_class (type);
     128            8 :                   decl = error_mark_node;
     129            8 :                 }
     130        18287 :               cp_function_chain->invalid_constexpr = true;
     131              :             }
     132              :         }
     133     34689729 :       else if (DECL_DECLARED_CONSTEXPR_P (decl)
     134     34689729 :                && variably_modified_type_p (type, NULL_TREE))
     135              :         {
     136            4 :           error_at (DECL_SOURCE_LOCATION (decl),
     137              :                     "%<constexpr%> variable %qD has variably-modified "
     138              :                     "type %qT", decl, type);
     139            4 :           decl = error_mark_node;
     140              :         }
     141              :     }
     142    321255269 :   return decl;
     143              : }
     144              : 
     145              : /* Issue a diagnostic with text GMSGID for constructs that are invalid in
     146              :    constexpr functions.  CONSTEXPR_FUNDEF_P is true if we're checking
     147              :    a constexpr function body; if so, don't report hard errors and issue
     148              :    a pedwarn pre-C++23, or a warning in C++23, if requested by
     149              :    -Winvalid-constexpr.  Otherwise, we're not in the context where we are
     150              :    checking if a function can be marked 'constexpr', so give a hard error.  */
     151              : 
     152              : ATTRIBUTE_GCC_DIAG(3,4)
     153              : static bool
     154          981 : constexpr_error (location_t location, bool constexpr_fundef_p,
     155              :                  const char *gmsgid, ...)
     156              : {
     157          981 :   diagnostics::diagnostic_info diagnostic;
     158          981 :   va_list ap;
     159          981 :   rich_location richloc (line_table, location);
     160          981 :   va_start (ap, gmsgid);
     161          981 :   bool ret;
     162          981 :   if (!constexpr_fundef_p)
     163              :     {
     164              :       /* Report an error that cannot be suppressed.  */
     165          713 :       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
     166              :                            diagnostics::kind::error);
     167          713 :       ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
     168              :     }
     169          268 :   else if (warn_invalid_constexpr)
     170              :     {
     171          148 :       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
     172          148 :                            (cxx_dialect < cxx23
     173              :                             ? diagnostics::kind::pedwarn
     174              :                             : diagnostics::kind::warning));
     175          148 :       diagnostic.m_option_id = OPT_Winvalid_constexpr;
     176          148 :       ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
     177              :     }
     178              :   else
     179              :     ret = false;
     180          981 :   va_end (ap);
     181         1962 :   return ret;
     182          981 : }
     183              : 
     184              : struct constexpr_fundef_hasher : ggc_ptr_hash<constexpr_fundef>
     185              : {
     186              :   static hashval_t hash (const constexpr_fundef *);
     187              :   static bool equal (const constexpr_fundef *, const constexpr_fundef *);
     188              : };
     189              : 
     190              : /* This table holds all constexpr function definitions seen in
     191              :    the current translation unit.  */
     192              : 
     193              : static GTY (()) hash_table<constexpr_fundef_hasher> *constexpr_fundef_table;
     194              : 
     195              : /* Utility function used for managing the constexpr function table.
     196              :    Return true if the entries pointed to by P and Q are for the
     197              :    same constexpr function.  */
     198              : 
     199              : inline bool
     200    581433226 : constexpr_fundef_hasher::equal (const constexpr_fundef *lhs,
     201              :                                 const constexpr_fundef *rhs)
     202              : {
     203    560922259 :   return lhs->decl == rhs->decl;
     204              : }
     205              : 
     206              : /* Utility function used for managing the constexpr function table.
     207              :    Return a hash value for the entry pointed to by Q.  */
     208              : 
     209              : inline hashval_t
     210    558074909 : constexpr_fundef_hasher::hash (const constexpr_fundef *fundef)
     211              : {
     212    558074909 :   return DECL_UID (fundef->decl);
     213              : }
     214              : 
     215              : /* Return a previously saved definition of function FUN.   */
     216              : 
     217              : constexpr_fundef *
     218     66045697 : retrieve_constexpr_fundef (tree fun)
     219              : {
     220     66045697 :   if (constexpr_fundef_table == NULL)
     221              :     return NULL;
     222              : 
     223     66041707 :   constexpr_fundef fundef = { fun, NULL_TREE, NULL_TREE, NULL_TREE };
     224     66041707 :   return constexpr_fundef_table->find (&fundef);
     225              : }
     226              : 
     227              : /* Check whether the parameter and return types of FUN are valid for a
     228              :    constexpr function, and complain if COMPLAIN.  */
     229              : 
     230              : bool
     231     29332807 : is_valid_constexpr_fn (tree fun, bool complain)
     232              : {
     233     29332807 :   bool ret = true;
     234              : 
     235     58665614 :   if (DECL_INHERITED_CTOR (fun)
     236      3436809 :       && TREE_CODE (fun) == TEMPLATE_DECL)
     237              :     {
     238            0 :       ret = false;
     239            0 :       if (complain)
     240            0 :         error ("inherited constructor %qD is not %<constexpr%>",
     241            0 :                DECL_INHERITED_CTOR (fun));
     242              :     }
     243              :   else
     244              :     {
     245     29332807 :       for (tree parm = FUNCTION_FIRST_USER_PARM (fun);
     246     59216879 :            parm != NULL_TREE; parm = TREE_CHAIN (parm))
     247     29884072 :         if (!literal_type_p (TREE_TYPE (parm)))
     248              :           {
     249        13879 :             ret = false;
     250        13879 :             if (complain)
     251              :               {
     252           22 :                 auto_diagnostic_group d;
     253           22 :                 if (constexpr_error (input_location, /*constexpr_fundef_p*/true,
     254              :                                      "invalid type for parameter %d of "
     255              :                                      "%<constexpr%> function %q+#D",
     256           22 :                                      DECL_PARM_INDEX (parm), fun))
     257           14 :                   explain_non_literal_class (TREE_TYPE (parm));
     258           22 :               }
     259              :           }
     260              :     }
     261              : 
     262     48539668 :   if (LAMBDA_TYPE_P (CP_DECL_CONTEXT (fun)) && cxx_dialect < cxx17)
     263              :     {
     264            3 :       ret = false;
     265            3 :       if (complain)
     266            3 :         inform (DECL_SOURCE_LOCATION (fun),
     267              :                 "lambdas are implicitly %<constexpr%> only in C++17 and later");
     268              :     }
     269     58665608 :   else if (DECL_DESTRUCTOR_P (fun) && cxx_dialect < cxx20)
     270              :     {
     271            0 :       ret = false;
     272            0 :       if (complain)
     273            0 :         error_at (DECL_SOURCE_LOCATION (fun),
     274              :                   "%<constexpr%> destructors only available with "
     275              :                   "%<-std=c++20%> or %<-std=gnu++20%>");
     276              :     }
     277     29332804 :   else if (!DECL_CONSTRUCTOR_P (fun) && !DECL_DESTRUCTOR_P (fun))
     278              :     {
     279     25299551 :       tree rettype = TREE_TYPE (TREE_TYPE (fun));
     280     25299551 :       if (!literal_type_p (rettype))
     281              :         {
     282        50943 :           ret = false;
     283        50943 :           if (complain)
     284              :             {
     285           16 :               auto_diagnostic_group d;
     286           16 :               if (constexpr_error (input_location, /*constexpr_fundef_p*/true,
     287              :                                    "invalid return type %qT of %<constexpr%> "
     288              :                                    "function %q+D", rettype, fun))
     289            9 :                 explain_non_literal_class (rettype);
     290           16 :             }
     291              :         }
     292              : 
     293              :       /* C++14 DR 1684 removed this restriction.  */
     294     25299551 :       if (cxx_dialect < cxx14
     295        32926 :           && DECL_IOBJ_MEMBER_FUNCTION_P (fun)
     296     25300668 :           && !CLASSTYPE_LITERAL_P (DECL_CONTEXT (fun)))
     297              :         {
     298            1 :           ret = false;
     299            1 :           if (complain)
     300              :             {
     301            1 :               auto_diagnostic_group d;
     302            1 :               if (pedwarn (DECL_SOURCE_LOCATION (fun), OPT_Wpedantic,
     303              :                              "enclosing class of %<constexpr%> non-static"
     304              :                              " member function %q+#D is not a literal type",
     305              :                              fun))
     306            1 :                 explain_non_literal_class (DECL_CONTEXT (fun));
     307            1 :             }
     308              :         }
     309              :     }
     310      4033253 :   else if (CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fun)) && cxx_dialect < cxx26)
     311              :     {
     312           69 :       ret = false;
     313           69 :       if (complain)
     314              :         {
     315           10 :           if (DECL_CONSTRUCTOR_P (fun))
     316            8 :             error ("%<constexpr%> constructor in %q#T that has "
     317              :                    "virtual base classes only available with "
     318            8 :                    "%<-std=c++2c%> or %<-std=gnu++2c%>", DECL_CONTEXT (fun));
     319              :           else
     320            2 :             error ("%<constexpr%> destructor in %q#T that has "
     321              :                    "virtual base classes only available with "
     322            2 :                    "%<-std=c++2c%> or %<-std=gnu++2c%>", DECL_CONTEXT (fun));
     323              :         }
     324              :     }
     325              : 
     326     29332807 :   return ret;
     327              : }
     328              : 
     329              : /* Subroutine of build_data_member_initialization.  MEMBER is a COMPONENT_REF
     330              :    for a member of an anonymous aggregate, INIT is the initializer for that
     331              :    member, and VEC_OUTER is the vector of constructor elements for the class
     332              :    whose constructor we are processing.  Add the initializer to the vector
     333              :    and return true to indicate success.  */
     334              : 
     335              : static bool
     336          903 : build_anon_member_initialization (tree member, tree init,
     337              :                                   vec<constructor_elt, va_gc> **vec_outer)
     338              : {
     339              :   /* MEMBER presents the relevant fields from the inside out, but we need
     340              :      to build up the initializer from the outside in so that we can reuse
     341              :      previously built CONSTRUCTORs if this is, say, the second field in an
     342              :      anonymous struct.  So we use a vec as a stack.  */
     343          903 :   auto_vec<tree, 2> fields;
     344         1902 :   do
     345              :     {
     346         1902 :       fields.safe_push (TREE_OPERAND (member, 1));
     347         1902 :       member = TREE_OPERAND (member, 0);
     348              :     }
     349         1902 :   while (ANON_AGGR_TYPE_P (TREE_TYPE (member))
     350         3810 :          && TREE_CODE (member) == COMPONENT_REF);
     351              : 
     352              :   /* VEC has the constructor elements vector for the context of FIELD.
     353              :      If FIELD is an anonymous aggregate, we will push inside it.  */
     354              :   vec<constructor_elt, va_gc> **vec = vec_outer;
     355              :   tree field;
     356         1902 :   while (field = fields.pop(),
     357         1902 :          ANON_AGGR_TYPE_P (TREE_TYPE (field)))
     358              :     {
     359          999 :       tree ctor;
     360              :       /* If there is already an outer constructor entry for the anonymous
     361              :          aggregate FIELD, use it; otherwise, insert one.  */
     362          999 :       if (vec_safe_is_empty (*vec)
     363          198 :           || (*vec)->last().index != field)
     364              :         {
     365          897 :           ctor = build_constructor (TREE_TYPE (field), NULL);
     366          897 :           CONSTRUCTOR_APPEND_ELT (*vec, field, ctor);
     367              :         }
     368              :       else
     369          102 :         ctor = (*vec)->last().value;
     370          999 :       vec = &CONSTRUCTOR_ELTS (ctor);
     371              :     }
     372              : 
     373              :   /* Now we're at the innermost field, the one that isn't an anonymous
     374              :      aggregate.  Add its initializer to the CONSTRUCTOR and we're done.  */
     375          903 :   gcc_assert (fields.is_empty());
     376          903 :   CONSTRUCTOR_APPEND_ELT (*vec, field, init);
     377              : 
     378          903 :   return true;
     379          903 : }
     380              : 
     381              : /* Subroutine of  build_constexpr_constructor_member_initializers.
     382              :    The expression tree T represents a data member initialization
     383              :    in a (constexpr) constructor definition.  Build a pairing of
     384              :    the data member with its initializer, and prepend that pair
     385              :    to the existing initialization pair INITS.  */
     386              : 
     387              : static bool
     388      5609197 : build_data_member_initialization (tree t, vec<constructor_elt, va_gc> **vec)
     389              : {
     390      6245408 :   tree member, init;
     391      6245408 :   if (TREE_CODE (t) == CLEANUP_POINT_EXPR)
     392      2824227 :     t = TREE_OPERAND (t, 0);
     393      6245408 :   if (TREE_CODE (t) == EXPR_STMT)
     394      2823332 :     t = TREE_OPERAND (t, 0);
     395      6245408 :   if (t == error_mark_node)
     396              :     return false;
     397      6245399 :   if (TREE_CODE (t) == STATEMENT_LIST)
     398              :     {
     399      7052422 :       for (tree stmt : tsi_range (t))
     400       810873 :         if (! build_data_member_initialization (stmt, vec))
     401            9 :           return false;
     402              :       return true;
     403              :     }
     404      5613038 :   if (TREE_CODE (t) == CLEANUP_STMT)
     405              :     {
     406              :       /* We can't see a CLEANUP_STMT in a constructor for a literal class,
     407              :          but we can in a constexpr constructor for a non-literal class.  Just
     408              :          ignore it; either all the initialization will be constant, in which
     409              :          case the cleanup can't run, or it can't be constexpr.
     410              :          Still recurse into CLEANUP_BODY.  */
     411       606091 :       return build_data_member_initialization (CLEANUP_BODY (t), vec);
     412              :     }
     413      5006947 :   if (TREE_CODE (t) == CONVERT_EXPR)
     414      2807474 :     t = TREE_OPERAND (t, 0);
     415      5006947 :   if (TREE_CODE (t) == INIT_EXPR)
     416              :     {
     417      2697806 :       member = TREE_OPERAND (t, 0);
     418      2697806 :       init = break_out_target_exprs (TREE_OPERAND (t, 1));
     419              :     }
     420      2309141 :   else if (TREE_CODE (t) == CALL_EXPR)
     421              :     {
     422      1901069 :       tree fn = get_callee_fndecl (t);
     423      3802138 :       if (!fn || !DECL_CONSTRUCTOR_P (fn))
     424              :         /* We're only interested in calls to subobject constructors.  */
     425              :         return true;
     426      1513725 :       member = CALL_EXPR_ARG (t, 0);
     427              :       /* We don't use build_cplus_new here because it complains about
     428              :          abstract bases.  Leaving the call unwrapped means that it has the
     429              :          wrong type, but cxx_eval_constant_expression doesn't care.  */
     430      1513725 :       init = break_out_target_exprs (t);
     431              :     }
     432       408072 :   else if (TREE_CODE (t) == BIND_EXPR)
     433        30120 :     return build_data_member_initialization (BIND_EXPR_BODY (t), vec);
     434              :   else
     435              :     /* Don't add anything else to the CONSTRUCTOR.  */
     436              :     return true;
     437      4211531 :   if (INDIRECT_REF_P (member))
     438        59065 :     member = TREE_OPERAND (member, 0);
     439      4211531 :   if (TREE_CODE (member) == NOP_EXPR)
     440              :     {
     441       531945 :       tree op = member;
     442       531945 :       STRIP_NOPS (op);
     443       531945 :       if (TREE_CODE (op) == ADDR_EXPR)
     444              :         {
     445          599 :           gcc_assert (same_type_ignoring_top_level_qualifiers_p
     446              :                       (TREE_TYPE (TREE_TYPE (op)),
     447              :                        TREE_TYPE (TREE_TYPE (member))));
     448              :           /* Initializing a cv-qualified member; we need to look through
     449              :              the const_cast.  */
     450              :           member = op;
     451              :         }
     452       531346 :       else if (op == current_class_ptr
     453      1062561 :                && (same_type_ignoring_top_level_qualifiers_p
     454       531215 :                    (TREE_TYPE (TREE_TYPE (member)),
     455              :                     current_class_type)))
     456              :         /* Delegating constructor.  */
     457              :         member = op;
     458              :       else
     459              :         {
     460              :           /* This is an initializer for an empty base; keep it for now so
     461              :              we can check it in cxx_eval_bare_aggregate.  */
     462       459211 :           gcc_assert (is_empty_class (TREE_TYPE (TREE_TYPE (member))));
     463              :         }
     464              :     }
     465      4211531 :   if (TREE_CODE (member) == ADDR_EXPR)
     466      1041444 :     member = TREE_OPERAND (member, 0);
     467      4211531 :   if (TREE_CODE (member) == COMPONENT_REF)
     468              :     {
     469      3656251 :       tree aggr = TREE_OPERAND (member, 0);
     470      3656251 :       if (TREE_CODE (aggr) == VAR_DECL)
     471              :         /* Initializing a local variable, don't add anything.  */
     472              :         return true;
     473      3656249 :       if (TREE_CODE (aggr) != COMPONENT_REF)
     474              :         /* Normal member initialization.  */
     475      3655343 :         member = TREE_OPERAND (member, 1);
     476          906 :       else if (VAR_P (get_base_address (aggr)))
     477              :         /* Initializing a local variable, don't add anything.  */
     478              :         return true;
     479          903 :       else if (ANON_AGGR_TYPE_P (TREE_TYPE (aggr)))
     480              :         /* Initializing a member of an anonymous union.  */
     481          903 :         return build_anon_member_initialization (member, init, vec);
     482              :       else
     483              :         /* We're initializing a vtable pointer in a base.  Leave it as
     484              :            COMPONENT_REF so we remember the path to get to the vfield.  */
     485            0 :         gcc_assert (TREE_TYPE (member) == vtbl_ptr_type_node);
     486              :     }
     487              : 
     488              :   /* Value-initialization can produce multiple initializers for the
     489              :      same field; use the last one.  */
     490      5238971 :   if (!vec_safe_is_empty (*vec) && (*vec)->last().index == member)
     491           56 :     (*vec)->last().value = init;
     492              :   else
     493      4210567 :     CONSTRUCTOR_APPEND_ELT (*vec, member, init);
     494              :   return true;
     495              : }
     496              : 
     497              : /* Subroutine of check_constexpr_ctor_body_1 and constexpr_fn_retval.
     498              :    In C++11 mode checks that the TYPE_DECLs in the BIND_EXPR_VARS of a
     499              :    BIND_EXPR conform to 7.1.5/3/4 on typedef and alias declarations.  */
     500              : 
     501              : static bool
     502         2401 : check_constexpr_bind_expr_vars (tree t)
     503              : {
     504         2401 :   gcc_assert (TREE_CODE (t) == BIND_EXPR);
     505              : 
     506         3239 :   for (tree var = BIND_EXPR_VARS (t); var; var = DECL_CHAIN (var))
     507          850 :     if (TREE_CODE (var) == TYPE_DECL
     508          831 :         && DECL_IMPLICIT_TYPEDEF_P (var)
     509          872 :         && !LAMBDA_TYPE_P (TREE_TYPE (var)))
     510              :       return false;
     511              :   return true;
     512              : }
     513              : 
     514              : /* Subroutine of check_constexpr_ctor_body.  */
     515              : 
     516              : static bool
     517         4135 : check_constexpr_ctor_body_1 (tree last, tree list)
     518              : {
     519         4135 :   switch (TREE_CODE (list))
     520              :     {
     521            6 :     case DECL_EXPR:
     522            6 :       if (TREE_CODE (DECL_EXPR_DECL (list)) == USING_DECL
     523            6 :           || TREE_CODE (DECL_EXPR_DECL (list)) == TYPE_DECL)
     524              :         return true;
     525              :       return false;
     526              : 
     527            4 :     case CLEANUP_POINT_EXPR:
     528            4 :       return check_constexpr_ctor_body (last, TREE_OPERAND (list, 0),
     529            4 :                                         /*complain=*/false);
     530              : 
     531         2058 :     case BIND_EXPR:
     532         2058 :        if (!check_constexpr_bind_expr_vars (list)
     533         2058 :            || !check_constexpr_ctor_body (last, BIND_EXPR_BODY (list),
     534              :                                           /*complain=*/false))
     535           43 :          return false;
     536              :        return true;
     537              : 
     538              :     case USING_STMT:
     539              :     case STATIC_ASSERT:
     540              :     case DEBUG_BEGIN_STMT:
     541              :       return true;
     542              : 
     543              :     default:
     544              :       return false;
     545              :     }
     546              : }
     547              : 
     548              : /* Make sure that there are no statements after LAST in the constructor
     549              :    body represented by LIST.  */
     550              : 
     551              : bool
     552      5550400 : check_constexpr_ctor_body (tree last, tree list, bool complain)
     553              : {
     554              :   /* C++14 doesn't require a constexpr ctor to have an empty body.  */
     555      5550400 :   if (cxx_dialect >= cxx14)
     556              :     return true;
     557              : 
     558        13770 :   bool ok = true;
     559        13770 :   if (TREE_CODE (list) == STATEMENT_LIST)
     560              :     {
     561        13743 :       tree_stmt_iterator i = tsi_last (list);
     562        17781 :       for (; !tsi_end_p (i); tsi_prev (&i))
     563              :         {
     564        15654 :           tree t = tsi_stmt (i);
     565        15654 :           if (t == last)
     566              :             break;
     567         4108 :           if (!check_constexpr_ctor_body_1 (last, t))
     568              :             {
     569              :               ok = false;
     570              :               break;
     571              :             }
     572              :         }
     573              :     }
     574           27 :   else if (list != last
     575           27 :            && !check_constexpr_ctor_body_1 (last, list))
     576              :     ok = false;
     577        13770 :   if (!ok && complain)
     578              :     {
     579           49 :       pedwarn (input_location, OPT_Wc__14_extensions,
     580              :                "%<constexpr%> constructor does not have empty body");
     581           49 :       ok = true;
     582              :     }
     583              :   return ok;
     584              : }
     585              : 
     586              : /* V is a vector of constructor elements built up for the base and member
     587              :    initializers of a constructor for TYPE.  They need to be in increasing
     588              :    offset order, which they might not be yet if TYPE has a primary base
     589              :    which is not first in the base-clause or a vptr and at least one base
     590              :    all of which are non-primary.  */
     591              : 
     592              : static vec<constructor_elt, va_gc> *
     593      3363823 : sort_constexpr_mem_initializers (tree type, vec<constructor_elt, va_gc> *v)
     594              : {
     595      3363823 :   tree pri = CLASSTYPE_PRIMARY_BINFO (type);
     596      3363823 :   tree field_type;
     597      3363823 :   unsigned i;
     598      3363823 :   constructor_elt *ce;
     599              : 
     600      3363823 :   if (pri)
     601        60910 :     field_type = BINFO_TYPE (pri);
     602      3302913 :   else if (TYPE_CONTAINS_VPTR_P (type))
     603        34754 :     field_type = vtbl_ptr_type_node;
     604              :   else
     605              :     return v;
     606              : 
     607              :   /* Find the element for the primary base or vptr and move it to the
     608              :      beginning of the vec.  */
     609       135098 :   for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
     610       100224 :     if (TREE_TYPE (ce->index) == field_type)
     611              :       break;
     612              : 
     613       116426 :   if (i > 0 && i < vec_safe_length (v))
     614              :     {
     615           22 :       vec<constructor_elt, va_gc> &vref = *v;
     616           22 :       constructor_elt elt = vref[i];
     617           44 :       for (; i > 0; --i)
     618           22 :         vref[i] = vref[i-1];
     619           22 :       vref[0] = elt;
     620              :     }
     621              : 
     622              :   return v;
     623              : }
     624              : 
     625              : /* Build compile-time evalable representations of member-initializer list
     626              :    for a constexpr constructor.  */
     627              : 
     628              : static tree
     629      3435939 : build_constexpr_constructor_member_initializers (tree type, tree body)
     630              : {
     631      3435939 :   vec<constructor_elt, va_gc> *vec = NULL;
     632      3435939 :   bool ok = true;
     633      5379190 :   while (true)
     634      5379190 :     switch (TREE_CODE (body))
     635              :       {
     636      1943180 :       case MUST_NOT_THROW_EXPR:
     637      1943180 :       case EH_SPEC_BLOCK:
     638      1943180 :       case TRY_FINALLY_EXPR: // For C++26 postconditions.
     639      1943180 :         body = TREE_OPERAND (body, 0);
     640      1943180 :         break;
     641              : 
     642           71 :       case STATEMENT_LIST:
     643      5379286 :         for (tree stmt : tsi_range (body))
     644              :           {
     645          145 :             body = stmt;
     646          145 :             if (TREE_CODE (body) == BIND_EXPR)
     647              :               break;
     648              :           }
     649              :         break;
     650              : 
     651      3435939 :       case BIND_EXPR:
     652      3435939 :         body = BIND_EXPR_BODY (body);
     653      3435939 :         goto found;
     654              : 
     655            0 :       default:
     656            0 :         gcc_unreachable ();
     657              :     }
     658      3435939 :  found:
     659      3435939 :   if (TREE_CODE (body) == TRY_BLOCK)
     660              :     {
     661           29 :       body = TREE_OPERAND (body, 0);
     662           29 :       if (TREE_CODE (body) == BIND_EXPR)
     663           29 :         body = BIND_EXPR_BODY (body);
     664              :     }
     665      3435939 :   if (TREE_CODE (body) == CLEANUP_POINT_EXPR)
     666              :     {
     667      1885279 :       body = TREE_OPERAND (body, 0);
     668      1885279 :       if (TREE_CODE (body) == EXPR_STMT)
     669      1885269 :         body = TREE_OPERAND (body, 0);
     670      1885279 :       if (TREE_CODE (body) == INIT_EXPR
     671      1885279 :           && (same_type_ignoring_top_level_qualifiers_p
     672            0 :               (TREE_TYPE (TREE_OPERAND (body, 0)),
     673              :                current_class_type)))
     674              :         {
     675              :           /* Trivial copy.  */
     676            0 :           return TREE_OPERAND (body, 1);
     677              :         }
     678      1885279 :       ok = build_data_member_initialization (body, &vec);
     679              :     }
     680      1550660 :   else if (TREE_CODE (body) == STATEMENT_LIST)
     681              :     {
     682      4457162 :       for (tree stmt : tsi_range (body))
     683              :         {
     684      2909774 :           ok = build_data_member_initialization (stmt, &vec);
     685      2909774 :           if (!ok)
     686              :             break;
     687              :         }
     688              :     }
     689         3271 :   else if (EXPR_P (body))
     690         3271 :     ok = build_data_member_initialization (body, &vec);
     691              :   else
     692            0 :     gcc_assert (errorcount > 0);
     693      3435939 :   if (ok)
     694              :     {
     695      3435930 :       if (vec_safe_length (vec) > 0)
     696              :         {
     697              :           /* In a delegating constructor, return the target.  */
     698      3183052 :           constructor_elt *ce = &(*vec)[0];
     699      3183052 :           if (ce->index == current_class_ptr)
     700              :             {
     701        72107 :               body = ce->value;
     702        72107 :               vec_free (vec);
     703        72107 :               return body;
     704              :             }
     705              :         }
     706      3363823 :       vec = sort_constexpr_mem_initializers (type, vec);
     707      3363823 :       return build_constructor (type, vec);
     708              :     }
     709              :   else
     710            9 :     return error_mark_node;
     711              : }
     712              : 
     713              : /* We have an expression tree T that represents a call, either CALL_EXPR
     714              :    or AGGR_INIT_EXPR.  If the call is lexically to a named function,
     715              :    return the _DECL for that function.  */
     716              : 
     717              : static tree
     718    442528053 : get_function_named_in_call (tree t)
     719              : {
     720    442528053 :   tree callee = cp_get_callee (t);
     721    442528053 :   tree fun = cp_get_fndecl_from_callee (callee, /*fold*/false);
     722    442528053 :   return fun ? fun : callee;
     723              : }
     724              : 
     725              : /* Subroutine of check_constexpr_fundef.  BODY is the body of a function
     726              :    declared to be constexpr, or a sub-statement thereof.  Returns the
     727              :    return value if suitable, error_mark_node for a statement not allowed in
     728              :    a constexpr function, or NULL_TREE if no return value was found.  */
     729              : 
     730              : tree
     731        70529 : constexpr_fn_retval (tree body)
     732              : {
     733        77329 :   switch (TREE_CODE (body))
     734              :     {
     735        18770 :     case STATEMENT_LIST:
     736        18770 :       {
     737        18770 :         tree expr = NULL_TREE;
     738        56240 :         for (tree stmt : tsi_range (body))
     739              :           {
     740        37499 :             tree s = constexpr_fn_retval (stmt);
     741        37499 :             if (s == error_mark_node)
     742              :               return error_mark_node;
     743        37472 :             else if (s == NULL_TREE)
     744              :               /* Keep iterating.  */;
     745        18735 :             else if (expr)
     746              :               /* Multiple return statements.  */
     747              :               return error_mark_node;
     748              :             else
     749              :               expr = s;
     750              :           }
     751              :         return expr;
     752              :       }
     753              : 
     754        32980 :     case RETURN_EXPR:
     755        32980 :       return break_out_target_exprs (TREE_OPERAND (body, 0));
     756              : 
     757           20 :     case DECL_EXPR:
     758           20 :       {
     759           20 :         tree decl = DECL_EXPR_DECL (body);
     760           20 :         if (TREE_CODE (decl) == USING_DECL
     761              :             /* Accept __func__, __FUNCTION__, and __PRETTY_FUNCTION__.  */
     762           20 :             || DECL_ARTIFICIAL (decl))
     763              :           return NULL_TREE;
     764            6 :         return error_mark_node;
     765              :       }
     766              : 
     767         6463 :     case CLEANUP_POINT_EXPR:
     768         6463 :       return constexpr_fn_retval (TREE_OPERAND (body, 0));
     769              : 
     770          343 :     case BIND_EXPR:
     771          343 :       if (!check_constexpr_bind_expr_vars (body))
     772            6 :         return error_mark_node;
     773          337 :       return constexpr_fn_retval (BIND_EXPR_BODY (body));
     774              : 
     775              :     case USING_STMT:
     776              :     case DEBUG_BEGIN_STMT:
     777              :       return NULL_TREE;
     778              : 
     779            0 :     case CALL_EXPR:
     780            0 :         {
     781            0 :           tree fun = get_function_named_in_call (body);
     782            0 :           if (fun != NULL_TREE
     783            0 :               && fndecl_built_in_p (fun, BUILT_IN_UNREACHABLE))
     784              :             return NULL_TREE;
     785              :         }
     786              :       /* Fallthru.  */
     787              : 
     788           30 :     default:
     789           30 :       return error_mark_node;
     790              :     }
     791              : }
     792              : 
     793              : /* Subroutine of check_constexpr_fundef.  BODY is the DECL_SAVED_TREE of
     794              :    FUN; do the necessary transformations to turn it into a single expression
     795              :    that we can store in the hash table.  */
     796              : 
     797              : static tree
     798     28728006 : massage_constexpr_body (tree fun, tree body)
     799              : {
     800     57456012 :   if (DECL_CONSTRUCTOR_P (fun))
     801      3435939 :     body = build_constexpr_constructor_member_initializers
     802      3435939 :       (DECL_CONTEXT (fun), body);
     803     25292067 :   else if (cxx_dialect < cxx14)
     804              :     {
     805        32795 :       if (TREE_CODE (body) == EH_SPEC_BLOCK)
     806            1 :         body = EH_SPEC_STMTS (body);
     807        32795 :       if (TREE_CODE (body) == MUST_NOT_THROW_EXPR)
     808        21416 :         body = TREE_OPERAND (body, 0);
     809        32795 :       body = constexpr_fn_retval (body);
     810              :     }
     811     28728006 :   return body;
     812              : }
     813              : 
     814              : /* CTYPE is a type constructed from BODY.  Return true if some
     815              :    bases/fields are uninitialized, and complain if COMPLAIN.  */
     816              : 
     817              : static bool
     818      3124020 : cx_check_missing_mem_inits (tree ctype, tree body, bool complain)
     819              : {
     820              :   /* We allow uninitialized bases/fields in C++20.  */
     821      3124020 :   if (cxx_dialect >= cxx20)
     822              :     return false;
     823              : 
     824        13621 :   unsigned nelts = 0;
     825              : 
     826        13621 :   if (body)
     827              :     {
     828        13617 :       if (TREE_CODE (body) != CONSTRUCTOR)
     829              :         return false;
     830        13566 :       nelts = CONSTRUCTOR_NELTS (body);
     831              :     }
     832        13570 :   tree field = TYPE_FIELDS (ctype);
     833              : 
     834        13570 :   if (TREE_CODE (ctype) == UNION_TYPE)
     835              :     {
     836          110 :       if (nelts == 0 && next_aggregate_field (field))
     837              :         {
     838            2 :           if (complain)
     839            2 :             error ("%<constexpr%> constructor for union %qT must "
     840              :                    "initialize exactly one non-static data member", ctype);
     841            2 :           return true;
     842              :         }
     843          108 :       return false;
     844              :     }
     845              : 
     846              :   /* Iterate over the CONSTRUCTOR, checking any missing fields don't
     847              :      need an explicit initialization.  */
     848              :   bool bad = false;
     849        28640 :   for (unsigned i = 0; i <= nelts; ++i)
     850              :     {
     851        28640 :       tree index = NULL_TREE;
     852        28640 :       if (i < nelts)
     853              :         {
     854        15180 :           index = CONSTRUCTOR_ELT (body, i)->index;
     855              :           /* Skip vptr adjustment represented with a COMPONENT_REF.  */
     856        15180 :           if (TREE_CODE (index) != FIELD_DECL)
     857          627 :             continue;
     858              :         }
     859              : 
     860       494865 :       for (; field != index; field = DECL_CHAIN (field))
     861              :         {
     862       466858 :           tree ftype;
     863       466858 :           if (TREE_CODE (field) != FIELD_DECL)
     864       931899 :             continue;
     865         1789 :           if (DECL_UNNAMED_BIT_FIELD (field))
     866           10 :             continue;
     867              :           /* Artificial fields can be ignored unless they're bases.  */
     868         1779 :           if (DECL_ARTIFICIAL (field) && !DECL_FIELD_IS_BASE (field))
     869            6 :             continue;
     870         1773 :           if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
     871              :             {
     872              :               /* Recurse to check the anonymous aggregate member.  */
     873            8 :               bad |= cx_check_missing_mem_inits
     874            4 :                 (TREE_TYPE (field), NULL_TREE, complain);
     875            4 :               if (bad && !complain)
     876            6 :                 return true;
     877            4 :               continue;
     878              :             }
     879         1769 :           ftype = TREE_TYPE (field);
     880         1769 :           if (!ftype || !TYPE_P (ftype) || !COMPLETE_TYPE_P (ftype))
     881              :             /* A flexible array can't be intialized here, so don't complain
     882              :                that it isn't.  */
     883            1 :             continue;
     884         1768 :           if (is_empty_field (field))
     885              :             /* An empty field doesn't need an initializer.  */
     886         1733 :             continue;
     887           35 :           ftype = strip_array_types (ftype);
     888           35 :           if (type_has_constexpr_default_constructor (ftype))
     889              :             {
     890              :               /* It's OK to skip a member with a trivial constexpr ctor.
     891              :                  A constexpr ctor that isn't trivial should have been
     892              :                  added in by now.  */
     893            7 :               gcc_checking_assert (!TYPE_HAS_COMPLEX_DFLT (ftype)
     894              :                                    || errorcount != 0);
     895            7 :               continue;
     896              :             }
     897           28 :           if (!complain)
     898              :             return true;
     899           22 :           auto_diagnostic_group d;
     900           22 :           error ("member %qD must be initialized by mem-initializer "
     901              :                  "in %<constexpr%> constructor", field);
     902           22 :           inform (DECL_SOURCE_LOCATION (field), "declared here");
     903           22 :           bad = true;
     904           22 :         }
     905        28007 :       if (field == NULL_TREE)
     906              :         break;
     907              : 
     908        14553 :       if (ANON_AGGR_TYPE_P (TREE_TYPE (index)))
     909              :         {
     910              :           /* Check the anonymous aggregate initializer is valid.  */
     911           76 :           bad |= cx_check_missing_mem_inits
     912           38 :             (TREE_TYPE (index), CONSTRUCTOR_ELT (body, i)->value, complain);
     913           38 :           if (bad && !complain)
     914              :             return true;
     915              :         }
     916        14553 :       field = DECL_CHAIN (field);
     917              :     }
     918              : 
     919              :   return bad;
     920              : }
     921              : 
     922              : /* We are processing the definition of the constexpr function FUN.
     923              :    Check that its body fulfills the apropriate requirements and
     924              :    enter it in the constexpr function definition table.  */
     925              : 
     926              : void
     927    159139371 : maybe_save_constexpr_fundef (tree fun)
     928              : {
     929    159139371 :   if (processing_template_decl
     930     65537066 :       || cp_function_chain->invalid_constexpr
     931    224658259 :       || (DECL_CLONED_FUNCTION_P (fun) && !DECL_DELETING_DESTRUCTOR_P (fun)))
     932    130411630 :     return;
     933              : 
     934              :   /* With -fimplicit-constexpr, try to make inlines constexpr.  We'll
     935              :      actually set DECL_DECLARED_CONSTEXPR_P below if the checks pass.  */
     936     50048060 :   bool implicit = false;
     937     50048060 :   if (flag_implicit_constexpr)
     938              :     {
     939           19 :       if (DECL_DELETING_DESTRUCTOR_P (fun)
     940           19 :           && decl_implicit_constexpr_p (DECL_CLONED_FUNCTION (fun)))
     941              :         /* Don't inherit implicit constexpr from the non-deleting
     942              :            destructor.  */
     943            0 :         DECL_DECLARED_CONSTEXPR_P (fun) = false;
     944              : 
     945           19 :       if (!DECL_DECLARED_CONSTEXPR_P (fun)
     946           16 :           && DECL_DECLARED_INLINE_P (fun)
     947           31 :           && !lookup_attribute ("noinline", DECL_ATTRIBUTES (fun)))
     948              :         implicit = true;
     949              :     }
     950              : 
     951     50048060 :   if (!DECL_DECLARED_CONSTEXPR_P (fun) && !implicit)
     952              :     return;
     953              : 
     954     28783654 :   bool complain = !DECL_GENERATED_P (fun) && !implicit;
     955              : 
     956     28783654 :   if (!is_valid_constexpr_fn (fun, complain))
     957              :     return;
     958              : 
     959     28727941 :   tree massaged = massage_constexpr_body (fun, DECL_SAVED_TREE (fun));
     960     28727941 :   if (massaged == NULL_TREE || massaged == error_mark_node)
     961              :     {
     962           72 :       if (!DECL_CONSTRUCTOR_P (fun) && complain)
     963           22 :         error ("body of %<constexpr%> function %qD not a return-statement",
     964              :                fun);
     965           36 :       return;
     966              :     }
     967              : 
     968     28727905 :   bool potential = potential_rvalue_constant_expression (massaged);
     969     28727905 :   if (!potential && complain)
     970          229 :     require_potential_rvalue_constant_expression_fncheck (massaged);
     971              : 
     972     32163823 :   if (DECL_CONSTRUCTOR_P (fun) && potential
     973     32161721 :       && !DECL_DEFAULTED_FN (fun))
     974              :     {
     975      3123966 :       if (cx_check_missing_mem_inits (DECL_CONTEXT (fun),
     976              :                                       massaged, complain))
     977              :         potential = false;
     978      3123940 :       else if (cxx_dialect > cxx11)
     979              :         {
     980              :           /* What we got from massage_constexpr_body is pretty much just the
     981              :              ctor-initializer, also check the body.  */
     982      3119143 :           massaged = DECL_SAVED_TREE (fun);
     983      3119143 :           potential = potential_rvalue_constant_expression (massaged);
     984      3119143 :           if (!potential && complain)
     985           16 :             require_potential_rvalue_constant_expression_fncheck (massaged);
     986              :         }
     987              :     }
     988              : 
     989     28727905 :   if (!potential && complain
     990              :       /* If -Wno-invalid-constexpr was specified, we haven't complained
     991              :          about non-constant expressions yet.  Register the function and
     992              :          complain in explain_invalid_constexpr_fn if the function is
     993              :          called.  */
     994          265 :       && warn_invalid_constexpr != 0)
     995              :     return;
     996              : 
     997     28727751 :   if (implicit)
     998              :     {
     999           12 :       if (potential)
    1000              :         {
    1001            2 :           DECL_DECLARED_CONSTEXPR_P (fun) = true;
    1002            2 :           DECL_LANG_SPECIFIC (fun)->u.fn.implicit_constexpr = true;
    1003            4 :           if (DECL_CONSTRUCTOR_P (fun))
    1004            0 :             TYPE_HAS_CONSTEXPR_CTOR (DECL_CONTEXT (fun)) = true;
    1005              :         }
    1006              :       else
    1007              :         /* Don't bother keeping the pre-generic body of unsuitable functions
    1008              :            not explicitly declared constexpr.  */
    1009              :         return;
    1010              :     }
    1011              : 
    1012     28727741 :   constexpr_fundef entry = {fun, NULL_TREE, NULL_TREE, NULL_TREE};
    1013     28727741 :   bool clear_ctx = false;
    1014     28727741 :   if (DECL_RESULT (fun) && DECL_CONTEXT (DECL_RESULT (fun)) == NULL_TREE)
    1015              :     {
    1016     28727741 :       clear_ctx = true;
    1017     28727741 :       DECL_CONTEXT (DECL_RESULT (fun)) = fun;
    1018              :     }
    1019     28727741 :   tree saved_fn = current_function_decl;
    1020     28727741 :   current_function_decl = fun;
    1021     28727741 :   entry.body = copy_fn (entry.decl, entry.parms, entry.result);
    1022     28727741 :   current_function_decl = saved_fn;
    1023     28727741 :   if (clear_ctx)
    1024     28727741 :     DECL_CONTEXT (DECL_RESULT (entry.decl)) = NULL_TREE;
    1025     28727741 :   if (!potential)
    1026              :     /* For a template instantiation, we want to remember the pre-generic body
    1027              :        for explain_invalid_constexpr_fn, but do tell cxx_eval_call_expression
    1028              :        that it doesn't need to bother trying to expand the function.  */
    1029        59873 :     entry.result = error_mark_node;
    1030              : 
    1031     28727741 :   register_constexpr_fundef (entry);
    1032              : }
    1033              : 
    1034              : /* BODY is a validated and massaged definition of a constexpr
    1035              :    function.  Register it in the hash table.  */
    1036              : 
    1037              : void
    1038     28763717 : register_constexpr_fundef (const constexpr_fundef &value)
    1039              : {
    1040              :   /* Create the constexpr function table if necessary.  */
    1041     28763717 :   if (constexpr_fundef_table == NULL)
    1042        26339 :     constexpr_fundef_table
    1043        26339 :       = hash_table<constexpr_fundef_hasher>::create_ggc (101);
    1044              : 
    1045     28763717 :   constexpr_fundef **slot = constexpr_fundef_table->find_slot
    1046     28763717 :     (const_cast<constexpr_fundef *> (&value), INSERT);
    1047              : 
    1048     28763717 :   gcc_assert (*slot == NULL);
    1049     28763717 :   *slot = ggc_alloc<constexpr_fundef> ();
    1050     28763717 :   **slot = value;
    1051     28763717 : }
    1052              : 
    1053              : /* FUN is a non-constexpr (or, with -Wno-invalid-constexpr, a constexpr
    1054              :    function called in a context that requires a constant expression).
    1055              :    If it comes from a constexpr template, explain why the instantiation
    1056              :    isn't constexpr.  Otherwise, explain why the function cannot be used
    1057              :    in a constexpr context.  */
    1058              : 
    1059              : void
    1060          799 : explain_invalid_constexpr_fn (tree fun)
    1061              : {
    1062          799 :   static hash_set<tree> *diagnosed;
    1063          799 :   tree body;
    1064              : 
    1065              :   /* Don't try to explain a function we already complained about.  */
    1066          799 :   if (function *f = DECL_STRUCT_FUNCTION (fun))
    1067          606 :     if (f->language->erroneous)
    1068          799 :       return;
    1069              : 
    1070              :   /* In C++23, a function marked 'constexpr' may not actually be a constant
    1071              :      expression.  We haven't diagnosed the problem yet: -Winvalid-constexpr
    1072              :      wasn't enabled.  The function was called, so diagnose why it cannot be
    1073              :      used in a constant expression.  */
    1074          750 :   if (warn_invalid_constexpr == 0 && DECL_DECLARED_CONSTEXPR_P (fun))
    1075              :     /* Go on.  */;
    1076              :   /* Only diagnose defaulted functions, lambdas, or instantiations.  */
    1077          722 :   else if (!DECL_DEFAULTED_FN (fun)
    1078          954 :            && !LAMBDA_TYPE_P (CP_DECL_CONTEXT (fun))
    1079          691 :            && !(flag_implicit_constexpr
    1080            8 :                 && !DECL_DECLARED_CONSTEXPR_P (fun)
    1081            8 :                 && DECL_DECLARED_INLINE_P (fun))
    1082         1408 :            && !is_instantiation_of_constexpr (fun))
    1083              :     {
    1084          668 :       inform (DECL_SOURCE_LOCATION (fun), "%qD declared here", fun);
    1085            3 :       if (flag_implicit_constexpr && !maybe_constexpr_fn (fun)
    1086          671 :           && decl_defined_p (fun))
    1087            3 :         inform (DECL_SOURCE_LOCATION (fun),
    1088              :                 "%<-fimplicit-constexpr%> only affects %<inline%> functions");
    1089          668 :       return;
    1090              :     }
    1091           82 :   if (diagnosed == NULL)
    1092           65 :     diagnosed = new hash_set<tree>;
    1093           82 :   if (diagnosed->add (fun))
    1094              :     /* Already explained.  */
    1095              :     return;
    1096              : 
    1097           81 :   iloc_sentinel ils = input_location;
    1098           81 :   if (!lambda_static_thunk_p (fun))
    1099              :     {
    1100              :       /* Diagnostics should completely ignore the static thunk, so leave
    1101              :          input_location set to our caller's location.  */
    1102           75 :       input_location = DECL_SOURCE_LOCATION (fun);
    1103           75 :       inform (input_location,
    1104              :               "%qD is not usable as a %<constexpr%> function because:", fun);
    1105              :     }
    1106              :   /* First check the declaration.  */
    1107           81 :   if (is_valid_constexpr_fn (fun, true))
    1108              :     {
    1109              :       /* Then if it's OK, the body.  */
    1110           75 :       if (!DECL_DECLARED_CONSTEXPR_P (fun)
    1111           75 :           && DECL_DEFAULTED_FN (fun))
    1112           10 :         explain_implicit_non_constexpr (fun);
    1113              :       else
    1114              :         {
    1115           65 :           if (constexpr_fundef *fd = retrieve_constexpr_fundef (fun))
    1116           46 :             body = fd->body;
    1117              :           else
    1118           19 :             body = DECL_SAVED_TREE (fun);
    1119           65 :           tree massaged = massage_constexpr_body (fun, body);
    1120           65 :           require_potential_rvalue_constant_expression (massaged);
    1121          130 :           if (DECL_CONSTRUCTOR_P (fun))
    1122              :             {
    1123           12 :               cx_check_missing_mem_inits (DECL_CONTEXT (fun), massaged, true);
    1124           12 :               if (cxx_dialect > cxx11)
    1125              :                 /* Also check the body, not just the ctor-initializer.  */
    1126           10 :                 require_potential_rvalue_constant_expression (body);
    1127              :             }
    1128           53 :           else if (massaged == NULL_TREE || massaged == error_mark_node)
    1129            1 :             error ("body of %<constexpr%> function %qD not a return-statement",
    1130              :                    fun);
    1131              :         }
    1132              :     }
    1133           81 : }
    1134              : 
    1135              : /* Objects of this type represent calls to constexpr functions
    1136              :    along with the bindings of parameters to their arguments, for
    1137              :    the purpose of compile time evaluation.  */
    1138              : 
    1139              : struct GTY((for_user)) constexpr_call {
    1140              :   /* Description of the constexpr function definition.  */
    1141              :   constexpr_fundef *fundef = nullptr;
    1142              :   /* Parameter bindings environment.  A TREE_VEC of arguments.  */
    1143              :   tree bindings = NULL_TREE;
    1144              :   /* Result of the call, indexed by the value of
    1145              :      constexpr_ctx::manifestly_const_eval.
    1146              :        unknown_type_node means the call is being evaluated.
    1147              :        error_mark_node means that the evaluation was erroneous or otherwise
    1148              :        uncacheable (e.g. because it depends on the caller).
    1149              :        Otherwise, the actual value of the call.  */
    1150              :   tree results[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
    1151              :   /* The hash of this call; we remember it here to avoid having to
    1152              :      recalculate it when expanding the hash table.  */
    1153              :   hashval_t hash = 0;
    1154              : 
    1155              :   /* The result slot corresponding to the given mce_value.  */
    1156     49656519 :   tree& result (mce_value mce) { return results[1 + int(mce)]; }
    1157              : };
    1158              : 
    1159              : struct constexpr_call_hasher : ggc_ptr_hash<constexpr_call>
    1160              : {
    1161              :   static hashval_t hash (constexpr_call *);
    1162              :   static bool equal (constexpr_call *, constexpr_call *);
    1163              : };
    1164              : 
    1165              : enum constexpr_switch_state {
    1166              :   /* Used when processing a switch for the first time by cxx_eval_switch_expr
    1167              :      and default: label for that switch has not been seen yet.  */
    1168              :   css_default_not_seen,
    1169              :   /* Used when processing a switch for the first time by cxx_eval_switch_expr
    1170              :      and default: label for that switch has been seen already.  */
    1171              :   css_default_seen,
    1172              :   /* Used when processing a switch for the second time by
    1173              :      cxx_eval_switch_expr, where default: label should match.  */
    1174              :   css_default_processing
    1175              : };
    1176              : 
    1177              : /* The constexpr expansion context part which needs one instance per
    1178              :    cxx_eval_outermost_constant_expr invocation.  VALUES is a map of values of
    1179              :    variables initialized within the expression.  */
    1180              : 
    1181              : class constexpr_global_ctx {
    1182              :   /* Values for any temporaries or local variables within the
    1183              :      constant-expression. Objects outside their lifetime have
    1184              :      value 'void_node'.  */
    1185              :   hash_map<tree,tree> values;
    1186              : public:
    1187              :   /* Number of cxx_eval_constant_expression calls (except skipped ones,
    1188              :      on simple constants or location wrappers) encountered during current
    1189              :      cxx_eval_outermost_constant_expr call.  */
    1190              :   HOST_WIDE_INT constexpr_ops_count;
    1191              :   /* Heap VAR_DECLs created during the evaluation of the outermost constant
    1192              :      expression.  */
    1193              :   auto_vec<tree, 16> heap_vars;
    1194              :   /* Vector of caught exceptions, including exceptions still not active at
    1195              :      the start of a handler (those are immediately followed up by HANDLER_TYPE
    1196              :      until __cxa_begin_catch finishes).  */
    1197              :   auto_vec<tree, 2> caught_exceptions;
    1198              :   /* Cleanups that need to be evaluated at the end of CLEANUP_POINT_EXPR.  */
    1199              :   vec<tree> *cleanups;
    1200              :   /* If non-null, only allow modification of existing values of the variables
    1201              :      in this set.  Set by modifiable_tracker, below.  */
    1202              :   hash_set<tree> *modifiable;
    1203              :   /* If cxx_eval_outermost_constant_expr is called on the consteval block
    1204              :      operator (), this is the FUNCTION_DECL of that operator ().  */
    1205              :   tree consteval_block;
    1206              :   /* Number of heap VAR_DECL deallocations.  */
    1207              :   unsigned heap_dealloc_count;
    1208              :   /* Number of uncaught exceptions.  */
    1209              :   unsigned uncaught_exceptions;
    1210              :   /* A contract statement that failed or was not constant, we only store the
    1211              :      first one that fails.  */
    1212              :   tree contract_statement;
    1213              :   /* [basic.contract.eval]/7.3 if this expression would otherwise be constant
    1214              :      then a non-const contract makes the program ill-formed.  */
    1215              :   bool contract_condition_non_const;
    1216              :   /* Some metafunctions aren't dependent just on their arguments, but also
    1217              :      on various other dependencies, e.g. has_identifier on a function parameter
    1218              :      reflection can change depending on further declarations of corresponding
    1219              :      function, is_complete_type depends on type definitions and template
    1220              :      specializations in between the calls, define_aggregate even defines
    1221              :      class types, etc.  Thus, we need to arrange for calls which call
    1222              :      at least some metafunctions to be non-cacheable, because their behavior
    1223              :      might not be the same.  Until we figure out which exact metafunctions
    1224              :      need this and which don't, do it for all of them.  */
    1225              :   bool metafns_called;
    1226              : 
    1227              :   /* Constructor.  */
    1228    509072041 :   constexpr_global_ctx ()
    1229   1018144082 :     : constexpr_ops_count (0), cleanups (NULL), modifiable (nullptr),
    1230    509072041 :       consteval_block (NULL_TREE), heap_dealloc_count (0),
    1231    509072041 :       uncaught_exceptions (0), contract_statement (NULL_TREE),
    1232    509072041 :       contract_condition_non_const (false), metafns_called (false) {}
    1233              : 
    1234    313088465 :   bool is_outside_lifetime (tree t)
    1235              :   {
    1236    313088465 :     if (tree *p = values.get (t))
    1237    101672144 :       if (*p == void_node)
    1238          189 :         return true;
    1239              :     return false;
    1240              :   }
    1241    380084592 :  tree get_value (tree t)
    1242              :   {
    1243    380084592 :     if (tree *p = values.get (t))
    1244    153053801 :       if (*p != void_node)
    1245    149839094 :         return *p;
    1246              :     return NULL_TREE;
    1247              :   }
    1248     65281272 :   tree *get_value_ptr (tree t, bool initializing)
    1249              :   {
    1250     65281272 :     if (modifiable && !modifiable->contains (t))
    1251              :       return nullptr;
    1252     65281261 :     if (tree *p = values.get (t))
    1253              :       {
    1254     65275993 :         if (*p != void_node)
    1255              :           return p;
    1256           48 :         else if (initializing)
    1257              :           {
    1258            6 :             *p = NULL_TREE;
    1259            6 :             return p;
    1260              :           }
    1261              :       }
    1262              :     return nullptr;
    1263              :   }
    1264    171049365 :   void put_value (tree t, tree v)
    1265              :   {
    1266    171049365 :     bool already_in_map = values.put (t, v);
    1267    171049365 :     if (!already_in_map && modifiable)
    1268           30 :       modifiable->add (t);
    1269    171049365 :   }
    1270    126704402 :   void destroy_value (tree t)
    1271              :   {
    1272    126704402 :     if (TREE_CODE (t) == VAR_DECL
    1273    126704402 :         || TREE_CODE (t) == PARM_DECL
    1274              :         || TREE_CODE (t) == RESULT_DECL)
    1275    126698104 :       values.put (t, void_node);
    1276              :     else
    1277         6298 :       values.remove (t);
    1278    126704402 :   }
    1279      8829812 :   void clear_value (tree t)
    1280              :   {
    1281     17659624 :     values.remove (t);
    1282              :   }
    1283              : };
    1284              : 
    1285              : /* Helper class for constexpr_global_ctx.  In some cases we want to avoid
    1286              :    side-effects from evaluation of a particular subexpression of a
    1287              :    constant-expression.  In such cases we use modifiable_tracker to prevent
    1288              :    modification of variables created outside of that subexpression.
    1289              : 
    1290              :    ??? We could change the hash_set to a hash_map, allow and track external
    1291              :    modifications, and roll them back in the destructor.  It's not clear to me
    1292              :    that this would be worthwhile.  */
    1293              : 
    1294              : class modifiable_tracker
    1295              : {
    1296              :   hash_set<tree> set;
    1297              :   constexpr_global_ctx *global;
    1298              : public:
    1299       173449 :   modifiable_tracker (constexpr_global_ctx *g): global(g)
    1300              :   {
    1301       173449 :     global->modifiable = &set;
    1302       173449 :   }
    1303       173449 :   ~modifiable_tracker ()
    1304              :   {
    1305       173479 :     for (tree t: set)
    1306           30 :       global->clear_value (t);
    1307       173449 :     global->modifiable = nullptr;
    1308       173449 :   }
    1309              : };
    1310              : 
    1311              : /* The constexpr expansion context.  CALL is the current function
    1312              :    expansion, CTOR is the current aggregate initializer, OBJECT is the
    1313              :    object being initialized by CTOR, either a VAR_DECL or a _REF.    */
    1314              : 
    1315              : struct constexpr_ctx {
    1316              :   /* The part of the context that needs to be unique to the whole
    1317              :      cxx_eval_outermost_constant_expr invocation.  */
    1318              :   constexpr_global_ctx *global;
    1319              :   /* The innermost call we're evaluating.  */
    1320              :   constexpr_call *call;
    1321              :   /* SAVE_EXPRs and TARGET_EXPR_SLOT vars of TARGET_EXPRs that we've seen
    1322              :      within the current LOOP_EXPR.  NULL if we aren't inside a loop.  */
    1323              :   vec<tree> *save_exprs;
    1324              :   /* The CONSTRUCTOR we're currently building up for an aggregate
    1325              :      initializer.  */
    1326              :   tree ctor;
    1327              :   /* The object we're building the CONSTRUCTOR for.  */
    1328              :   tree object;
    1329              :   /* If inside SWITCH_EXPR.  */
    1330              :   constexpr_switch_state *css_state;
    1331              :   /* The aggregate initialization context inside which this one is nested.  This
    1332              :      is used by lookup_placeholder to resolve PLACEHOLDER_EXPRs.  */
    1333              :   const constexpr_ctx *parent;
    1334              : 
    1335              :   /* Whether we should error on a non-constant expression or fail quietly.
    1336              :      This flag needs to be here, but some of the others could move to global
    1337              :      if they get larger than a word.  */
    1338              :   bool quiet;
    1339              :   /* Whether we are strictly conforming to constant expression rules or
    1340              :      trying harder to get a constant value.  */
    1341              :   bool strict;
    1342              :   /* Whether __builtin_is_constant_evaluated () should be true.  */
    1343              :   mce_value manifestly_const_eval;
    1344              : };
    1345              : 
    1346              : /* Return ctx->quiet.  For use in reflect.cc.  */
    1347              : 
    1348              : bool
    1349          295 : cxx_constexpr_quiet_p (const constexpr_ctx *ctx)
    1350              : {
    1351          295 :   return ctx->quiet;
    1352              : }
    1353              : 
    1354              : /* Return ctx->manifestly_const_eval.  For use in reflect.cc.  */
    1355              : 
    1356              : mce_value
    1357          198 : cxx_constexpr_manifestly_const_eval (const constexpr_ctx *ctx)
    1358              : {
    1359          198 :   return ctx->manifestly_const_eval;
    1360              : }
    1361              : 
    1362              : /* Return ctx->call->fundef->decl or NULL_TREE.  For use in
    1363              :    reflect.cc.  */
    1364              : 
    1365              : tree
    1366         1048 : cxx_constexpr_caller (const constexpr_ctx *ctx)
    1367              : {
    1368         1048 :   if (ctx->call)
    1369          469 :     return ctx->call->fundef->decl;
    1370              :   else
    1371              :     return NULL_TREE;
    1372              : }
    1373              : 
    1374              : /* Return ctx->global->consteval_block.  For use in reflect.cc.  */
    1375              : 
    1376              : tree
    1377           79 : cxx_constexpr_consteval_block (const constexpr_ctx *ctx)
    1378              : {
    1379           79 :   return ctx->global->consteval_block;
    1380              : }
    1381              : 
    1382              : /* Predicates for the meaning of *jump_target.  */
    1383              : 
    1384              : static bool
    1385     66107904 : returns (tree *jump_target)
    1386              : {
    1387     11357213 :   return *jump_target && TREE_CODE (*jump_target) == RETURN_EXPR;
    1388              : }
    1389              : 
    1390              : static bool
    1391     62297305 : breaks (tree *jump_target)
    1392              : {
    1393     62297305 :   return (*jump_target
    1394     62297305 :           && ((TREE_CODE (*jump_target) == LABEL_DECL
    1395           55 :                && LABEL_DECL_BREAK (*jump_target))
    1396       917021 :               || TREE_CODE (*jump_target) == BREAK_STMT
    1397       876806 :               || TREE_CODE (*jump_target) == EXIT_EXPR));
    1398              : }
    1399              : 
    1400              : static bool
    1401     87532591 : continues (tree *jump_target)
    1402              : {
    1403     87532591 :   return (*jump_target
    1404     87532591 :           && ((TREE_CODE (*jump_target) == LABEL_DECL
    1405           91 :                && LABEL_DECL_CONTINUE (*jump_target))
    1406       894655 :               || TREE_CODE (*jump_target) == CONTINUE_STMT));
    1407              : }
    1408              : 
    1409              : static bool
    1410      9124767 : switches (tree *jump_target)
    1411              : {
    1412        41980 :   return *jump_target && TREE_CODE (*jump_target) == INTEGER_CST;
    1413              : }
    1414              : 
    1415              : static bool
    1416   1516854552 : throws (tree *jump_target)
    1417              : {
    1418              :   /* void_node is for use in potential_constant_expression_1, otherwise
    1419              :      it should an artificial VAR_DECL created by constant evaluation
    1420              :      of __cxa_allocate_exception ().  */
    1421    111804128 :   return (*jump_target && (VAR_P (*jump_target) || *jump_target == void_node));
    1422              : }
    1423              : 
    1424              : /* True if the constexpr relaxations afforded by P2280R4 for unknown
    1425              :    references and objects are in effect.  */
    1426              : 
    1427              : static bool
    1428    207471664 : p2280_active_p (const constexpr_ctx *ctx)
    1429              : {
    1430     28625611 :   if (ctx->manifestly_const_eval != mce_true)
    1431              :     /* Disable these relaxations during speculative constexpr folding,
    1432              :        as it can significantly increase compile time/memory use
    1433              :        (PR119387).  */
    1434              :     return false;
    1435              : 
    1436              :   /* P2280R4 was accepted as a DR against C++11.  */
    1437            0 :   return cxx_dialect >= cxx11;
    1438              : }
    1439              : 
    1440              : /* Remove T from the global values map, checking for attempts to destroy
    1441              :    a value that has already finished its lifetime.  */
    1442              : 
    1443              : static void
    1444    126546672 : destroy_value_checked (const constexpr_ctx* ctx, tree t, bool *non_constant_p)
    1445              : {
    1446    126546672 :   if (t == error_mark_node || TREE_TYPE (t) == error_mark_node)
    1447              :     return;
    1448              : 
    1449              :   /* Don't error again here if we've already reported a problem.  */
    1450    126546655 :   if (!*non_constant_p
    1451    102262144 :       && DECL_P (t)
    1452              :       /* Non-trivial destructors have their lifetimes ended explicitly
    1453              :          with a clobber, so don't worry about it here.  */
    1454    102256030 :       && (!TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t))
    1455              :           /* ...except parameters are remapped in cxx_eval_call_expression,
    1456              :              and the destructor call during cleanup won't be able to tell that
    1457              :              this value has already been destroyed, so complain now.  This is
    1458              :              not quite unobservable, but is extremely unlikely to crop up in
    1459              :              practice; see g++.dg/cpp2a/constexpr-lifetime2.C.  */
    1460       415661 :           || TREE_CODE (t) == PARM_DECL)
    1461    228387744 :       && ctx->global->is_outside_lifetime (t))
    1462              :     {
    1463           54 :       if (!ctx->quiet)
    1464              :         {
    1465           18 :           auto_diagnostic_group d;
    1466           18 :           error ("destroying %qE outside its lifetime", t);
    1467           18 :           inform (DECL_SOURCE_LOCATION (t), "declared here");
    1468           18 :         }
    1469           54 :       *non_constant_p = true;
    1470              :     }
    1471    126546655 :   ctx->global->destroy_value (t);
    1472              : }
    1473              : 
    1474              : /* This internal flag controls whether we should avoid doing anything during
    1475              :    constexpr evaluation that would cause extra DECL_UID generation, such as
    1476              :    template instantiation and function body copying.  */
    1477              : 
    1478              : static bool uid_sensitive_constexpr_evaluation_value;
    1479              : 
    1480              : /* An internal counter that keeps track of the number of times
    1481              :    uid_sensitive_constexpr_evaluation_p returned true.  */
    1482              : 
    1483              : static unsigned uid_sensitive_constexpr_evaluation_true_counter;
    1484              : 
    1485              : /* The accessor for uid_sensitive_constexpr_evaluation_value which also
    1486              :    increments the corresponding counter.  */
    1487              : 
    1488              : static bool
    1489      8083464 : uid_sensitive_constexpr_evaluation_p ()
    1490              : {
    1491      8041520 :   if (uid_sensitive_constexpr_evaluation_value)
    1492              :     {
    1493       227249 :       ++uid_sensitive_constexpr_evaluation_true_counter;
    1494       227243 :       return true;
    1495              :     }
    1496              :   else
    1497              :     return false;
    1498              : }
    1499              : 
    1500              : /* The default constructor for uid_sensitive_constexpr_evaluation_sentinel
    1501              :    enables the internal flag for uid_sensitive_constexpr_evaluation_p
    1502              :    during the lifetime of the sentinel object.  Upon its destruction, the
    1503              :    previous value of uid_sensitive_constexpr_evaluation_p is restored.  */
    1504              : 
    1505     76807774 : uid_sensitive_constexpr_evaluation_sentinel
    1506     76807774 : ::uid_sensitive_constexpr_evaluation_sentinel ()
    1507     76807774 :   : ovr (uid_sensitive_constexpr_evaluation_value, true)
    1508              : {
    1509     76807774 : }
    1510              : 
    1511              : /* The default constructor for uid_sensitive_constexpr_evaluation_checker
    1512              :    records the current number of times that uid_sensitive_constexpr_evaluation_p
    1513              :    has been called and returned true.  */
    1514              : 
    1515   3621472499 : uid_sensitive_constexpr_evaluation_checker
    1516   3621472499 : ::uid_sensitive_constexpr_evaluation_checker ()
    1517   3621472499 :   : saved_counter (uid_sensitive_constexpr_evaluation_true_counter)
    1518              : {
    1519   3621472499 : }
    1520              : 
    1521              : /* Returns true iff uid_sensitive_constexpr_evaluation_p is true, and
    1522              :    some constexpr evaluation was restricted due to u_s_c_e_p being called
    1523              :    and returning true during the lifetime of this checker object.  */
    1524              : 
    1525              : bool
    1526   2399318811 : uid_sensitive_constexpr_evaluation_checker::evaluation_restricted_p () const
    1527              : {
    1528   2399318811 :   return (uid_sensitive_constexpr_evaluation_value
    1529   2399318811 :           && saved_counter != uid_sensitive_constexpr_evaluation_true_counter);
    1530              : }
    1531              : 
    1532              : 
    1533              : /* A table of all constexpr calls that have been evaluated by the
    1534              :    compiler in this translation unit.  */
    1535              : 
    1536              : static GTY (()) hash_table<constexpr_call_hasher> *constexpr_call_table;
    1537              : 
    1538              : /* Compute a hash value for a constexpr call representation.  */
    1539              : 
    1540              : inline hashval_t
    1541    174839289 : constexpr_call_hasher::hash (constexpr_call *info)
    1542              : {
    1543    174839289 :   return info->hash;
    1544              : }
    1545              : 
    1546              : /* Return true if the objects pointed to by P and Q represent calls
    1547              :    to the same constexpr function with the same arguments.
    1548              :    Otherwise, return false.  */
    1549              : 
    1550              : bool
    1551    181966109 : constexpr_call_hasher::equal (constexpr_call *lhs, constexpr_call *rhs)
    1552              : {
    1553    181966109 :   if (lhs == rhs)
    1554              :     return true;
    1555    181966109 :   if (lhs->hash != rhs->hash)
    1556              :     return false;
    1557     20510967 :   if (!constexpr_fundef_hasher::equal (lhs->fundef, rhs->fundef))
    1558              :     return false;
    1559     20510967 :   return cp_tree_equal (lhs->bindings, rhs->bindings);
    1560              : }
    1561              : 
    1562              : /* Initialize the constexpr call table, if needed.  */
    1563              : 
    1564              : static void
    1565     25918096 : maybe_initialize_constexpr_call_table (void)
    1566              : {
    1567     25918096 :   if (constexpr_call_table == NULL)
    1568        17531 :     constexpr_call_table = hash_table<constexpr_call_hasher>::create_ggc (101);
    1569     25918096 : }
    1570              : 
    1571              : /* During constexpr CALL_EXPR evaluation, to avoid issues with sharing when
    1572              :    a function happens to get called recursively, we unshare the callee
    1573              :    function's body and evaluate this unshared copy instead of evaluating the
    1574              :    original body.
    1575              : 
    1576              :    FUNDEF_COPIES_TABLE is a per-function freelist of these unshared function
    1577              :    copies.  The underlying data structure of FUNDEF_COPIES_TABLE is a hash_map
    1578              :    that's keyed off of the original FUNCTION_DECL and whose value is a
    1579              :    TREE_LIST of this function's unused copies awaiting reuse.
    1580              : 
    1581              :    This is not GC-deletable to avoid GC affecting UID generation.  */
    1582              : 
    1583              : static GTY(()) decl_tree_map *fundef_copies_table;
    1584              : 
    1585              : /* Reuse a copy or create a new unshared copy of the function FUN.
    1586              :    Return this copy.  We use a TREE_LIST whose PURPOSE is body, VALUE
    1587              :    is parms, TYPE is result.  */
    1588              : 
    1589              : static tree
    1590     49229593 : get_fundef_copy (constexpr_fundef *fundef)
    1591              : {
    1592     49229593 :   tree copy;
    1593     49229593 :   bool existed;
    1594     49229593 :   tree *slot = &(hash_map_safe_get_or_insert<hm_ggc>
    1595     49229593 :                  (fundef_copies_table, fundef->decl, &existed, 127));
    1596              : 
    1597     49229593 :   if (!existed)
    1598              :     {
    1599              :       /* There is no cached function available, or in use.  We can use
    1600              :          the function directly.  That the slot is now created records
    1601              :          that this function is now in use.  */
    1602      6995696 :       copy = build_tree_list (fundef->body, fundef->parms);
    1603      6995696 :       TREE_TYPE (copy) = fundef->result;
    1604              :     }
    1605     42233897 :   else if (*slot == NULL_TREE)
    1606              :     {
    1607         4361 :       if (uid_sensitive_constexpr_evaluation_p ())
    1608            6 :         return NULL_TREE;
    1609              : 
    1610              :       /* We've already used the function itself, so make a copy.  */
    1611         4355 :       copy = build_tree_list (NULL, NULL);
    1612         4355 :       tree saved_body = DECL_SAVED_TREE (fundef->decl);
    1613         4355 :       tree saved_parms = DECL_ARGUMENTS (fundef->decl);
    1614         4355 :       tree saved_result = DECL_RESULT (fundef->decl);
    1615         4355 :       tree saved_fn = current_function_decl;
    1616         4355 :       DECL_SAVED_TREE (fundef->decl) = fundef->body;
    1617         4355 :       DECL_ARGUMENTS (fundef->decl) = fundef->parms;
    1618         4355 :       DECL_RESULT (fundef->decl) = fundef->result;
    1619         4355 :       current_function_decl = fundef->decl;
    1620         4355 :       TREE_PURPOSE (copy) = copy_fn (fundef->decl, TREE_VALUE (copy),
    1621         4355 :                                      TREE_TYPE (copy));
    1622         4355 :       current_function_decl = saved_fn;
    1623         4355 :       DECL_RESULT (fundef->decl) = saved_result;
    1624         4355 :       DECL_ARGUMENTS (fundef->decl) = saved_parms;
    1625         4355 :       DECL_SAVED_TREE (fundef->decl) = saved_body;
    1626              :     }
    1627              :   else
    1628              :     {
    1629              :       /* We have a cached function available.  */
    1630     42229536 :       copy = *slot;
    1631     42229536 :       *slot = TREE_CHAIN (copy);
    1632              :     }
    1633              : 
    1634              :   return copy;
    1635              : }
    1636              : 
    1637              : /* Save the copy COPY of function FUN for later reuse by
    1638              :    get_fundef_copy().  By construction, there will always be an entry
    1639              :    to find.  */
    1640              : 
    1641              : static void
    1642     49229585 : save_fundef_copy (tree fun, tree copy)
    1643              : {
    1644     49229585 :   tree *slot = fundef_copies_table->get (fun);
    1645     49229585 :   TREE_CHAIN (copy) = *slot;
    1646     49229585 :   *slot = copy;
    1647     49229585 : }
    1648              : 
    1649              : static tree cxx_eval_bare_aggregate (const constexpr_ctx *, tree,
    1650              :                                      value_cat, bool *, bool *, tree *);
    1651              : static tree cxx_fold_indirect_ref (const constexpr_ctx *, location_t, tree, tree,
    1652              :                                    bool *, tree *);
    1653              : static tree find_heap_var_refs (tree *, int *, void *);
    1654              : 
    1655              : /* For exception object EXC if it has class type and usable what () method
    1656              :    which returns cv char * return the xmalloced string literal which it returns
    1657              :    if possible, otherwise return NULL.  */
    1658              : 
    1659              : static char *
    1660          228 : exception_what_str (const constexpr_ctx *ctx, tree exc)
    1661              : {
    1662          228 :   tree type = strip_array_types (TREE_TYPE (exc));
    1663          228 :   if (!CLASS_TYPE_P (type))
    1664              :     return NULL;
    1665          187 :   tree std_exception = lookup_qualified_name (std_node, "exception",
    1666              :                                               LOOK_want::NORMAL, false);
    1667          187 :   if (TREE_CODE (std_exception) != TYPE_DECL)
    1668              :     return NULL;
    1669          184 :   if (!CLASS_TYPE_P (TREE_TYPE (std_exception)))
    1670              :     return NULL;
    1671          184 :   base_kind b_kind;
    1672          184 :   tree binfo = lookup_base (type, TREE_TYPE (std_exception), ba_check, &b_kind,
    1673              :                             tf_none);
    1674          184 :   if (binfo == NULL_TREE || binfo == error_mark_node)
    1675              :     return NULL;
    1676          180 :   if (type != TREE_TYPE (exc))
    1677          142 :     exc = build4 (ARRAY_REF, type, exc, size_zero_node, NULL, NULL);
    1678          180 :   tree call
    1679          180 :     = finish_class_member_access_expr (exc, get_identifier ("what"), false,
    1680              :                                        tf_none);
    1681          180 :   if (call == error_mark_node)
    1682              :     return NULL;
    1683          180 :   releasing_vec what_args;
    1684          180 :   call = finish_call_expr (call, &what_args, false, false, tf_none);
    1685          180 :   if (call == error_mark_node)
    1686              :     return NULL;
    1687          180 :   if (TREE_CODE (TREE_TYPE (call)) != POINTER_TYPE
    1688          180 :       || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (call)))
    1689          180 :       || !COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (call)))
    1690          180 :       || !tree_int_cst_equal (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (call))),
    1691          180 :                               TYPE_SIZE_UNIT (char_type_node))
    1692          360 :       || TYPE_PRECISION (TREE_TYPE (TREE_TYPE (call))) != BITS_PER_UNIT)
    1693            0 :     return NULL;
    1694          180 :   if (!potential_constant_expression (call))
    1695              :     return NULL;
    1696          180 :   bool non_constant_p = false, overflow_p = false;
    1697          180 :   tree jmp_target = NULL;
    1698          180 :   tree ptr = cxx_eval_constant_expression (ctx, call, vc_prvalue,
    1699              :                                            &non_constant_p, &overflow_p,
    1700              :                                            &jmp_target);
    1701          180 :   if (throws (&jmp_target) || non_constant_p)
    1702              :     return NULL;
    1703          180 :   if (reduced_constant_expression_p (ptr))
    1704           40 :     if (const char *msg = c_getstr (ptr))
    1705           40 :       return xstrdup (msg);
    1706          140 :   auto_vec <char, 32> v;
    1707         5799 :   for (unsigned i = 0; i < INT_MAX; ++i)
    1708              :     {
    1709         5799 :       tree t = call;
    1710         5799 :       if (i)
    1711         5659 :         t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (ptr), ptr, size_int (i));
    1712         5799 :       t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
    1713         5799 :       non_constant_p = false;
    1714         5799 :       overflow_p = false;
    1715         5799 :       jmp_target = NULL;
    1716         5799 :       tree t2 = cxx_eval_constant_expression (ctx, t, vc_prvalue,
    1717              :                                               &non_constant_p, &overflow_p,
    1718              :                                               &jmp_target);
    1719         5799 :       if (throws (&jmp_target)
    1720         5799 :           || non_constant_p
    1721         5799 :           || !tree_fits_shwi_p (t2))
    1722            0 :         return NULL;
    1723         5799 :       char c = tree_to_shwi (t2);
    1724         5799 :       v.safe_push (c);
    1725         5799 :       if (c == '\0')
    1726              :         break;
    1727              :     }
    1728          280 :   return xstrdup (v.address ());
    1729          320 : }
    1730              : 
    1731              : /* Diagnose constant expression evaluation encountering call to
    1732              :    std::terminate due to exception EXC.  */
    1733              : 
    1734              : static void
    1735           11 : diagnose_std_terminate (location_t loc, const constexpr_ctx *ctx, tree exc)
    1736              : {
    1737           11 :   tree type = strip_array_types (TREE_TYPE (exc));
    1738           11 :   if (char *str = exception_what_str (ctx, exc))
    1739              :     {
    1740            2 :       error_at (loc, "%qs called after throwing an exception of type %qT; "
    1741              :                      "%<what()%>: %qs", "std::terminate", type, str);
    1742            2 :       free (str);
    1743              :     }
    1744              :   else
    1745              :     {
    1746            9 :       if (type != TREE_TYPE (exc))
    1747            9 :         exc = build4 (ARRAY_REF, type, exc, size_zero_node, NULL, NULL);
    1748            9 :       bool non_constant_p = false, overflow_p = false;
    1749            9 :       tree jmp_target = NULL;
    1750            9 :       tree val = cxx_eval_constant_expression (ctx, exc, vc_prvalue,
    1751              :                                                &non_constant_p, &overflow_p,
    1752              :                                                &jmp_target);
    1753            9 :       gcc_assert (!throws (&jmp_target) && !non_constant_p);
    1754            9 :       if (reduced_constant_expression_p (val))
    1755            9 :         error_at (loc, "%qs called after throwing an exception %qE",
    1756              :                        "std::terminate", val);
    1757              :       else
    1758            0 :         error_at (loc, "%qs called after throwing an exception of type %qT",
    1759              :                        "std::terminate", type);
    1760              :     }
    1761           11 : }
    1762              : 
    1763              : /* Diagnose constant expression evaluation encountering call to
    1764              :    uncaught exception EXC.  */
    1765              : 
    1766              : static void
    1767          217 : diagnose_uncaught_exception (location_t loc, const constexpr_ctx *ctx, tree exc)
    1768              : {
    1769          217 :   tree type = strip_array_types (TREE_TYPE (exc));
    1770          217 :   if (char *str = exception_what_str (ctx, exc))
    1771              :     {
    1772          178 :       error_at (loc, "uncaught exception of type %qT; %<what()%>: %qs", type, str);
    1773          178 :       free (str);
    1774              :     }
    1775              :   else
    1776              :     {
    1777           39 :       if (type != TREE_TYPE (exc))
    1778           39 :         exc = build4 (ARRAY_REF, type, exc, size_zero_node, NULL, NULL);
    1779           39 :       bool non_constant_p = false, overflow_p = false;
    1780           39 :       tree jmp_target = NULL;
    1781           39 :       tree val = cxx_eval_constant_expression (ctx, exc, vc_prvalue,
    1782              :                                                &non_constant_p, &overflow_p,
    1783              :                                                &jmp_target);
    1784           39 :       gcc_assert (!throws (&jmp_target) && !non_constant_p);
    1785           39 :       if (reduced_constant_expression_p (val))
    1786           38 :         error_at (loc, "uncaught exception %qE", val);
    1787              :       else
    1788            1 :         error_at (loc, "uncaught exception of type %qT", type);
    1789              :     }
    1790          217 : }
    1791              : 
    1792              : /* Kinds of __cxa_* functions (and a few other EH related ones) we handle as
    1793              :    magic constexpr functions for C++26.  */
    1794              : 
    1795              : enum cxa_builtin {
    1796              :   CXA_NONE = 0,
    1797              :   CXA_ALLOCATE_EXCEPTION = 1,
    1798              :   CXA_FREE_EXCEPTION = 2,
    1799              :   CXA_THROW = 3,
    1800              :   CXA_BEGIN_CATCH = 4,
    1801              :   CXA_END_CATCH = 5,
    1802              :   CXA_RETHROW = 6,
    1803              :   CXA_GET_EXCEPTION_PTR = 7,
    1804              :   CXA_BAD_CAST = 8,
    1805              :   CXA_BAD_TYPEID = 9,
    1806              :   CXA_THROW_BAD_ARRAY_NEW_LENGTH = 10,
    1807              :   STD_RETHROW_EXCEPTION = 11,
    1808              :   BUILTIN_EH_PTR_ADJUST_REF = 12,
    1809              :   BUILTIN_UNCAUGHT_EXCEPTIONS = 13,
    1810              :   BUILTIN_CURRENT_EXCEPTION = 14
    1811              : };
    1812              : 
    1813              : /* Return cxa_builtin if FNDECL is a __cxa_* function handled as
    1814              :    magic constexpr function for C++26.  Return CXA_NONE otherwise.  */
    1815              : 
    1816              : static enum cxa_builtin
    1817     26582278 : cxx_cxa_builtin_fn_p (tree fndecl)
    1818              : {
    1819     26582278 :   if (cxx_dialect < cxx26)
    1820              :     return CXA_NONE;
    1821      2344978 :   if (DECL_LANGUAGE (fndecl) != lang_c)
    1822              :     {
    1823      2018736 :       if (!decl_in_std_namespace_p (fndecl))
    1824              :         return CXA_NONE;
    1825       785180 :       if (id_equal (DECL_NAME (fndecl), "rethrow_exception"))
    1826              :         return STD_RETHROW_EXCEPTION;
    1827              :       return CXA_NONE;
    1828              :     }
    1829       326242 :   if (!startswith (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "__cxa_"))
    1830              :     return CXA_NONE;
    1831        45688 :   if (id_equal (DECL_NAME (fndecl), "__cxa_allocate_exception"))
    1832              :     return CXA_ALLOCATE_EXCEPTION;
    1833        12764 :   if (id_equal (DECL_NAME (fndecl), "__cxa_free_exception"))
    1834              :     return CXA_FREE_EXCEPTION;
    1835        12763 :   if (id_equal (DECL_NAME (fndecl), "__cxa_throw"))
    1836              :     return CXA_THROW;
    1837         7520 :   if (id_equal (DECL_NAME (fndecl), "__cxa_begin_catch"))
    1838              :     return CXA_BEGIN_CATCH;
    1839         2585 :   if (id_equal (DECL_NAME (fndecl), "__cxa_end_catch"))
    1840              :     return CXA_END_CATCH;
    1841          858 :   if (id_equal (DECL_NAME (fndecl), "__cxa_rethrow"))
    1842              :     return CXA_RETHROW;
    1843          804 :   if (id_equal (DECL_NAME (fndecl), "__cxa_get_exception_ptr"))
    1844              :     return CXA_GET_EXCEPTION_PTR;
    1845          782 :   if (id_equal (DECL_NAME (fndecl), "__cxa_bad_cast"))
    1846              :     return CXA_BAD_CAST;
    1847          498 :   if (id_equal (DECL_NAME (fndecl), "__cxa_bad_typeid"))
    1848              :     return CXA_BAD_TYPEID;
    1849          490 :   if (id_equal (DECL_NAME (fndecl), "__cxa_throw_bad_array_new_length"))
    1850              :     return CXA_THROW_BAD_ARRAY_NEW_LENGTH;
    1851              :   return CXA_NONE;
    1852              : }
    1853              : 
    1854              : /* Helper function for cxx_eval_cxa_builtin_fn.
    1855              :    Check if ARG is a valid first argument of __cxa_throw or
    1856              :    __cxa_free_exception or __builtin_eh_ptr_adjust_ref.  Return NULL_TREE if
    1857              :    not, otherwise return the artificial __cxa_allocate_exception allocated
    1858              :    VAR_DECL.  FREE_EXC is true for __cxa_free_exception, false otherwise.  */
    1859              : 
    1860              : static tree
    1861          823 : cxa_check_throw_arg (tree arg, bool free_exc)
    1862              : {
    1863          823 :   STRIP_NOPS (arg);
    1864          823 :   if (TREE_CODE (arg) != ADDR_EXPR)
    1865              :     return NULL_TREE;
    1866          823 :   arg = TREE_OPERAND (arg, 0);
    1867          823 :   if (!VAR_P (arg)
    1868          823 :       || !DECL_ARTIFICIAL (arg)
    1869          823 :       || ((!free_exc || DECL_NAME (arg) != heap_uninit_identifier)
    1870          823 :           && DECL_NAME (arg) != heap_identifier)
    1871         1646 :       || !DECL_LANG_SPECIFIC (arg))
    1872            0 :     return NULL_TREE;
    1873              :   return arg;
    1874              : }
    1875              : 
    1876              : /* Helper function for cxx_eval_cxa_builtin_fn.
    1877              :    "Allocate" on the constexpr heap an exception object of TYPE
    1878              :    with REFCOUNT.  */
    1879              : 
    1880              : static tree
    1881        10074 : cxa_allocate_exception (location_t loc, const constexpr_ctx *ctx, tree type,
    1882              :                         tree refcount)
    1883              : {
    1884        10074 :   tree var = build_decl (loc, VAR_DECL, heap_uninit_identifier, type);
    1885        10074 :   DECL_ARTIFICIAL (var) = 1;
    1886        10074 :   retrofit_lang_decl (var);
    1887        10074 :   DECL_EXCEPTION_REFCOUNT (var) = refcount;
    1888        10074 :   ctx->global->heap_vars.safe_push (var);
    1889        10074 :   return var;
    1890              : }
    1891              : 
    1892              : /* Evaluate various __cxa_* calls as magic constexpr builtins for
    1893              :    C++26 constexpr exception support (P3068R5).  */
    1894              : 
    1895              : static tree
    1896        15408 : cxx_eval_cxa_builtin_fn (const constexpr_ctx *ctx, tree call,
    1897              :                          enum cxa_builtin kind, tree fndecl,
    1898              :                          bool *non_constant_p, bool *overflow_p,
    1899              :                          tree *jump_target)
    1900              : {
    1901        15408 :   int nargs = call_expr_nargs (call);
    1902        15408 :   location_t loc = cp_expr_loc_or_input_loc (call);
    1903        15408 :   tree args[4], arg;
    1904        15408 :   if (nargs > 4)
    1905              :     {
    1906            0 :     invalid_nargs:
    1907            0 :       if (!ctx->quiet)
    1908            0 :         error_at (loc, "call to %qD function with incorrect "
    1909              :                   "number of arguments", fndecl);
    1910            0 :       *non_constant_p = true;
    1911            0 :       return call;
    1912              :     }
    1913        15408 :   if ((kind == CXA_BEGIN_CATCH || kind == CXA_GET_EXCEPTION_PTR)
    1914         3350 :       && nargs == 1
    1915         3350 :       && (arg = CALL_EXPR_ARG (call, 0))
    1916         3350 :       && TREE_CODE (arg) == CALL_EXPR
    1917         3350 :       && call_expr_nargs (arg) == 1
    1918        18758 :       && integer_zerop (CALL_EXPR_ARG (arg, 0)))
    1919         3350 :     if (tree fun = get_function_named_in_call (arg))
    1920         3350 :       if (fndecl_built_in_p (fun, BUILT_IN_EH_POINTER))
    1921              :         {
    1922         3350 :           if (ctx->global->caught_exceptions.length () < 2)
    1923              :             {
    1924         1607 :             no_caught_exceptions:
    1925         1607 :               if (!ctx->quiet)
    1926            0 :                 error_at (loc, "%qD called with no caught exceptions pending",
    1927              :                           fndecl);
    1928         1607 :               *non_constant_p = true;
    1929         1607 :               return call;
    1930              :             }
    1931              :           /* Both __cxa_get_exception_ptr (__builtin_eh_pointer (0))
    1932              :              and __cxa_begin_catch (__builtin_eh_pointer (0)) calls expect
    1933              :              ctx->global->caught_exceptions vector to end with
    1934              :              __cxa_allocate_exception created artificial VAR_DECL (the
    1935              :              exception object) followed by handler type, pushed by TRY_BLOCK
    1936              :              evaluation.  The only difference between the functions is that
    1937              :              __cxa_begin_catch pops the handler type from the vector and keeps
    1938              :              the VAR_DECL last and decreases uncaught_exceptions.  The
    1939              :              VAR_DECL after __cxa_begin_catch serves as the current exception
    1940              :              and is then popped in __cxa_end_catch evaluation.  */
    1941         1743 :           tree handler_type = ctx->global->caught_exceptions.last ();
    1942         1743 :           if (handler_type && VAR_P (handler_type))
    1943            0 :             goto no_caught_exceptions;
    1944         1743 :           unsigned idx = ctx->global->caught_exceptions.length () - 2;
    1945         1743 :           arg = ctx->global->caught_exceptions[idx];
    1946         1743 :           gcc_assert (VAR_P (arg));
    1947         1743 :           if (kind == CXA_BEGIN_CATCH)
    1948              :             {
    1949         1729 :               ctx->global->caught_exceptions.pop ();
    1950         1729 :               --ctx->global->uncaught_exceptions;
    1951              :             }
    1952         1743 :           if (handler_type == NULL_TREE)
    1953              :             /* Used for catch (...).  Just return void.  */
    1954           33 :             return void_node;
    1955         1710 :           else if (POINTER_TYPE_P (handler_type))
    1956              :             {
    1957              :               /* Used for catch of a pointer.  */
    1958           33 :               if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
    1959           33 :                 arg = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (arg)), arg,
    1960              :                               size_zero_node, NULL_TREE, NULL_TREE);
    1961           33 :               arg = cp_convert (handler_type, arg,
    1962           33 :                                 ctx->quiet ? tf_none : tf_warning_or_error);
    1963           33 :               if (arg == error_mark_node)
    1964              :                 {
    1965            0 :                   *non_constant_p = true;
    1966            0 :                   return call;
    1967              :                 }
    1968              :             }
    1969              :           else
    1970              :             {
    1971              :               /* Used for catch of a non-pointer type.  */
    1972         1677 :               tree exc_type = strip_array_types (TREE_TYPE (arg));
    1973         1677 :               tree exc_ptr_type = build_pointer_type (exc_type);
    1974         1677 :               arg = build_fold_addr_expr_with_type (arg, exc_ptr_type);
    1975         1677 :               if (CLASS_TYPE_P (handler_type))
    1976              :                 {
    1977         1637 :                   tree ptr_type = build_pointer_type (handler_type);
    1978         1637 :                   arg = cp_convert (ptr_type, arg,
    1979         1637 :                                     ctx->quiet ? tf_none
    1980              :                                     : tf_warning_or_error);
    1981         1637 :                   if (arg == error_mark_node)
    1982              :                     {
    1983            0 :                       *non_constant_p = true;
    1984            0 :                       return call;
    1985              :                     }
    1986              :                 }
    1987              :             }
    1988         1710 :           return cxx_eval_constant_expression (ctx, arg, vc_prvalue,
    1989              :                                                non_constant_p, overflow_p,
    1990         1710 :                                                jump_target);
    1991              :         }
    1992        22806 :   for (int i = 0; i < nargs; ++i)
    1993              :     {
    1994        10748 :       args[i] = cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (call, i),
    1995              :                                               vc_prvalue, non_constant_p,
    1996              :                                               overflow_p, jump_target);
    1997        10748 :       if (*non_constant_p)
    1998              :         return call;
    1999        10748 :       if (*jump_target)
    2000              :         return NULL_TREE;
    2001              :     }
    2002        12058 :   switch (kind)
    2003              :     {
    2004         8370 :     case CXA_ALLOCATE_EXCEPTION:
    2005         8370 :       if (nargs != 1)
    2006            0 :         goto invalid_nargs;
    2007         8370 :       if (!tree_fits_uhwi_p (args[0]))
    2008              :         {
    2009            0 :           if (!ctx->quiet)
    2010            0 :             error_at (loc, "cannot allocate exception: size not constant");
    2011            0 :           *non_constant_p = true;
    2012            0 :           return call;
    2013              :         }
    2014              :       else
    2015              :         {
    2016        16740 :           tree type = build_array_type_nelts (char_type_node,
    2017         8370 :                                               tree_to_uhwi (args[0]));
    2018         8370 :           tree var = cxa_allocate_exception (loc, ctx, type, size_zero_node);
    2019         8370 :           ctx->global->put_value (var, NULL_TREE);
    2020         8370 :           return fold_convert (ptr_type_node, build_address (var));
    2021              :         }
    2022            1 :     case CXA_FREE_EXCEPTION:
    2023            1 :       if (nargs != 1)
    2024            0 :         goto invalid_nargs;
    2025            1 :       arg = cxa_check_throw_arg (args[0], true);
    2026            1 :       if (arg == NULL_TREE)
    2027              :         {
    2028            0 :         invalid_ptr:
    2029            0 :           if (!ctx->quiet)
    2030            0 :             error_at (loc, "first argument to %qD function not result of "
    2031              :                       "%<__cxa_allocate_exception%>", fndecl);
    2032            0 :           *non_constant_p = true;
    2033            0 :           return call;
    2034              :         }
    2035            1 :       DECL_NAME (arg) = heap_deleted_identifier;
    2036            1 :       ctx->global->destroy_value (arg);
    2037            1 :       ctx->global->heap_dealloc_count++;
    2038            1 :       return void_node;
    2039          752 :     case CXA_THROW:
    2040          752 :       if (nargs != 3)
    2041            0 :         goto invalid_nargs;
    2042          752 :       arg = cxa_check_throw_arg (args[0], false);
    2043          752 :       if (arg == NULL_TREE)
    2044            0 :         goto invalid_ptr;
    2045          752 :       DECL_EXCEPTION_REFCOUNT (arg)
    2046          752 :         = size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg),
    2047              :                       size_one_node);
    2048          752 :       ++ctx->global->uncaught_exceptions;
    2049          752 :       *jump_target = arg;
    2050          752 :       return void_node;
    2051            0 :     case CXA_BEGIN_CATCH:
    2052            0 :     case CXA_GET_EXCEPTION_PTR:
    2053            0 :       goto invalid_nargs;
    2054         1727 :     case CXA_END_CATCH:
    2055         1727 :       if (nargs != 0)
    2056            0 :         goto invalid_nargs;
    2057         1727 :       if (ctx->global->caught_exceptions.is_empty ())
    2058              :         {
    2059            0 :         no_active_exc:
    2060            0 :           if (!ctx->quiet)
    2061            0 :             error_at (loc, "%qD called with no caught exceptions active",
    2062              :                       fndecl);
    2063            0 :           *non_constant_p = true;
    2064            0 :           return call;
    2065              :         }
    2066              :       else
    2067              :         {
    2068         1727 :           arg = ctx->global->caught_exceptions.pop ();
    2069         1727 :           if (arg == NULL_TREE || !VAR_P (arg))
    2070            0 :             goto no_active_exc;
    2071         1727 :         free_except:
    2072         1758 :           DECL_EXCEPTION_REFCOUNT (arg)
    2073         1758 :             = size_binop (MINUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg),
    2074              :                           size_one_node);
    2075         1758 :           if (integer_zerop (DECL_EXCEPTION_REFCOUNT (arg)))
    2076              :             {
    2077         1669 :               if (type_build_dtor_call (TREE_TYPE (arg)))
    2078              :                 {
    2079              :                   /* So that we don't complain about out-of-consteval use.  */
    2080         1594 :                   temp_override<tree> ovr (current_function_decl);
    2081         1594 :                   if (ctx->call && ctx->call->fundef)
    2082         1594 :                     current_function_decl = ctx->call->fundef->decl;
    2083         1594 :                   tree cleanup
    2084         1605 :                     = cxx_maybe_build_cleanup (arg, (ctx->quiet ? tf_none
    2085              :                                                      : tf_warning_or_error));
    2086         1594 :                   if (cleanup == error_mark_node)
    2087            0 :                     *non_constant_p = true;
    2088         1594 :                   tree jmp_target = NULL_TREE;
    2089         1594 :                   cxx_eval_constant_expression (ctx, cleanup, vc_discard,
    2090              :                                                 non_constant_p, overflow_p,
    2091              :                                                 &jmp_target);
    2092         1594 :                   if (throws (&jmp_target))
    2093            0 :                     *jump_target = jmp_target;
    2094         1594 :                 }
    2095         1669 :               DECL_NAME (arg) = heap_deleted_identifier;
    2096         1669 :               ctx->global->destroy_value (arg);
    2097         1669 :               ctx->global->heap_dealloc_count++;
    2098              :             }
    2099              :         }
    2100         1758 :       return void_node;
    2101           48 :     case CXA_RETHROW:
    2102           48 :       if (nargs != 0)
    2103            0 :         goto invalid_nargs;
    2104           48 :       unsigned idx;
    2105           96 :       FOR_EACH_VEC_ELT_REVERSE (ctx->global->caught_exceptions, idx, arg)
    2106           34 :         if (arg == NULL_TREE || !VAR_P (arg))
    2107            0 :           --idx;
    2108              :         else
    2109              :           break;
    2110           48 :       if (arg == NULL_TREE)
    2111              :         {
    2112           14 :           if (!ctx->quiet)
    2113            4 :             error_at (loc, "%qD called with no caught exceptions active",
    2114              :                       fndecl);
    2115           14 :           *non_constant_p = true;
    2116           14 :           return call;
    2117              :         }
    2118           34 :       DECL_EXCEPTION_REFCOUNT (arg)
    2119           34 :         = size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg), size_one_node);
    2120           34 :       ++ctx->global->uncaught_exceptions;
    2121           34 :       *jump_target = arg;
    2122           34 :       return void_node;
    2123          143 :     case CXA_BAD_CAST:
    2124          143 :     case CXA_BAD_TYPEID:
    2125          143 :     case CXA_THROW_BAD_ARRAY_NEW_LENGTH:
    2126          143 :       if (nargs != 0)
    2127            0 :         goto invalid_nargs;
    2128              :       else
    2129              :         {
    2130          143 :           tree name;
    2131          143 :           switch (kind)
    2132              :             {
    2133          117 :             case CXA_BAD_CAST:
    2134          117 :               name = get_identifier ("bad_cast");
    2135          117 :               break;
    2136            5 :             case CXA_BAD_TYPEID:
    2137            5 :               name = get_identifier ("bad_typeid");
    2138            5 :               break;
    2139           21 :             case CXA_THROW_BAD_ARRAY_NEW_LENGTH:
    2140           21 :               name = get_identifier ("bad_array_new_length");
    2141           21 :               break;
    2142              :             default:
    2143              :               gcc_unreachable ();
    2144              :             }
    2145          143 :           tree decl = lookup_qualified_name (std_node, name);
    2146          143 :           if (TREE_CODE (decl) != TYPE_DECL
    2147          128 :               || !CLASS_TYPE_P (TREE_TYPE (decl))
    2148          271 :               || !type_build_ctor_call (TREE_TYPE (decl)))
    2149              :             {
    2150           15 :               if (!ctx->quiet)
    2151            4 :                 error_at (loc, "%qD called without %<std::%D%> being defined",
    2152              :                           fndecl, name);
    2153           15 :               *non_constant_p = true;
    2154           15 :               return call;
    2155              :             }
    2156          128 :           tree type = TREE_TYPE (decl);
    2157          128 :           tree var = cxa_allocate_exception (loc, ctx, type, size_one_node);
    2158          128 :           tree ctor
    2159          128 :             = build_special_member_call (var, complete_ctor_identifier,
    2160              :                                          NULL, type, LOOKUP_NORMAL,
    2161          128 :                                          ctx->quiet ? tf_none
    2162              :                                          : tf_warning_or_error);
    2163          128 :           if (ctor == error_mark_node)
    2164              :             {
    2165            0 :               *non_constant_p = true;
    2166            0 :               return call;
    2167              :             }
    2168          128 :           if (TREE_CONSTANT (ctor))
    2169            0 :             ctx->global->put_value (var, ctor);
    2170              :           else
    2171              :             {
    2172          128 :               ctx->global->put_value (var, NULL_TREE);
    2173          128 :               cxx_eval_constant_expression (ctx, ctor, vc_discard,
    2174              :                                             non_constant_p, overflow_p,
    2175              :                                             jump_target);
    2176          128 :               if (*non_constant_p)
    2177              :                 return call;
    2178          128 :               if (throws (jump_target))
    2179              :                 return NULL_TREE;
    2180              :             }
    2181          128 :           ++ctx->global->uncaught_exceptions;
    2182          128 :           *jump_target = var;
    2183              :         }
    2184          128 :       return void_node;
    2185           30 :     case BUILTIN_UNCAUGHT_EXCEPTIONS:
    2186           30 :       if (nargs != 0)
    2187            0 :         goto invalid_nargs;
    2188              :       /* Similarly to __builtin_is_constant_evaluated (), we don't
    2189              :          want to give a definite answer during mce_unknown evaluation,
    2190              :          because that might prevent evaluation later on when some
    2191              :          exceptions might be uncaught.  But unlike that, we don't
    2192              :          want to constant fold it even during cp_fold, because at runtime
    2193              :          std::uncaught_exceptions () might still be non-zero.  */
    2194           30 :       if (ctx->manifestly_const_eval != mce_true)
    2195              :         {
    2196           17 :           *non_constant_p = true;
    2197           17 :           return call;
    2198              :         }
    2199           13 :       return build_int_cst (integer_type_node,
    2200           13 :                             ctx->global->uncaught_exceptions);
    2201          917 :     case BUILTIN_CURRENT_EXCEPTION:
    2202          917 :       if (nargs != 0)
    2203            0 :         goto invalid_nargs;
    2204              :       else
    2205              :         {
    2206          917 :           tree name = get_identifier ("exception_ptr");
    2207          917 :           tree decl = lookup_qualified_name (std_node, name);
    2208          917 :           tree fld;
    2209          917 :           if (TREE_CODE (decl) != TYPE_DECL
    2210          917 :               || !CLASS_TYPE_P (TREE_TYPE (decl))
    2211          917 :               || !COMPLETE_TYPE_P (TREE_TYPE (decl))
    2212          917 :               || !(fld = next_aggregate_field (TYPE_FIELDS (TREE_TYPE (decl))))
    2213          917 :               || DECL_ARTIFICIAL (fld)
    2214          917 :               || TREE_CODE (TREE_TYPE (fld)) != POINTER_TYPE
    2215          917 :               || next_aggregate_field (DECL_CHAIN (fld))
    2216         1834 :               || !tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (decl)),
    2217          917 :                                       TYPE_SIZE (TREE_TYPE (fld))))
    2218              :             {
    2219            0 :               if (!ctx->quiet)
    2220            0 :                 error_at (loc, "%qD called without supportable %qs",
    2221              :                           fndecl, "std::exception_ptr");
    2222            0 :               *non_constant_p = true;
    2223            0 :               return call;
    2224              :             }
    2225         1834 :           FOR_EACH_VEC_ELT_REVERSE (ctx->global->caught_exceptions, idx, arg)
    2226           17 :             if (arg == NULL_TREE || !VAR_P (arg))
    2227            0 :               --idx;
    2228              :             else
    2229              :               break;
    2230              :           /* Similarly to __builtin_is_constant_evaluated (), we don't
    2231              :              want to give a definite answer during mce_unknown evaluation,
    2232              :              because that might prevent evaluation later on when some
    2233              :              exceptions might be current.  But unlike that, we don't
    2234              :              want to constant fold it to null even during cp_fold, because
    2235              :              at runtime std::current_exception () might still be non-null.  */
    2236          917 :           if (ctx->manifestly_const_eval != mce_true && arg == NULL_TREE)
    2237              :             {
    2238          897 :               *non_constant_p = true;
    2239          897 :               return call;
    2240              :             }
    2241           20 :           if (arg == NULL_TREE)
    2242            3 :             arg = build_zero_cst (TREE_TYPE (fld));
    2243              :           else
    2244              :             {
    2245           17 :               DECL_EXCEPTION_REFCOUNT (arg)
    2246           17 :                 = size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg),
    2247              :                               size_one_node);
    2248           17 :               arg = fold_convert (ptr_type_node, build_address (arg));
    2249              :             }
    2250           20 :           return build_constructor_single (TREE_TYPE (decl), fld, arg);
    2251              :         }
    2252           19 :     case STD_RETHROW_EXCEPTION:
    2253           19 :       if (nargs != 1)
    2254            0 :         goto invalid_nargs;
    2255           19 :       if (TYPE_REF_P (TREE_TYPE (args[0])))
    2256              :         {
    2257           19 :           arg = args[0];
    2258           19 :           STRIP_NOPS (arg);
    2259           19 :           if (TREE_CODE (arg) == ADDR_EXPR)
    2260              :             {
    2261           19 :               args[0]
    2262           19 :                 = cxx_eval_constant_expression (ctx, TREE_OPERAND (arg, 0),
    2263              :                                                 vc_prvalue, non_constant_p,
    2264              :                                                 overflow_p, jump_target);
    2265           19 :               if (*non_constant_p)
    2266              :                 return call;
    2267           19 :               if (*jump_target)
    2268              :                 return NULL_TREE;
    2269              :             }
    2270              :         }
    2271           19 :       if (TREE_CODE (args[0]) != CONSTRUCTOR
    2272           19 :           || CONSTRUCTOR_NELTS (args[0]) != 1)
    2273              :         {
    2274            0 :         invalid_std_rethrow:
    2275            0 :           if (!ctx->quiet)
    2276            0 :             error_at (loc, "%qD called with unexpected %qs argument",
    2277              :                       fndecl, "std::exception_ptr");
    2278            0 :           *non_constant_p = true;
    2279            0 :           return void_node;
    2280              :         }
    2281           19 :       arg = cxa_check_throw_arg (CONSTRUCTOR_ELT (args[0], 0)->value, false);
    2282           19 :       if (arg == NULL_TREE)
    2283            0 :         goto invalid_std_rethrow;
    2284           19 :       DECL_EXCEPTION_REFCOUNT (arg)
    2285           19 :         = size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg), size_one_node);
    2286           19 :       ++ctx->global->uncaught_exceptions;
    2287           19 :       *jump_target = arg;
    2288           19 :       return void_node;
    2289           51 :     case BUILTIN_EH_PTR_ADJUST_REF:
    2290           51 :       if (nargs != 2)
    2291            0 :         goto invalid_nargs;
    2292           51 :       arg = cxa_check_throw_arg (args[0], false);
    2293           51 :       if (arg == NULL_TREE)
    2294            0 :         goto invalid_ptr;
    2295           51 :       if (integer_onep (args[1]))
    2296           20 :         DECL_EXCEPTION_REFCOUNT (arg)
    2297           40 :           = size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg),
    2298              :                         size_one_node);
    2299           31 :       else if (integer_minus_onep (args[1]))
    2300           31 :         goto free_except;
    2301              :       else
    2302              :         {
    2303            0 :           if (!ctx->quiet)
    2304            0 :             error_at (loc, "%qD called with second argument "
    2305              :                       "other than 1 or -1", fndecl);
    2306            0 :           *non_constant_p = true;
    2307              :         }
    2308           20 :       return void_node;
    2309            0 :     default:
    2310            0 :       gcc_unreachable ();
    2311              :     }
    2312              : }
    2313              : 
    2314              : /* Variables and functions to manage constexpr call expansion context.
    2315              :    These do not need to be marked for PCH or GC.  */
    2316              : 
    2317              : /* FIXME remember and print actual constant arguments.  */
    2318              : static vec<tree> call_stack;
    2319              : static int call_stack_tick;
    2320              : static int last_cx_error_tick;
    2321              : 
    2322              : /* Attempt to evaluate T which represents a call to __builtin_constexpr_diag.
    2323              :    The arguments should be an integer (0 for inform, 1 for warning, 2 for
    2324              :    error) optionally with 16 ored in if it should use caller's caller location
    2325              :    instead of caller's location and 2 messages which are either a pointer to
    2326              :    a STRING_CST or class with data () and size () member functions like
    2327              :    string_view or u8string_view.  The first message is a tag, with "" passed
    2328              :    for no tag, data () should return const char *, the tag should only contain
    2329              :    alphanumeric letters or underscores.  The second message is the diagnostic
    2330              :    message, data () can be either const char * or const char8_t *.  size ()
    2331              :    should return the corresponding length of the strings in bytes as an
    2332              :    integer.  */
    2333              : 
    2334              : static tree
    2335          103 : cxx_eval_constexpr_diag (const constexpr_ctx *ctx, tree t, bool *non_constant_p,
    2336              :                          bool *overflow_p, tree *jump_target)
    2337              : {
    2338          103 :   location_t loc = EXPR_LOCATION (t);
    2339          103 :   if (call_expr_nargs (t) != 3)
    2340              :     {
    2341            6 :       if (!ctx->quiet)
    2342            6 :         error_at (loc, "wrong number of arguments to %qs call",
    2343              :                   "__builtin_constexpr_diag");
    2344            6 :       *non_constant_p = true;
    2345            6 :       return t;
    2346              :     }
    2347              :   tree args[3];
    2348          388 :   for (int i = 0; i < 3; ++i)
    2349              :     {
    2350          291 :       tree arg = convert_from_reference (CALL_EXPR_ARG (t, i));
    2351          291 :       arg = cxx_eval_constant_expression (ctx, arg,
    2352              :                                           (i == 0
    2353          263 :                                            || POINTER_TYPE_P (TREE_TYPE (arg)))
    2354          485 :                                           ? vc_prvalue : vc_glvalue,
    2355              :                                           non_constant_p, overflow_p,
    2356              :                                           jump_target);
    2357          291 :       if (*jump_target)
    2358              :         return NULL_TREE;
    2359          291 :       if (*non_constant_p)
    2360              :         return t;
    2361          291 :       args[i] = arg;
    2362              :     }
    2363          194 :   if (TREE_CODE (args[0]) != INTEGER_CST
    2364           97 :       || wi::to_widest (args[0]) < 0
    2365           95 :       || wi::to_widest (args[0]) > 18
    2366          194 :       || (wi::to_widest (args[0]) & 15) > 2)
    2367              :     {
    2368            4 :       if (!ctx->quiet)
    2369            4 :         error_at (loc, "first %qs call argument should be 0, 1, 2, 16, 17 or "
    2370              :                   "18", "__builtin_constexpr_diag");
    2371            4 :       *non_constant_p = true;
    2372            4 :       return t;
    2373              :     }
    2374           93 :   const char *msgs[2] = {};
    2375           93 :   int lens[3] = {};
    2376          558 :   cexpr_str cstrs[2];
    2377          233 :   diagnostics::kind kind = diagnostics::kind::error;
    2378          233 :   for (int i = 1; i < 3; ++i)
    2379              :     {
    2380          168 :       tree arg = args[i];
    2381          168 :       if (POINTER_TYPE_P (TREE_TYPE (arg)))
    2382              :         {
    2383           99 :           tree str = arg;
    2384           99 :           STRIP_NOPS (str);
    2385           99 :           if (TREE_CODE (str) == ADDR_EXPR
    2386           99 :               && TREE_CODE (TREE_OPERAND (str, 0)) == STRING_CST)
    2387              :             {
    2388           99 :               str = TREE_OPERAND (str, 0);
    2389           99 :               tree eltype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (str)));
    2390           99 :               if (eltype == char_type_node
    2391           12 :                   || (i == 2 && eltype == char8_type_node))
    2392          168 :                 arg = str;
    2393              :             }
    2394              :         }
    2395          168 :       cstrs[i - 1].message = arg;
    2396          168 :       if (!cstrs[i - 1].type_check (loc, i == 2))
    2397              :         {
    2398           20 :           *non_constant_p = true;
    2399           20 :           return t;
    2400              :         }
    2401          148 :       if (!cstrs[i - 1].extract (loc, msgs[i - 1], lens[i - 1], ctx,
    2402              :                                  non_constant_p, overflow_p, jump_target))
    2403              :         {
    2404            8 :           if (*jump_target)
    2405              :             return NULL_TREE;
    2406            8 :           *non_constant_p = true;
    2407            8 :           return t;
    2408              :         }
    2409              :     }
    2410           65 :   if (msgs[0])
    2411              :     {
    2412          361 :       for (int i = 0; i < lens[0]; ++i)
    2413          298 :         if (!ISALNUM (msgs[0][i]) && msgs[0][i] != '_')
    2414              :           {
    2415            2 :             if (!ctx->quiet)
    2416            2 :               error_at (loc, "%qs tag string contains %qc character other than"
    2417              :                              " letters, digits or %<_%>",
    2418              :                         "__builtin_constexpr_diag", msgs[0][i]);
    2419            2 :             *non_constant_p = true;
    2420            2 :             return t;
    2421              :           }
    2422              :     }
    2423           63 :   if (ctx->manifestly_const_eval == mce_unknown)
    2424              :     {
    2425            0 :       *non_constant_p = true;
    2426            0 :       return t;
    2427              :     }
    2428           63 :   int arg0 = tree_to_uhwi (args[0]);
    2429           63 :   if (arg0 & 16)
    2430              :     {
    2431           16 :       arg0 &= 15;
    2432           16 :       if (!call_stack.is_empty ())
    2433              :         {
    2434           16 :           tree call = call_stack.last ();
    2435           16 :           if (EXPR_HAS_LOCATION (call))
    2436           16 :             loc = EXPR_LOCATION (call);
    2437              :         }
    2438              :     }
    2439           63 :   if (arg0 == 0)
    2440              :     kind = diagnostics::kind::note;
    2441           39 :   else if (arg0 == 1)
    2442           18 :     kind = diagnostics::kind::warning;
    2443           63 :   if (lens[0])
    2444              :     {
    2445           44 :       const char *color = "error";
    2446           44 :       if (kind == diagnostics::kind::note)
    2447              :         color = "note";
    2448           30 :       else if (kind == diagnostics::kind::warning)
    2449           16 :         color = "warning";
    2450           44 :       emit_diagnostic (kind, loc, 0, "constexpr message: %.*s [%r%.*s%R]",
    2451              :                        lens[1], msgs[1], color, lens[0], msgs[0]);
    2452              :     }
    2453              :   else
    2454           19 :     emit_diagnostic (kind, loc, 0, "constexpr message: %.*s",
    2455              :                      lens[1], msgs[1]);
    2456           63 :   return void_node;
    2457          279 : }
    2458              : 
    2459              : /* Attempt to evaluate T which represents a call to a builtin function.
    2460              :    We assume here that all builtin functions evaluate to scalar types
    2461              :    represented by _CST nodes.  */
    2462              : 
    2463              : static tree
    2464     14136090 : cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun,
    2465              :                                 value_cat lval,
    2466              :                                 bool *non_constant_p, bool *overflow_p,
    2467              :                                 tree *jump_target)
    2468              : {
    2469     14136090 :   const int nargs = call_expr_nargs (t);
    2470     14136090 :   tree *args = (tree *) alloca (nargs * sizeof (tree));
    2471     14136090 :   tree new_call;
    2472     14136090 :   int i;
    2473              : 
    2474              :   /* Don't fold __builtin_constant_p within a constexpr function.  */
    2475     14136090 :   bool bi_const_p = DECL_IS_BUILTIN_CONSTANT_P (fun);
    2476              : 
    2477              :   /* If we aren't requiring a constant expression, defer __builtin_constant_p
    2478              :      in a constexpr function until we have values for the parameters.  */
    2479      1688984 :   if (bi_const_p
    2480      1688984 :       && ctx->manifestly_const_eval != mce_true
    2481      1579376 :       && current_function_decl
    2482      1578218 :       && DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    2483              :     {
    2484      1285602 :       *non_constant_p = true;
    2485      1285602 :       return t;
    2486              :     }
    2487              : 
    2488     12850488 :   if (fndecl_built_in_p (fun, BUILT_IN_FRONTEND))
    2489      3930930 :     switch (DECL_FE_FUNCTION_CODE (fun))
    2490              :       {
    2491      3922446 :       case CP_BUILT_IN_IS_CONSTANT_EVALUATED:
    2492              :         /* For __builtin_is_constant_evaluated, defer it if not
    2493              :            ctx->manifestly_const_eval (as sometimes we try to constant evaluate
    2494              :            without manifestly_const_eval even expressions or parts thereof
    2495              :            which will later be manifestly const_eval evaluated), otherwise fold
    2496              :            it to true.  */
    2497      3922446 :         if (ctx->manifestly_const_eval == mce_unknown)
    2498              :           {
    2499      3887899 :             *non_constant_p = true;
    2500      3887899 :             return t;
    2501              :           }
    2502        34547 :         return constant_boolean_node (ctx->manifestly_const_eval == mce_true,
    2503        34547 :                                       boolean_type_node);
    2504              : 
    2505         4568 :       case CP_BUILT_IN_SOURCE_LOCATION:
    2506         4568 :         {
    2507         4568 :           temp_override<tree> ovr (current_function_decl);
    2508         4568 :           if (ctx->call && ctx->call->fundef)
    2509         1443 :             current_function_decl = ctx->call->fundef->decl;
    2510         4568 :           return fold_builtin_source_location (t);
    2511         4568 :         }
    2512              : 
    2513           51 :       case CP_BUILT_IN_EH_PTR_ADJUST_REF:
    2514           51 :         return cxx_eval_cxa_builtin_fn (ctx, t, BUILTIN_EH_PTR_ADJUST_REF,
    2515              :                                         fun, non_constant_p, overflow_p,
    2516           51 :                                         jump_target);
    2517              : 
    2518          917 :       case CP_BUILT_IN_CURRENT_EXCEPTION:
    2519          917 :         return cxx_eval_cxa_builtin_fn (ctx, t, BUILTIN_CURRENT_EXCEPTION,
    2520              :                                         fun, non_constant_p, overflow_p,
    2521          917 :                                         jump_target);
    2522              : 
    2523           30 :       case CP_BUILT_IN_UNCAUGHT_EXCEPTIONS:
    2524           30 :         return cxx_eval_cxa_builtin_fn (ctx, t, BUILTIN_UNCAUGHT_EXCEPTIONS,
    2525              :                                         fun, non_constant_p, overflow_p,
    2526           30 :                                         jump_target);
    2527              : 
    2528          103 :       case CP_BUILT_IN_CONSTEXPR_DIAG:
    2529          103 :         return cxx_eval_constexpr_diag (ctx, t, non_constant_p, overflow_p,
    2530          103 :                                         jump_target);
    2531              : 
    2532              :       default:
    2533              :         break;
    2534              :       }
    2535              : 
    2536      8922373 :   int strops = 0;
    2537      8922373 :   int strret = 0;
    2538      8922373 :   bool bos = false;
    2539      8922373 :   if (fndecl_built_in_p (fun, BUILT_IN_NORMAL))
    2540      8213717 :     switch (DECL_FUNCTION_CODE (fun))
    2541              :       {
    2542              :       case BUILT_IN_STRLEN:
    2543              :       case BUILT_IN_STRNLEN:
    2544      8922283 :         strops = 1;
    2545              :         break;
    2546       112493 :       case BUILT_IN_MEMCHR:
    2547       112493 :       case BUILT_IN_STRCHR:
    2548       112493 :       case BUILT_IN_STRRCHR:
    2549       112493 :         strops = 1;
    2550       112493 :         strret = 1;
    2551       112493 :         break;
    2552        73121 :       case BUILT_IN_MEMCMP:
    2553        73121 :       case BUILT_IN_STRCMP:
    2554        73121 :         strops = 2;
    2555        73121 :         break;
    2556        28878 :       case BUILT_IN_STRSTR:
    2557        28878 :         strops = 2;
    2558        28878 :         strret = 1;
    2559        28878 :         break;
    2560           42 :       case BUILT_IN_ASAN_POINTER_COMPARE:
    2561           42 :       case BUILT_IN_ASAN_POINTER_SUBTRACT:
    2562           42 :       case BUILT_IN_OBSERVABLE_CHKPT:
    2563              :         /* These builtins shall be ignored during constant expression
    2564              :            evaluation.  */
    2565           42 :         return void_node;
    2566           48 :       case BUILT_IN_UNREACHABLE:
    2567           48 :       case BUILT_IN_TRAP:
    2568           48 :         if (!*non_constant_p && !ctx->quiet)
    2569              :           {
    2570              :             /* Do not allow__builtin_unreachable in constexpr function.
    2571              :                The __builtin_unreachable call with BUILTINS_LOCATION
    2572              :                comes from cp_maybe_instrument_return.  */
    2573           13 :             if (EXPR_LOCATION (t) == BUILTINS_LOCATION)
    2574            0 :               error ("%<constexpr%> call flows off the end of the function");
    2575              :             else
    2576           13 :               error ("%q+E is not a constant expression", t);
    2577              :           }
    2578           48 :         *non_constant_p = true;
    2579           48 :         return t;
    2580         2667 :       case BUILT_IN_OBJECT_SIZE:
    2581         2667 :       case BUILT_IN_DYNAMIC_OBJECT_SIZE:
    2582         2667 :         bos = ctx->manifestly_const_eval == mce_true;
    2583         2667 :         break;
    2584              :       default:
    2585              :         break;
    2586              :       }
    2587              : 
    2588              :   /* Be permissive for arguments to built-ins; __builtin_constant_p should
    2589              :      return constant false for a non-constant argument.  */
    2590      8922283 :   constexpr_ctx new_ctx = *ctx;
    2591      8922283 :   new_ctx.quiet = true;
    2592     25068634 :   for (i = 0; i < nargs; ++i)
    2593              :     {
    2594     16146352 :       tree arg = CALL_EXPR_ARG (t, i);
    2595     16146352 :       tree oarg = arg;
    2596              : 
    2597              :       /* To handle string built-ins we need to pass ADDR_EXPR<STRING_CST> since
    2598              :          expand_builtin doesn't know how to look in the values table.  */
    2599     16146352 :       bool strop = i < strops;
    2600     16146352 :       if (strop)
    2601              :         {
    2602       448494 :           STRIP_NOPS (arg);
    2603       448494 :           if (TREE_CODE (arg) == ADDR_EXPR)
    2604         7919 :             arg = TREE_OPERAND (arg, 0);
    2605              :           else
    2606              :             strop = false;
    2607              :         }
    2608              : 
    2609              :       /* If builtin_valid_in_constant_expr_p is true,
    2610              :          potential_constant_expression_1 has not recursed into the arguments
    2611              :          of the builtin, verify it here.  */
    2612     16146352 :       if (!builtin_valid_in_constant_expr_p (fun)
    2613     16146352 :           || potential_constant_expression (arg))
    2614              :         {
    2615     16146221 :           bool dummy1 = false, dummy2 = false;
    2616     16146221 :           tree jmp_target = NULL_TREE;
    2617     16146221 :           arg = cxx_eval_constant_expression (&new_ctx, arg, vc_prvalue,
    2618              :                                               &dummy1, &dummy2, &jmp_target);
    2619     16146220 :           if (jmp_target)
    2620              :             {
    2621            0 :               *jump_target = jmp_target;
    2622            0 :               return NULL_TREE;
    2623              :             }
    2624              :         }
    2625              : 
    2626     16146351 :       if (bi_const_p)
    2627              :         /* For __builtin_constant_p, fold all expressions with constant values
    2628              :            even if they aren't C++ constant-expressions.  */
    2629       403381 :         arg = cp_fold_rvalue (arg);
    2630     15742970 :       else if (strop)
    2631              :         {
    2632         7919 :           if (TREE_CODE (arg) == CONSTRUCTOR)
    2633          100 :             arg = braced_lists_to_strings (TREE_TYPE (arg), arg);
    2634         7919 :           if (TREE_CODE (arg) == STRING_CST)
    2635         2970 :             arg = build_address (arg);
    2636              :           else
    2637              :             arg = oarg;
    2638              :         }
    2639              : 
    2640     16146351 :       args[i] = arg;
    2641              :     }
    2642      8922282 :   if (bos)
    2643              :     {
    2644           90 :       tree arg = args[0];
    2645           90 :       STRIP_NOPS (arg);
    2646           90 :       if (TREE_CODE (arg) == ADDR_EXPR)
    2647           90 :         args[0] = arg;
    2648              :     }
    2649              : 
    2650      8922282 :   bool save_ffbcp = force_folding_builtin_constant_p;
    2651      8922282 :   force_folding_builtin_constant_p |= ctx->manifestly_const_eval == mce_true;
    2652      8922282 :   tree save_cur_fn = current_function_decl;
    2653              :   /* Return name of ctx->call->fundef->decl for __builtin_FUNCTION ().  */
    2654      8922282 :   if (fndecl_built_in_p (fun, BUILT_IN_FUNCTION)
    2655           37 :       && ctx->call
    2656      8922286 :       && ctx->call->fundef)
    2657            4 :     current_function_decl = ctx->call->fundef->decl;
    2658      8922282 :   if (fndecl_built_in_p (fun,
    2659              :                          CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
    2660              :                          BUILT_IN_FRONTEND))
    2661              :     {
    2662          336 :       location_t loc = EXPR_LOCATION (t);
    2663          336 :       if (nargs >= 1)
    2664          333 :         VERIFY_CONSTANT (args[0]);
    2665          136 :       new_call
    2666          136 :         = fold_builtin_is_pointer_inverconvertible_with_class (loc, nargs,
    2667              :                                                                args);
    2668              :     }
    2669      8921946 :   else if (fndecl_built_in_p (fun,
    2670              :                               CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
    2671              :                               BUILT_IN_FRONTEND))
    2672              :     {
    2673          471 :       location_t loc = EXPR_LOCATION (t);
    2674          471 :       if (nargs >= 2)
    2675              :         {
    2676          465 :           VERIFY_CONSTANT (args[0]);
    2677          237 :           VERIFY_CONSTANT (args[1]);
    2678              :         }
    2679          243 :       new_call = fold_builtin_is_corresponding_member (loc, nargs, args);
    2680              :     }
    2681      8921475 :   else if (fndecl_built_in_p (fun, CP_BUILT_IN_IS_STRING_LITERAL,
    2682              :                               BUILT_IN_FRONTEND))
    2683              :     {
    2684         2008 :       location_t loc = EXPR_LOCATION (t);
    2685         2008 :       if (nargs >= 1)
    2686              :         {
    2687         2008 :           tree arg = CALL_EXPR_ARG (t, 0);
    2688         2008 :           arg = cxx_eval_constant_expression (ctx, arg, vc_prvalue,
    2689              :                                               non_constant_p, overflow_p,
    2690              :                                               jump_target);
    2691         2008 :           if (*jump_target)
    2692              :             return NULL_TREE;
    2693         2008 :           args[0] = arg;
    2694              :         }
    2695         2008 :       new_call = fold_builtin_is_string_literal (loc, nargs, args);
    2696              :     }
    2697              :   else
    2698     17838934 :     new_call = fold_builtin_call_array (EXPR_LOCATION (t), TREE_TYPE (t),
    2699      8919467 :                                         CALL_EXPR_FN (t), nargs, args);
    2700      8921854 :   current_function_decl = save_cur_fn;
    2701      8921854 :   force_folding_builtin_constant_p = save_ffbcp;
    2702      8921854 :   if (new_call == NULL)
    2703              :     {
    2704      6375698 :       if (!*non_constant_p && !ctx->quiet)
    2705              :         {
    2706            0 :           new_call = build_call_array_loc (EXPR_LOCATION (t), TREE_TYPE (t),
    2707            0 :                                            CALL_EXPR_FN (t), nargs, args);
    2708            0 :           error ("%q+E is not a constant expression", new_call);
    2709              :         }
    2710      6375698 :       *non_constant_p = true;
    2711      6375698 :       return t;
    2712              :     }
    2713              : 
    2714      2546156 :   if (!potential_constant_expression (new_call))
    2715              :     {
    2716          734 :       if (!*non_constant_p && !ctx->quiet)
    2717            4 :         error ("%q+E is not a constant expression", new_call);
    2718          734 :       *non_constant_p = true;
    2719          734 :       return t;
    2720              :     }
    2721              : 
    2722      2545422 :   if (strret)
    2723              :     {
    2724              :       /* memchr returns a pointer into the first argument, but we replaced the
    2725              :          argument above with a STRING_CST; put it back it now.  */
    2726          119 :       tree op = CALL_EXPR_ARG (t, strret-1);
    2727          119 :       STRIP_NOPS (new_call);
    2728          119 :       if (TREE_CODE (new_call) == POINTER_PLUS_EXPR)
    2729           60 :         TREE_OPERAND (new_call, 0) = op;
    2730           59 :       else if (TREE_CODE (new_call) == ADDR_EXPR)
    2731      2545422 :         new_call = op;
    2732              :     }
    2733              : 
    2734      2545422 :   return cxx_eval_constant_expression (&new_ctx, new_call, lval,
    2735              :                                        non_constant_p, overflow_p,
    2736      2545422 :                                        jump_target);
    2737              : }
    2738              : 
    2739              : /* TEMP is the constant value of a temporary object of type TYPE.  Adjust
    2740              :    the type of the value to match.  */
    2741              : 
    2742              : static tree
    2743     84288778 : adjust_temp_type (tree type, tree temp)
    2744              : {
    2745     84288778 :   if (same_type_p (TREE_TYPE (temp), type))
    2746              :     return temp;
    2747              :   /* Avoid wrapping an aggregate value in a NOP_EXPR.  */
    2748     38238911 :   if (TREE_CODE (temp) == CONSTRUCTOR)
    2749              :     {
    2750              :       /* build_constructor wouldn't retain various CONSTRUCTOR flags.  */
    2751      3207505 :       tree t = copy_node (temp);
    2752      3207505 :       TREE_TYPE (t) = type;
    2753      3207505 :       return t;
    2754              :     }
    2755     35031406 :   if (TREE_CODE (temp) == EMPTY_CLASS_EXPR)
    2756            0 :     return build0 (EMPTY_CLASS_EXPR, type);
    2757     35031406 :   gcc_assert (scalarish_type_p (type));
    2758              :   /* Now we know we're dealing with a scalar, and a prvalue of non-class
    2759              :      type is cv-unqualified.  */
    2760     35031406 :   return cp_fold_convert (cv_unqualified (type), temp);
    2761              : }
    2762              : 
    2763              : /* If T is a CONSTRUCTOR, return an unshared copy of T and any
    2764              :    sub-CONSTRUCTORs.  Otherwise return T.
    2765              : 
    2766              :    We use this whenever we initialize an object as a whole, whether it's a
    2767              :    parameter, a local variable, or a subobject, so that subsequent
    2768              :    modifications don't affect other places where it was used.  */
    2769              : 
    2770              : tree
    2771     68776712 : unshare_constructor (tree t MEM_STAT_DECL)
    2772              : {
    2773     68776712 :   if (!t || TREE_CODE (t) != CONSTRUCTOR)
    2774              :     return t;
    2775     12250601 :   auto_vec <tree*, 4> ptrs;
    2776     12250601 :   ptrs.safe_push (&t);
    2777     12250601 :   while (!ptrs.is_empty ())
    2778              :     {
    2779     15100152 :       tree *p = ptrs.pop ();
    2780     15100152 :       tree n = copy_node (*p PASS_MEM_STAT);
    2781     23338533 :       CONSTRUCTOR_ELTS (n) = vec_safe_copy (CONSTRUCTOR_ELTS (*p) PASS_MEM_STAT);
    2782     15100152 :       *p = n;
    2783     15100152 :       vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (n);
    2784     15100152 :       constructor_elt *ce;
    2785     57242941 :       for (HOST_WIDE_INT i = 0; vec_safe_iterate (v, i, &ce); ++i)
    2786     14792036 :         if (ce->value && TREE_CODE (ce->value) == CONSTRUCTOR)
    2787      2849551 :           ptrs.safe_push (&ce->value);
    2788              :     }
    2789     12250601 :   return t;
    2790     12250601 : }
    2791              : 
    2792              : /* If T is a CONSTRUCTOR, ggc_free T and any sub-CONSTRUCTORs.  */
    2793              : 
    2794              : static void
    2795       805954 : free_constructor (tree t)
    2796              : {
    2797       805954 :   if (!t || TREE_CODE (t) != CONSTRUCTOR)
    2798            0 :     return;
    2799       805954 :   releasing_vec ctors;
    2800       805954 :   vec_safe_push (ctors, t);
    2801      1649715 :   while (!ctors->is_empty ())
    2802              :     {
    2803       843761 :       tree c = ctors->pop ();
    2804       843761 :       if (vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (c))
    2805              :         {
    2806              :           constructor_elt *ce;
    2807       316803 :           for (HOST_WIDE_INT i = 0; vec_safe_iterate (elts, i, &ce); ++i)
    2808       204311 :             if (ce->value && TREE_CODE (ce->value) == CONSTRUCTOR)
    2809        37807 :               vec_safe_push (ctors, ce->value);
    2810       112492 :           ggc_free (elts);
    2811              :         }
    2812       843761 :       ggc_free (c);
    2813              :     }
    2814       805954 : }
    2815              : 
    2816              : /* Helper function of cxx_bind_parameters_in_call.  Return non-NULL
    2817              :    if *TP is address of a static variable (or part of it) currently being
    2818              :    constructed or of a heap artificial variable.  */
    2819              : 
    2820              : static tree
    2821     23751028 : addr_of_non_const_var (tree *tp, int *walk_subtrees, void *data)
    2822              : {
    2823     23751028 :   if (TREE_CODE (*tp) == ADDR_EXPR)
    2824      3671576 :     if (tree var = get_base_address (TREE_OPERAND (*tp, 0)))
    2825      3671576 :       if (VAR_P (var) && TREE_STATIC (var))
    2826              :         {
    2827      1729621 :           if (DECL_NAME (var) == heap_uninit_identifier
    2828      1729621 :               || DECL_NAME (var) == heap_identifier
    2829      1729621 :               || DECL_NAME (var) == heap_vec_uninit_identifier
    2830      3459242 :               || DECL_NAME (var) == heap_vec_identifier)
    2831              :             return var;
    2832              : 
    2833      1729621 :           constexpr_global_ctx *global = (constexpr_global_ctx *) data;
    2834      1729621 :           if (global->get_value (var))
    2835              :             return var;
    2836              :         }
    2837     23394116 :   if (TYPE_P (*tp))
    2838         1839 :     *walk_subtrees = false;
    2839              :   return NULL_TREE;
    2840              : }
    2841              : 
    2842              : /* Subroutine of cxx_eval_call_expression.
    2843              :    We are processing a call expression (either CALL_EXPR or
    2844              :    AGGR_INIT_EXPR) in the context of CTX.  Evaluate
    2845              :    all arguments and bind their values to correspondings
    2846              :    parameters, making up the NEW_CALL context.  */
    2847              : 
    2848              : static tree
    2849    123127637 : cxx_bind_parameters_in_call (const constexpr_ctx *ctx, tree t, tree fun,
    2850              :                              tree orig_fun, bool *non_constant_p,
    2851              :                              bool *overflow_p, bool *non_constant_args,
    2852              :                              tree *jump_target)
    2853              : {
    2854    123127637 :   int nargs = call_expr_nargs (t);
    2855    123127637 :   tree parms = DECL_ARGUMENTS (fun);
    2856    123127637 :   int i, j = 0;
    2857    123127637 :   if (DECL_HAS_IN_CHARGE_PARM_P (fun) && fun != orig_fun)
    2858         1236 :     ++nargs;
    2859    123127637 :   if (DECL_HAS_VTT_PARM_P (fun)
    2860         1238 :       && fun != orig_fun
    2861    123128873 :       && (DECL_COMPLETE_CONSTRUCTOR_P (orig_fun)
    2862          902 :           || DECL_COMPLETE_DESTRUCTOR_P (orig_fun)))
    2863          345 :     ++nargs;
    2864              :   /* We don't record ellipsis args below.  */
    2865    123127637 :   int nparms = list_length (parms);
    2866    123127637 :   int nbinds = nargs < nparms ? nargs : nparms;
    2867    123127637 :   tree binds = make_tree_vec (nbinds);
    2868              : 
    2869              :   /* The call is not a constant expression if it involves the cdtor for a type
    2870              :      with virtual bases before C++26.  */
    2871    123127637 :   if (cxx_dialect < cxx26
    2872    123127637 :       && (DECL_HAS_IN_CHARGE_PARM_P (fun) || DECL_HAS_VTT_PARM_P (fun)))
    2873              :     {
    2874           17 :       if (!ctx->quiet)
    2875              :         {
    2876            3 :           error_at (cp_expr_loc_or_input_loc (t),
    2877              :                     "call to non-%<constexpr%> function %qD", fun);
    2878            3 :           explain_invalid_constexpr_fn (fun);
    2879              :         }
    2880           17 :       *non_constant_p = true;
    2881           17 :       return binds;
    2882              :     }
    2883              : 
    2884    202685771 :   for (i = 0; i < nargs; ++i)
    2885              :     {
    2886    137181718 :       tree x, arg;
    2887    137181718 :       tree type = parms ? TREE_TYPE (parms) : void_type_node;
    2888    137181718 :       if (parms && DECL_BY_REFERENCE (parms))
    2889         9254 :         type = TREE_TYPE (type);
    2890    137181718 :       if (i == 1
    2891    137181718 :           && j == 0
    2892     26470107 :           && DECL_HAS_IN_CHARGE_PARM_P (fun)
    2893    137182843 :           && orig_fun != fun)
    2894              :         {
    2895         1125 :           if (DECL_COMPLETE_CONSTRUCTOR_P (orig_fun)
    2896         1125 :               || DECL_COMPLETE_DESTRUCTOR_P (orig_fun))
    2897          325 :             x = boolean_true_node;
    2898              :           else
    2899          800 :             x = boolean_false_node;
    2900              :           j = -1;
    2901              :         }
    2902    137180593 :       else if (i == 2
    2903    137180593 :                && j == -1
    2904         1125 :                && DECL_HAS_VTT_PARM_P (fun)
    2905         1125 :                && orig_fun != fun
    2906    137181718 :                && (DECL_COMPLETE_CONSTRUCTOR_P (orig_fun)
    2907          811 :                    || DECL_COMPLETE_DESTRUCTOR_P (orig_fun)))
    2908              :         {
    2909          325 :           x = build_zero_cst (type);
    2910          325 :           j = -2;
    2911              :         }
    2912              :       else
    2913    137180268 :         x = get_nth_callarg (t, i + j);
    2914              :       /* For member function, the first argument is a pointer to the implied
    2915              :          object.  For a constructor, it might still be a dummy object, in
    2916              :          which case we get the real argument from ctx.  */
    2917    212027180 :       if (i == 0 && DECL_CONSTRUCTOR_P (fun)
    2918    154112691 :           && is_dummy_object (x))
    2919              :         {
    2920      8005970 :           x = ctx->object;
    2921      8005970 :           x = build_address (x);
    2922              :         }
    2923    137181718 :       if (TREE_ADDRESSABLE (type))
    2924              :         {
    2925              :           /* Undo convert_for_arg_passing work here.  */
    2926        15437 :           x = convert_from_reference (x);
    2927        15437 :           arg = cxx_eval_constant_expression (ctx, x, vc_glvalue,
    2928              :                                               non_constant_p, overflow_p,
    2929              :                                               jump_target);
    2930              :         }
    2931              :       else
    2932              :         /* Normally we would strip a TARGET_EXPR in an initialization context
    2933              :            such as this, but here we do the elision differently: we keep the
    2934              :            TARGET_EXPR, and use its CONSTRUCTOR as the value of the parm.  */
    2935    137166281 :         arg = cxx_eval_constant_expression (ctx, x, vc_prvalue,
    2936              :                                             non_constant_p, overflow_p,
    2937              :                                             jump_target);
    2938    137181718 :       if (*jump_target)
    2939              :         break;
    2940              :       /* Check we aren't dereferencing a null pointer when calling a non-static
    2941              :          member function, which is undefined behaviour.  */
    2942    106013561 :       if (i == 0 && DECL_OBJECT_MEMBER_FUNCTION_P (fun)
    2943     61781313 :           && integer_zerop (arg)
    2944              :           /* But ignore calls from within compiler-generated code, to handle
    2945              :              cases like lambda function pointer conversion operator thunks
    2946              :              which pass NULL as the 'this' pointer.  */
    2947    137296259 :           && !(TREE_CODE (t) == CALL_EXPR && CALL_FROM_THUNK_P (t)))
    2948              :         {
    2949          312 :           if (!ctx->quiet)
    2950            6 :             error_at (cp_expr_loc_or_input_loc (x),
    2951              :                       "dereferencing a null pointer");
    2952          312 :           *non_constant_p = true;
    2953              :         }
    2954              :       /* Don't VERIFY_CONSTANT here.  */
    2955    137181677 :       if (*non_constant_p && ctx->quiet)
    2956              :         break;
    2957              :       /* Just discard ellipsis args after checking their constantitude.  */
    2958     79558151 :       if (!parms)
    2959          283 :         continue;
    2960              : 
    2961     79557868 :       if (!*non_constant_p)
    2962              :         {
    2963              :           /* Make sure the binding has the same type as the parm.  But
    2964              :              only for constant args.  */
    2965     79557224 :           if (TREE_ADDRESSABLE (type))
    2966              :             {
    2967         9395 :               if (!same_type_p (type, TREE_TYPE (arg)))
    2968              :                 {
    2969            9 :                   arg = build_fold_addr_expr (arg);
    2970            9 :                   arg = cp_fold_convert (build_reference_type (type), arg);
    2971            9 :                   arg = convert_from_reference (arg);
    2972              :                 }
    2973              :             }
    2974     79547829 :           else if (!TYPE_REF_P (type))
    2975     61025670 :             arg = adjust_temp_type (type, arg);
    2976     79557224 :           if (!TREE_CONSTANT (arg))
    2977     53393041 :             *non_constant_args = true;
    2978     26164183 :           else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    2979              :             /* The destructor needs to see any modifications the callee makes
    2980              :                to the argument.  */
    2981            0 :             *non_constant_args = true;
    2982              :             /* If arg is or contains address of a heap artificial variable or
    2983              :                of a static variable being constructed, avoid caching the
    2984              :                function call, as those variables might be modified by the
    2985              :                function, or might be modified by the callers in between
    2986              :                the cached function and just read by the function.  */
    2987     26164183 :           else if (!*non_constant_args
    2988     26164183 :                    && cp_walk_tree (&arg, addr_of_non_const_var, ctx->global,
    2989              :                                     NULL))
    2990       356912 :             *non_constant_args = true;
    2991              : 
    2992              :           /* For virtual calls, adjust the this argument, so that it is
    2993              :              the object on which the method is called, rather than
    2994              :              one of its bases.  */
    2995     79557224 :           if (i == 0 && DECL_VIRTUAL_P (fun))
    2996              :             {
    2997        16711 :               tree addr = arg;
    2998        16711 :               STRIP_NOPS (addr);
    2999        16711 :               if (TREE_CODE (addr) == ADDR_EXPR)
    3000              :                 {
    3001        16691 :                   tree obj = TREE_OPERAND (addr, 0);
    3002        16691 :                   while (TREE_CODE (obj) == COMPONENT_REF
    3003         7846 :                          && DECL_FIELD_IS_BASE (TREE_OPERAND (obj, 1))
    3004        24539 :                          && !same_type_ignoring_top_level_qualifiers_p
    3005         7794 :                                         (TREE_TYPE (obj), DECL_CONTEXT (fun)))
    3006           54 :                     obj = TREE_OPERAND (obj, 0);
    3007        16691 :                   if (obj != TREE_OPERAND (addr, 0))
    3008           51 :                     arg = build_fold_addr_expr_with_type (obj,
    3009              :                                                           TREE_TYPE (arg));
    3010              :                 }
    3011              :             }
    3012     79557224 :           TREE_VEC_ELT (binds, i) = arg;
    3013              :         }
    3014     79557868 :       parms = TREE_CHAIN (parms);
    3015              :     }
    3016              : 
    3017              :   return binds;
    3018              : }
    3019              : 
    3020              : static int
    3021     65017233 : push_cx_call_context (tree call)
    3022              : {
    3023     65017233 :   ++call_stack_tick;
    3024     65017233 :   if (!EXPR_HAS_LOCATION (call))
    3025        55957 :     SET_EXPR_LOCATION (call, input_location);
    3026     65017233 :   call_stack.safe_push (call);
    3027     65017233 :   int len = call_stack.length ();
    3028     65017233 :   if (len > max_constexpr_depth)
    3029           30 :     return false;
    3030              :   return len;
    3031              : }
    3032              : 
    3033              : static void
    3034     65017231 : pop_cx_call_context (void)
    3035              : {
    3036     65017231 :   ++call_stack_tick;
    3037     65017231 :   call_stack.pop ();
    3038     65017231 : }
    3039              : 
    3040              : vec<tree>
    3041       244521 : cx_error_context (void)
    3042              : {
    3043       244521 :   vec<tree> r = vNULL;
    3044       244521 :   if (call_stack_tick != last_cx_error_tick
    3045       244521 :       && !call_stack.is_empty ())
    3046              :     r = call_stack;
    3047       244521 :   last_cx_error_tick = call_stack_tick;
    3048       244521 :   return r;
    3049              : }
    3050              : 
    3051              : /* E is an operand of a failed assertion, fold it either with or without
    3052              :    constexpr context.  */
    3053              : 
    3054              : static tree
    3055          641 : fold_operand (tree e, const constexpr_ctx *ctx)
    3056              : {
    3057          641 :   if (ctx)
    3058              :     {
    3059           32 :       bool new_non_constant_p = false, new_overflow_p = false;
    3060           32 :       tree jmp_target = NULL_TREE;
    3061           32 :       e = cxx_eval_constant_expression (ctx, e, vc_prvalue,
    3062              :                                         &new_non_constant_p,
    3063              :                                         &new_overflow_p, &jmp_target);
    3064              :     }
    3065              :   else
    3066          609 :     e = fold_non_dependent_expr (e, tf_none, /*manifestly_const_eval=*/true);
    3067          641 :   return e;
    3068              : }
    3069              : 
    3070              : /* If we have a condition in conjunctive normal form (CNF), find the first
    3071              :    failing clause.  In other words, given an expression like
    3072              : 
    3073              :      true && true && false && true && false
    3074              : 
    3075              :    return the first 'false'.  EXPR is the expression.  */
    3076              : 
    3077              : static tree
    3078          320 : find_failing_clause_r (const constexpr_ctx *ctx, tree expr)
    3079              : {
    3080          421 :   if (TREE_CODE (expr) == TRUTH_ANDIF_EXPR)
    3081              :     {
    3082              :       /* First check the left side...  */
    3083          186 :       tree e = find_failing_clause_r (ctx, TREE_OPERAND (expr, 0));
    3084          186 :       if (e == NULL_TREE)
    3085              :         /* ...if we didn't find a false clause, check the right side.  */
    3086          101 :         e = find_failing_clause_r (ctx, TREE_OPERAND (expr, 1));
    3087              :       return e;
    3088              :     }
    3089          235 :   tree e = contextual_conv_bool (expr, tf_none);
    3090          235 :   e = fold_operand (e, ctx);
    3091          235 :   if (integer_zerop (e))
    3092              :     /* This is the failing clause.  */
    3093          134 :     return expr;
    3094              :   return NULL_TREE;
    3095              : }
    3096              : 
    3097              : /* Wrapper for find_failing_clause_r.  */
    3098              : 
    3099              : tree
    3100         1637 : find_failing_clause (const constexpr_ctx *ctx, tree expr)
    3101              : {
    3102         1637 :   if (TREE_CODE (expr) == TRUTH_ANDIF_EXPR)
    3103          134 :     if (tree e = find_failing_clause_r (ctx, expr))
    3104         1637 :       expr = e;
    3105         1637 :   return expr;
    3106              : }
    3107              : 
    3108              : /* Emit additional diagnostics for failing condition BAD.
    3109              :    Used by finish_static_assert and IFN_ASSUME constexpr diagnostics.
    3110              :    If SHOW_EXPR_P is true, print the condition (because it was
    3111              :    instantiation-dependent).  */
    3112              : 
    3113              : void
    3114         1637 : diagnose_failing_condition (tree bad, location_t cloc, bool show_expr_p,
    3115              :                             const constexpr_ctx *ctx /* = nullptr */)
    3116              : {
    3117              :   /* Nobody wants to see the artificial (bool) cast.  */
    3118         1637 :   bad = tree_strip_nop_conversions (bad);
    3119         1637 :   if (TREE_CODE (bad) == CLEANUP_POINT_EXPR)
    3120            3 :     bad = TREE_OPERAND (bad, 0);
    3121              : 
    3122         1637 :   auto_diagnostic_nesting_level sentinel;
    3123              : 
    3124              :   /* Actually explain the failure if this is a concept check or a
    3125              :      requires-expression.  */
    3126         1637 :   if (concept_check_p (bad) || TREE_CODE (bad) == REQUIRES_EXPR)
    3127          287 :     diagnose_constraints (cloc, bad, NULL_TREE);
    3128              :   /* Similarly if this is a standard trait.  */
    3129         1350 :   else if (maybe_diagnose_standard_trait (cloc, bad))
    3130              :     ;
    3131         1022 :   else if (COMPARISON_CLASS_P (bad)
    3132         1022 :            && (ARITHMETIC_TYPE_P (TREE_TYPE (TREE_OPERAND (bad, 0)))
    3133           31 :                || REFLECTION_TYPE_P (TREE_TYPE (TREE_OPERAND (bad, 0)))))
    3134              :     {
    3135          203 :       tree op0 = fold_operand (TREE_OPERAND (bad, 0), ctx);
    3136          203 :       tree op1 = fold_operand (TREE_OPERAND (bad, 1), ctx);
    3137          203 :       tree cond = build2 (TREE_CODE (bad), boolean_type_node, op0, op1);
    3138          203 :       inform (cloc, "the comparison reduces to %qE", cond);
    3139              :     }
    3140          819 :   else if (show_expr_p)
    3141          577 :     inform (cloc, "%qE evaluates to false", bad);
    3142         1637 : }
    3143              : 
    3144              : /* Process an assert/assume of ORIG_ARG.  If it's not supposed to be evaluated,
    3145              :    do it without changing the current evaluation state.  If it evaluates to
    3146              :    false, complain and return false; otherwise, return true.  */
    3147              : 
    3148              : static bool
    3149       173449 : cxx_eval_assert (const constexpr_ctx *ctx, tree arg, const char *msg,
    3150              :                  location_t loc, bool evaluated,
    3151              :                  bool *non_constant_p, bool *overflow_p)
    3152              : {
    3153       173449 :   if (*non_constant_p)
    3154              :     return true;
    3155              : 
    3156       173449 :   tree eval, jmp_target = NULL_TREE;
    3157       173449 :   if (!evaluated)
    3158              :     {
    3159       173449 :       if (!potential_rvalue_constant_expression (arg))
    3160           16 :         return true;
    3161              : 
    3162       173433 :       constexpr_ctx new_ctx = *ctx;
    3163       173433 :       new_ctx.quiet = true;
    3164       173433 :       bool new_non_constant_p = false, new_overflow_p = false;
    3165              :       /* Avoid modification of existing values.  */
    3166       173433 :       modifiable_tracker ms (new_ctx.global);
    3167       173433 :       eval = cxx_eval_constant_expression (&new_ctx, arg, vc_prvalue,
    3168              :                                            &new_non_constant_p,
    3169              :                                            &new_overflow_p, &jmp_target);
    3170       173433 :     }
    3171              :   else
    3172            0 :     eval = cxx_eval_constant_expression (ctx, arg, vc_prvalue,
    3173              :                                          non_constant_p,
    3174              :                                          overflow_p, &jmp_target);
    3175       173433 :   if (jmp_target)
    3176              :     return true;
    3177              : 
    3178       173433 :   if (!*non_constant_p && integer_zerop (eval))
    3179              :     {
    3180           42 :       if (!ctx->quiet)
    3181              :         {
    3182              :           /* See if we can find which clause was failing
    3183              :              (for logical AND).  */
    3184           13 :           tree bad = find_failing_clause (ctx, arg);
    3185              :           /* If not, or its location is unusable, fall back to the
    3186              :              previous location.  */
    3187           13 :           location_t cloc = cp_expr_loc_or_loc (bad, loc);
    3188              : 
    3189              :           /* Report the error. */
    3190           13 :           auto_diagnostic_group d;
    3191           13 :           error_at (cloc, msg);
    3192           13 :           diagnose_failing_condition (bad, cloc, true, ctx);
    3193           13 :           return bad;
    3194           13 :         }
    3195           29 :       *non_constant_p = true;
    3196           29 :       return false;
    3197              :     }
    3198              : 
    3199              :   return true;
    3200              : }
    3201              : 
    3202              : /* Evaluate a call T to a GCC internal function when possible and return
    3203              :    the evaluated result or, under the control of CTX, give an error, set
    3204              :    NON_CONSTANT_P, and return the unevaluated call T otherwise.  */
    3205              : 
    3206              : static tree
    3207       370398 : cxx_eval_internal_function (const constexpr_ctx *ctx, tree t,
    3208              :                             value_cat lval,
    3209              :                             bool *non_constant_p, bool *overflow_p,
    3210              :                             tree *jump_target)
    3211              : {
    3212       370398 :   enum tree_code opcode = ERROR_MARK;
    3213              : 
    3214       370398 :   switch (CALL_EXPR_IFN (t))
    3215              :     {
    3216          159 :     case IFN_UBSAN_NULL:
    3217          159 :     case IFN_UBSAN_BOUNDS:
    3218          159 :     case IFN_UBSAN_VPTR:
    3219          159 :     case IFN_FALLTHROUGH:
    3220          159 :       return void_node;
    3221              : 
    3222       173449 :     case IFN_ASSUME:
    3223       173449 :       if (!cxx_eval_assert (ctx, CALL_EXPR_ARG (t, 0),
    3224              :                             G_("failed %<assume%> attribute assumption"),
    3225       173449 :                             EXPR_LOCATION (t), /*eval*/false,
    3226              :                             non_constant_p, overflow_p))
    3227              :         return t;
    3228       173420 :       return void_node;
    3229              : 
    3230              :     case IFN_ADD_OVERFLOW:
    3231              :       opcode = PLUS_EXPR;
    3232              :       break;
    3233          355 :     case IFN_SUB_OVERFLOW:
    3234          355 :       opcode = MINUS_EXPR;
    3235          355 :       break;
    3236       193883 :     case IFN_MUL_OVERFLOW:
    3237       193883 :       opcode = MULT_EXPR;
    3238       193883 :       break;
    3239              : 
    3240           74 :     case IFN_LAUNDER:
    3241           74 :       return cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, 0),
    3242              :                                            vc_prvalue, non_constant_p,
    3243           74 :                                            overflow_p, jump_target);
    3244              : 
    3245            0 :     case IFN_DEFERRED_INIT:
    3246            0 :       return build_clobber (TREE_TYPE (t), CLOBBER_OBJECT_BEGIN);
    3247              : 
    3248         2011 :     case IFN_VEC_CONVERT:
    3249         2011 :       {
    3250         2011 :         tree arg = cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, 0),
    3251              :                                                  vc_prvalue, non_constant_p,
    3252              :                                                  overflow_p, jump_target);
    3253         2011 :         if (*jump_target)
    3254              :           return NULL_TREE;
    3255         2011 :         if (TREE_CODE (arg) == VECTOR_CST)
    3256         1912 :           if (tree r = fold_const_call (CFN_VEC_CONVERT, TREE_TYPE (t), arg))
    3257              :             return r;
    3258              :       }
    3259              :       /* FALLTHRU */
    3260              : 
    3261          104 :     default:
    3262          104 :       if (!ctx->quiet)
    3263            0 :         error_at (cp_expr_loc_or_input_loc (t),
    3264              :                   "call to internal function %qE", t);
    3265          104 :       *non_constant_p = true;
    3266          104 :       return t;
    3267              :     }
    3268              : 
    3269              :   /* Evaluate constant arguments using OPCODE and return a complex
    3270              :      number containing the result and the overflow bit.  */
    3271       194705 :   tree arg0 = cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, 0), lval,
    3272              :                                             non_constant_p, overflow_p,
    3273              :                                             jump_target);
    3274       194705 :   tree arg1 = cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, 1), lval,
    3275              :                                             non_constant_p, overflow_p,
    3276              :                                             jump_target);
    3277       194705 :   if (*jump_target)
    3278              :     return NULL_TREE;
    3279       194705 :   if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
    3280              :     {
    3281            2 :       location_t loc = cp_expr_loc_or_input_loc (t);
    3282            2 :       tree type = TREE_TYPE (TREE_TYPE (t));
    3283            2 :       tree result = fold_binary_loc (loc, opcode, type,
    3284              :                                      fold_convert_loc (loc, type, arg0),
    3285              :                                      fold_convert_loc (loc, type, arg1));
    3286            2 :       tree ovf
    3287            2 :         = build_int_cst (type, arith_overflowed_p (opcode, type, arg0, arg1));
    3288              :       /* Reset TREE_OVERFLOW to avoid warnings for the overflow.  */
    3289            2 :       if (TREE_OVERFLOW (result))
    3290            0 :         TREE_OVERFLOW (result) = 0;
    3291              : 
    3292            2 :       return build_complex (TREE_TYPE (t), result, ovf);
    3293              :     }
    3294              : 
    3295       194703 :   *non_constant_p = true;
    3296       194703 :   return t;
    3297              : }
    3298              : 
    3299              : /* Clean CONSTRUCTOR_NO_CLEARING from CTOR and its sub-aggregates.  */
    3300              : 
    3301              : static void
    3302      4317509 : clear_no_implicit_zero (tree ctor)
    3303              : {
    3304      4317509 :   if (CONSTRUCTOR_NO_CLEARING (ctor))
    3305              :     {
    3306       951649 :       CONSTRUCTOR_NO_CLEARING (ctor) = false;
    3307      4061867 :       for (auto &e: CONSTRUCTOR_ELTS (ctor))
    3308      1288760 :         if (TREE_CODE (e.value) == CONSTRUCTOR)
    3309       398016 :           clear_no_implicit_zero (e.value);
    3310              :     }
    3311      4317509 : }
    3312              : 
    3313              : /* Complain about a const object OBJ being modified in a constant expression.
    3314              :    EXPR is the MODIFY_EXPR expression performing the modification.  */
    3315              : 
    3316              : static void
    3317           63 : modifying_const_object_error (tree expr, tree obj)
    3318              : {
    3319           63 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    3320           63 :   auto_diagnostic_group d;
    3321          126 :   error_at (loc, "modifying a const object %qE is not allowed in "
    3322           63 :             "a constant expression", TREE_OPERAND (expr, 0));
    3323              : 
    3324              :   /* Find the underlying object that was declared as const.  */
    3325           63 :   location_t decl_loc = UNKNOWN_LOCATION;
    3326          138 :   for (tree probe = obj; decl_loc == UNKNOWN_LOCATION; )
    3327           75 :     switch (TREE_CODE (probe))
    3328              :       {
    3329           39 :       case BIT_FIELD_REF:
    3330           39 :       case COMPONENT_REF:
    3331           39 :         {
    3332           39 :           tree elt = TREE_OPERAND (probe, 1);
    3333           39 :           if (CP_TYPE_CONST_P (TREE_TYPE (elt)))
    3334           27 :             decl_loc = DECL_SOURCE_LOCATION (elt);
    3335           39 :           probe = TREE_OPERAND (probe, 0);
    3336              :         }
    3337           39 :         break;
    3338              : 
    3339            0 :       case ARRAY_REF:
    3340            0 :       case REALPART_EXPR:
    3341            0 :       case IMAGPART_EXPR:
    3342            0 :         probe = TREE_OPERAND (probe, 0);
    3343            0 :         break;
    3344              : 
    3345           36 :       default:
    3346           36 :         decl_loc = location_of (probe);
    3347           36 :         break;
    3348              :       }
    3349           63 :   inform (decl_loc, "originally declared %<const%> here");
    3350           63 : }
    3351              : 
    3352              : /* Return true if FNDECL is a replaceable global allocation function that
    3353              :    should be useable during constant expression evaluation.  */
    3354              : 
    3355              : static inline bool
    3356     27872155 : cxx_replaceable_global_alloc_fn (tree fndecl)
    3357              : {
    3358     27872155 :   return (cxx_dialect >= cxx20
    3359     26353388 :           && IDENTIFIER_NEWDEL_OP_P (DECL_NAME (fndecl))
    3360      1626981 :           && CP_DECL_CONTEXT (fndecl) == global_namespace
    3361     29498822 :           && (DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl)
    3362       825374 :               || DECL_IS_OPERATOR_DELETE_P (fndecl)));
    3363              : }
    3364              : 
    3365              : /* Return true if FNDECL is a placement new function that should be
    3366              :    useable during constant expression evaluation of std::construct_at.  */
    3367              : 
    3368              : static inline bool
    3369     26883807 : cxx_placement_new_fn (tree fndecl)
    3370              : {
    3371     26883807 :   return (cxx_dialect >= cxx20 && std_placement_new_fn_p (fndecl));
    3372              : }
    3373              : 
    3374              : /* Return true if FNDECL is std::construct_at.  */
    3375              : 
    3376              : static inline bool
    3377      1160095 : is_std_construct_at (tree fndecl)
    3378              : {
    3379      1160095 :   if (!decl_in_std_namespace_p (fndecl))
    3380              :     return false;
    3381              : 
    3382      1136859 :   tree name = DECL_NAME (fndecl);
    3383      1136859 :   return name && id_equal (name, "construct_at");
    3384              : }
    3385              : 
    3386              : /* Overload for the above taking constexpr_call*.  */
    3387              : 
    3388              : static inline bool
    3389       914086 : is_std_construct_at (const constexpr_call *call)
    3390              : {
    3391       914086 :   return (call
    3392       772834 :           && call->fundef
    3393      1686920 :           && is_std_construct_at (call->fundef->decl));
    3394              : }
    3395              : 
    3396              : /* True if CTX is an instance of std::NAME class.  */
    3397              : 
    3398              : bool
    3399     10545287 : is_std_class (tree ctx, const char *name)
    3400              : {
    3401     10545287 :   if (ctx == NULL_TREE || !CLASS_TYPE_P (ctx) || !TYPE_MAIN_DECL (ctx))
    3402              :     return false;
    3403              : 
    3404     10544362 :   tree decl = TYPE_MAIN_DECL (ctx);
    3405     10544362 :   tree dname = DECL_NAME (decl);
    3406     10544362 :   if (dname == NULL_TREE || !id_equal (dname, name))
    3407              :     return false;
    3408              : 
    3409       553974 :   return decl_in_std_namespace_p (decl);
    3410              : }
    3411              : 
    3412              : /* True if CTX is an instance of std::allocator.  */
    3413              : 
    3414              : bool
    3415       401705 : is_std_allocator (tree ctx)
    3416              : {
    3417       401705 :   return is_std_class (ctx, "allocator");
    3418              : }
    3419              : 
    3420              : /* Return true if FNDECL is std::allocator<T>::{,de}allocate.  */
    3421              : 
    3422              : static bool
    3423       419722 : is_std_allocator_allocate (tree fndecl)
    3424              : {
    3425       419722 :   tree name = DECL_NAME (fndecl);
    3426       419722 :   if (name == NULL_TREE
    3427       419722 :       || !(id_equal (name, "allocate") || id_equal (name, "deallocate")))
    3428              :     return false;
    3429              : 
    3430       397065 :   return is_std_allocator (DECL_CONTEXT (fndecl));
    3431              : }
    3432              : 
    3433              : /* Overload for the above taking constexpr_call*.  */
    3434              : 
    3435              : static inline bool
    3436       246230 : is_std_allocator_allocate (const constexpr_call *call)
    3437              : {
    3438       246230 :   return (call
    3439       154727 :           && call->fundef
    3440       400957 :           && is_std_allocator_allocate (call->fundef->decl));
    3441              : }
    3442              : 
    3443              : /* Return true if FNDECL is std::source_location::current.  */
    3444              : 
    3445              : static inline bool
    3446        33905 : is_std_source_location_current (tree fndecl)
    3447              : {
    3448        33905 :   if (!decl_in_std_namespace_p (fndecl))
    3449              :     return false;
    3450              : 
    3451        24801 :   tree name = DECL_NAME (fndecl);
    3452        24801 :   if (name == NULL_TREE || !id_equal (name, "current"))
    3453              :     return false;
    3454              : 
    3455          159 :   tree ctx = DECL_CONTEXT (fndecl);
    3456          159 :   if (ctx == NULL_TREE || !CLASS_TYPE_P (ctx) || !TYPE_MAIN_DECL (ctx))
    3457              :     return false;
    3458              : 
    3459          159 :   name = DECL_NAME (TYPE_MAIN_DECL (ctx));
    3460          159 :   return name && id_equal (name, "source_location");
    3461              : }
    3462              : 
    3463              : /* Overload for the above taking constexpr_call*.  */
    3464              : 
    3465              : static inline bool
    3466        42370 : is_std_source_location_current (const constexpr_call *call)
    3467              : {
    3468        42370 :   return (call
    3469        33905 :           && call->fundef
    3470        76275 :           && is_std_source_location_current (call->fundef->decl));
    3471              : }
    3472              : 
    3473              : /* Return true if FNDECL is __dynamic_cast.  */
    3474              : 
    3475              : static inline bool
    3476     26587635 : cxx_dynamic_cast_fn_p (tree fndecl)
    3477              : {
    3478     26587635 :   return (cxx_dialect >= cxx20
    3479     25068863 :           && id_equal (DECL_NAME (fndecl), "__dynamic_cast")
    3480         5361 :           && CP_DECL_CONTEXT (fndecl) == abi_node
    3481              :           /* Only consider implementation-detail __dynamic_cast calls that
    3482              :              correspond to a dynamic_cast, and ignore direct calls to
    3483              :              abi::__dynamic_cast.  */
    3484     26592996 :           && DECL_ARTIFICIAL (fndecl));
    3485              : }
    3486              : 
    3487              : /* Often, we have an expression in the form of address + offset, e.g.
    3488              :    "&_ZTV1A + 16".  Extract the object from it, i.e. "_ZTV1A".  */
    3489              : 
    3490              : static tree
    3491         4608 : extract_obj_from_addr_offset (tree expr)
    3492              : {
    3493         4608 :   if (TREE_CODE (expr) == POINTER_PLUS_EXPR)
    3494         2173 :     expr = TREE_OPERAND (expr, 0);
    3495         4608 :   STRIP_NOPS (expr);
    3496         4608 :   if (TREE_CODE (expr) == ADDR_EXPR)
    3497         4597 :     expr = TREE_OPERAND (expr, 0);
    3498         4608 :   return expr;
    3499              : }
    3500              : 
    3501              : /* Given a PATH like
    3502              : 
    3503              :      g.D.2181.D.2154.D.2102.D.2093
    3504              : 
    3505              :    find a component with type TYPE.  Return NULL_TREE if not found, and
    3506              :    error_mark_node if the component is not accessible.  If STOP is non-null,
    3507              :    this function will return NULL_TREE if STOP is found before TYPE.  */
    3508              : 
    3509              : static tree
    3510         2218 : get_component_with_type (tree path, tree type, tree stop)
    3511              : {
    3512         6416 :   while (true)
    3513              :     {
    3514         4317 :       if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (path), type))
    3515              :         /* Found it.  */
    3516              :         return path;
    3517         3148 :       else if (stop
    3518         3148 :                && (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (path),
    3519              :                                                               stop)))
    3520              :         return NULL_TREE;
    3521         3103 :       else if (TREE_CODE (path) == COMPONENT_REF
    3522         3103 :                && DECL_FIELD_IS_BASE (TREE_OPERAND (path, 1)))
    3523              :         {
    3524              :           /* We need to check that the component we're accessing is in fact
    3525              :              accessible.  */
    3526         3103 :           if (TREE_PRIVATE (TREE_OPERAND (path, 1))
    3527         3103 :               || TREE_PROTECTED (TREE_OPERAND (path, 1)))
    3528         1004 :             return error_mark_node;
    3529         2099 :           path = TREE_OPERAND (path, 0);
    3530              :         }
    3531              :       else
    3532              :         return NULL_TREE;
    3533              :     }
    3534              : }
    3535              : 
    3536              : /* Evaluate a call to __dynamic_cast (permitted by P1327R1).
    3537              : 
    3538              :    The declaration of __dynamic_cast is:
    3539              : 
    3540              :    void* __dynamic_cast (const void* __src_ptr,
    3541              :                          const __class_type_info* __src_type,
    3542              :                          const __class_type_info* __dst_type,
    3543              :                          ptrdiff_t __src2dst);
    3544              : 
    3545              :    where src2dst has the following possible values
    3546              : 
    3547              :    >-1: src_type is a unique public non-virtual base of dst_type
    3548              :         dst_ptr + src2dst == src_ptr
    3549              :    -1: unspecified relationship
    3550              :    -2: src_type is not a public base of dst_type
    3551              :    -3: src_type is a multiple public non-virtual base of dst_type  */
    3552              : 
    3553              : static tree
    3554         2554 : cxx_eval_dynamic_cast_fn (const constexpr_ctx *ctx, tree call,
    3555              :                           bool *non_constant_p, bool *overflow_p,
    3556              :                           tree *jump_target)
    3557              : {
    3558              :   /* T will be something like
    3559              :       __dynamic_cast ((B*) b, &_ZTI1B, &_ZTI1D, 8)
    3560              :      dismantle it.  */
    3561         2554 :   gcc_assert (call_expr_nargs (call) == 4);
    3562         2554 :   tsubst_flags_t complain = ctx->quiet ? tf_none : tf_warning_or_error;
    3563         2554 :   tree obj = CALL_EXPR_ARG (call, 0);
    3564         2554 :   tree type = CALL_EXPR_ARG (call, 2);
    3565         2554 :   HOST_WIDE_INT hint = int_cst_value (CALL_EXPR_ARG (call, 3));
    3566         2554 :   location_t loc = cp_expr_loc_or_input_loc (call);
    3567              : 
    3568              :   /* Get the target type of the dynamic_cast.  */
    3569         2554 :   gcc_assert (TREE_CODE (type) == ADDR_EXPR);
    3570         2554 :   type = TREE_OPERAND (type, 0);
    3571         2554 :   type = TREE_TYPE (DECL_NAME (type));
    3572              : 
    3573              :   /* TYPE can only be either T* or T&.  We can't know which of these it
    3574              :      is by looking at TYPE, but OBJ will be "(T*) x" in the first case,
    3575              :      and something like "(T*)(T&)(T*) x" in the second case.
    3576              :      This is true for the reference cases in C++ < 26 or when exceptions
    3577              :      aren't enabled, in that case we should diagnose errors.  For C++26
    3578              :      with exceptions we should silently evaluate to null pointer and
    3579              :      let the callers call __cxa_bad_cast () later to throw an exception.  */
    3580         2554 :   bool fail_for_non_constant_p = false;
    3581        11597 :   while (CONVERT_EXPR_P (obj) || TREE_CODE (obj) == SAVE_EXPR)
    3582              :     {
    3583         9043 :       if (cxx_dialect < cxx26 || !flag_exceptions)
    3584         5557 :         fail_for_non_constant_p |= TYPE_REF_P (TREE_TYPE (obj));
    3585         9043 :       obj = TREE_OPERAND (obj, 0);
    3586              :     }
    3587              : 
    3588              :   /* Evaluate the object so that we know its dynamic type.  */
    3589         2554 :   obj = cxx_eval_constant_expression (ctx, obj, vc_prvalue, non_constant_p,
    3590              :                                       overflow_p, jump_target);
    3591         2554 :   if (*non_constant_p)
    3592              :     return call;
    3593         2435 :   if (*jump_target)
    3594              :     return NULL_TREE;
    3595              : 
    3596              :   /* For dynamic_cast from classes with virtual bases we can get something
    3597              :      like (virt_base *)(&d + 16) as OBJ.  Try to convert that into
    3598              :      d.D.1234 using cxx_fold_indirect_ref.  */
    3599         2435 :   if (cxx_dialect >= cxx26 && CONVERT_EXPR_P (obj))
    3600              :     {
    3601          607 :       tree objo = obj;
    3602          607 :       STRIP_NOPS (objo);
    3603          607 :       if (TREE_CODE (objo) == POINTER_PLUS_EXPR)
    3604              :         {
    3605          576 :           objo = cxx_fold_indirect_ref (ctx, loc, TREE_TYPE (TREE_TYPE (obj)),
    3606              :                                         obj, NULL, jump_target);
    3607          576 :           if (objo)
    3608          576 :             obj = build_fold_addr_expr (objo);
    3609              :         }
    3610              :     }
    3611              : 
    3612              :   /* We expect OBJ to be in form of &d.D.2102 when HINT == 0,
    3613              :      but when HINT is > 0, it can also be something like
    3614              :      &d.D.2102 + 18446744073709551608, which includes the BINFO_OFFSET.  */
    3615         2435 :   obj = extract_obj_from_addr_offset (obj);
    3616         2435 :   const tree objtype = TREE_TYPE (obj);
    3617              :   /* If OBJ doesn't refer to a base field, we're done.  */
    3618         4797 :   if (tree t = (TREE_CODE (obj) == COMPONENT_REF
    3619         2435 :                 ? TREE_OPERAND (obj, 1) : obj))
    3620         2435 :     if (TREE_CODE (t) != FIELD_DECL || !DECL_FIELD_IS_BASE (t))
    3621              :       {
    3622           73 :         if (fail_for_non_constant_p)
    3623              :           {
    3624           55 :             if (!ctx->quiet)
    3625              :               {
    3626            2 :                 auto_diagnostic_group d;
    3627            2 :                 error_at (loc, "reference %<dynamic_cast%> failed");
    3628            2 :                 inform (loc, "dynamic type %qT of its operand does "
    3629              :                         "not have a base class of type %qT",
    3630              :                         objtype, type);
    3631            2 :               }
    3632           55 :             *non_constant_p = true;
    3633              :           }
    3634           73 :         return integer_zero_node;
    3635              :       }
    3636              : 
    3637              :   /* [class.cdtor] When a dynamic_cast is used in a constructor ...
    3638              :      or in a destructor ... if the operand of the dynamic_cast refers
    3639              :      to the object under construction or destruction, this object is
    3640              :      considered to be a most derived object that has the type of the
    3641              :      constructor or destructor's class.  */
    3642         2362 :   tree vtable = build_vfield_ref (obj, objtype);
    3643         2362 :   vtable = cxx_eval_constant_expression (ctx, vtable, vc_prvalue,
    3644              :                                          non_constant_p, overflow_p,
    3645              :                                          jump_target);
    3646         2362 :   if (*non_constant_p)
    3647              :     return call;
    3648         2185 :   if (*jump_target)
    3649              :     return NULL_TREE;
    3650              :   /* With -fsanitize=vptr, we initialize all vtable pointers to null,
    3651              :      so it's possible that we got a null pointer now.  */
    3652         2185 :   if (integer_zerop (vtable))
    3653              :     {
    3654           12 :       if (!ctx->quiet)
    3655            3 :         error_at (loc, "virtual table pointer is used uninitialized");
    3656           12 :       *non_constant_p = true;
    3657           12 :       return integer_zero_node;
    3658              :     }
    3659              :   /* VTABLE will be &_ZTV1A + 16 or similar, get _ZTV1A.  */
    3660         2173 :   vtable = extract_obj_from_addr_offset (vtable);
    3661         2173 :   const tree mdtype = DECL_CONTEXT (vtable);
    3662              : 
    3663              :   /* Given dynamic_cast<T>(v),
    3664              : 
    3665              :      [expr.dynamic.cast] If C is the class type to which T points or refers,
    3666              :      the runtime check logically executes as follows:
    3667              : 
    3668              :      If, in the most derived object pointed (referred) to by v, v points
    3669              :      (refers) to a public base class subobject of a C object, and if only
    3670              :      one object of type C is derived from the subobject pointed (referred)
    3671              :      to by v the result points (refers) to that C object.
    3672              : 
    3673              :      In this case, HINT >= 0 or -3.  */
    3674         2173 :   if (hint >= 0 || hint == -3)
    3675              :     {
    3676              :       /* Look for a component with type TYPE.  */
    3677          664 :       tree t = get_component_with_type (obj, type, mdtype);
    3678              :       /* If not accessible, give an error.  */
    3679          664 :       if (t == error_mark_node)
    3680              :         {
    3681          198 :           if (fail_for_non_constant_p)
    3682              :             {
    3683          108 :               if (!ctx->quiet)
    3684              :                 {
    3685           12 :                   auto_diagnostic_group d;
    3686           12 :                   error_at (loc, "reference %<dynamic_cast%> failed");
    3687           12 :                   inform (loc, "static type %qT of its operand is a "
    3688              :                           "non-public base class of dynamic type %qT",
    3689              :                           objtype, type);
    3690              : 
    3691           12 :                 }
    3692          108 :               *non_constant_p = true;
    3693              :             }
    3694          198 :           return integer_zero_node;
    3695              :         }
    3696          466 :       else if (t)
    3697              :         /* The result points to the TYPE object.  */
    3698          421 :         return cp_build_addr_expr (t, complain);
    3699              :       /* Else, TYPE was not found, because the HINT turned out to be wrong.
    3700              :          Fall through to the normal processing.  */
    3701              :     }
    3702              : 
    3703              :   /* Otherwise, if v points (refers) to a public base class subobject of the
    3704              :      most derived object, and the type of the most derived object has a base
    3705              :      class, of type C, that is unambiguous and public, the result points
    3706              :      (refers) to the C subobject of the most derived object.
    3707              : 
    3708              :      But it can also be an invalid case.  */
    3709              : 
    3710              :   /* Get the most derived object.  */
    3711         1554 :   obj = get_component_with_type (obj, mdtype, NULL_TREE);
    3712         1554 :   if (obj == error_mark_node)
    3713              :     {
    3714          806 :       if (fail_for_non_constant_p)
    3715              :         {
    3716          350 :           if (!ctx->quiet)
    3717              :             {
    3718           38 :               auto_diagnostic_group d;
    3719           38 :               error_at (loc, "reference %<dynamic_cast%> failed");
    3720           38 :               inform (loc, "static type %qT of its operand is a non-public"
    3721              :                       " base class of dynamic type %qT", objtype, mdtype);
    3722           38 :             }
    3723          350 :           *non_constant_p = true;
    3724              :         }
    3725          806 :       return integer_zero_node;
    3726              :     }
    3727              :   else
    3728          748 :     gcc_assert (obj);
    3729              : 
    3730              :   /* Check that the type of the most derived object has a base class
    3731              :      of type TYPE that is unambiguous and public.  */
    3732          748 :   base_kind b_kind;
    3733          748 :   tree binfo = lookup_base (mdtype, type, ba_check, &b_kind, tf_none);
    3734          748 :   if (!binfo || binfo == error_mark_node)
    3735              :     {
    3736          339 :       if (fail_for_non_constant_p)
    3737              :         {
    3738          134 :           if (!ctx->quiet)
    3739              :             {
    3740           16 :               auto_diagnostic_group d;
    3741           16 :               error_at (loc, "reference %<dynamic_cast%> failed");
    3742           16 :               if (b_kind == bk_ambig)
    3743            6 :                 inform (loc, "%qT is an ambiguous base class of dynamic "
    3744              :                         "type %qT of its operand", type, mdtype);
    3745              :               else
    3746           10 :                 inform (loc, "dynamic type %qT of its operand does not "
    3747              :                         "have an unambiguous public base class %qT",
    3748              :                         mdtype, type);
    3749           16 :             }
    3750          134 :           *non_constant_p = true;
    3751              :         }
    3752          339 :       return integer_zero_node;
    3753              :     }
    3754              :   /* If so, return the TYPE subobject of the most derived object.  */
    3755          409 :   obj = convert_to_base_statically (obj, binfo);
    3756          409 :   return cp_build_addr_expr (obj, complain);
    3757              : }
    3758              : 
    3759              : /* Data structure used by replace_decl and replace_decl_r.  */
    3760              : 
    3761              : struct replace_decl_data
    3762              : {
    3763              :   /* The _DECL we want to replace.  */
    3764              :   tree decl;
    3765              :   /* The replacement for DECL.  */
    3766              :   tree replacement;
    3767              :   /* Trees we've visited.  */
    3768              :   hash_set<tree> *pset;
    3769              :   /* Whether we've performed any replacements.  */
    3770              :   bool changed;
    3771              : };
    3772              : 
    3773              : /* Helper function for replace_decl, called through cp_walk_tree.  */
    3774              : 
    3775              : static tree
    3776      9943153 : replace_decl_r (tree *tp, int *walk_subtrees, void *data)
    3777              : {
    3778      9943153 :   replace_decl_data *d = (replace_decl_data *) data;
    3779              : 
    3780              :   /* We could be replacing
    3781              :        &<retval>.bar -> &foo.bar
    3782              :      where foo is a static VAR_DECL, so we need to recompute TREE_CONSTANT
    3783              :      on the ADDR_EXPR around it.  */
    3784      9943153 :   if (TREE_CODE (*tp) == ADDR_EXPR)
    3785              :     {
    3786       788357 :       d->pset->add (*tp);
    3787       788357 :       auto save_changed = d->changed;
    3788       788357 :       d->changed = false;
    3789       788357 :       cp_walk_tree (&TREE_OPERAND (*tp, 0), replace_decl_r, d, nullptr);
    3790       788357 :       if (d->changed)
    3791              :         {
    3792          290 :           cxx_mark_addressable (*tp);
    3793          290 :           recompute_tree_invariant_for_addr_expr (*tp);
    3794              :         }
    3795              :       else
    3796       788067 :         d->changed = save_changed;
    3797       788357 :       *walk_subtrees = 0;
    3798              :     }
    3799      9154796 :   else if (*tp == d->decl)
    3800              :     {
    3801          513 :       *tp = unshare_expr (d->replacement);
    3802          513 :       d->changed = true;
    3803          513 :       *walk_subtrees = 0;
    3804              :     }
    3805      9154283 :   else if (TYPE_P (*tp)
    3806      9154283 :            || d->pset->add (*tp))
    3807      2354525 :     *walk_subtrees = 0;
    3808              : 
    3809      9943153 :   return NULL_TREE;
    3810              : }
    3811              : 
    3812              : /* Replace every occurrence of DECL with (an unshared copy of)
    3813              :    REPLACEMENT within the expression *TP.  Returns true iff a
    3814              :    replacement was performed.  */
    3815              : 
    3816              : bool
    3817      1269919 : replace_decl (tree *tp, tree decl, tree replacement)
    3818              : {
    3819      1269919 :   gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p
    3820              :                        (TREE_TYPE (decl), TREE_TYPE (replacement)));
    3821      1269919 :   hash_set<tree> pset;
    3822      1269919 :   replace_decl_data data = { decl, replacement, &pset, false };
    3823      1269919 :   cp_walk_tree (tp, replace_decl_r, &data, NULL);
    3824      1269919 :   return data.changed;
    3825      1269919 : }
    3826              : 
    3827              : /* Evaluate the call T to virtual function thunk THUNK_FNDECL.  */
    3828              : 
    3829              : static tree
    3830           30 : cxx_eval_thunk_call (const constexpr_ctx *ctx, tree t, tree thunk_fndecl,
    3831              :                      value_cat lval,
    3832              :                      bool *non_constant_p, bool *overflow_p, tree *jump_target)
    3833              : {
    3834           30 :   tree function = THUNK_TARGET (thunk_fndecl);
    3835              : 
    3836           30 :   if (THUNK_VIRTUAL_OFFSET (thunk_fndecl))
    3837              :     {
    3838           13 :       if (!ctx->quiet)
    3839              :         {
    3840            3 :           if (!DECL_DECLARED_CONSTEXPR_P (function))
    3841              :             {
    3842            0 :               error ("call to non-%<constexpr%> function %qD", function);
    3843            0 :               explain_invalid_constexpr_fn (function);
    3844              :             }
    3845              :           else
    3846              :             /* virtual_offset is only set for virtual bases, which make the
    3847              :                class non-literal, so we don't need to handle it here.  */
    3848            3 :             error ("calling constexpr member function %qD through virtual "
    3849              :                    "base subobject", function);
    3850              :         }
    3851           13 :       *non_constant_p = true;
    3852           13 :       return t;
    3853              :     }
    3854              : 
    3855           17 :   tree new_call = copy_node (t);
    3856           17 :   CALL_EXPR_FN (new_call) = function;
    3857           17 :   TREE_TYPE (new_call) = TREE_TYPE (TREE_TYPE (function));
    3858              : 
    3859           17 :   tree offset = size_int (THUNK_FIXED_OFFSET (thunk_fndecl));
    3860              : 
    3861           17 :   if (DECL_THIS_THUNK_P (thunk_fndecl))
    3862              :     {
    3863              :       /* 'this'-adjusting thunk.  */
    3864           11 :       tree this_arg = CALL_EXPR_ARG (t, 0);
    3865           11 :       this_arg = build2 (POINTER_PLUS_EXPR, TREE_TYPE (this_arg),
    3866              :                          this_arg, offset);
    3867           11 :       CALL_EXPR_ARG (new_call, 0) = this_arg;
    3868              :     }
    3869              :   else
    3870              :     /* Return-adjusting thunk.  */
    3871            6 :     new_call = build2 (POINTER_PLUS_EXPR, TREE_TYPE (new_call),
    3872              :                        new_call, offset);
    3873              : 
    3874           17 :   return cxx_eval_constant_expression (ctx, new_call, lval,
    3875              :                                        non_constant_p, overflow_p,
    3876           17 :                                        jump_target);
    3877              : }
    3878              : 
    3879              : /* If OBJECT is of const class type, evaluate it to a CONSTRUCTOR and set
    3880              :    its TREE_READONLY flag according to READONLY_P.  Used for constexpr
    3881              :    'tors to detect modifying const objects in a constexpr context.  */
    3882              : 
    3883              : static void
    3884      7863344 : cxx_set_object_constness (const constexpr_ctx *ctx, tree object,
    3885              :                           bool readonly_p, bool *non_constant_p,
    3886              :                           bool *overflow_p, tree *jump_target)
    3887              : {
    3888     15726688 :   if (CLASS_TYPE_P (TREE_TYPE (object))
    3889     15726688 :       && CP_TYPE_CONST_P (TREE_TYPE (object)))
    3890              :     {
    3891              :       /* Subobjects might not be stored in ctx->global->values but we
    3892              :          can get its CONSTRUCTOR by evaluating *this.  */
    3893       961267 :       tree e = cxx_eval_constant_expression (ctx, object, vc_prvalue,
    3894              :                                              non_constant_p, overflow_p,
    3895              :                                              jump_target);
    3896       961267 :       if (!*non_constant_p
    3897      8789355 :           && !throws (jump_target)
    3898      1887278 :           && TREE_CODE (e) == CONSTRUCTOR)
    3899       926011 :         TREE_READONLY (e) = readonly_p;
    3900              :     }
    3901      7863344 : }
    3902              : 
    3903              : /* Allocate an exception for OBJECT and throw it.  */
    3904              : 
    3905              : tree
    3906         1576 : cxa_allocate_and_throw_exception (location_t loc, const constexpr_ctx *ctx,
    3907              :                                   tree object)
    3908              : {
    3909         1576 :   tree type = TREE_TYPE (object);
    3910              :   /* This simulates a call to __cxa_allocate_exception.  We need
    3911              :      (struct exception *) &heap -- memory on the heap so that
    3912              :      it can survive the stack being unwound.  */
    3913         1576 :   tree arr = build_array_of_n_type (type, 1);
    3914         1576 :   tree var = cxa_allocate_exception (loc, ctx, arr, size_zero_node);
    3915         1576 :   DECL_NAME (var) = heap_identifier;
    3916         1576 :   ctx->global->put_value (var, NULL_TREE);
    3917              : 
    3918              :   /* *(struct exception *) &heap  = exc{ ... }  */
    3919         1576 :   tree ptr = build_nop (build_pointer_type (type), build_address (var));
    3920         1576 :   object = cp_build_init_expr (cp_build_fold_indirect_ref (ptr), object);
    3921         1576 :   bool non_constant_p = false, overflow_p = false;
    3922         1576 :   tree jump_target = NULL_TREE;
    3923         1576 :   cxx_eval_constant_expression (ctx, object, vc_prvalue, &non_constant_p,
    3924              :                                 &overflow_p, &jump_target);
    3925         1576 :   if (non_constant_p)
    3926              :     {
    3927            0 :       if (!ctx->quiet)
    3928            0 :         error_at (loc, "couldn%'t throw %qT", type);
    3929            0 :       return NULL_TREE;
    3930              :     }
    3931              : 
    3932              :   /* Now we can __cxa_throw.  */
    3933         1576 :   DECL_EXCEPTION_REFCOUNT (var)
    3934         1576 :     = size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (var), size_one_node);
    3935         1576 :   ++ctx->global->uncaught_exceptions;
    3936              : 
    3937         1576 :   return var;
    3938              : }
    3939              : 
    3940              : /* Subroutine of cxx_eval_constant_expression.
    3941              :    Evaluate the call expression tree T in the context of OLD_CALL expression
    3942              :    evaluation.  */
    3943              : 
    3944              : static tree
    3945    138424437 : cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
    3946              :                           value_cat lval,
    3947              :                           bool *non_constant_p, bool *overflow_p,
    3948              :                           tree *jump_target)
    3949              : {
    3950    138424437 :   location_t loc = cp_expr_loc_or_input_loc (t);
    3951    138424437 :   tree fun = get_function_named_in_call (t);
    3952              : 
    3953    138424437 :   if (fun == NULL_TREE)
    3954       370398 :     return cxx_eval_internal_function (ctx, t, lval,
    3955              :                                        non_constant_p, overflow_p,
    3956       370398 :                                        jump_target);
    3957              : 
    3958    138054039 :   if (TREE_CODE (fun) != FUNCTION_DECL)
    3959              :     {
    3960              :       /* Might be a constexpr function pointer.  */
    3961       217264 :       fun = cxx_eval_constant_expression (ctx, fun, vc_prvalue,
    3962              :                                           non_constant_p, overflow_p,
    3963              :                                           jump_target);
    3964       217264 :       if (*jump_target)
    3965              :         return NULL_TREE;
    3966       217264 :       STRIP_NOPS (fun);
    3967       217264 :       if (TREE_CODE (fun) == ADDR_EXPR)
    3968        20713 :         fun = TREE_OPERAND (fun, 0);
    3969              :       /* For TARGET_VTABLE_USES_DESCRIPTORS targets, there is no
    3970              :          indirection, the called expression is a pointer into the
    3971              :          virtual table which should contain FDESC_EXPR.  Extract the
    3972              :          FUNCTION_DECL from there.  */
    3973              :       else if (TARGET_VTABLE_USES_DESCRIPTORS
    3974              :                && TREE_CODE (fun) == POINTER_PLUS_EXPR
    3975              :                && TREE_CODE (TREE_OPERAND (fun, 0)) == ADDR_EXPR
    3976              :                && TREE_CODE (TREE_OPERAND (fun, 1)) == INTEGER_CST)
    3977              :         {
    3978              :           tree d = TREE_OPERAND (TREE_OPERAND (fun, 0), 0);
    3979              :           if (VAR_P (d)
    3980              :               && DECL_VTABLE_OR_VTT_P (d)
    3981              :               && TREE_CODE (TREE_TYPE (d)) == ARRAY_TYPE
    3982              :               && TREE_TYPE (TREE_TYPE (d)) == vtable_entry_type
    3983              :               && DECL_INITIAL (d)
    3984              :               && TREE_CODE (DECL_INITIAL (d)) == CONSTRUCTOR)
    3985              :             {
    3986              :               tree i = int_const_binop (TRUNC_DIV_EXPR, TREE_OPERAND (fun, 1),
    3987              :                                         TYPE_SIZE_UNIT (vtable_entry_type));
    3988              :               HOST_WIDE_INT idx = find_array_ctor_elt (DECL_INITIAL (d), i);
    3989              :               if (idx >= 0)
    3990              :                 {
    3991              :                   tree fdesc
    3992              :                     = (*CONSTRUCTOR_ELTS (DECL_INITIAL (d)))[idx].value;
    3993              :                   if (TREE_CODE (fdesc) == FDESC_EXPR
    3994              :                       && integer_zerop (TREE_OPERAND (fdesc, 1)))
    3995              :                     fun = TREE_OPERAND (fdesc, 0);
    3996              :                 }
    3997              :             }
    3998              :         }
    3999              :     }
    4000    138054039 :   if (TREE_CODE (fun) != FUNCTION_DECL)
    4001              :     {
    4002       196551 :       if (!ctx->quiet && !*non_constant_p)
    4003            0 :         error_at (loc, "expression %qE does not designate a %<constexpr%> "
    4004              :                   "function", fun);
    4005       196551 :       *non_constant_p = true;
    4006       196551 :       return t;
    4007              :     }
    4008    137857488 :   tree orig_fun = fun;
    4009    137857488 :   if (DECL_CLONED_FUNCTION_P (fun) && !DECL_DELETING_DESTRUCTOR_P (fun))
    4010     17734564 :     fun = DECL_CLONED_FUNCTION (fun);
    4011              : 
    4012    137857488 :   if (is_ubsan_builtin_p (fun))
    4013           58 :     return void_node;
    4014              : 
    4015    137857430 :   if (fndecl_built_in_p (fun))
    4016     14136090 :     return cxx_eval_builtin_function_call (ctx, t, fun,
    4017              :                                            lval, non_constant_p, overflow_p,
    4018     14136089 :                                            jump_target);
    4019    123721340 :   if (DECL_THUNK_P (fun))
    4020           30 :     return cxx_eval_thunk_call (ctx, t, fun, lval, non_constant_p, overflow_p,
    4021           30 :                                 jump_target);
    4022    123721310 :   if (metafunction_p (fun))
    4023              :     {
    4024              :       /* To be able to evaluate a metafunction, we may have to instantiate
    4025              :          constexpr functions.  If we're not allowed to instantiate, leave
    4026              :          this for later.  Don't evaluate metafunctions at all when mce_unknown,
    4027              :          otherwise we might fold those prematurely.  See
    4028              :          g++.dg/reflect/p2996-17.C.  */
    4029        37583 :       if (uid_sensitive_constexpr_evaluation_p ()
    4030        37303 :           || ctx->manifestly_const_eval == mce_unknown)
    4031              :         {
    4032        10080 :           *non_constant_p = true;
    4033        10080 :           return t;
    4034              :         }
    4035        27503 :       ctx->global->metafns_called = true;
    4036        27503 :       tree e = process_metafunction (ctx, fun, t, non_constant_p, overflow_p,
    4037              :                                      jump_target);
    4038        27503 :       if (*jump_target)
    4039              :         return NULL_TREE;
    4040        25921 :       if (*non_constant_p)
    4041              :         return t;
    4042        25772 :       e = cxx_eval_constant_expression (ctx, e, vc_prvalue,
    4043              :                                         non_constant_p, overflow_p,
    4044              :                                         jump_target);
    4045        25772 :       if (*jump_target)
    4046              :         return NULL_TREE;
    4047        25772 :       if (*non_constant_p)
    4048              :         return t;
    4049              :       return e;
    4050              :     }
    4051    123683727 :   bool non_constexpr_call = false;
    4052    123683727 :   if (!maybe_constexpr_fn (fun))
    4053              :     {
    4054       595245 :       if (TREE_CODE (t) == CALL_EXPR
    4055       592032 :           && cxx_replaceable_global_alloc_fn (fun)
    4056       972541 :           && (CALL_FROM_NEW_OR_DELETE_P (t)
    4057       163176 :               || is_std_allocator_allocate (ctx->call)))
    4058              :         {
    4059       294258 :           const bool new_op_p = IDENTIFIER_NEW_OP_P (DECL_NAME (fun));
    4060       294258 :           const int nargs = call_expr_nargs (t);
    4061       294258 :           tree arg0 = NULL_TREE;
    4062       487394 :           for (int i = 0; i < nargs; ++i)
    4063              :             {
    4064       295014 :               tree arg = CALL_EXPR_ARG (t, i);
    4065       295014 :               arg = cxx_eval_constant_expression (ctx, arg, vc_prvalue,
    4066              :                                                   non_constant_p, overflow_p,
    4067              :                                                   jump_target);
    4068       295014 :               if (*jump_target)
    4069              :                 return NULL_TREE;
    4070              :               /* Deleting a non-constant pointer has a better error message
    4071              :                  below.  */
    4072       295006 :               if (new_op_p || i != 0)
    4073       254796 :                 VERIFY_CONSTANT (arg);
    4074       152926 :               if (i == 0)
    4075              :                 arg0 = arg;
    4076              :             }
    4077       192380 :           gcc_assert (arg0);
    4078       192380 :           if (new_op_p)
    4079              :             {
    4080       152170 :               if (!tree_fits_uhwi_p (arg0))
    4081              :                 {
    4082              :                   /* We should not get here; the VERIFY_CONSTANT above
    4083              :                      should have already caught it.  */
    4084            0 :                   gcc_checking_assert (false);
    4085              :                   if (!ctx->quiet)
    4086              :                     error_at (loc, "cannot allocate array: size not constant");
    4087              :                   *non_constant_p = true;
    4088              :                   return t;
    4089              :                 }
    4090       304340 :               tree type = build_array_type_nelts (char_type_node,
    4091       152170 :                                                   tree_to_uhwi (arg0));
    4092       152170 :               tree var = build_decl (loc, VAR_DECL,
    4093       152170 :                                      (IDENTIFIER_OVL_OP_FLAGS (DECL_NAME (fun))
    4094              :                                       & OVL_OP_FLAG_VEC)
    4095              :                                      ? heap_vec_uninit_identifier
    4096              :                                      : heap_uninit_identifier,
    4097       152170 :                                      type);
    4098       152170 :               DECL_ARTIFICIAL (var) = 1;
    4099       152170 :               ctx->global->heap_vars.safe_push (var);
    4100       152170 :               ctx->global->put_value (var, NULL_TREE);
    4101       152170 :               return fold_convert (ptr_type_node, build_address (var));
    4102              :             }
    4103              :           else
    4104              :             {
    4105        40210 :               STRIP_NOPS (arg0);
    4106        40210 :               if (TREE_CODE (arg0) == ADDR_EXPR
    4107        40210 :                   && VAR_P (TREE_OPERAND (arg0, 0)))
    4108              :                 {
    4109        40210 :                   tree var = TREE_OPERAND (arg0, 0);
    4110        40210 :                   if (DECL_NAME (var) == heap_uninit_identifier
    4111        40210 :                       || DECL_NAME (var) == heap_identifier)
    4112              :                     {
    4113        40038 :                       if (IDENTIFIER_OVL_OP_FLAGS (DECL_NAME (fun))
    4114              :                           & OVL_OP_FLAG_VEC)
    4115              :                         {
    4116            9 :                           if (!ctx->quiet)
    4117              :                             {
    4118            3 :                               auto_diagnostic_group d;
    4119            3 :                               error_at (loc, "array deallocation of object "
    4120              :                                              "allocated with non-array "
    4121              :                                              "allocation");
    4122            3 :                               inform (DECL_SOURCE_LOCATION (var),
    4123              :                                       "allocation performed here");
    4124            3 :                             }
    4125            9 :                           *non_constant_p = true;
    4126            9 :                           return t;
    4127              :                         }
    4128        40029 :                       DECL_NAME (var) = heap_deleted_identifier;
    4129        40029 :                       ctx->global->destroy_value (var);
    4130        40029 :                       ctx->global->heap_dealloc_count++;
    4131        40029 :                       return void_node;
    4132              :                     }
    4133          172 :                   else if (DECL_NAME (var) == heap_vec_uninit_identifier
    4134          172 :                            || DECL_NAME (var) == heap_vec_identifier)
    4135              :                     {
    4136          148 :                       if ((IDENTIFIER_OVL_OP_FLAGS (DECL_NAME (fun))
    4137              :                            & OVL_OP_FLAG_VEC) == 0)
    4138              :                         {
    4139            9 :                           if (!ctx->quiet)
    4140              :                             {
    4141            3 :                               auto_diagnostic_group d;
    4142            3 :                               error_at (loc, "non-array deallocation of "
    4143              :                                              "object allocated with array "
    4144              :                                              "allocation");
    4145            3 :                               inform (DECL_SOURCE_LOCATION (var),
    4146              :                                       "allocation performed here");
    4147            3 :                             }
    4148            9 :                           *non_constant_p = true;
    4149            9 :                           return t;
    4150              :                         }
    4151          139 :                       DECL_NAME (var) = heap_deleted_identifier;
    4152          139 :                       ctx->global->destroy_value (var);
    4153          139 :                       ctx->global->heap_dealloc_count++;
    4154          139 :                       return void_node;
    4155              :                     }
    4156           24 :                   else if (DECL_NAME (var) == heap_deleted_identifier)
    4157              :                     {
    4158           15 :                       if (!ctx->quiet)
    4159            6 :                         error_at (loc, "deallocation of already deallocated "
    4160              :                                        "storage");
    4161           15 :                       *non_constant_p = true;
    4162           15 :                       return t;
    4163              :                     }
    4164              :                 }
    4165            9 :               if (!ctx->quiet)
    4166            3 :                 error_at (loc, "deallocation of storage that was "
    4167              :                                "not previously allocated");
    4168            9 :               *non_constant_p = true;
    4169            9 :               return t;
    4170              :             }
    4171              :         }
    4172              :       /* Allow placement new in std::construct_at, just return the second
    4173              :          argument.  */
    4174       300987 :       if (TREE_CODE (t) == CALL_EXPR
    4175       297774 :           && cxx_placement_new_fn (fun)
    4176       464788 :           && is_std_construct_at (ctx->call))
    4177              :         {
    4178        30975 :           const int nargs = call_expr_nargs (t);
    4179        30975 :           tree arg1 = NULL_TREE;
    4180        92925 :           for (int i = 0; i < nargs; ++i)
    4181              :             {
    4182        61950 :               tree arg = CALL_EXPR_ARG (t, i);
    4183        61950 :               arg = cxx_eval_constant_expression (ctx, arg, vc_prvalue,
    4184              :                                                   non_constant_p, overflow_p,
    4185              :                                                   jump_target);
    4186        61950 :               if (*jump_target)
    4187              :                 return NULL_TREE;
    4188        61950 :               if (i == 1)
    4189              :                 arg1 = arg;
    4190              :               else
    4191        61950 :                 VERIFY_CONSTANT (arg);
    4192              :             }
    4193        30975 :           gcc_assert (arg1);
    4194              :           return arg1;
    4195              :         }
    4196       270012 :       else if (cxx_dynamic_cast_fn_p (fun))
    4197         2554 :         return cxx_eval_dynamic_cast_fn (ctx, t, non_constant_p, overflow_p,
    4198         2554 :                                          jump_target);
    4199       267458 :       else if (enum cxa_builtin kind = cxx_cxa_builtin_fn_p (fun))
    4200        14410 :         return cxx_eval_cxa_builtin_fn (ctx, t, kind, fun,
    4201              :                                         non_constant_p, overflow_p,
    4202        14410 :                                         jump_target);
    4203              : 
    4204              :       /* Calls to non-constexpr functions can be diagnosed right away
    4205              :          before C++26, though in C++26 evaluation of the arguments might
    4206              :          throw and if caught it could be still constant expression.
    4207              :          So for C++26 this is diagnosed only after
    4208              :          cxx_bind_parameters_in_call.  */
    4209       253048 :       if (cxx_dialect >= cxx26)
    4210              :         non_constexpr_call = true;
    4211              :       else
    4212              :         {
    4213       213893 :           if (!ctx->quiet)
    4214              :             {
    4215          193 :               if (!lambda_static_thunk_p (fun))
    4216          193 :                 error_at (loc, "call to non-%<constexpr%> function %qD", fun);
    4217          193 :               explain_invalid_constexpr_fn (fun);
    4218              :             }
    4219       213893 :           *non_constant_p = true;
    4220       213893 :           return t;
    4221              :         }
    4222              :     }
    4223              : 
    4224    123127637 :   constexpr_ctx new_ctx = *ctx;
    4225    123127637 :   ctx = &new_ctx;
    4226    140058627 :   if (DECL_CONSTRUCTOR_P (fun) && !ctx->object
    4227    125592419 :       && TREE_CODE (t) == AGGR_INIT_EXPR)
    4228              :     {
    4229              :       /* We want to have an initialization target for an AGGR_INIT_EXPR.
    4230              :          If we don't already have one in CTX, use the AGGR_INIT_EXPR_SLOT.  */
    4231         1876 :       new_ctx.object = AGGR_INIT_EXPR_SLOT (t);
    4232         1876 :       tree ctor = new_ctx.ctor = build_constructor (DECL_CONTEXT (fun), NULL);
    4233         1876 :       CONSTRUCTOR_NO_CLEARING (ctor) = true;
    4234         1876 :       ctx->global->put_value (new_ctx.object, ctor);
    4235              :     }
    4236              :   /* An immediate invocation is manifestly constant evaluated including the
    4237              :      arguments of the call, so use mce_true even for the argument
    4238              :      evaluation.  */
    4239    246255274 :   if (DECL_IMMEDIATE_FUNCTION_P (fun))
    4240      2952896 :     new_ctx.manifestly_const_eval = mce_true;
    4241              : 
    4242              :   /* We used to shortcut trivial constructor/op= here, but nowadays
    4243              :      we can only get a trivial function here with -fno-elide-constructors.  */
    4244    123127677 :   gcc_checking_assert (!trivial_fn_p (fun)
    4245              :                        || !flag_elide_constructors
    4246              :                        /* Or it's a call from maybe_thunk_body (111075).  */
    4247              :                        || (TREE_CODE (t) == CALL_EXPR ? CALL_FROM_THUNK_P (t)
    4248              :                            : AGGR_INIT_FROM_THUNK_P (t))
    4249              :                        /* We don't elide constructors when processing
    4250              :                           a noexcept-expression.  */
    4251              :                        || cp_noexcept_operand);
    4252              : 
    4253    123127637 :   bool non_constant_args = false;
    4254    123127637 :   constexpr_call new_call;
    4255    123127637 :   new_call.bindings
    4256    123127637 :     = cxx_bind_parameters_in_call (ctx, t, fun, orig_fun, non_constant_p,
    4257              :                                    overflow_p, &non_constant_args,
    4258              :                                    jump_target);
    4259              : 
    4260              :   /* We build up the bindings list before we know whether we already have this
    4261              :      call cached.  If we don't end up saving these bindings, ggc_free them when
    4262              :      this function exits.  */
    4263    123127637 :   class free_bindings
    4264              :   {
    4265              :     tree *bindings;
    4266              :   public:
    4267    123127637 :     free_bindings (tree &b): bindings (&b) { }
    4268    123127635 :     ~free_bindings () { if (bindings) ggc_free (*bindings); }
    4269      4317333 :     void preserve () { bindings = NULL; }
    4270    123127637 :   } fb (new_call.bindings);
    4271              : 
    4272    123127637 :   if (*jump_target)
    4273              :     return NULL_TREE;
    4274    123127596 :   if (*non_constant_p)
    4275              :     return t;
    4276     65503418 :   if (non_constexpr_call)
    4277              :     {
    4278         3039 :       if (!ctx->quiet)
    4279              :         {
    4280          219 :           if (!lambda_static_thunk_p (fun))
    4281          219 :             error_at (loc, "call to non-%<constexpr%> function %qD", fun);
    4282          219 :           explain_invalid_constexpr_fn (fun);
    4283              :         }
    4284         3039 :       *non_constant_p = true;
    4285         3039 :       return t;
    4286              :     }
    4287              : 
    4288              :   /* We can't defer instantiating the function any longer.  */
    4289     65500379 :   if (!DECL_INITIAL (fun)
    4290      2866744 :       && (DECL_TEMPLOID_INSTANTIATION (fun) || DECL_DEFAULTED_FN (fun))
    4291     65500379 :       && !uid_sensitive_constexpr_evaluation_p ())
    4292              :     {
    4293      2639947 :       location_t save_loc = input_location;
    4294      2639947 :       input_location = loc;
    4295      2639947 :       ++function_depth;
    4296      2639947 :       if (ctx->manifestly_const_eval == mce_true)
    4297       312698 :         FNDECL_MANIFESTLY_CONST_EVALUATED (fun) = true;
    4298      2639947 :       if (DECL_TEMPLOID_INSTANTIATION (fun))
    4299      2639940 :         instantiate_decl (fun, /*defer_ok*/false, /*expl_inst*/false);
    4300              :       else
    4301            7 :         synthesize_method (fun);
    4302      2639947 :       --function_depth;
    4303      2639947 :       input_location = save_loc;
    4304              :     }
    4305              : 
    4306              :   /* If in direct recursive call, optimize definition search.  */
    4307     65500379 :   if (ctx && ctx->call && ctx->call->fundef && ctx->call->fundef->decl == fun)
    4308        27586 :     new_call.fundef = ctx->call->fundef;
    4309              :   else
    4310              :     {
    4311     65472793 :       new_call.fundef = retrieve_constexpr_fundef (fun);
    4312     65472793 :       if (new_call.fundef == NULL || new_call.fundef->body == NULL
    4313     65005069 :           || new_call.fundef->result == error_mark_node
    4314     64989650 :           || fun == current_function_decl)
    4315              :         {
    4316       483146 :           if (!ctx->quiet)
    4317              :             {
    4318              :               /* We need to check for current_function_decl here in case we're
    4319              :                  being called during cp_fold_function, because at that point
    4320              :                  DECL_INITIAL is set properly and we have a fundef but we
    4321              :                  haven't lowered invisirefs yet (c++/70344).  */
    4322          170 :               if (DECL_INITIAL (fun) == error_mark_node
    4323          170 :                   || fun == current_function_decl)
    4324           15 :                 error_at (loc, "%qD called in a constant expression before its "
    4325              :                           "definition is complete", fun);
    4326          155 :               else if (DECL_INITIAL (fun))
    4327              :                 {
    4328              :                   /* The definition of fun was somehow unsuitable.  But pretend
    4329              :                      that lambda static thunks don't exist.  */
    4330          118 :                   if (!lambda_static_thunk_p (fun))
    4331          112 :                     error_at (loc, "%qD called in a constant expression", fun);
    4332          118 :                   explain_invalid_constexpr_fn (fun);
    4333              :                 }
    4334              :               else
    4335           37 :                 error_at (loc, "%qD used before its definition", fun);
    4336              :             }
    4337       483146 :           *non_constant_p = true;
    4338       483146 :           return t;
    4339              :         }
    4340              :     }
    4341              : 
    4342              :   /* Don't complain about problems evaluating an ill-formed function.  */
    4343     65017233 :   if (function *f = DECL_STRUCT_FUNCTION (fun))
    4344     65017233 :     if (f->language->erroneous)
    4345          597 :       new_ctx.quiet = true;
    4346              : 
    4347     65017233 :   int depth_ok = push_cx_call_context (t);
    4348              : 
    4349              :   /* Remember the object we are constructing or destructing.  */
    4350     65017233 :   tree new_obj = NULL_TREE;
    4351    130034466 :   if (DECL_CONSTRUCTOR_P (fun) || DECL_DESTRUCTOR_P (fun))
    4352              :     {
    4353              :       /* In a cdtor, it should be the first `this' argument.
    4354              :          At this point it has already been evaluated in the call
    4355              :          to cxx_bind_parameters_in_call.  */
    4356      9646762 :       new_obj = TREE_VEC_ELT (new_call.bindings, 0);
    4357      9646762 :       bool empty_base = false;
    4358      9646762 :       new_obj = cxx_fold_indirect_ref (ctx, loc, DECL_CONTEXT (fun), new_obj,
    4359              :                                        &empty_base, jump_target);
    4360      9646762 :       if (*jump_target)
    4361            0 :         return NULL_TREE;
    4362              :       /* If we're initializing an empty class, don't set constness, because
    4363              :          cxx_fold_indirect_ref will return the wrong object to set constness
    4364              :          of.  */
    4365      9646762 :       if (empty_base)
    4366              :         new_obj = NULL_TREE;
    4367      4207714 :       else if (ctx->call && ctx->call->fundef
    4368     16318530 :                && DECL_CONSTRUCTOR_P (ctx->call->fundef->decl))
    4369              :         {
    4370      2356823 :           tree cur_obj = TREE_VEC_ELT (ctx->call->bindings, 0);
    4371      2356823 :           STRIP_NOPS (cur_obj);
    4372      2356823 :           if (TREE_CODE (cur_obj) == ADDR_EXPR)
    4373      2355567 :             cur_obj = TREE_OPERAND (cur_obj, 0);
    4374      2356823 :           if (new_obj == cur_obj)
    4375              :             /* We're calling the target constructor of a delegating
    4376              :                constructor, or accessing a base subobject through a
    4377              :                NOP_EXPR as part of a call to a base constructor, so
    4378              :                there is no new (sub)object.  */
    4379      1783404 :             new_obj = NULL_TREE;
    4380              :         }
    4381              :     }
    4382              : 
    4383     65017233 :   tree result = NULL_TREE;
    4384              : 
    4385     65017233 :   constexpr_call *entry = NULL;
    4386     65017233 :   if (depth_ok && !non_constant_args && ctx->strict)
    4387              :     {
    4388     25918096 :       new_call.hash = constexpr_fundef_hasher::hash (new_call.fundef);
    4389     25918096 :       new_call.hash
    4390     25918096 :         = iterative_hash_template_arg (new_call.bindings, new_call.hash);
    4391              : 
    4392              :       /* If we have seen this call before, we are done.  */
    4393     25918096 :       maybe_initialize_constexpr_call_table ();
    4394     25918096 :       bool insert = depth_ok < constexpr_cache_depth;
    4395     25918096 :       constexpr_call **slot
    4396     31089124 :         = constexpr_call_table->find_slot (&new_call,
    4397              :                                            insert ? INSERT : NO_INSERT);
    4398     25918096 :       entry = slot ? *slot : NULL;
    4399     24828257 :       if (entry == NULL)
    4400              :         {
    4401              :           /* Only cache up to constexpr_cache_depth to limit memory use.  */
    4402      5407172 :           if (insert)
    4403              :             {
    4404              :               /* We need to keep a pointer to the entry, not just the slot, as
    4405              :                  the slot can move during evaluation of the body.  */
    4406      4317333 :               *slot = entry = ggc_alloc<constexpr_call> ();
    4407      4317333 :               *entry = new_call;
    4408      4317333 :               entry->result (ctx->manifestly_const_eval) = unknown_type_node;
    4409      4317333 :               fb.preserve ();
    4410              : 
    4411              :               /* Unshare args going into the hash table to separate them
    4412              :                  from the caller's context, for better GC and to avoid
    4413              :                  problems with verify_gimple.  */
    4414      4317333 :               tree bound = new_call.bindings;
    4415      6963011 :               for (int i = 0; i < TREE_VEC_LENGTH (bound); ++i)
    4416              :                 {
    4417      2645678 :                   tree &arg = TREE_VEC_ELT (bound, i);
    4418      2645678 :                   arg = unshare_expr_without_location (arg);
    4419              :                 }
    4420              :             }
    4421              :         }
    4422              :       /* Calls that are in progress have their result set to unknown_type_node,
    4423              :          so that we can detect circular dependencies.  Now that we only cache
    4424              :          up to constexpr_cache_depth this won't catch circular dependencies that
    4425              :          start deeper, but they'll hit the recursion or ops limit.  */
    4426     20510924 :       else if (entry->result (ctx->manifestly_const_eval) == unknown_type_node)
    4427              :         {
    4428            6 :           if (!ctx->quiet)
    4429            0 :             error ("call has circular dependency");
    4430            6 :           *non_constant_p = true;
    4431            6 :           entry->result (ctx->manifestly_const_eval) = result = error_mark_node;
    4432              :         }
    4433              :       else
    4434     20510918 :         result = entry->result (ctx->manifestly_const_eval);
    4435              :     }
    4436              : 
    4437     65017233 :   if (!depth_ok)
    4438              :     {
    4439           30 :       if (!ctx->quiet)
    4440            3 :         error ("%<constexpr%> evaluation depth exceeds maximum of %d (use "
    4441              :                "%<-fconstexpr-depth=%> to increase the maximum)",
    4442              :                max_constexpr_depth);
    4443           30 :       *non_constant_p = true;
    4444           30 :       result = error_mark_node;
    4445              :     }
    4446              :   else
    4447              :     {
    4448     65017203 :       bool cacheable = !!entry;
    4449     65017203 :       if (result && result != error_mark_node)
    4450              :         /* OK */;
    4451     49229593 :       else if (!DECL_SAVED_TREE (fun))
    4452              :         {
    4453              :           /* When at_eof >= 3, cgraph has started throwing away
    4454              :              DECL_SAVED_TREE, so fail quietly.  FIXME we get here because of
    4455              :              late code generation for VEC_INIT_EXPR, which needs to be
    4456              :              completely reconsidered.  */
    4457            0 :           gcc_assert (at_eof >= 3 && ctx->quiet);
    4458            0 :           *non_constant_p = true;
    4459              :         }
    4460     49229593 :       else if (tree copy = get_fundef_copy (new_call.fundef))
    4461              :         {
    4462     49229587 :           tree body, parms, res;
    4463     49229587 :           releasing_vec ctors;
    4464              : 
    4465              :           /* Reuse or create a new unshared copy of this function's body.  */
    4466     49229587 :           body = TREE_PURPOSE (copy);
    4467     49229587 :           parms = TREE_VALUE (copy);
    4468     49229587 :           res = TREE_TYPE (copy);
    4469              : 
    4470              :           /* Associate the bindings with the remapped parms.  */
    4471     49229587 :           tree bound = new_call.bindings;
    4472     49229587 :           tree remapped = parms;
    4473    113153076 :           for (int i = 0; i < TREE_VEC_LENGTH (bound); ++i)
    4474              :             {
    4475     63923489 :               tree arg = TREE_VEC_ELT (bound, i);
    4476     63923489 :               if (entry)
    4477              :                 {
    4478              :                   /* Unshare again so the callee doesn't change the
    4479              :                      argument values in the hash table. XXX Could we unshare
    4480              :                      lazily in cxx_eval_store_expression?  */
    4481      2806268 :                   arg = unshare_constructor (arg);
    4482      2806268 :                   if (TREE_CODE (arg) == CONSTRUCTOR)
    4483       805458 :                     vec_safe_push (ctors, arg);
    4484              :                 }
    4485     63923489 :               ctx->global->put_value (remapped, arg);
    4486     63923489 :               remapped = DECL_CHAIN (remapped);
    4487              :             }
    4488     49229587 :           if (remapped)
    4489              :             {
    4490              :               /* We shouldn't have any parms without args, but fail gracefully
    4491              :                  in error recovery.  */
    4492            6 :               gcc_checking_assert (seen_error ());
    4493            6 :               *non_constant_p = true;
    4494              :             }
    4495              :           /* Add the RESULT_DECL to the values map, too.  */
    4496     49229587 :           gcc_assert (!DECL_BY_REFERENCE (res));
    4497     49229587 :           ctx->global->put_value (res, NULL_TREE);
    4498              : 
    4499              :           /* Remember the current call we're evaluating.  */
    4500     49229587 :           constexpr_ctx call_ctx = *ctx;
    4501     49229587 :           call_ctx.call = &new_call;
    4502     49229587 :           unsigned save_heap_alloc_count = ctx->global->heap_vars.length ();
    4503     49229587 :           unsigned save_heap_dealloc_count = ctx->global->heap_dealloc_count;
    4504     49229587 :           bool save_metafns_called = ctx->global->metafns_called;
    4505              : 
    4506              :           /* Make sure we fold std::is_constant_evaluated to true in an
    4507              :              immediate function.  */
    4508     98459174 :           if (DECL_IMMEDIATE_FUNCTION_P (fun))
    4509      1910455 :             call_ctx.manifestly_const_eval = mce_true;
    4510              : 
    4511              :           /* If this is a constexpr destructor, the object's const and volatile
    4512              :              semantics are no longer in effect; see [class.dtor]p5.  */
    4513     57092931 :           if (new_obj && DECL_DESTRUCTOR_P (fun))
    4514       658950 :             cxx_set_object_constness (ctx, new_obj, /*readonly_p=*/false,
    4515              :                                       non_constant_p, overflow_p, jump_target);
    4516              : 
    4517              :           /* If this is a constructor, we are beginning the lifetime of the
    4518              :              object we are initializing.  */
    4519     49229587 :           if (new_obj
    4520     15726688 :               && DECL_CONSTRUCTOR_P (fun)
    4521      7204394 :               && TREE_CODE (new_obj) == COMPONENT_REF
    4522     51051435 :               && TREE_CODE (TREE_TYPE (TREE_OPERAND (new_obj, 0))) == UNION_TYPE)
    4523              :             {
    4524         4730 :               tree ctor = build_constructor (TREE_TYPE (new_obj), NULL);
    4525         4730 :               CONSTRUCTOR_NO_CLEARING (ctor) = true;
    4526         4730 :               tree activate = build2 (INIT_EXPR, TREE_TYPE (new_obj),
    4527              :                                       new_obj, ctor);
    4528         4730 :               cxx_eval_constant_expression (ctx, activate,
    4529              :                                             lval, non_constant_p, overflow_p,
    4530              :                                             jump_target);
    4531         4730 :               ggc_free (activate);
    4532         4730 :               if (*jump_target)
    4533            0 :                 return NULL_TREE;
    4534              :             }
    4535              : 
    4536     49229587 :           ctx->global->metafns_called = false;
    4537              : 
    4538     49229587 :           tree jmp_target = NULL_TREE;
    4539     49229587 :           cxx_eval_constant_expression (&call_ctx, body,
    4540              :                                         vc_discard, non_constant_p, overflow_p,
    4541              :                                         &jmp_target);
    4542              : 
    4543     49229585 :           if (!*non_constant_p && throws (&jmp_target))
    4544              :             {
    4545         1350 :               result = NULL_TREE;
    4546         1350 :               cacheable = false;
    4547         1350 :               *jump_target = jmp_target;
    4548              :             }
    4549     98456470 :           else if (DECL_CONSTRUCTOR_P (fun))
    4550              :             /* This can be null for a subobject constructor call, in
    4551              :                which case what we care about is the initialization
    4552              :                side-effects rather than the value.  We could get at the
    4553              :                value by evaluating *this, but we don't bother; there's
    4554              :                no need to put such a call in the hash table.  */
    4555      8903928 :             result = lval ? ctx->object : ctx->ctor;
    4556     40324307 :           else if (VOID_TYPE_P (TREE_TYPE (res)))
    4557      3195973 :             result = void_node;
    4558              :           else
    4559              :             {
    4560     37128334 :               result = ctx->global->get_value (res);
    4561      9055058 :               if (result == NULL_TREE && !*non_constant_p
    4562     37128538 :                   && !DECL_DESTRUCTOR_P (fun))
    4563              :                 {
    4564          102 :                   if (!ctx->quiet)
    4565            6 :                     error ("%<constexpr%> call flows off the end "
    4566              :                            "of the function");
    4567          102 :                   *non_constant_p = true;
    4568              :                 }
    4569              :             }
    4570              : 
    4571     49229585 :           if (ctx->global->metafns_called)
    4572        32810 :             cacheable = false;
    4573     49229585 :           ctx->global->metafns_called |= save_metafns_called;
    4574              : 
    4575              :           /* At this point, the object's constructor will have run, so
    4576              :              the object is no longer under construction, and its possible
    4577              :              'const' semantics now apply.  Make a note of this fact by
    4578              :              marking the CONSTRUCTOR TREE_READONLY.  */
    4579     57092929 :           if (new_obj && DECL_CONSTRUCTOR_P (fun))
    4580      7204394 :             cxx_set_object_constness (ctx, new_obj, /*readonly_p=*/true,
    4581              :                                       non_constant_p, overflow_p, jump_target);
    4582              : 
    4583              :           /* Remove the parms/result from the values map.  */
    4584     49229585 :           destroy_value_checked (ctx, res, non_constant_p);
    4585    113153079 :           for (tree parm = parms; parm; parm = TREE_CHAIN (parm))
    4586     63923494 :             destroy_value_checked (ctx, parm, non_constant_p);
    4587              : 
    4588              :           /* Free any parameter CONSTRUCTORs we aren't returning directly.  */
    4589     50035043 :           while (!ctors->is_empty ())
    4590              :             {
    4591       805458 :               tree c = ctors->pop ();
    4592       805458 :               if (c != result)
    4593       805458 :                 free_constructor (c);
    4594              :             }
    4595              : 
    4596              :           /* Make the unshared function copy we used available for re-use.  */
    4597     49229585 :           save_fundef_copy (fun, copy);
    4598              : 
    4599              :           /* If the call allocated some heap object that hasn't been
    4600              :              deallocated during the call, or if it deallocated some heap
    4601              :              object it has not allocated, the call isn't really stateless
    4602              :              for the constexpr evaluation and should not be cached.
    4603              :              It is fine if the call allocates something and deallocates it
    4604              :              too.  */
    4605     49229585 :           if (cacheable
    4606     58267934 :               && (save_heap_alloc_count != ctx->global->heap_vars.length ()
    4607      9035725 :                   || (save_heap_dealloc_count
    4608      9035725 :                       != ctx->global->heap_dealloc_count)))
    4609              :             {
    4610         2624 :               tree heap_var;
    4611         2624 :               unsigned int i;
    4612         2624 :               if ((ctx->global->heap_vars.length ()
    4613         2624 :                    - ctx->global->heap_dealloc_count)
    4614         2624 :                   != save_heap_alloc_count - save_heap_dealloc_count)
    4615              :                 cacheable = false;
    4616              :               else
    4617        70048 :                 FOR_EACH_VEC_ELT_FROM (ctx->global->heap_vars, i, heap_var,
    4618              :                                        save_heap_alloc_count)
    4619        68458 :                   if (DECL_NAME (heap_var) != heap_deleted_identifier)
    4620              :                     {
    4621              :                       cacheable = false;
    4622              :                       break;
    4623              :                     }
    4624              :             }
    4625              : 
    4626              :             /* Rewrite all occurrences of the function's RESULT_DECL with the
    4627              :                current object under construction.  */
    4628     49229585 :             if (!*non_constant_p
    4629     37368945 :                 && ctx->object
    4630     11897143 :                 && CLASS_TYPE_P (TREE_TYPE (res))
    4631     51292103 :                 && !is_empty_class (TREE_TYPE (res)))
    4632              :               {
    4633      1269793 :                 if (!same_type_ignoring_top_level_qualifiers_p
    4634      1269793 :                     (TREE_TYPE (res), TREE_TYPE (ctx->object)))
    4635            0 :                   *non_constant_p = true;
    4636      1269793 :                 else if (replace_decl (&result, res, ctx->object))
    4637              :                   {
    4638          238 :                     cacheable = false;
    4639          238 :                     result = cxx_eval_constant_expression (ctx, result, lval,
    4640              :                                                            non_constant_p,
    4641              :                                                            overflow_p,
    4642              :                                                            jump_target);
    4643          238 :                     if (*jump_target)
    4644              :                       {
    4645            0 :                         cacheable = false;
    4646            0 :                         result = NULL_TREE;
    4647              :                       }
    4648              :                   }
    4649              :               }
    4650              : 
    4651              :           /* Only cache a permitted result of a constant expression.  */
    4652     49229347 :           if (cacheable && !reduced_constant_expression_p (result))
    4653              :             cacheable = false;
    4654              : 
    4655              :           /* Only cache a result without contract violations.  */
    4656     44589309 :           if (cacheable && ctx->global->contract_statement)
    4657     44832760 :             cacheable = false;
    4658     49229585 :         }
    4659              :       else
    4660              :         /* Couldn't get a function copy to evaluate.  */
    4661            6 :         *non_constant_p = true;
    4662              : 
    4663     65017201 :       if (result == error_mark_node)
    4664            0 :         *non_constant_p = true;
    4665     65017201 :       if (*non_constant_p || *overflow_p)
    4666     11860802 :         result = error_mark_node;
    4667     53156399 :       else if (!result)
    4668      2448951 :         result = void_node;
    4669     65017201 :       if (entry)
    4670              :         {
    4671     49656512 :           entry->result (ctx->manifestly_const_eval)
    4672     24828256 :             = cacheable ? result : error_mark_node;
    4673              : 
    4674     24828256 :           if (result != error_mark_node
    4675     20225154 :               && ctx->manifestly_const_eval == mce_unknown)
    4676              :             {
    4677              :               /* Evaluation succeeded and was independent of whether we're in a
    4678              :                  manifestly constant-evaluated context, so we can also reuse
    4679              :                  this result when evaluating this call with a fixed context.  */
    4680      1769639 :               if (!entry->result (mce_true))
    4681       663243 :                 entry->result (mce_true) = entry->result (mce_unknown);
    4682      1769639 :               if (!entry->result (mce_false))
    4683       633409 :                 entry->result (mce_false) = entry->result (mce_unknown);
    4684              :             }
    4685              :         }
    4686              :     }
    4687              : 
    4688              :   /* The result of a constexpr function must be completely initialized.
    4689              : 
    4690              :      However, in C++20, a constexpr constructor doesn't necessarily have
    4691              :      to initialize all the fields, so we don't clear CONSTRUCTOR_NO_CLEARING
    4692              :      in order to detect reading an unitialized object in constexpr instead
    4693              :      of value-initializing it.  (reduced_constant_expression_p is expected to
    4694              :      take care of clearing the flag.)  */
    4695     65017231 :   if (TREE_CODE (result) == CONSTRUCTOR
    4696     65017231 :       && (cxx_dialect < cxx20
    4697     16306038 :           || !DECL_CONSTRUCTOR_P (fun)))
    4698      3919493 :     clear_no_implicit_zero (result);
    4699              : 
    4700     65017231 :   pop_cx_call_context ();
    4701     65017231 :   return result;
    4702    123127635 : }
    4703              : 
    4704              : /* Return true if T is a valid constant initializer.  If a CONSTRUCTOR
    4705              :    initializes all the members, the CONSTRUCTOR_NO_CLEARING flag will be
    4706              :    cleared.  If called recursively on a FIELD_DECL's CONSTRUCTOR, SZ
    4707              :    is DECL_SIZE of the FIELD_DECL, otherwise NULL.
    4708              :    FIXME speed this up, it's taking 16% of compile time on sieve testcase.  */
    4709              : 
    4710              : bool
    4711   1073323804 : reduced_constant_expression_p (tree t, tree sz /* = NULL_TREE */)
    4712              : {
    4713   1073323804 :   if (t == NULL_TREE)
    4714              :     return false;
    4715              : 
    4716   1068723835 :   switch (TREE_CODE (t))
    4717              :     {
    4718              :     case PTRMEM_CST:
    4719              :     case REFLECT_EXPR:
    4720              :       /* Even if we can't lower this yet, it's constant.  */
    4721              :       return true;
    4722              : 
    4723              :     case OMP_DECLARE_MAPPER:
    4724              :       return true;
    4725              : 
    4726     51446514 :     case CONSTRUCTOR:
    4727              :       /* And we need to handle PTRMEM_CST wrapped in a CONSTRUCTOR.  */
    4728     51446514 :       tree field;
    4729     51446514 :       if (!AGGREGATE_TYPE_P (TREE_TYPE (t)))
    4730              :         /* A constant vector would be folded to VECTOR_CST.
    4731              :            A CONSTRUCTOR of scalar type means uninitialized.  */
    4732              :         return false;
    4733     51430537 :       if (CONSTRUCTOR_NO_CLEARING (t))
    4734              :         {
    4735      3234694 :           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    4736              :             {
    4737              :               /* There must be a valid constant initializer at every array
    4738              :                  index.  */
    4739         1840 :               tree min = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (t)));
    4740         1840 :               tree max = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (t)));
    4741         1840 :               tree cursor = min;
    4742        26935 :               for (auto &e: CONSTRUCTOR_ELTS (t))
    4743              :                 {
    4744        21525 :                   if (!reduced_constant_expression_p (e.value))
    4745              :                     return false;
    4746        21475 :                   if (array_index_cmp (cursor, e.index) != 0)
    4747              :                     return false;
    4748        21415 :                   if (TREE_CODE (e.index) == RANGE_EXPR)
    4749            0 :                     cursor = TREE_OPERAND (e.index, 1);
    4750        21415 :                   if (TREE_CODE (e.value) == RAW_DATA_CST)
    4751            0 :                     cursor
    4752            0 :                       = int_const_binop (PLUS_EXPR, cursor,
    4753            0 :                                          size_int (RAW_DATA_LENGTH (e.value)));
    4754              :                   else
    4755        21415 :                     cursor = int_const_binop (PLUS_EXPR, cursor,
    4756        21415 :                                               size_one_node);
    4757              :                 }
    4758         1730 :               if (find_array_ctor_elt (t, max) == -1)
    4759              :                 return false;
    4760         1642 :               goto ok;
    4761              :             }
    4762      3232854 :           else if (cxx_dialect >= cxx20
    4763      3232854 :                    && TREE_CODE (TREE_TYPE (t)) == UNION_TYPE)
    4764              :             {
    4765              :               /* A union can have at most one active member.  A union with no
    4766              :                  active member has no constituent values, so all constituent
    4767              :                  values are constant.  */
    4768              :               field = NULL_TREE;
    4769              :             }
    4770              :           else
    4771      3230891 :             field = next_subobject_field (TYPE_FIELDS (TREE_TYPE (t)));
    4772              :         }
    4773              :       else
    4774              :         field = NULL_TREE;
    4775    540125994 :       for (auto &e: CONSTRUCTOR_ELTS (t))
    4776              :         {
    4777              :           /* If VAL is null, we're in the middle of initializing this
    4778              :              element.  */
    4779    435535545 :           if (!reduced_constant_expression_p (e.value,
    4780    435535545 :                                               (e.index
    4781    435535527 :                                                && (TREE_CODE (e.index)
    4782              :                                                    == FIELD_DECL))
    4783     45112126 :                                               ? DECL_SIZE (e.index)
    4784              :                                               : NULL_TREE))
    4785              :             return false;
    4786              :           /* We want to remove initializers for empty fields in a struct to
    4787              :              avoid confusing output_constructor.  */
    4788    435027500 :           if (is_empty_field (e.index)
    4789    435027500 :               && TREE_CODE (TREE_TYPE (t)) == RECORD_TYPE)
    4790              :             return false;
    4791              :           /* Check for non-empty fields between initialized fields when
    4792              :              CONSTRUCTOR_NO_CLEARING.  */
    4793    434752466 :           for (; field && e.index != field;
    4794       361809 :                field = next_subobject_field (DECL_CHAIN (field)))
    4795       365317 :             if (!is_really_empty_class (TREE_TYPE (field),
    4796              :                                         /*ignore_vptr*/false))
    4797              :               return false;
    4798    434387149 :           if (field)
    4799      3672270 :             field = next_subobject_field (DECL_CHAIN (field));
    4800              :         }
    4801              :       /* There could be a non-empty field at the end.  */
    4802     50550935 :       for (; field; field = next_subobject_field (DECL_CHAIN (field)))
    4803       275025 :         if (!is_really_empty_class (TREE_TYPE (field), /*ignore_vptr*/false))
    4804              :           {
    4805              :             /* Ignore FIELD_DECLs with bit positions beyond DECL_SIZE of
    4806              :                the parent FIELD_DECL (if any) for classes with virtual
    4807              :                bases.  */
    4808         4391 :             if (cxx_dialect >= cxx26
    4809         2334 :                 && sz
    4810         4766 :                 && tree_int_cst_le (sz, bit_position (field)))
    4811              :               break;
    4812         4139 :             return false;
    4813              :           }
    4814     50275910 : ok:
    4815     50277804 :       if (CONSTRUCTOR_NO_CLEARING (t))
    4816              :         /* All the fields are initialized.  */
    4817      3124869 :         CONSTRUCTOR_NO_CLEARING (t) = false;
    4818              :       return true;
    4819              : 
    4820   1017107614 :     default:
    4821              :       /* FIXME are we calling this too much?  */
    4822   1017107614 :       return initializer_constant_valid_p (t, TREE_TYPE (t)) != NULL_TREE;
    4823              :     }
    4824              : }
    4825              : 
    4826              : /* *TP was not deemed constant by reduced_constant_expression_p.  Explain
    4827              :    why and suggest what could be done about it.  */
    4828              : 
    4829              : static tree
    4830         1010 : verify_constant_explain_r (tree *tp, int *walk_subtrees, void *)
    4831              : {
    4832         1010 :   bool ref_p = false;
    4833              : 
    4834              :   /* No need to look into types or unevaluated operands.  */
    4835         1010 :   if (TYPE_P (*tp) || unevaluated_p (TREE_CODE (*tp)))
    4836              :     {
    4837            0 :       *walk_subtrees = false;
    4838            0 :       return NULL_TREE;
    4839              :     }
    4840              : 
    4841         1010 :   switch (TREE_CODE (*tp))
    4842              :     {
    4843           85 :     CASE_CONVERT:
    4844           85 :       if (TREE_CODE (TREE_OPERAND (*tp, 0)) != ADDR_EXPR)
    4845              :         break;
    4846           66 :       ref_p = TYPE_REF_P (TREE_TYPE (*tp));
    4847           66 :       *tp = TREE_OPERAND (*tp, 0);
    4848          198 :       gcc_fallthrough ();
    4849          198 :     case ADDR_EXPR:
    4850          198 :       {
    4851          198 :         tree op = TREE_OPERAND (*tp, 0);
    4852          198 :         if (VAR_P (op)
    4853          113 :             && DECL_DECLARED_CONSTEXPR_P (op)
    4854           39 :             && !TREE_STATIC (op)
    4855              :             /* ??? We should also say something about temporaries.  */
    4856          234 :             && !DECL_ARTIFICIAL (op))
    4857              :           {
    4858           33 :             if (ref_p)
    4859           12 :               inform (location_of (*tp), "reference to %qD is not a constant "
    4860              :                       "expression", op);
    4861              :             else
    4862           21 :               inform (location_of (*tp), "pointer to %qD is not a constant "
    4863              :                       "expression", op);
    4864           33 :             const location_t op_loc = DECL_SOURCE_LOCATION (op);
    4865           33 :             rich_location richloc (line_table, op_loc);
    4866           33 :             richloc.add_fixit_insert_before (op_loc, "static ");
    4867           33 :             inform (&richloc,
    4868              :                     "address of non-static constexpr variable %qD may differ on "
    4869              :                     "each invocation of the enclosing function; add %<static%> "
    4870              :                     "to give it a constant address", op);
    4871           33 :           }
    4872              :         break;
    4873              :       }
    4874              :     default:
    4875              :       break;
    4876              :     }
    4877              : 
    4878              :   return NULL_TREE;
    4879              : }
    4880              : 
    4881              : /* Some expressions may have constant operands but are not constant
    4882              :    themselves, such as 1/0.  Call this function to check for that
    4883              :    condition.
    4884              : 
    4885              :    We only call this in places that require an arithmetic constant, not in
    4886              :    places where we might have a non-constant expression that can be a
    4887              :    component of a constant expression, such as the address of a constexpr
    4888              :    variable that might be dereferenced later.  */
    4889              : 
    4890              : static bool
    4891    543858002 : verify_constant (tree t, bool allow_non_constant, bool *non_constant_p,
    4892              :                  bool *overflow_p)
    4893              : {
    4894    534339493 :   if (!*non_constant_p && !reduced_constant_expression_p (t)
    4895    546299709 :       && t != void_node)
    4896              :     {
    4897      2441484 :       if (!allow_non_constant)
    4898              :         {
    4899          262 :           auto_diagnostic_group d;
    4900          377 :           error_at (cp_expr_loc_or_input_loc (t),
    4901              :                     "%q+E is not a constant expression", t);
    4902          262 :           cp_walk_tree_without_duplicates (&t, verify_constant_explain_r,
    4903              :                                            nullptr);
    4904          262 :         }
    4905      2441484 :       *non_constant_p = true;
    4906              :     }
    4907    543858002 :   if (TREE_OVERFLOW_P (t))
    4908              :     {
    4909          678 :       if (!allow_non_constant)
    4910              :         {
    4911          155 :           permerror (input_location, "overflow in constant expression");
    4912              :           /* If we're being permissive (and are in an enforcing
    4913              :              context), ignore the overflow.  */
    4914          155 :           if (flag_permissive)
    4915           75 :             return *non_constant_p;
    4916              :         }
    4917          603 :       *overflow_p = true;
    4918              :     }
    4919    543857927 :   return *non_constant_p;
    4920              : }
    4921              : 
    4922              : /* Check whether the shift operation with code CODE and type TYPE on LHS
    4923              :    and RHS is undefined.  If it is, give an error with an explanation,
    4924              :    and return true; return false otherwise.  */
    4925              : 
    4926              : static bool
    4927     53754849 : cxx_eval_check_shift_p (location_t loc, const constexpr_ctx *ctx,
    4928              :                         enum tree_code code, tree type, tree lhs, tree rhs)
    4929              : {
    4930     53754849 :   if ((code != LSHIFT_EXPR && code != RSHIFT_EXPR)
    4931      3675359 :       || TREE_CODE (lhs) != INTEGER_CST
    4932      3675247 :       || TREE_CODE (rhs) != INTEGER_CST)
    4933              :     return false;
    4934              : 
    4935      3675247 :   tree lhstype = TREE_TYPE (lhs);
    4936      3675247 :   unsigned HOST_WIDE_INT uprec = TYPE_PRECISION (TREE_TYPE (lhs));
    4937              : 
    4938              :   /* [expr.shift] The behavior is undefined if the right operand
    4939              :      is negative, or greater than or equal to the length in bits
    4940              :      of the promoted left operand.  */
    4941      3675247 :   if (tree_int_cst_sgn (rhs) == -1)
    4942              :     {
    4943          126 :       if (!ctx->quiet)
    4944           35 :         permerror (loc, "right operand of shift expression %q+E is negative",
    4945              :                    build2_loc (loc, code, type, lhs, rhs));
    4946          126 :       return (!flag_permissive || ctx->quiet);
    4947              :     }
    4948      3675121 :   if (compare_tree_int (rhs, uprec) >= 0)
    4949              :     {
    4950          200 :       if (!ctx->quiet)
    4951           34 :         permerror (loc, "right operand of shift expression %q+E is greater "
    4952              :                    "than or equal to the precision %wu of the left operand",
    4953              :                    build2_loc (loc, code, type, lhs, rhs), uprec);
    4954          200 :       return (!flag_permissive || ctx->quiet);
    4955              :     }
    4956              : 
    4957              :   /* The value of E1 << E2 is E1 left-shifted E2 bit positions; [...]
    4958              :      if E1 has a signed type and non-negative value, and E1x2^E2 is
    4959              :      representable in the corresponding unsigned type of the result type,
    4960              :      then that value, converted to the result type, is the resulting value;
    4961              :      otherwise, the behavior is undefined.
    4962              :      For C++20:
    4963              :      The value of E1 << E2 is the unique value congruent to E1 x 2^E2 modulo
    4964              :      2^N, where N is the range exponent of the type of the result.  */
    4965      3674921 :   if (code == LSHIFT_EXPR
    4966      3497535 :       && !TYPE_OVERFLOW_WRAPS (lhstype)
    4967      2054957 :       && cxx_dialect >= cxx11
    4968      5710596 :       && cxx_dialect < cxx20)
    4969              :     {
    4970        54030 :       if (tree_int_cst_sgn (lhs) == -1)
    4971              :         {
    4972           74 :           if (!ctx->quiet)
    4973           18 :             permerror (loc,
    4974              :                        "left operand of shift expression %q+E is negative",
    4975              :                        build2_loc (loc, code, type, lhs, rhs));
    4976           74 :           return (!flag_permissive || ctx->quiet);
    4977              :         }
    4978              :       /* For signed x << y the following:
    4979              :          (unsigned) x >> ((prec (lhs) - 1) - y)
    4980              :          if > 1, is undefined.  The right-hand side of this formula
    4981              :          is the highest bit of the LHS that can be set (starting from 0),
    4982              :          so that the shift doesn't overflow.  We then right-shift the LHS
    4983              :          to see whether any other bit is set making the original shift
    4984              :          undefined -- the result is not representable in the corresponding
    4985              :          unsigned type.  */
    4986        53956 :       tree t = build_int_cst (unsigned_type_node, uprec - 1);
    4987        53956 :       t = fold_build2 (MINUS_EXPR, unsigned_type_node, t, rhs);
    4988        53956 :       tree ulhs = fold_convert (unsigned_type_for (lhstype), lhs);
    4989        53956 :       t = fold_build2 (RSHIFT_EXPR, TREE_TYPE (ulhs), ulhs, t);
    4990        53956 :       if (tree_int_cst_lt (integer_one_node, t))
    4991              :         {
    4992           41 :           if (!ctx->quiet)
    4993            7 :             permerror (loc, "shift expression %q+E overflows",
    4994              :                        build2_loc (loc, code, type, lhs, rhs));
    4995           41 :           return (!flag_permissive || ctx->quiet);
    4996              :         }
    4997              :     }
    4998              :   return false;
    4999              : }
    5000              : 
    5001              : /* Subroutine of cxx_eval_constant_expression.
    5002              :    Attempt to reduce the unary expression tree T to a compile time value.
    5003              :    If successful, return the value.  Otherwise issue a diagnostic
    5004              :    and return error_mark_node.  */
    5005              : 
    5006              : static tree
    5007     21106779 : cxx_eval_unary_expression (const constexpr_ctx *ctx, tree t,
    5008              :                            bool /*lval*/,
    5009              :                            bool *non_constant_p, bool *overflow_p,
    5010              :                            tree *jump_target)
    5011              : {
    5012     21106779 :   tree r;
    5013     21106779 :   tree orig_arg = TREE_OPERAND (t, 0);
    5014     21106779 :   tree arg = cxx_eval_constant_expression (ctx, orig_arg, vc_prvalue,
    5015              :                                            non_constant_p, overflow_p,
    5016              :                                            jump_target);
    5017     21106778 :   if (*jump_target)
    5018              :     return NULL_TREE;
    5019     21106777 :   VERIFY_CONSTANT (arg);
    5020     17551114 :   location_t loc = EXPR_LOCATION (t);
    5021     17551114 :   enum tree_code code = TREE_CODE (t);
    5022     17551114 :   tree type = TREE_TYPE (t);
    5023     17551114 :   r = fold_unary_loc (loc, code, type, arg);
    5024     17551114 :   if (r == NULL_TREE)
    5025              :     {
    5026           17 :       if (arg == orig_arg)
    5027              :         r = t;
    5028              :       else
    5029           13 :         r = build1_loc (loc, code, type, arg);
    5030              :     }
    5031     17551114 :   VERIFY_CONSTANT (r);
    5032              :   return r;
    5033              : }
    5034              : 
    5035              : /* Helper function for cxx_eval_binary_expression.  Try to optimize
    5036              :    original POINTER_PLUS_EXPR T, LHS p+ RHS, return NULL_TREE if the
    5037              :    generic folding should be used.  */
    5038              : 
    5039              : static tree
    5040      5822434 : cxx_fold_pointer_plus_expression (const constexpr_ctx *ctx, tree t,
    5041              :                                   tree lhs, tree rhs, bool *non_constant_p,
    5042              :                                   bool *overflow_p, tree *jump_target)
    5043              : {
    5044      5822434 :   STRIP_NOPS (lhs);
    5045      5822434 :   if (TREE_CODE (lhs) != ADDR_EXPR)
    5046              :     return NULL_TREE;
    5047              : 
    5048      5430642 :   lhs = TREE_OPERAND (lhs, 0);
    5049              : 
    5050              :   /* &A[i] p+ j => &A[i + j] */
    5051      5430642 :   if (TREE_CODE (lhs) == ARRAY_REF
    5052       100467 :       && TREE_CODE (TREE_OPERAND (lhs, 1)) == INTEGER_CST
    5053       100467 :       && TREE_CODE (rhs) == INTEGER_CST
    5054       100467 :       && TYPE_SIZE_UNIT (TREE_TYPE (lhs))
    5055      5531109 :       && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) == INTEGER_CST)
    5056              :     {
    5057       100467 :       tree orig_type = TREE_TYPE (t);
    5058       100467 :       location_t loc = EXPR_LOCATION (t);
    5059       100467 :       tree type = TREE_TYPE (lhs);
    5060              : 
    5061       100467 :       t = fold_convert_loc (loc, ssizetype, TREE_OPERAND (lhs, 1));
    5062       100467 :       tree nelts = array_type_nelts_top (TREE_TYPE (TREE_OPERAND (lhs, 0)));
    5063       100467 :       nelts = cxx_eval_constant_expression (ctx, nelts, vc_prvalue,
    5064              :                                             non_constant_p, overflow_p,
    5065              :                                             jump_target);
    5066       100467 :       if (*non_constant_p)
    5067              :         return NULL_TREE;
    5068       100455 :       if (*jump_target)
    5069              :         return NULL_TREE;
    5070              :       /* Don't fold an out-of-bound access.  */
    5071       100455 :       if (!tree_int_cst_le (t, nelts))
    5072              :         return NULL_TREE;
    5073       100455 :       rhs = cp_fold_convert (ssizetype, rhs);
    5074              :       /* Don't fold if rhs can't be divided exactly by TYPE_SIZE_UNIT.
    5075              :          constexpr int A[1]; ... (char *)&A[0] + 1 */
    5076       100455 :       if (!integer_zerop (fold_build2_loc (loc, TRUNC_MOD_EXPR, sizetype,
    5077       100455 :                                            rhs, TYPE_SIZE_UNIT (type))))
    5078              :         return NULL_TREE;
    5079              :       /* Make sure to treat the second operand of POINTER_PLUS_EXPR
    5080              :          as signed.  */
    5081       100423 :       rhs = fold_build2_loc (loc, EXACT_DIV_EXPR, ssizetype, rhs,
    5082       100423 :                              TYPE_SIZE_UNIT (type));
    5083       100423 :       t = size_binop_loc (loc, PLUS_EXPR, rhs, t);
    5084       100423 :       t = build4_loc (loc, ARRAY_REF, type, TREE_OPERAND (lhs, 0),
    5085              :                       t, NULL_TREE, NULL_TREE);
    5086       100423 :       t = cp_build_addr_expr (t, tf_warning_or_error);
    5087       100423 :       t = cp_fold_convert (orig_type, t);
    5088       100423 :       return cxx_eval_constant_expression (ctx, t, vc_prvalue,
    5089              :                                            non_constant_p, overflow_p,
    5090       100423 :                                            jump_target);
    5091              :     }
    5092              : 
    5093              :   return NULL_TREE;
    5094              : }
    5095              : 
    5096              : /* Try to fold expressions like
    5097              :    (struct S *) (&a[0].D.2378 + 12)
    5098              :    into
    5099              :    &MEM <struct T> [(void *)&a + 12B]
    5100              :    This is something normally done by gimple_fold_stmt_to_constant_1
    5101              :    on GIMPLE, but is undesirable on GENERIC if we are e.g. going to
    5102              :    dereference the address because some details are lost.
    5103              :    For pointer comparisons we want such folding though so that
    5104              :    match.pd address_compare optimization works.  */
    5105              : 
    5106              : static tree
    5107      7011998 : cxx_maybe_fold_addr_pointer_plus (tree t)
    5108              : {
    5109     14023999 :   while (CONVERT_EXPR_P (t)
    5110      7399352 :          && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
    5111       387351 :     t = TREE_OPERAND (t, 0);
    5112      7011998 :   if (TREE_CODE (t) != POINTER_PLUS_EXPR)
    5113              :     return NULL_TREE;
    5114      6036076 :   tree op0 = TREE_OPERAND (t, 0);
    5115      6036076 :   tree op1 = TREE_OPERAND (t, 1);
    5116      6036076 :   if (TREE_CODE (op1) != INTEGER_CST)
    5117              :     return NULL_TREE;
    5118      6036076 :   while (CONVERT_EXPR_P (op0)
    5119     12070120 :          && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (op0, 0))))
    5120      6034044 :     op0 = TREE_OPERAND (op0, 0);
    5121      6036076 :   if (TREE_CODE (op0) != ADDR_EXPR)
    5122              :     return NULL_TREE;
    5123      6036076 :   op1 = fold_convert (ptr_type_node, op1);
    5124      6036076 :   tree r = fold_build2 (MEM_REF, TREE_TYPE (TREE_TYPE (op0)), op0, op1);
    5125      6036076 :   return build1_loc (EXPR_LOCATION (t), ADDR_EXPR, TREE_TYPE (op0), r);
    5126              : }
    5127              : 
    5128              : /* Subroutine of cxx_eval_constant_expression.
    5129              :    Like cxx_eval_unary_expression, except for binary expressions.  */
    5130              : 
    5131              : static tree
    5132     76858611 : cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t,
    5133              :                             value_cat lval,
    5134              :                             bool *non_constant_p, bool *overflow_p,
    5135              :                             tree *jump_target)
    5136              : {
    5137     76858611 :   tree r = NULL_TREE;
    5138     76858611 :   tree orig_lhs = TREE_OPERAND (t, 0);
    5139     76858611 :   tree orig_rhs = TREE_OPERAND (t, 1);
    5140     76858611 :   tree lhs, rhs;
    5141     76858611 :   lhs = cxx_eval_constant_expression (ctx, orig_lhs, vc_prvalue,
    5142              :                                       non_constant_p, overflow_p,
    5143              :                                       jump_target);
    5144              :   /* Don't VERIFY_CONSTANT here, it's unnecessary and will break pointer
    5145              :      subtraction.  */
    5146     76858610 :   if (*non_constant_p)
    5147              :     return t;
    5148     59527864 :   if (*jump_target)
    5149              :     return NULL_TREE;
    5150     59527794 :   rhs = cxx_eval_constant_expression (ctx, orig_rhs, vc_prvalue,
    5151              :                                       non_constant_p, overflow_p,
    5152              :                                       jump_target);
    5153     59527794 :   if (*non_constant_p)
    5154              :     return t;
    5155     58621324 :   if (*jump_target)
    5156              :     return NULL_TREE;
    5157              : 
    5158     58621319 :   location_t loc = EXPR_LOCATION (t);
    5159     58621319 :   enum tree_code code = TREE_CODE (t);
    5160     58621319 :   tree type = TREE_TYPE (t);
    5161              : 
    5162     58621319 :   if (code == EQ_EXPR || code == NE_EXPR)
    5163              :     {
    5164      8997797 :       bool is_code_eq = (code == EQ_EXPR);
    5165              : 
    5166      8997797 :       if (TREE_CODE (lhs) == PTRMEM_CST
    5167          192 :           && TREE_CODE (rhs) == PTRMEM_CST)
    5168              :         {
    5169           61 :           tree lmem = PTRMEM_CST_MEMBER (lhs);
    5170           61 :           tree rmem = PTRMEM_CST_MEMBER (rhs);
    5171           61 :           bool eq;
    5172           61 :           if (TREE_CODE (lmem) == TREE_CODE (rmem)
    5173           61 :               && TREE_CODE (lmem) == FIELD_DECL
    5174           61 :               && TREE_CODE (DECL_CONTEXT (lmem)) == UNION_TYPE
    5175           88 :               && same_type_p (DECL_CONTEXT (lmem),
    5176              :                               DECL_CONTEXT (rmem)))
    5177              :             /* If both refer to (possibly different) members of the same union
    5178              :                (12.3), they compare equal. */
    5179              :             eq = true;
    5180              :           else
    5181           34 :             eq = cp_tree_equal (lhs, rhs);
    5182           61 :           r = constant_boolean_node (eq == is_code_eq, type);
    5183           61 :         }
    5184      8997736 :       else if ((TREE_CODE (lhs) == PTRMEM_CST
    5185      8997605 :                 || TREE_CODE (rhs) == PTRMEM_CST)
    5186      8997736 :                && (null_member_pointer_value_p (lhs)
    5187          131 :                    || null_member_pointer_value_p (rhs)))
    5188          131 :         r = constant_boolean_node (!is_code_eq, type);
    5189      8997605 :       else if (TREE_CODE (lhs) == PTRMEM_CST)
    5190            0 :         lhs = cplus_expand_constant (lhs);
    5191      8997605 :       else if (TREE_CODE (rhs) == PTRMEM_CST)
    5192            0 :         rhs = cplus_expand_constant (rhs);
    5193      8997605 :       else if (REFLECT_EXPR_P (lhs) && REFLECT_EXPR_P (rhs))
    5194              :         {
    5195         1952 :           const bool eq = compare_reflections (lhs, rhs);
    5196         1952 :           r = constant_boolean_node (eq == is_code_eq, type);
    5197              :         }
    5198              :     }
    5199            0 :   if (r == NULL_TREE
    5200     58619175 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5201     22230421 :       && POINTER_TYPE_P (TREE_TYPE (lhs)))
    5202              :     {
    5203      3505999 :       if (tree lhso = cxx_maybe_fold_addr_pointer_plus (lhs))
    5204      2951352 :         lhs = fold_convert (TREE_TYPE (lhs), lhso);
    5205      3505999 :       if (tree rhso = cxx_maybe_fold_addr_pointer_plus (rhs))
    5206      3084724 :         rhs = fold_convert (TREE_TYPE (rhs), rhso);
    5207              :     }
    5208      5822589 :   if (code == POINTER_PLUS_EXPR && !*non_constant_p
    5209     64443908 :       && integer_zerop (lhs) && !integer_zerop (rhs))
    5210              :     {
    5211          155 :       if (!ctx->quiet)
    5212           45 :         error ("arithmetic involving a null pointer in %qE", lhs);
    5213          155 :       *non_constant_p = true;
    5214          155 :       return t;
    5215              :     }
    5216     58621164 :   else if (code == POINTER_PLUS_EXPR)
    5217              :     {
    5218      5822434 :       r = cxx_fold_pointer_plus_expression (ctx, t, lhs, rhs, non_constant_p,
    5219              :                                             overflow_p, jump_target);
    5220      5822434 :       if (*jump_target)
    5221              :         return NULL_TREE;
    5222              :     }
    5223     52798730 :   else if (code == SPACESHIP_EXPR)
    5224              :     {
    5225        23583 :       r = genericize_spaceship (loc, type, lhs, rhs);
    5226        23583 :       return cxx_eval_constant_expression (ctx, r, lval, non_constant_p,
    5227        23583 :                                            overflow_p, jump_target);
    5228              :     }
    5229              : 
    5230     58597581 :   if (r == NULL_TREE)
    5231              :     {
    5232     58495014 :       if (ctx->manifestly_const_eval == mce_true
    5233     40542178 :           && (flag_constexpr_fp_except
    5234     40542175 :               || TREE_CODE (type) != REAL_TYPE))
    5235              :         {
    5236     40492983 :           auto ofcc = make_temp_override (folding_cxx_constexpr, true);
    5237     40492983 :           r = fold_binary_initializer_loc (loc, code, type, lhs, rhs);
    5238     40492983 :         }
    5239              :       else
    5240     18002031 :         r = fold_binary_loc (loc, code, type, lhs, rhs);
    5241              :     }
    5242              : 
    5243     58495014 :   if (r == NULL_TREE
    5244      4842830 :       && (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
    5245          100 :       && TREE_CODE (lhs) == INTEGER_CST
    5246           98 :       && TREE_CODE (rhs) == INTEGER_CST
    5247     63440411 :       && wi::neg_p (wi::to_wide (rhs)))
    5248              :     {
    5249              :       /* For diagnostics and -fpermissive emulate previous behavior of
    5250              :          handling shifts by negative amount.  */
    5251           98 :       tree nrhs = const_unop (NEGATE_EXPR, TREE_TYPE (rhs), rhs);
    5252           98 :       if (nrhs)
    5253          119 :         r = fold_binary_loc (loc,
    5254              :                              code == LSHIFT_EXPR ? RSHIFT_EXPR : LSHIFT_EXPR,
    5255              :                              type, lhs, nrhs);
    5256              :     }
    5257              : 
    5258     58597581 :   if (r == NULL_TREE)
    5259              :     {
    5260      4842732 :       if (lhs == orig_lhs && rhs == orig_rhs)
    5261              :         r = t;
    5262              :       else
    5263      1282955 :         r = build2_loc (loc, code, type, lhs, rhs);
    5264              :     }
    5265     53754849 :   else if (cxx_eval_check_shift_p (loc, ctx, code, type, lhs, rhs))
    5266          433 :     *non_constant_p = true;
    5267              :   /* Don't VERIFY_CONSTANT if this might be dealing with a pointer to
    5268              :      a local array in a constexpr function.  */
    5269     58597581 :   bool ptr = INDIRECT_TYPE_P (TREE_TYPE (lhs));
    5270     48894715 :   if (!ptr)
    5271     48894715 :     VERIFY_CONSTANT (r);
    5272              :   return r;
    5273              : }
    5274              : 
    5275              : /* Subroutine of cxx_eval_constant_expression.
    5276              :    Attempt to evaluate condition expressions.  */
    5277              : 
    5278              : static tree
    5279     18366324 : cxx_eval_conditional_expression (const constexpr_ctx *ctx, tree t,
    5280              :                                  value_cat lval,
    5281              :                                  bool *non_constant_p, bool *overflow_p,
    5282              :                                  tree *jump_target)
    5283              : {
    5284     18366324 :   tree val = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
    5285              :                                            vc_prvalue,
    5286              :                                            non_constant_p, overflow_p,
    5287              :                                            jump_target);
    5288     18366324 :   if (*jump_target)
    5289              :     return NULL_TREE;
    5290     18366308 :   VERIFY_CONSTANT (val);
    5291     16868059 :   if (TREE_CODE (t) == IF_STMT && IF_STMT_CONSTEVAL_P (t))
    5292              :     {
    5293              :       /* Evaluate the condition as if it was
    5294              :          if (__builtin_is_constant_evaluated ()), i.e. defer it if not
    5295              :          ctx->manifestly_const_eval (as sometimes we try to constant evaluate
    5296              :          without manifestly_const_eval even expressions or parts thereof which
    5297              :          will later be manifestly const_eval evaluated), otherwise fold it to
    5298              :          true.  */
    5299       715526 :       if (ctx->manifestly_const_eval == mce_unknown)
    5300              :         {
    5301       662043 :           *non_constant_p = true;
    5302       662043 :           return t;
    5303              :         }
    5304        53483 :       val = constant_boolean_node (ctx->manifestly_const_eval == mce_true,
    5305              :                                    boolean_type_node);
    5306              :     }
    5307              :   /* Don't VERIFY_CONSTANT the other operands.  */
    5308     16206016 :   const bool zero_p = integer_zerop (val);
    5309     16206016 :   if (zero_p)
    5310     10141046 :     val = TREE_OPERAND (t, 2);
    5311              :   else
    5312      6064970 :     val = TREE_OPERAND (t, 1);
    5313     16206016 :   if (TREE_CODE (t) == IF_STMT && !val)
    5314      4950094 :     val = void_node;
    5315              : 
    5316              :   /* P2564: If we aren't in immediate function context (including a manifestly
    5317              :      constant-evaluated expression), check any uses of immediate functions in
    5318              :      the arm we're discarding.  But don't do this inside a call; we already
    5319              :      checked when parsing the function.  */
    5320     16206016 :   if (ctx->manifestly_const_eval != mce_true
    5321      3488328 :       && !in_immediate_context ()
    5322      3407600 :       && !ctx->call
    5323     16965983 :       && cp_fold_immediate (&TREE_OPERAND (t, zero_p ? 1 : 2),
    5324       759967 :                             ctx->manifestly_const_eval))
    5325              :     {
    5326            7 :       *non_constant_p = true;
    5327            7 :       return t;
    5328              :     }
    5329              : 
    5330              :   /* A TARGET_EXPR may be nested inside another TARGET_EXPR, but still
    5331              :      serve as the initializer for the same object as the outer TARGET_EXPR,
    5332              :      as in
    5333              :        A a = true ? A{} : A{};
    5334              :      so strip the inner TARGET_EXPR so we don't materialize a temporary.  */
    5335     16206009 :   if (TREE_CODE (val) == TARGET_EXPR)
    5336         2236 :     val = TARGET_EXPR_INITIAL (val);
    5337     16206009 :   return cxx_eval_constant_expression (ctx, val, lval, non_constant_p,
    5338     16206009 :                                        overflow_p, jump_target);
    5339              : }
    5340              : 
    5341              : /* Subroutine of cxx_eval_constant_expression.
    5342              :    Attempt to evaluate vector condition expressions.  Unlike
    5343              :    cxx_eval_conditional_expression, VEC_COND_EXPR acts like a normal
    5344              :    ternary arithmetics operation, where all 3 arguments have to be
    5345              :    evaluated as constants and then folding computes the result from
    5346              :    them.  */
    5347              : 
    5348              : static tree
    5349         4582 : cxx_eval_vector_conditional_expression (const constexpr_ctx *ctx, tree t,
    5350              :                                         bool *non_constant_p, bool *overflow_p,
    5351              :                                         tree *jump_target)
    5352              : {
    5353         4582 :   tree arg1 = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
    5354              :                                             vc_prvalue,
    5355              :                                             non_constant_p, overflow_p,
    5356              :                                             jump_target);
    5357         4582 :   if (*jump_target)
    5358              :     return NULL_TREE;
    5359         4582 :   VERIFY_CONSTANT (arg1);
    5360         3234 :   tree arg2 = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1),
    5361              :                                             vc_prvalue,
    5362              :                                             non_constant_p, overflow_p,
    5363              :                                             jump_target);
    5364         3234 :   if (*jump_target)
    5365              :     return NULL_TREE;
    5366         3234 :   VERIFY_CONSTANT (arg2);
    5367         3167 :   tree arg3 = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 2),
    5368              :                                             vc_prvalue,
    5369              :                                             non_constant_p, overflow_p,
    5370              :                                             jump_target);
    5371         3167 :   if (*jump_target)
    5372              :     return NULL_TREE;
    5373         3167 :   VERIFY_CONSTANT (arg3);
    5374         3167 :   location_t loc = EXPR_LOCATION (t);
    5375         3167 :   tree type = TREE_TYPE (t);
    5376         3167 :   tree r = fold_ternary_loc (loc, VEC_COND_EXPR, type, arg1, arg2, arg3);
    5377         3167 :   if (r == NULL_TREE)
    5378              :     {
    5379            0 :       if (arg1 == TREE_OPERAND (t, 0)
    5380            0 :           && arg2 == TREE_OPERAND (t, 1)
    5381            0 :           && arg3 == TREE_OPERAND (t, 2))
    5382              :         r = t;
    5383              :       else
    5384            0 :         r = build3_loc (loc, VEC_COND_EXPR, type, arg1, arg2, arg3);
    5385              :     }
    5386         3167 :   VERIFY_CONSTANT (r);
    5387              :   return r;
    5388              : }
    5389              : 
    5390              : /* Returns less than, equal to, or greater than zero if KEY is found to be
    5391              :    less than, to match, or to be greater than the constructor_elt's INDEX.  */
    5392              : 
    5393              : static int
    5394       253420 : array_index_cmp (tree key, tree index)
    5395              : {
    5396       253420 :   gcc_assert (TREE_CODE (key) == INTEGER_CST);
    5397              : 
    5398       253420 :   switch (TREE_CODE (index))
    5399              :     {
    5400       250543 :     case INTEGER_CST:
    5401       250543 :       return tree_int_cst_compare (key, index);
    5402         2877 :     case RANGE_EXPR:
    5403         2877 :       {
    5404         2877 :         tree lo = TREE_OPERAND (index, 0);
    5405         2877 :         tree hi = TREE_OPERAND (index, 1);
    5406         2877 :         if (tree_int_cst_lt (key, lo))
    5407              :           return -1;
    5408         2591 :         else if (tree_int_cst_lt (hi, key))
    5409              :           return 1;
    5410              :         else
    5411         2591 :           return 0;
    5412              :       }
    5413            0 :     default:
    5414            0 :       gcc_unreachable ();
    5415              :     }
    5416              : }
    5417              : 
    5418              : /* Extract a single INTEGER_CST from RAW_DATA_CST RAW_DATA at
    5419              :    relative index OFF.  */
    5420              : 
    5421              : static tree
    5422        29316 : raw_data_cst_elt (tree raw_data, unsigned int off)
    5423              : {
    5424        29316 :   return build_int_cst (TREE_TYPE (raw_data),
    5425        29316 :                         TYPE_UNSIGNED (TREE_TYPE (raw_data))
    5426        58632 :                         ? (HOST_WIDE_INT)
    5427        29073 :                           RAW_DATA_UCHAR_ELT (raw_data, off)
    5428              :                         : (HOST_WIDE_INT)
    5429          243 :                           RAW_DATA_SCHAR_ELT (raw_data, off));
    5430              : }
    5431              : 
    5432              : /* Returns the index of the constructor_elt of ARY which matches DINDEX, or -1
    5433              :    if none.  If INSERT is true, insert a matching element rather than fail.  */
    5434              : 
    5435              : static HOST_WIDE_INT
    5436      6361246 : find_array_ctor_elt (tree ary, tree dindex, bool insert)
    5437              : {
    5438      6361246 :   if (tree_int_cst_sgn (dindex) < 0)
    5439              :     return -1;
    5440              : 
    5441      6361246 :   unsigned HOST_WIDE_INT i = tree_to_uhwi (dindex);
    5442      6361246 :   vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (ary);
    5443      6361246 :   unsigned HOST_WIDE_INT len = vec_safe_length (elts);
    5444              : 
    5445      9595954 :   unsigned HOST_WIDE_INT end = len;
    5446      9595954 :   unsigned HOST_WIDE_INT begin = 0;
    5447              : 
    5448              :   /* If the last element of the CONSTRUCTOR has its own index, we can assume
    5449              :      that the same is true of the other elements and index directly.  */
    5450      6049589 :   if (end > 0)
    5451              :     {
    5452      5929155 :       tree cindex = (*elts)[end - 1].index;
    5453      5929155 :       if (cindex == NULL_TREE)
    5454              :         {
    5455              :           /* Verify that if the last index is missing, all indexes
    5456              :              are missing and there is no RAW_DATA_CST.  */
    5457        15538 :           if (flag_checking)
    5458       188292 :             for (unsigned int j = 0; j < len - 1; ++j)
    5459       172754 :               gcc_assert ((*elts)[j].index == NULL_TREE
    5460              :                           && TREE_CODE ((*elts)[j].value) != RAW_DATA_CST);
    5461        15538 :           if (i < end)
    5462        15538 :             return i;
    5463              :           else
    5464              :             {
    5465            0 :               begin = end;
    5466            0 :               if (i == end)
    5467              :                 /* If the element is to be added right at the end,
    5468              :                    make sure it is added with cleared index too.  */
    5469      3546365 :                 dindex = NULL_TREE;
    5470            0 :               else if (insert)
    5471              :                 /* Otherwise, in order not to break the assumption
    5472              :                    that CONSTRUCTOR either has all indexes or none,
    5473              :                    we need to add indexes to all elements.  */
    5474            0 :                 for (unsigned int j = 0; j < len; ++j)
    5475            0 :                   (*elts)[j].index = build_int_cst (TREE_TYPE (dindex), j);
    5476              :             }
    5477              :         }
    5478      5913617 :       else if (TREE_CODE (cindex) == INTEGER_CST
    5479      5913617 :                && compare_tree_int (cindex, end - 1) == 0)
    5480              :         {
    5481      5788101 :           tree value = (*elts)[end - 1].value;
    5482      5788101 :           if (i < end)
    5483              :             {
    5484      2799433 :               if (i == end - 1 && TREE_CODE (value) == RAW_DATA_CST)
    5485              :                 begin = end - 1;
    5486              :               else
    5487      2799343 :                 return i;
    5488              :             }
    5489      2988668 :           else if (TREE_CODE (value) == RAW_DATA_CST
    5490      3020824 :                    && wi::to_offset (dindex) < (wi::to_offset (cindex)
    5491        32156 :                                                 + RAW_DATA_LENGTH (value)))
    5492        16078 :             begin = end - 1;
    5493              :           else
    5494      2972590 :             begin = end;
    5495              :         }
    5496              :     }
    5497              : 
    5498              :   /* Otherwise, find a matching index by means of a binary search.  */
    5499      3679503 :   while (begin != end)
    5500              :     {
    5501       231942 :       unsigned HOST_WIDE_INT middle = (begin + end) / 2;
    5502       231942 :       constructor_elt &elt = (*elts)[middle];
    5503       231942 :       tree idx = elt.index;
    5504              : 
    5505       231942 :       int cmp = array_index_cmp (dindex, idx);
    5506       231942 :       if (cmp > 0
    5507        61019 :           && TREE_CODE (elt.value) == RAW_DATA_CST
    5508       315272 :           && wi::to_offset (dindex) < (wi::to_offset (idx)
    5509        83330 :                                        + RAW_DATA_LENGTH (elt.value)))
    5510        29178 :         cmp = 0;
    5511       231942 :       if (cmp < 0)
    5512              :         end = middle;
    5513       130645 :       else if (cmp > 0)
    5514        31841 :         begin = middle + 1;
    5515              :       else
    5516              :         {
    5517        98804 :           if (insert && TREE_CODE (elt.value) == RAW_DATA_CST)
    5518              :             {
    5519              :               /* We need to split the RAW_DATA_CST elt.  */
    5520          122 :               constructor_elt e;
    5521          122 :               gcc_checking_assert (TREE_CODE (idx) != RANGE_EXPR);
    5522          244 :               unsigned int off = (wi::to_offset (dindex)
    5523          244 :                                   - wi::to_offset (idx)).to_uhwi ();
    5524          122 :               tree value = elt.value;
    5525          122 :               unsigned int len = RAW_DATA_LENGTH (value);
    5526          122 :               if (off > 1 && len >= off + 3)
    5527           22 :                 value = copy_node (elt.value);
    5528          122 :               if (off)
    5529              :                 {
    5530           33 :                   if (off > 1)
    5531           33 :                     RAW_DATA_LENGTH (elt.value) = off;
    5532              :                   else
    5533            0 :                     elt.value = raw_data_cst_elt (elt.value, 0);
    5534           33 :                   e.index = size_binop (PLUS_EXPR, elt.index,
    5535              :                                         build_int_cst (TREE_TYPE (elt.index),
    5536              :                                                        off));
    5537           33 :                   e.value = NULL_TREE;
    5538           33 :                   ++middle;
    5539           33 :                   vec_safe_insert (CONSTRUCTOR_ELTS (ary), middle, e);
    5540              :                 }
    5541          122 :               (*elts)[middle].value = raw_data_cst_elt (value, off);
    5542          122 :               if (len >= off + 2)
    5543              :                 {
    5544          111 :                   e.index = (*elts)[middle].index;
    5545          111 :                   e.index = size_binop (PLUS_EXPR, e.index,
    5546              :                                         build_one_cst (TREE_TYPE (e.index)));
    5547          111 :                   if (len >= off + 3)
    5548              :                     {
    5549          111 :                       RAW_DATA_LENGTH (value) -= off + 1;
    5550          111 :                       RAW_DATA_POINTER (value) += off + 1;
    5551          111 :                       e.value = value;
    5552              :                     }
    5553              :                   else
    5554            0 :                     e.value = raw_data_cst_elt (value, off + 1);
    5555          111 :                   vec_safe_insert (CONSTRUCTOR_ELTS (ary), middle + 1, e);
    5556              :                 }
    5557          122 :               return middle;
    5558              :             }
    5559        18490 :           if (insert && TREE_CODE (idx) == RANGE_EXPR)
    5560              :             {
    5561              :               /* We need to split the range.  */
    5562          343 :               constructor_elt e;
    5563          343 :               tree lo = TREE_OPERAND (idx, 0);
    5564          343 :               tree hi = TREE_OPERAND (idx, 1);
    5565          343 :               tree value = elt.value;
    5566          343 :               dindex = fold_convert (sizetype, dindex);
    5567          343 :               if (tree_int_cst_lt (lo, dindex))
    5568              :                 {
    5569              :                   /* There are still some lower elts; shorten the range.  */
    5570          170 :                   tree new_hi = int_const_binop (MINUS_EXPR, dindex,
    5571           85 :                                                  size_one_node);
    5572           85 :                   if (tree_int_cst_equal (lo, new_hi))
    5573              :                     /* Only one element left, no longer a range.  */
    5574           33 :                     elt.index = lo;
    5575              :                   else
    5576           52 :                     TREE_OPERAND (idx, 1) = new_hi;
    5577              :                   /* Append the element we want to insert.  */
    5578           85 :                   ++middle;
    5579           85 :                   e.index = dindex;
    5580           85 :                   e.value = unshare_constructor (value);
    5581           85 :                   vec_safe_insert (CONSTRUCTOR_ELTS (ary), middle, e);
    5582              :                 }
    5583              :               else
    5584              :                 /* No lower elts, the range elt is now ours.  */
    5585          258 :                 elt.index = dindex;
    5586              : 
    5587          343 :               if (tree_int_cst_lt (dindex, hi))
    5588              :                 {
    5589              :                   /* There are still some higher elts; append a range.  */
    5590          478 :                   tree new_lo = int_const_binop (PLUS_EXPR, dindex,
    5591          239 :                                                  size_one_node);
    5592          239 :                   if (tree_int_cst_equal (new_lo, hi))
    5593           98 :                     e.index = hi;
    5594              :                   else
    5595          141 :                     e.index = build2 (RANGE_EXPR, sizetype, new_lo, hi);
    5596          239 :                   e.value = unshare_constructor (value);
    5597          239 :                   vec_safe_insert (CONSTRUCTOR_ELTS (ary), middle + 1, e);
    5598              :                 }
    5599              :             }
    5600        98682 :           return middle;
    5601              :         }
    5602              :     }
    5603              : 
    5604      3447561 :   if (insert)
    5605              :     {
    5606      3371206 :       constructor_elt e = { dindex, NULL_TREE };
    5607      3371206 :       vec_safe_insert (CONSTRUCTOR_ELTS (ary), end, e);
    5608      3371206 :       return end;
    5609              :     }
    5610              : 
    5611              :   return -1;
    5612              : }
    5613              : 
    5614              : /* Return a pointer to the constructor_elt of CTOR which matches INDEX.  If no
    5615              :    matching constructor_elt exists, then add one to CTOR.
    5616              : 
    5617              :    As an optimization, if POS_HINT is non-negative then it is used as a guess
    5618              :    for the (integer) index of the matching constructor_elt within CTOR.
    5619              : 
    5620              :    If POS_HINT is -2, it means do not insert.  */
    5621              : 
    5622              : static constructor_elt *
    5623     25591101 : get_or_insert_ctor_field (tree ctor, tree index, int pos_hint = -1)
    5624              : {
    5625              :   /* Check the hint first.  */
    5626      2242248 :   if (pos_hint >= 0 && (unsigned)pos_hint < CONSTRUCTOR_NELTS (ctor)
    5627     27833349 :       && CONSTRUCTOR_ELT (ctor, pos_hint)->index == index)
    5628              :     return CONSTRUCTOR_ELT (ctor, pos_hint);
    5629              : 
    5630     23348902 :   bool insertp = (pos_hint != -2);
    5631     23348902 :   tree type = TREE_TYPE (ctor);
    5632     23348902 :   if (TREE_CODE (type) == VECTOR_TYPE && index == NULL_TREE)
    5633              :     {
    5634        11226 :       gcc_assert (insertp);
    5635        11226 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (ctor), index, NULL_TREE);
    5636        11226 :       return &CONSTRUCTOR_ELTS (ctor)->last();
    5637              :     }
    5638     23337676 :   else if (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == VECTOR_TYPE)
    5639              :     {
    5640      4431734 :       if (TREE_CODE (index) == RANGE_EXPR)
    5641              :         {
    5642              :           /* Support for RANGE_EXPR index lookups is currently limited to
    5643              :              accessing an existing element via POS_HINT, or appending a new
    5644              :              element to the end of CTOR.  ??? Support for other access
    5645              :              patterns may also be needed.  */
    5646            3 :           vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (ctor);
    5647            3 :           if (vec_safe_length (elts))
    5648              :             {
    5649            3 :               tree lo = TREE_OPERAND (index, 0);
    5650            3 :               gcc_assert (array_index_cmp (elts->last().index, lo) < 0);
    5651              :             }
    5652            3 :           gcc_assert (insertp);
    5653            3 :           CONSTRUCTOR_APPEND_ELT (elts, index, NULL_TREE);
    5654            3 :           return &elts->last();
    5655              :         }
    5656              : 
    5657      4431731 :       HOST_WIDE_INT i = find_array_ctor_elt (ctor, index, insertp);
    5658      4431731 :       if (i < 0)
    5659              :         {
    5660          919 :           gcc_assert (!insertp);
    5661              :           return nullptr;
    5662              :         }
    5663      4430812 :       constructor_elt *cep = CONSTRUCTOR_ELT (ctor, i);
    5664      4430812 :       if (!insertp && cep->index && TREE_CODE (cep->index) == RANGE_EXPR)
    5665              :         {
    5666              :           /* Split a range even if we aren't inserting new entries.  */
    5667            0 :           gcc_assert (!insertp);
    5668            0 :           i = find_array_ctor_elt (ctor, index, /*insert*/true);
    5669            0 :           gcc_assert (i >= 0);
    5670            0 :           cep = CONSTRUCTOR_ELT (ctor, i);
    5671              :         }
    5672      4430812 :       gcc_assert (cep->index == NULL_TREE
    5673              :                   || TREE_CODE (cep->index) != RANGE_EXPR);
    5674              :       return cep;
    5675              :     }
    5676              :   else
    5677              :     {
    5678     18905942 :       gcc_assert (TREE_CODE (index) == FIELD_DECL
    5679              :                   && (same_type_ignoring_top_level_qualifiers_p
    5680              :                       (DECL_CONTEXT (index), TREE_TYPE (ctor))));
    5681              : 
    5682              :       /* We must keep the CONSTRUCTOR's ELTS in FIELD order.
    5683              :          Usually we meet initializers in that order, but it is
    5684              :          possible for base types to be placed not in program
    5685              :          order.  */
    5686     18905942 :       tree fields = TYPE_FIELDS (DECL_CONTEXT (index));
    5687     18905942 :       unsigned HOST_WIDE_INT idx = 0;
    5688     18905942 :       constructor_elt *cep = NULL;
    5689              : 
    5690              :       /* Check if we're changing the active member of a union.  */
    5691       296884 :       if (TREE_CODE (type) == UNION_TYPE && CONSTRUCTOR_NELTS (ctor)
    5692     19054625 :           && CONSTRUCTOR_ELT (ctor, 0)->index != index)
    5693         4498 :         vec_safe_truncate (CONSTRUCTOR_ELTS (ctor), 0);
    5694              :       /* If the bit offset of INDEX is larger than that of the last
    5695              :          constructor_elt, then we can just immediately append a new
    5696              :          constructor_elt to the end of CTOR.  */
    5697     18901444 :       else if (CONSTRUCTOR_NELTS (ctor)
    5698     25222997 :                && tree_int_cst_compare (bit_position (index),
    5699     24700026 :                                         bit_position (CONSTRUCTOR_ELTS (ctor)
    5700     12350013 :                                                       ->last().index)) > 0)
    5701              :         {
    5702      3650608 :           idx = CONSTRUCTOR_NELTS (ctor);
    5703      3650608 :           goto insert;
    5704              :         }
    5705              : 
    5706              :       /* Otherwise, we need to iterate over CTOR to find or insert INDEX
    5707              :          appropriately.  */
    5708              : 
    5709     16753756 :       for (; vec_safe_iterate (CONSTRUCTOR_ELTS (ctor), idx, &cep);
    5710      1498422 :            idx++, fields = DECL_CHAIN (fields))
    5711              :         {
    5712     10197827 :           if (index == cep->index)
    5713      8676072 :             goto found;
    5714              : 
    5715              :           /* The field we're initializing must be on the field
    5716              :              list.  Look to see if it is present before the
    5717              :              field the current ELT initializes.  */
    5718     16280467 :           for (; fields != cep->index; fields = DECL_CHAIN (fields))
    5719     14782045 :             if (index == fields)
    5720        23333 :               goto insert;
    5721              :         }
    5722              :       /* We fell off the end of the CONSTRUCTOR, so insert a new
    5723              :          entry at the end.  */
    5724              : 
    5725     10229870 :     insert:
    5726     10229870 :       if (!insertp)
    5727              :         return nullptr;
    5728              : 
    5729     10229867 :       {
    5730     10229867 :         constructor_elt ce = { index, NULL_TREE };
    5731              : 
    5732     10229867 :         vec_safe_insert (CONSTRUCTOR_ELTS (ctor), idx, ce);
    5733     10229867 :         cep = CONSTRUCTOR_ELT (ctor, idx);
    5734              :       }
    5735     18905939 :     found:;
    5736              : 
    5737     18905939 :       return cep;
    5738              :     }
    5739              : }
    5740              : 
    5741              : /* Under the control of CTX, issue a detailed diagnostic for
    5742              :    an out-of-bounds subscript INDEX into the expression ARRAY.  */
    5743              : 
    5744              : static void
    5745          570 : diag_array_subscript (location_t loc, const constexpr_ctx *ctx, tree array, tree index)
    5746              : {
    5747          570 :   if (!ctx->quiet)
    5748              :     {
    5749          116 :       tree arraytype = TREE_TYPE (array);
    5750              : 
    5751              :       /* Convert the unsigned array subscript to a signed integer to avoid
    5752              :          printing huge numbers for small negative values.  */
    5753          116 :       tree sidx = fold_convert (ssizetype, index);
    5754          116 :       STRIP_ANY_LOCATION_WRAPPER (array);
    5755          116 :       if (DECL_P (array))
    5756              :         {
    5757           75 :           auto_diagnostic_group d;
    5758           75 :           if (TYPE_DOMAIN (arraytype))
    5759           69 :             error_at (loc, "array subscript value %qE is outside the bounds "
    5760              :                       "of array %qD of type %qT", sidx, array, arraytype);
    5761              :           else
    5762            6 :             error_at (loc, "nonzero array subscript %qE is used with array %qD of "
    5763              :                       "type %qT with unknown bounds", sidx, array, arraytype);
    5764           75 :           inform (DECL_SOURCE_LOCATION (array), "declared here");
    5765           75 :         }
    5766           41 :       else if (TYPE_DOMAIN (arraytype))
    5767           38 :         error_at (loc, "array subscript value %qE is outside the bounds "
    5768              :                   "of array type %qT", sidx, arraytype);
    5769              :       else
    5770            3 :         error_at (loc, "nonzero array subscript %qE is used with array of type %qT "
    5771              :                   "with unknown bounds", sidx, arraytype);
    5772              :     }
    5773          570 : }
    5774              : 
    5775              : /* Return the number of elements for TYPE (which is an ARRAY_TYPE or
    5776              :    a VECTOR_TYPE).  */
    5777              : 
    5778              : static tree
    5779     12122057 : get_array_or_vector_nelts (const constexpr_ctx *ctx, tree type,
    5780              :                            bool *non_constant_p, bool *overflow_p,
    5781              :                            tree *jump_target)
    5782              : {
    5783     12122057 :   tree nelts;
    5784     12122057 :   if (TREE_CODE (type) == ARRAY_TYPE)
    5785              :     {
    5786     12122057 :       if (TYPE_DOMAIN (type))
    5787     12121809 :         nelts = array_type_nelts_top (type);
    5788              :       else
    5789          248 :         nelts = size_zero_node;
    5790              :     }
    5791            0 :   else if (VECTOR_TYPE_P (type))
    5792            0 :     nelts = size_int (TYPE_VECTOR_SUBPARTS (type));
    5793              :   else
    5794            0 :     gcc_unreachable ();
    5795              : 
    5796              :   /* For VLAs, the number of elements won't be an integer constant.  */
    5797     12122057 :   nelts = cxx_eval_constant_expression (ctx, nelts, vc_prvalue,
    5798              :                                         non_constant_p, overflow_p,
    5799              :                                         jump_target);
    5800     12122057 :   return nelts;
    5801              : }
    5802              : 
    5803              : /* Extract element INDEX consisting of CHARS_PER_ELT chars from
    5804              :    STRING_CST STRING.  */
    5805              : 
    5806              : static tree
    5807      1594391 : extract_string_elt (tree string, unsigned chars_per_elt, unsigned index)
    5808              : {
    5809      1594391 :   tree type = cv_unqualified (TREE_TYPE (TREE_TYPE (string)));
    5810      1594391 :   tree r;
    5811              : 
    5812      1594391 :   if (chars_per_elt == 1)
    5813      1451734 :     r = build_int_cst (type, TREE_STRING_POINTER (string)[index]);
    5814              :   else
    5815              :     {
    5816       142657 :       const unsigned char *ptr
    5817       142657 :         = ((const unsigned char *)TREE_STRING_POINTER (string)
    5818       142657 :            + index * chars_per_elt);
    5819       142657 :       r = native_interpret_expr (type, ptr, chars_per_elt);
    5820              :     }
    5821      1594391 :   return r;
    5822              : }
    5823              : 
    5824              : /* Subroutine of cxx_eval_array_reference.  T is an ARRAY_REF; evaluate the
    5825              :    subscript, diagnose any problems with it, and return the result.  */
    5826              : 
    5827              : static tree
    5828     12308785 : eval_and_check_array_index (const constexpr_ctx *ctx,
    5829              :                             tree t, bool allow_one_past,
    5830              :                             bool *non_constant_p, bool *overflow_p,
    5831              :                             tree *jump_target)
    5832              : {
    5833     12308785 :   location_t loc = cp_expr_loc_or_input_loc (t);
    5834     12308785 :   tree ary = TREE_OPERAND (t, 0);
    5835     12308785 :   t = TREE_OPERAND (t, 1);
    5836     12308785 :   tree index = cxx_eval_constant_expression (ctx, t, vc_prvalue,
    5837              :                                              non_constant_p, overflow_p,
    5838              :                                              jump_target);
    5839     12308785 :   if (*jump_target)
    5840              :     return NULL_TREE;
    5841     12308785 :   VERIFY_CONSTANT (index);
    5842              : 
    5843     12121504 :   if (!tree_fits_shwi_p (index)
    5844     12121504 :       || tree_int_cst_sgn (index) < 0)
    5845              :     {
    5846          112 :       diag_array_subscript (loc, ctx, ary, index);
    5847          112 :       *non_constant_p = true;
    5848          112 :       return t;
    5849              :     }
    5850              : 
    5851     12121392 :   tree nelts = get_array_or_vector_nelts (ctx, TREE_TYPE (ary), non_constant_p,
    5852              :                                           overflow_p, jump_target);
    5853     12121392 :   if (*jump_target)
    5854              :     return NULL_TREE;
    5855     12121392 :   VERIFY_CONSTANT (nelts);
    5856     12121329 :   if (allow_one_past
    5857     12121329 :       ? !tree_int_cst_le (index, nelts)
    5858      7782277 :       : !tree_int_cst_lt (index, nelts))
    5859              :     {
    5860          458 :       diag_array_subscript (loc, ctx, ary, index);
    5861          458 :       *non_constant_p = true;
    5862          458 :       return t;
    5863              :     }
    5864              : 
    5865              :   return index;
    5866              : }
    5867              : 
    5868              : /* Subroutine of cxx_eval_constant_expression.
    5869              :    Attempt to reduce a reference to an array slot.  */
    5870              : 
    5871              : static tree
    5872      8289696 : cxx_eval_array_reference (const constexpr_ctx *ctx, tree t,
    5873              :                           value_cat lval,
    5874              :                           bool *non_constant_p, bool *overflow_p,
    5875              :                           tree *jump_target)
    5876              : {
    5877      8289696 :   tree oldary = TREE_OPERAND (t, 0);
    5878      8289696 :   tree ary = cxx_eval_constant_expression (ctx, oldary,
    5879              :                                            lval,
    5880              :                                            non_constant_p, overflow_p,
    5881              :                                            jump_target);
    5882      8289696 :   if (*non_constant_p)
    5883              :     return t;
    5884      8092633 :   if (*jump_target)
    5885              :     return NULL_TREE;
    5886      8092633 :   if (!lval
    5887      3752246 :       && TREE_CODE (ary) == VIEW_CONVERT_EXPR
    5888        54095 :       && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (ary, 0)))
    5889      8146728 :       && (TYPE_MAIN_VARIANT (TREE_TYPE (t))
    5890        54095 :           == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_OPERAND (ary, 0))))))
    5891        54095 :     ary = TREE_OPERAND (ary, 0);
    5892              : 
    5893      8092633 :   tree oldidx = TREE_OPERAND (t, 1);
    5894      8092633 :   tree index = eval_and_check_array_index (ctx, t, lval,
    5895              :                                            non_constant_p, overflow_p,
    5896              :                                            jump_target);
    5897      8092633 :   if (*non_constant_p)
    5898              :     return t;
    5899      7904785 :   if (*jump_target)
    5900              :     return NULL_TREE;
    5901              : 
    5902      7904785 :   if (lval && ary == oldary && index == oldidx)
    5903              :     return t;
    5904      4366583 :   else if (lval == vc_discard)
    5905              :     return t;
    5906      4366583 :   else if (lval)
    5907       800610 :     return build4 (ARRAY_REF, TREE_TYPE (t), ary, index, NULL, NULL);
    5908              : 
    5909      3565973 :   unsigned len = 0, elem_nchars = 1;
    5910      3565973 :   tree elem_type = TREE_TYPE (TREE_TYPE (ary));
    5911      3565973 :   if (TREE_CODE (ary) == CONSTRUCTOR)
    5912      1927785 :     len = CONSTRUCTOR_NELTS (ary);
    5913      1638188 :   else if (TREE_CODE (ary) == STRING_CST)
    5914              :     {
    5915      1584101 :       elem_nchars = (TYPE_PRECISION (elem_type)
    5916      1584101 :                      / TYPE_PRECISION (char_type_node));
    5917      1584101 :       len = (unsigned) TREE_STRING_LENGTH (ary) / elem_nchars;
    5918              :     }
    5919        54087 :   else if (TREE_CODE (ary) == VECTOR_CST)
    5920              :     /* We don't create variable-length VECTOR_CSTs.  */
    5921        54087 :     len = VECTOR_CST_NELTS (ary).to_constant ();
    5922              :   else
    5923              :     {
    5924              :       /* We can't do anything with other tree codes, so use
    5925              :          VERIFY_CONSTANT to complain and fail.  */
    5926            0 :       VERIFY_CONSTANT (ary);
    5927            0 :       gcc_unreachable ();
    5928              :     }
    5929              : 
    5930      3565973 :   bool found;
    5931      3565973 :   HOST_WIDE_INT i = 0;
    5932      3565973 :   if (TREE_CODE (ary) == CONSTRUCTOR)
    5933              :     {
    5934      1927785 :       HOST_WIDE_INT ix = find_array_ctor_elt (ary, index);
    5935      1927785 :       found = (ix >= 0);
    5936      1927785 :       if (found)
    5937      1852437 :         i = ix;
    5938              :     }
    5939              :   else
    5940              :     {
    5941      1638188 :       i = tree_to_shwi (index);
    5942      1638188 :       found = (i < len);
    5943              :     }
    5944              : 
    5945      3565973 :   if (found)
    5946              :     {
    5947      3490174 :       tree r;
    5948      3490174 :       if (TREE_CODE (ary) == CONSTRUCTOR)
    5949              :         {
    5950      1852437 :           r = (*CONSTRUCTOR_ELTS (ary))[i].value;
    5951      1852437 :           if (TREE_CODE (r) == RAW_DATA_CST)
    5952              :             {
    5953        29194 :               tree ridx = (*CONSTRUCTOR_ELTS (ary))[i].index;
    5954        29194 :               gcc_checking_assert (ridx);
    5955        29194 :               unsigned int off
    5956        29194 :                 = (wi::to_offset (index) - wi::to_offset (ridx)).to_uhwi ();
    5957        29194 :               r = raw_data_cst_elt (r, off);
    5958              :             }
    5959              :         }
    5960      1637737 :       else if (TREE_CODE (ary) == VECTOR_CST)
    5961        54087 :         r = VECTOR_CST_ELT (ary, i);
    5962              :       else
    5963      1583650 :         r = extract_string_elt (ary, elem_nchars, i);
    5964              : 
    5965      1666931 :       if (r)
    5966              :         /* Don't VERIFY_CONSTANT here.  */
    5967      3490174 :         return r;
    5968              : 
    5969              :       /* Otherwise the element doesn't have a value yet.  */
    5970              :     }
    5971              : 
    5972              :   /* Not found.  */
    5973              : 
    5974        75799 :   if (is_really_empty_class (elem_type, /*ignore_vptr*/false))
    5975           72 :     return build_constructor (elem_type, NULL);
    5976              : 
    5977        75727 :   if (TREE_CODE (ary) == CONSTRUCTOR
    5978        75727 :       && CONSTRUCTOR_NO_CLEARING (ary))
    5979              :     {
    5980              :       /* 'ary' is part of the aggregate initializer we're currently
    5981              :          building; if there's no initializer for this element yet,
    5982              :          that's an error.  */
    5983           51 :       if (!ctx->quiet)
    5984           16 :         error ("accessing uninitialized array element");
    5985           51 :       *non_constant_p = true;
    5986           51 :       return t;
    5987              :     }
    5988              : 
    5989              :   /* If it's within the array bounds but doesn't have an explicit
    5990              :      initializer, it's initialized from {}.  But use build_value_init
    5991              :      directly for non-aggregates to avoid creating a garbage CONSTRUCTOR.  */
    5992        75676 :   tree val;
    5993        75676 :   constexpr_ctx new_ctx;
    5994        75676 :   if (CP_AGGREGATE_TYPE_P (elem_type))
    5995              :     {
    5996          494 :       tree empty_ctor = build_constructor (init_list_type_node, NULL);
    5997          494 :       val = digest_init (elem_type, empty_ctor, tf_warning_or_error);
    5998              :     }
    5999              :   else
    6000        75182 :     val = build_value_init (elem_type, tf_warning_or_error);
    6001              : 
    6002              :   /* Create a new constructor only if we don't already have a suitable one.  */
    6003        75676 :   const bool new_ctor = (!SCALAR_TYPE_P (elem_type)
    6004        76202 :                          && (!ctx->ctor
    6005           45 :                              || !same_type_ignoring_top_level_qualifiers_p
    6006           45 :                                   (elem_type, TREE_TYPE (ctx->ctor))));
    6007          517 :   if (new_ctor)
    6008              :     {
    6009          517 :       new_ctx = *ctx;
    6010              :       /* We clear the object here.  We used to replace it with T, but that
    6011              :          caused problems (101371, 108158); and anyway, T is the initializer,
    6012              :          not the target object.  */
    6013          517 :       new_ctx.object = NULL_TREE;
    6014          517 :       new_ctx.ctor = build_constructor (elem_type, NULL);
    6015          517 :       ctx = &new_ctx;
    6016              :     }
    6017        75676 :   t = cxx_eval_constant_expression (ctx, val, lval, non_constant_p,
    6018              :                                     overflow_p, jump_target);
    6019        75676 :   if (new_ctor && t != ctx->ctor)
    6020          496 :     free_constructor (ctx->ctor);
    6021              :   return t;
    6022              : }
    6023              : 
    6024              : /* Subroutine of cxx_eval_constant_expression.
    6025              :    Attempt to reduce a field access of a value of class type.  */
    6026              : 
    6027              : static tree
    6028     65538762 : cxx_eval_component_reference (const constexpr_ctx *ctx, tree t,
    6029              :                               value_cat lval,
    6030              :                               bool *non_constant_p, bool *overflow_p,
    6031              :                               tree *jump_target)
    6032              : {
    6033     65538762 :   unsigned HOST_WIDE_INT i;
    6034     65538762 :   tree field;
    6035     65538762 :   tree value;
    6036     65538762 :   tree part = TREE_OPERAND (t, 1);
    6037     65538762 :   tree orig_whole = TREE_OPERAND (t, 0);
    6038     65538762 :   tree whole = cxx_eval_constant_expression (ctx, orig_whole,
    6039              :                                              lval,
    6040              :                                              non_constant_p, overflow_p,
    6041              :                                              jump_target);
    6042     65538762 :   if (*non_constant_p)
    6043              :     return t;
    6044     45711455 :   if (*jump_target)
    6045              :     return NULL_TREE;
    6046     45711452 :   if (INDIRECT_REF_P (whole)
    6047     45711452 :       && integer_zerop (TREE_OPERAND (whole, 0)))
    6048              :     {
    6049          177 :       if (!ctx->quiet)
    6050           39 :         error ("dereferencing a null pointer in %qE", orig_whole);
    6051          177 :       *non_constant_p = true;
    6052          177 :       return t;
    6053              :     }
    6054              : 
    6055     45711275 :   if (TREE_CODE (whole) == PTRMEM_CST)
    6056         1486 :     whole = cplus_expand_constant (whole);
    6057     45711275 :   if (whole == orig_whole)
    6058              :     return t;
    6059     28558400 :   if (lval == vc_discard)
    6060              :     return t;
    6061     28558376 :   if (lval)
    6062     10186299 :     return fold_build3 (COMPONENT_REF, TREE_TYPE (t),
    6063              :                         whole, part, NULL_TREE);
    6064              :   /* Don't VERIFY_CONSTANT here; we only want to check that we got a
    6065              :      CONSTRUCTOR.  */
    6066     18372077 :   if (TREE_CODE (whole) != CONSTRUCTOR)
    6067              :     {
    6068            0 :       if (!ctx->quiet)
    6069            0 :         error ("%qE is not a constant expression", orig_whole);
    6070            0 :       *non_constant_p = true;
    6071            0 :       return t;
    6072              :     }
    6073     18370585 :   if ((cxx_dialect < cxx14 || CONSTRUCTOR_MUTABLE_POISON (whole))
    6074     18373751 :       && DECL_MUTABLE_P (part))
    6075              :     {
    6076          144 :       if (!ctx->quiet)
    6077           16 :         error ("mutable %qD is not usable in a constant expression", part);
    6078          144 :       *non_constant_p = true;
    6079          144 :       return t;
    6080              :     }
    6081              : 
    6082     18371933 :   bool pmf = TYPE_PTRMEMFUNC_P (TREE_TYPE (whole));
    6083     26488769 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (whole), i, field, value)
    6084              :     {
    6085              :       /* Use name match for PMF fields, as a variant will have a
    6086              :          different FIELD_DECL with a different type.  */
    6087     26390108 :       if (pmf ? DECL_NAME (field) == DECL_NAME (part)
    6088              :           : field == part)
    6089              :         {
    6090     18273272 :           if (value == void_node)
    6091            3 :             goto uninit;
    6092     18273269 :           if (value)
    6093              :             {
    6094     18273251 :               STRIP_ANY_LOCATION_WRAPPER (value);
    6095     18273251 :               return value;
    6096              :             }
    6097              :           else
    6098              :             /* We're in the middle of initializing it.  */
    6099              :             break;
    6100              :         }
    6101              :     }
    6102        98679 :   if (TREE_CODE (TREE_TYPE (whole)) == UNION_TYPE)
    6103              :     {
    6104          106 :       if (CONSTRUCTOR_NELTS (whole) > 0)
    6105              :         {
    6106              :           /* DR 1188 says we don't have to deal with this.  */
    6107           91 :           if (!ctx->quiet)
    6108              :             {
    6109           19 :               constructor_elt *cep = CONSTRUCTOR_ELT (whole, 0);
    6110           19 :               if (cep->value == NULL_TREE)
    6111            9 :                 error ("accessing uninitialized member %qD", part);
    6112              :               else
    6113           10 :                 error ("accessing %qD member instead of active %qD member "
    6114              :                        "in constant expression", part, cep->index);
    6115              :             }
    6116           91 :           *non_constant_p = true;
    6117           91 :           return t;
    6118              :         }
    6119           15 :       else if (!CONSTRUCTOR_NO_CLEARING (whole))
    6120              :         {
    6121              :           /* Value-initialized union, check if looking at the first member.  */
    6122           12 :           tree first = next_aggregate_field (TYPE_FIELDS (TREE_TYPE (whole)));
    6123           12 :           if (first != part)
    6124              :             {
    6125            9 :               if (!ctx->quiet)
    6126            3 :                 error ("accessing %qD member instead of initialized %qD "
    6127              :                        "member in constant expression", part, first);
    6128            9 :               *non_constant_p = true;
    6129            9 :               return t;
    6130              :             }
    6131              :         }
    6132              :     }
    6133              : 
    6134              :   /* We only create a CONSTRUCTOR for a subobject when we modify it, so empty
    6135              :      classes never get represented; throw together a value now.  */
    6136        98579 :   if (is_really_empty_class (TREE_TYPE (t), /*ignore_vptr*/false))
    6137        89982 :     return build_constructor (TREE_TYPE (t), NULL);
    6138              : 
    6139         8597 :   gcc_assert (DECL_CONTEXT (part) == TYPE_MAIN_VARIANT (TREE_TYPE (whole)));
    6140              : 
    6141         8597 :   if (CONSTRUCTOR_NO_CLEARING (whole))
    6142              :     {
    6143          101 :     uninit:
    6144              :       /* 'whole' is part of the aggregate initializer we're currently
    6145              :          building; if there's no initializer for this member yet, that's an
    6146              :          error.  */
    6147          104 :       if (!ctx->quiet)
    6148           22 :         error ("accessing uninitialized member %qD", part);
    6149          104 :       *non_constant_p = true;
    6150          104 :       return t;
    6151              :     }
    6152              : 
    6153              :   /* If there's no explicit init for this field, it's value-initialized.  */
    6154              : 
    6155         8496 :   if (AGGREGATE_TYPE_P (TREE_TYPE (t)))
    6156              :     {
    6157              :       /* As in cxx_eval_store_expression, insert an empty CONSTRUCTOR
    6158              :          and copy the flags.  */
    6159         7988 :       constructor_elt *e = get_or_insert_ctor_field (whole, part);
    6160         7988 :       e->value = value = build_constructor (TREE_TYPE (part), NULL);
    6161         7988 :       CONSTRUCTOR_ZERO_PADDING_BITS (value)
    6162         7988 :         = CONSTRUCTOR_ZERO_PADDING_BITS (whole);
    6163         7988 :       return value;
    6164              :     }
    6165              : 
    6166          508 :   value = build_value_init (TREE_TYPE (t), tf_warning_or_error);
    6167          508 :   return cxx_eval_constant_expression (ctx, value,
    6168              :                                        lval,
    6169              :                                        non_constant_p, overflow_p,
    6170          508 :                                        jump_target);
    6171              : }
    6172              : 
    6173              : /* Subroutine of cxx_eval_constant_expression.
    6174              :    Attempt to reduce a field access of a value of class type that is
    6175              :    expressed as a BIT_FIELD_REF.  */
    6176              : 
    6177              : static tree
    6178        15766 : cxx_eval_bit_field_ref (const constexpr_ctx *ctx, tree t,
    6179              :                         value_cat lval,
    6180              :                         bool *non_constant_p, bool *overflow_p,
    6181              :                         tree *jump_target)
    6182              : {
    6183        15766 :   tree orig_whole = TREE_OPERAND (t, 0);
    6184        15766 :   tree retval, fldval, utype, mask;
    6185        15766 :   bool fld_seen = false;
    6186        15766 :   HOST_WIDE_INT istart, isize;
    6187        15766 :   tree whole = cxx_eval_constant_expression (ctx, orig_whole,
    6188              :                                              lval,
    6189              :                                              non_constant_p, overflow_p,
    6190              :                                              jump_target);
    6191        15766 :   tree start, field, value;
    6192        15766 :   unsigned HOST_WIDE_INT i;
    6193              : 
    6194        15766 :   if (*jump_target)
    6195              :     return NULL_TREE;
    6196        15766 :   if (whole == orig_whole)
    6197              :     return t;
    6198              :   /* Don't VERIFY_CONSTANT here; we only want to check that we got a
    6199              :      CONSTRUCTOR.  */
    6200        15574 :   if (!*non_constant_p
    6201        15574 :       && TREE_CODE (whole) != VECTOR_CST
    6202         1495 :       && TREE_CODE (whole) != CONSTRUCTOR)
    6203              :     {
    6204            0 :       if (!ctx->quiet)
    6205            0 :         error ("%qE is not a constant expression", orig_whole);
    6206            0 :       *non_constant_p = true;
    6207              :     }
    6208        15574 :   if (*non_constant_p)
    6209              :     return t;
    6210              : 
    6211        15574 :   if (TREE_CODE (whole) == VECTOR_CST || !INTEGRAL_TYPE_P (TREE_TYPE (t)))
    6212              :     {
    6213        14079 :       if (tree r = fold_ternary (BIT_FIELD_REF, TREE_TYPE (t), whole,
    6214              :                                  TREE_OPERAND (t, 1), TREE_OPERAND (t, 2)))
    6215              :         return r;
    6216            0 :       if (!ctx->quiet)
    6217            0 :         error ("%qE is not a constant expression", orig_whole);
    6218            0 :       *non_constant_p = true;
    6219            0 :       return t;
    6220              :     }
    6221              : 
    6222         1495 :   start = TREE_OPERAND (t, 2);
    6223         1495 :   istart = tree_to_shwi (start);
    6224         1495 :   isize = tree_to_shwi (TREE_OPERAND (t, 1));
    6225         1495 :   utype = TREE_TYPE (t);
    6226         1495 :   if (!TYPE_UNSIGNED (utype))
    6227            0 :     utype = build_nonstandard_integer_type (TYPE_PRECISION (utype), 1);
    6228         1495 :   retval = build_int_cst (utype, 0);
    6229        20930 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (whole), i, field, value)
    6230              :     {
    6231        19435 :       tree bitpos = bit_position (field);
    6232        19435 :       STRIP_ANY_LOCATION_WRAPPER (value);
    6233        19435 :       if (bitpos == start && DECL_SIZE (field) == TREE_OPERAND (t, 1))
    6234              :         return value;
    6235        19435 :       if (TREE_CODE (TREE_TYPE (field)) == INTEGER_TYPE
    6236        19435 :           && TREE_CODE (value) == INTEGER_CST
    6237        19435 :           && tree_fits_shwi_p (bitpos)
    6238        38870 :           && tree_fits_shwi_p (DECL_SIZE (field)))
    6239              :         {
    6240        19435 :           HOST_WIDE_INT bit = tree_to_shwi (bitpos);
    6241        19435 :           HOST_WIDE_INT sz = tree_to_shwi (DECL_SIZE (field));
    6242        19435 :           HOST_WIDE_INT shift;
    6243        19435 :           if (bit >= istart && bit + sz <= istart + isize)
    6244              :             {
    6245         4485 :               fldval = fold_convert (utype, value);
    6246         4485 :               mask = build_int_cst_type (utype, -1);
    6247         4485 :               mask = fold_build2 (LSHIFT_EXPR, utype, mask,
    6248              :                                   size_int (TYPE_PRECISION (utype) - sz));
    6249         4485 :               mask = fold_build2 (RSHIFT_EXPR, utype, mask,
    6250              :                                   size_int (TYPE_PRECISION (utype) - sz));
    6251         4485 :               fldval = fold_build2 (BIT_AND_EXPR, utype, fldval, mask);
    6252         4485 :               shift = bit - istart;
    6253         4485 :               if (BYTES_BIG_ENDIAN)
    6254              :                 shift = TYPE_PRECISION (utype) - shift - sz;
    6255         4485 :               fldval = fold_build2 (LSHIFT_EXPR, utype, fldval,
    6256              :                                     size_int (shift));
    6257         4485 :               retval = fold_build2 (BIT_IOR_EXPR, utype, retval, fldval);
    6258         4485 :               fld_seen = true;
    6259              :             }
    6260              :         }
    6261              :     }
    6262         1495 :   if (fld_seen)
    6263         1495 :     return fold_convert (TREE_TYPE (t), retval);
    6264            0 :   gcc_unreachable ();
    6265              :   return error_mark_node;
    6266              : }
    6267              : 
    6268              : /* Helper for cxx_eval_bit_cast.
    6269              :    Check [bit.cast]/3 rules, bit_cast is constexpr only if the To and From
    6270              :    types and types of all subobjects have is_union_v<T>, is_pointer_v<T>,
    6271              :    is_member_pointer_v<T>, is_volatile_v<T> false and has no non-static
    6272              :    data members of reference type.  */
    6273              : 
    6274              : static bool
    6275         5538 : check_bit_cast_type (const constexpr_ctx *ctx, location_t loc, tree type,
    6276              :                      tree orig_type)
    6277              : {
    6278         6061 :   if (TREE_CODE (type) == UNION_TYPE)
    6279              :     {
    6280           63 :       if (!ctx->quiet)
    6281              :         {
    6282           21 :           if (type == orig_type)
    6283            6 :             error_at (loc, "%qs is not a constant expression because %qT is "
    6284              :                            "a union type", "__builtin_bit_cast", type);
    6285              :           else
    6286           15 :             error_at (loc, "%qs is not a constant expression because %qT "
    6287              :                            "contains a union type", "__builtin_bit_cast",
    6288              :                       orig_type);
    6289              :         }
    6290           63 :       return true;
    6291              :     }
    6292              :   if (TREE_CODE (type) == POINTER_TYPE)
    6293              :     {
    6294           57 :       if (!ctx->quiet)
    6295              :         {
    6296           18 :           if (type == orig_type)
    6297            6 :             error_at (loc, "%qs is not a constant expression because %qT is "
    6298              :                            "a pointer type", "__builtin_bit_cast", type);
    6299              :           else
    6300           12 :             error_at (loc, "%qs is not a constant expression because %qT "
    6301              :                            "contains a pointer type", "__builtin_bit_cast",
    6302              :                       orig_type);
    6303              :         }
    6304           57 :       return true;
    6305              :     }
    6306              :   if (TREE_CODE (type) == REFERENCE_TYPE)
    6307              :     {
    6308            0 :       if (!ctx->quiet)
    6309              :         {
    6310            0 :           if (type == orig_type)
    6311            0 :             error_at (loc, "%qs is not a constant expression because %qT is "
    6312              :                            "a reference type", "__builtin_bit_cast", type);
    6313              :           else
    6314            0 :             error_at (loc, "%qs is not a constant expression because %qT "
    6315              :                            "contains a reference type", "__builtin_bit_cast",
    6316              :                       orig_type);
    6317              :         }
    6318            0 :       return true;
    6319              :     }
    6320         1887 :   if (TYPE_PTRMEM_P (type))
    6321              :     {
    6322           36 :       if (!ctx->quiet)
    6323              :         {
    6324           12 :           if (type == orig_type)
    6325           12 :             error_at (loc, "%qs is not a constant expression because %qT is "
    6326              :                            "a pointer to member type", "__builtin_bit_cast",
    6327              :                       type);
    6328              :           else
    6329            0 :             error_at (loc, "%qs is not a constant expression because %qT "
    6330              :                            "contains a pointer to member type",
    6331              :                       "__builtin_bit_cast", orig_type);
    6332              :         }
    6333           36 :       return true;
    6334              :     }
    6335         5905 :   if (TYPE_VOLATILE (type))
    6336              :     {
    6337            0 :       if (!ctx->quiet)
    6338              :         {
    6339            0 :           if (type == orig_type)
    6340            0 :             error_at (loc, "%qs is not a constant expression because %qT is "
    6341              :                            "volatile", "__builtin_bit_cast", type);
    6342              :           else
    6343            0 :             error_at (loc, "%qs is not a constant expression because %qT "
    6344              :                            "contains a volatile subobject",
    6345              :                       "__builtin_bit_cast", orig_type);
    6346              :         }
    6347            0 :       return true;
    6348              :     }
    6349         5905 :   if (TREE_CODE (type) == RECORD_TYPE)
    6350        58406 :     for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    6351        56627 :       if (TREE_CODE (field) == FIELD_DECL
    6352        56627 :           && check_bit_cast_type (ctx, loc, TREE_TYPE (field), orig_type))
    6353              :         return true;
    6354         5815 :   if (TREE_CODE (type) == ARRAY_TYPE)
    6355          523 :     return check_bit_cast_type (ctx, loc, TREE_TYPE (type), orig_type);
    6356              :   return false;
    6357              : }
    6358              : 
    6359              : /* Helper function for cxx_eval_bit_cast.  For unsigned char or
    6360              :    std::byte members of CONSTRUCTOR (recursively) if they contain
    6361              :    some indeterminate bits (as set in MASK), remove the ctor elts,
    6362              :    mark the CONSTRUCTOR as CONSTRUCTOR_NO_CLEARING and clear the
    6363              :    bits in MASK.  */
    6364              : 
    6365              : static void
    6366          707 : clear_uchar_or_std_byte_in_mask (location_t loc, tree t, unsigned char *mask)
    6367              : {
    6368          707 :   if (TREE_CODE (t) != CONSTRUCTOR)
    6369              :     return;
    6370              : 
    6371              :   unsigned i, j = 0;
    6372              :   tree index, value;
    6373         2284 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), i, index, value)
    6374              :     {
    6375         1577 :       tree type = TREE_TYPE (value);
    6376         1577 :       if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
    6377         2715 :           && DECL_BIT_FIELD_TYPE (index) != NULL_TREE)
    6378              :         {
    6379          270 :           if (is_byte_access_type_not_plain_char (DECL_BIT_FIELD_TYPE (index)))
    6380              :             {
    6381          135 :               HOST_WIDE_INT fldsz = TYPE_PRECISION (TREE_TYPE (index));
    6382          135 :               gcc_assert (fldsz != 0);
    6383          135 :               HOST_WIDE_INT pos = int_byte_position (index);
    6384          135 :               HOST_WIDE_INT bpos
    6385          135 :                 = tree_to_uhwi (DECL_FIELD_BIT_OFFSET (index));
    6386          135 :               bpos %= BITS_PER_UNIT;
    6387          135 :               HOST_WIDE_INT end
    6388          135 :                 = ROUND_UP (bpos + fldsz, BITS_PER_UNIT) / BITS_PER_UNIT;
    6389          135 :               gcc_assert (end == 1 || end == 2);
    6390          135 :               unsigned char *p = mask + pos;
    6391          135 :               unsigned char mask_save[2];
    6392          135 :               mask_save[0] = mask[pos];
    6393          135 :               mask_save[1] = end == 2 ? mask[pos + 1] : 0;
    6394          135 :               if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
    6395              :                 sorry_at (loc, "PDP11 bit-field handling unsupported"
    6396              :                                " in %qs", "__builtin_bit_cast");
    6397          135 :               else if (BYTES_BIG_ENDIAN)
    6398              :                 {
    6399              :                   /* Big endian.  */
    6400              :                   if (bpos + fldsz <= BITS_PER_UNIT)
    6401              :                     *p &= ~(((1 << fldsz) - 1)
    6402              :                             << (BITS_PER_UNIT - bpos - fldsz));
    6403              :                   else
    6404              :                     {
    6405              :                       gcc_assert (bpos);
    6406              :                       *p &= ~(((1U << BITS_PER_UNIT) - 1) >> bpos);
    6407              :                       p++;
    6408              :                       fldsz -= BITS_PER_UNIT - bpos;
    6409              :                       gcc_assert (fldsz && fldsz < BITS_PER_UNIT);
    6410              :                       *p &= ((1U << BITS_PER_UNIT) - 1) >> fldsz;
    6411              :                     }
    6412              :                 }
    6413              :               else
    6414              :                 {
    6415              :                   /* Little endian.  */
    6416          135 :                   if (bpos + fldsz <= BITS_PER_UNIT)
    6417          135 :                     *p &= ~(((1 << fldsz) - 1) << bpos);
    6418              :                   else
    6419              :                     {
    6420            0 :                       gcc_assert (bpos);
    6421            0 :                       *p &= ~(((1 << BITS_PER_UNIT) - 1) << bpos);
    6422            0 :                       p++;
    6423            0 :                       fldsz -= BITS_PER_UNIT - bpos;
    6424            0 :                       gcc_assert (fldsz && fldsz < BITS_PER_UNIT);
    6425            0 :                       *p &= ~((1 << fldsz) - 1);
    6426              :                     }
    6427              :                 }
    6428          135 :               if (mask_save[0] != mask[pos]
    6429           99 :                   || (end == 2 && mask_save[1] != mask[pos + 1]))
    6430              :                 {
    6431           36 :                   CONSTRUCTOR_NO_CLEARING (t) = 1;
    6432           36 :                   continue;
    6433              :                 }
    6434              :             }
    6435              :         }
    6436         1307 :       else if (is_byte_access_type_not_plain_char (type))
    6437              :         {
    6438          228 :           HOST_WIDE_INT pos;
    6439          228 :           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    6440          132 :             pos = tree_to_shwi (index);
    6441              :           else
    6442           96 :             pos = int_byte_position (index);
    6443          228 :           if (mask[pos])
    6444              :             {
    6445           48 :               CONSTRUCTOR_NO_CLEARING (t) = 1;
    6446           48 :               mask[pos] = 0;
    6447           48 :               continue;
    6448              :             }
    6449              :         }
    6450         1493 :       if (TREE_CODE (value) == CONSTRUCTOR)
    6451              :         {
    6452          368 :           HOST_WIDE_INT pos;
    6453          368 :           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    6454          144 :             pos = tree_to_shwi (index)
    6455           72 :                   * tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))));
    6456              :           else
    6457          296 :             pos = int_byte_position (index);
    6458          368 :           clear_uchar_or_std_byte_in_mask (loc, value, mask + pos);
    6459              :         }
    6460         1493 :       if (i != j)
    6461              :         {
    6462          180 :           CONSTRUCTOR_ELT (t, j)->index = index;
    6463          180 :           CONSTRUCTOR_ELT (t, j)->value = value;
    6464              :         }
    6465         1493 :       ++j;
    6466              :     }
    6467         1414 :   if (CONSTRUCTOR_NELTS (t) != j)
    6468           84 :     vec_safe_truncate (CONSTRUCTOR_ELTS (t), j);
    6469              : }
    6470              : 
    6471              : /* Subroutine of cxx_eval_constant_expression.
    6472              :    Attempt to evaluate a BIT_CAST_EXPR.  */
    6473              : 
    6474              : static tree
    6475         1125 : cxx_eval_bit_cast (const constexpr_ctx *ctx, tree t, bool *non_constant_p,
    6476              :                    bool *overflow_p, tree *jump_target)
    6477              : {
    6478         1125 :   if (check_bit_cast_type (ctx, EXPR_LOCATION (t), TREE_TYPE (t),
    6479         1125 :                            TREE_TYPE (t))
    6480         3652 :       || check_bit_cast_type (ctx, cp_expr_loc_or_loc (TREE_OPERAND (t, 0),
    6481         1044 :                                                        EXPR_LOCATION (t)),
    6482         1044 :                               TREE_TYPE (TREE_OPERAND (t, 0)),
    6483         1044 :                               TREE_TYPE (TREE_OPERAND (t, 0))))
    6484              :     {
    6485          156 :       *non_constant_p = true;
    6486          156 :       return t;
    6487              :     }
    6488              : 
    6489          969 :   tree op = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), vc_prvalue,
    6490              :                                           non_constant_p, overflow_p,
    6491              :                                           jump_target);
    6492          969 :   if (*non_constant_p)
    6493              :     return t;
    6494          708 :   if (*jump_target)
    6495              :     return NULL_TREE;
    6496              : 
    6497          708 :   location_t loc = EXPR_LOCATION (t);
    6498          708 :   if (BITS_PER_UNIT != 8 || CHAR_BIT != 8)
    6499              :     {
    6500              :       if (!ctx->quiet)
    6501              :         sorry_at (loc, "%qs cannot be constant evaluated on the target",
    6502              :                        "__builtin_bit_cast");
    6503              :       *non_constant_p = true;
    6504              :       return t;
    6505              :     }
    6506              : 
    6507          708 :   if (!tree_fits_shwi_p (TYPE_SIZE_UNIT (TREE_TYPE (t))))
    6508              :     {
    6509            0 :       if (!ctx->quiet)
    6510            0 :         sorry_at (loc, "%qs cannot be constant evaluated because the "
    6511              :                        "type is too large", "__builtin_bit_cast");
    6512            0 :       *non_constant_p = true;
    6513            0 :       return t;
    6514              :     }
    6515              : 
    6516          708 :   HOST_WIDE_INT len = tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (t)));
    6517          708 :   if (len < 0 || (int) len != len)
    6518              :     {
    6519            0 :       if (!ctx->quiet)
    6520            0 :         sorry_at (loc, "%qs cannot be constant evaluated because the "
    6521              :                        "type is too large", "__builtin_bit_cast");
    6522            0 :       *non_constant_p = true;
    6523            0 :       return t;
    6524              :     }
    6525              : 
    6526          708 :   unsigned char buf[64];
    6527          708 :   unsigned char *ptr, *mask;
    6528          708 :   size_t alen = (size_t) len * 2;
    6529          708 :   if (alen <= sizeof (buf))
    6530              :     ptr = buf;
    6531              :   else
    6532            3 :     ptr = XNEWVEC (unsigned char, alen);
    6533          708 :   mask = ptr + (size_t) len;
    6534              :   /* At the beginning consider everything indeterminate.  */
    6535          708 :   memset (mask, ~0, (size_t) len);
    6536              : 
    6537          708 :   if (native_encode_initializer (op, ptr, len, 0, mask) != len)
    6538              :     {
    6539            0 :       if (!ctx->quiet)
    6540            0 :         sorry_at (loc, "%qs cannot be constant evaluated because the "
    6541              :                        "argument cannot be encoded", "__builtin_bit_cast");
    6542            0 :       *non_constant_p = true;
    6543            0 :       if (ptr != buf)
    6544            0 :         XDELETE (ptr);
    6545            0 :       return t;
    6546              :     }
    6547              : 
    6548          708 :   tree r = NULL_TREE;
    6549          708 :   if (can_native_interpret_type_p (TREE_TYPE (t)))
    6550              :     {
    6551          369 :       r = native_interpret_expr (TREE_TYPE (t), ptr, len);
    6552          369 :       if (is_byte_access_type_not_plain_char (TREE_TYPE (t)))
    6553              :         {
    6554           46 :           gcc_assert (len == 1);
    6555           46 :           if (mask[0])
    6556              :             {
    6557           24 :               memset (mask, 0, len);
    6558           24 :               r = build_constructor (TREE_TYPE (r), NULL);
    6559           24 :               CONSTRUCTOR_NO_CLEARING (r) = 1;
    6560              :             }
    6561              :         }
    6562              :     }
    6563          339 :   else if (TREE_CODE (TREE_TYPE (t)) == RECORD_TYPE)
    6564              :     {
    6565          339 :       r = native_interpret_aggregate (TREE_TYPE (t), ptr, 0, len);
    6566          339 :       if (r != NULL_TREE)
    6567              :         {
    6568          339 :           clear_type_padding_in_mask (TREE_TYPE (t), mask);
    6569          339 :           clear_uchar_or_std_byte_in_mask (loc, r, mask);
    6570          339 :           if (CHECKING_P)
    6571              :             {
    6572          339 :               tree e = cxx_eval_bare_aggregate (ctx, r, vc_prvalue,
    6573              :                                                 non_constant_p, overflow_p,
    6574              :                                                 jump_target);
    6575          339 :               gcc_checking_assert (e == r && !*jump_target);
    6576              :               r = e;
    6577              :             }
    6578              :         }
    6579              :     }
    6580              : 
    6581          708 :   if (r != NULL_TREE)
    6582              :     {
    6583         5935 :       for (int i = 0; i < len; i++)
    6584         5317 :         if (mask[i])
    6585              :           {
    6586           90 :             if (!ctx->quiet)
    6587           30 :               error_at (loc, "%qs accessing uninitialized byte at offset %d",
    6588              :                              "__builtin_bit_cast", i);
    6589           90 :             *non_constant_p = true;
    6590           90 :             r = t;
    6591           90 :             break;
    6592              :           }
    6593          708 :       if (ptr != buf)
    6594            3 :         XDELETE (ptr);
    6595          708 :       return r;
    6596              :     }
    6597              : 
    6598            0 :   if (!ctx->quiet)
    6599            0 :     sorry_at (loc, "%qs cannot be constant evaluated because the "
    6600              :                    "argument cannot be interpreted", "__builtin_bit_cast");
    6601            0 :   *non_constant_p = true;
    6602            0 :   if (ptr != buf)
    6603            0 :     XDELETE (ptr);
    6604              :   return t;
    6605              : }
    6606              : 
    6607              : /* Subroutine of cxx_eval_constant_expression.
    6608              :    Evaluate a short-circuited logical expression T in the context
    6609              :    of a given constexpr CALL.  BAILOUT_VALUE is the value for
    6610              :    early return.  CONTINUE_VALUE is used here purely for
    6611              :    sanity check purposes.  */
    6612              : 
    6613              : static tree
    6614     10698614 : cxx_eval_logical_expression (const constexpr_ctx *ctx, tree t,
    6615              :                              tree bailout_value, tree continue_value,
    6616              :                              bool *non_constant_p, bool *overflow_p,
    6617              :                              tree *jump_target)
    6618              : {
    6619     10698614 :   tree r;
    6620     10698614 :   tree lhs = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
    6621              :                                            vc_prvalue, non_constant_p,
    6622              :                                            overflow_p, jump_target);
    6623     10698613 :   if (*jump_target)
    6624              :     return NULL_TREE;
    6625     10698604 :   VERIFY_CONSTANT (lhs);
    6626      6706970 :   if (tree_int_cst_equal (lhs, bailout_value))
    6627              :     return lhs;
    6628      5459236 :   gcc_assert (tree_int_cst_equal (lhs, continue_value));
    6629      5459236 :   r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1),
    6630              :                                     vc_prvalue, non_constant_p,
    6631              :                                     overflow_p, jump_target);
    6632      5459236 :   if (*jump_target)
    6633              :     return NULL_TREE;
    6634      5459236 :   VERIFY_CONSTANT (r);
    6635              :   return r;
    6636              : }
    6637              : 
    6638              : /* REF is a COMPONENT_REF designating a particular field.  V is a vector of
    6639              :    CONSTRUCTOR elements to initialize (part of) an object containing that
    6640              :    field.  Return a pointer to the constructor_elt corresponding to the
    6641              :    initialization of the field.  */
    6642              : 
    6643              : static constructor_elt *
    6644            0 : base_field_constructor_elt (vec<constructor_elt, va_gc> *v, tree ref)
    6645              : {
    6646            0 :   tree aggr = TREE_OPERAND (ref, 0);
    6647            0 :   tree field = TREE_OPERAND (ref, 1);
    6648            0 :   HOST_WIDE_INT i;
    6649            0 :   constructor_elt *ce;
    6650              : 
    6651            0 :   gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
    6652              : 
    6653            0 :   if (TREE_CODE (aggr) == COMPONENT_REF)
    6654              :     {
    6655            0 :       constructor_elt *base_ce
    6656            0 :         = base_field_constructor_elt (v, aggr);
    6657            0 :       v = CONSTRUCTOR_ELTS (base_ce->value);
    6658              :     }
    6659              : 
    6660            0 :   for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
    6661            0 :     if (ce->index == field)
    6662            0 :       return ce;
    6663              : 
    6664            0 :   gcc_unreachable ();
    6665              :   return NULL;
    6666              : }
    6667              : 
    6668              : /* Some of the expressions fed to the constexpr mechanism are calls to
    6669              :    constructors, which have type void.  In that case, return the type being
    6670              :    initialized by the constructor.  */
    6671              : 
    6672              : static tree
    6673    521262521 : initialized_type (tree t)
    6674              : {
    6675    522365006 :   if (TYPE_P (t))
    6676              :     return t;
    6677    522364549 :   tree type = TREE_TYPE (t);
    6678    522364549 :   if (TREE_CODE (t) == CALL_EXPR)
    6679              :     {
    6680              :       /* A constructor call has void type, so we need to look deeper.  */
    6681     67737403 :       tree fn = get_function_named_in_call (t);
    6682     67735409 :       if (fn && TREE_CODE (fn) == FUNCTION_DECL
    6683    135353375 :           && DECL_CXX_CONSTRUCTOR_P (fn))
    6684      3779791 :         type = DECL_CONTEXT (fn);
    6685              :     }
    6686    454627146 :   else if (TREE_CODE (t) == COMPOUND_EXPR)
    6687      1102485 :     return initialized_type (TREE_OPERAND (t, 1));
    6688    453524661 :   else if (TREE_CODE (t) == AGGR_INIT_EXPR)
    6689       772342 :     type = TREE_TYPE (AGGR_INIT_EXPR_SLOT (t));
    6690    521262064 :   return cv_unqualified (type);
    6691              : }
    6692              : 
    6693              : /* We're about to initialize element INDEX of an array or class from VALUE.
    6694              :    Set up NEW_CTX appropriately by adjusting .object to refer to the
    6695              :    subobject and creating a new CONSTRUCTOR if the element is itself
    6696              :    a class or array.  */
    6697              : 
    6698              : static void
    6699      2077433 : init_subob_ctx (const constexpr_ctx *ctx, constexpr_ctx &new_ctx,
    6700              :                tree index, tree &value)
    6701              : {
    6702      2077433 :   new_ctx = *ctx;
    6703              : 
    6704      2077433 :   if (index && TREE_CODE (index) != INTEGER_CST
    6705      1817307 :       && TREE_CODE (index) != FIELD_DECL
    6706            3 :       && TREE_CODE (index) != RANGE_EXPR)
    6707              :     /* This won't have an element in the new CONSTRUCTOR.  */
    6708              :     return;
    6709              : 
    6710      2077433 :   tree type = initialized_type (value);
    6711      2077433 :   if (!AGGREGATE_TYPE_P (type) && !VECTOR_TYPE_P (type))
    6712              :     /* A non-aggregate member doesn't get its own CONSTRUCTOR.  */
    6713              :     return;
    6714              : 
    6715       719672 :   tree ctxtype = NULL_TREE;
    6716       719672 :   if (ctx->ctor)
    6717       719655 :     ctxtype = TREE_TYPE (ctx->ctor);
    6718           17 :   else if (ctx->object)
    6719           14 :     ctxtype = TREE_TYPE (ctx->object);
    6720              :   else
    6721              :     {
    6722              :       /* This can happen if the enclosing object is also an empty subobject
    6723              :          (c++/125315).  */
    6724            3 :       gcc_checking_assert (is_empty_field (index));
    6725              :       return;
    6726              :     }
    6727              : 
    6728       719669 :   if (VECTOR_TYPE_P (type)
    6729         2950 :       && VECTOR_TYPE_P (ctxtype)
    6730          922 :       && index == NULL_TREE)
    6731              :     /* A vector inside of a vector CONSTRUCTOR, e.g. when a larger
    6732              :        vector is constructed from smaller vectors, doesn't get its own
    6733              :        CONSTRUCTOR either.  */
    6734              :     return;
    6735              : 
    6736              :   /* The sub-aggregate initializer might contain a placeholder;
    6737              :      update object to refer to the subobject and ctor to refer to
    6738              :      the (newly created) sub-initializer.  */
    6739       718747 :   if (ctx->object)
    6740              :     {
    6741       579726 :       if (index == NULL_TREE || TREE_CODE (index) == RANGE_EXPR)
    6742              :         /* There's no well-defined subobject for this index.  */
    6743            3 :         new_ctx.object = NULL_TREE;
    6744              :       else
    6745       579723 :         new_ctx.object = build_ctor_subob_ref (index, type, ctx->object);
    6746              :     }
    6747              : 
    6748       718747 :   if (is_empty_field (index)
    6749       718747 :       && TREE_CODE (ctxtype) != UNION_TYPE)
    6750              :     /* Leave ctor null for an empty subobject of a non-union class, they aren't
    6751              :        represented in the result of evaluation.  */
    6752       641916 :     new_ctx.ctor = NULL_TREE;
    6753              :   else
    6754              :     {
    6755        76831 :       tree elt = build_constructor (type, NULL);
    6756        76831 :       CONSTRUCTOR_NO_CLEARING (elt) = true;
    6757        76831 :       new_ctx.ctor = elt;
    6758              :     }
    6759              : 
    6760       718747 :   if (TREE_CODE (value) == TARGET_EXPR)
    6761              :     /* Avoid creating another CONSTRUCTOR when we expand the TARGET_EXPR.  */
    6762        54183 :     value = TARGET_EXPR_INITIAL (value);
    6763              : }
    6764              : 
    6765              : /* We're about to process an initializer for a class or array TYPE.  Make
    6766              :    sure that CTX is set up appropriately.  */
    6767              : 
    6768              : static void
    6769      1610492 : verify_ctor_sanity (const constexpr_ctx *ctx, tree type)
    6770              : {
    6771              :   /* We don't bother building a ctor for an empty base subobject.  */
    6772      1610492 :   if (is_empty_class (type))
    6773              :     return;
    6774              : 
    6775              :   /* We're in the middle of an initializer that might involve placeholders;
    6776              :      our caller should have created a CONSTRUCTOR for us to put the
    6777              :      initializer into.  We will either return that constructor or T.  */
    6778       974928 :   gcc_assert (ctx->ctor);
    6779       974928 :   gcc_assert (same_type_ignoring_top_level_qualifiers_p
    6780              :               (type, TREE_TYPE (ctx->ctor)));
    6781              :   /* We used to check that ctx->ctor was empty, but that isn't the case when
    6782              :      the object is zero-initialized before calling the constructor.  */
    6783       974928 :   if (ctx->object)
    6784              :     {
    6785       815026 :       tree otype = TREE_TYPE (ctx->object);
    6786       815026 :       gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, otype)
    6787              :                   /* Handle flexible array members.  */
    6788              :                   || (TREE_CODE (otype) == ARRAY_TYPE
    6789              :                       && TYPE_DOMAIN (otype) == NULL_TREE
    6790              :                       && TREE_CODE (type) == ARRAY_TYPE
    6791              :                       && (same_type_ignoring_top_level_qualifiers_p
    6792              :                           (TREE_TYPE (type), TREE_TYPE (otype)))));
    6793              :     }
    6794       974928 :   gcc_assert (!ctx->object || !DECL_P (ctx->object)
    6795              :               || ctx->global->get_value (ctx->object) == ctx->ctor);
    6796              : }
    6797              : 
    6798              : /* Subroutine of cxx_eval_constant_expression.
    6799              :    The expression tree T denotes a C-style array or a C-style
    6800              :    aggregate.  Reduce it to a constant expression.  */
    6801              : 
    6802              : static tree
    6803      1609827 : cxx_eval_bare_aggregate (const constexpr_ctx *ctx, tree t,
    6804              :                          value_cat lval,
    6805              :                          bool *non_constant_p, bool *overflow_p,
    6806              :                          tree *jump_target)
    6807              : {
    6808      1609827 :   vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
    6809      1609827 :   bool changed = false;
    6810      1609827 :   gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (t));
    6811      1609827 :   tree type = TREE_TYPE (t);
    6812              : 
    6813      1609827 :   constexpr_ctx new_ctx;
    6814      1609827 :   if (TYPE_PTRMEMFUNC_P (type) || VECTOR_TYPE_P (type))
    6815              :     {
    6816              :       /* We don't really need the ctx->ctor business for a PMF or
    6817              :          vector, but it's simpler to use the same code.  */
    6818        32140 :       new_ctx = *ctx;
    6819        32140 :       new_ctx.ctor = build_constructor (type, NULL);
    6820        32140 :       new_ctx.object = NULL_TREE;
    6821        32140 :       ctx = &new_ctx;
    6822      1609827 :     };
    6823      1609827 :   verify_ctor_sanity (ctx, type);
    6824      1609827 :   vec<constructor_elt, va_gc> **p = nullptr;
    6825      1609827 :   if (ctx->ctor)
    6826              :     {
    6827      1609810 :       p = &CONSTRUCTOR_ELTS (ctx->ctor);
    6828      3217417 :       vec_alloc (*p, vec_safe_length (v));
    6829      1609810 :       if (CONSTRUCTOR_PLACEHOLDER_BOUNDARY (t))
    6830        16053 :         CONSTRUCTOR_PLACEHOLDER_BOUNDARY (ctx->ctor) = 1;
    6831              :     }
    6832              : 
    6833      1609827 :   unsigned i;
    6834      1609827 :   tree index, value;
    6835      1609827 :   bool constant_p = true;
    6836      1609827 :   bool side_effects_p = false;
    6837      3337671 :   FOR_EACH_CONSTRUCTOR_ELT (v, i, index, value)
    6838              :     {
    6839      2071235 :       tree orig_value = value;
    6840      2071235 :       init_subob_ctx (ctx, new_ctx, index, value);
    6841              :       /* Like in cxx_eval_store_expression, omit entries for empty fields.  */
    6842      2071235 :       bool no_slot = new_ctx.ctor == NULL_TREE;
    6843      2071235 :       int pos_hint = -1;
    6844      2071235 :       if (!ctx->ctor)
    6845              :         /* The enclosing object could be an empty subobject so we have no
    6846              :            CONSTRUCTOR (c++/125336).  */
    6847           17 :         gcc_checking_assert (is_empty_class (type));
    6848      2071218 :       else if (new_ctx.ctor != ctx->ctor && !no_slot)
    6849              :         {
    6850              :           /* If we built a new CONSTRUCTOR, attach it now so that other
    6851              :              initializers can refer to it.  */
    6852        70770 :           constructor_elt *cep = get_or_insert_ctor_field (ctx->ctor, index);
    6853        70770 :           cep->value = new_ctx.ctor;
    6854        70770 :           pos_hint = cep - (*p)->begin();
    6855        70770 :         }
    6856      2000448 :       else if (TREE_CODE (type) == UNION_TYPE)
    6857              :         /* Otherwise if we're constructing a non-aggregate union member, set
    6858              :            the active union member now so that we can later detect and diagnose
    6859              :            if its initializer attempts to activate another member.  */
    6860         1095 :         get_or_insert_ctor_field (ctx->ctor, index);
    6861      2071235 :       tree elt = cxx_eval_constant_expression (&new_ctx, value,
    6862              :                                                lval,
    6863              :                                                non_constant_p, overflow_p,
    6864              :                                                jump_target);
    6865      2071235 :       if (*jump_target)
    6866              :         return NULL_TREE;
    6867              :       /* Don't VERIFY_CONSTANT here.  */
    6868      2071232 :       if (ctx->quiet && *non_constant_p)
    6869              :         break;
    6870      1727844 :       if (elt != orig_value)
    6871       633459 :         changed = true;
    6872              : 
    6873      1727844 :       if (!TREE_CONSTANT (elt))
    6874       532875 :         constant_p = false;
    6875      1727844 :       if (TREE_SIDE_EFFECTS (elt))
    6876          191 :         side_effects_p = true;
    6877      1727844 :       if (index && TREE_CODE (index) == COMPONENT_REF)
    6878              :         {
    6879              :           /* This is an initialization of a vfield inside a base
    6880              :              subaggregate that we already initialized; push this
    6881              :              initialization into the previous initialization.  */
    6882            0 :           constructor_elt *inner = base_field_constructor_elt (*p, index);
    6883            0 :           inner->value = elt;
    6884            0 :           changed = true;
    6885            0 :         }
    6886      1727844 :       else if (no_slot)
    6887              :         /* This is an initializer for an empty field; now that we've
    6888              :            checked that it's constant, we can ignore it.  */
    6889              :         changed = true;
    6890      1086464 :       else if (ctx->ctor)
    6891              :         {
    6892      1086464 :           if (TREE_CODE (type) == UNION_TYPE
    6893      1086464 :               && (*p)->last().index != index)
    6894              :             /* The initializer erroneously changed the active union member that
    6895              :                we're initializing.  */
    6896            7 :             gcc_assert (*non_constant_p);
    6897              :           else
    6898              :             {
    6899              :               /* The initializer might have mutated the underlying CONSTRUCTOR,
    6900              :                  so recompute the location of the target constructer_elt.  */
    6901      1086457 :               constructor_elt *cep
    6902      1086457 :                 = get_or_insert_ctor_field (ctx->ctor, index, pos_hint);
    6903      1086457 :               cep->value = elt;
    6904              :             }
    6905              : 
    6906              :           /* Adding or replacing an element might change the ctor's flags.  */
    6907      1086464 :           TREE_CONSTANT (ctx->ctor) = constant_p;
    6908      1086464 :           TREE_SIDE_EFFECTS (ctx->ctor) = side_effects_p;
    6909              :         }
    6910              :     }
    6911      1609824 :   if (*non_constant_p)
    6912              :     return t;
    6913      1266385 :   if (!changed)
    6914              :     {
    6915       184764 :       if (VECTOR_TYPE_P (type))
    6916        14357 :         t = fold (t);
    6917       184764 :       return t;
    6918              :     }
    6919      1081621 :   t = ctx->ctor;
    6920      1081621 :   if (!t)
    6921            8 :     t = build_constructor (type, NULL);
    6922              :   /* We're done building this CONSTRUCTOR, so now we can interpret an
    6923              :      element without an explicit initializer as value-initialized.  */
    6924      1081621 :   CONSTRUCTOR_NO_CLEARING (t) = false;
    6925      1081621 :   TREE_CONSTANT (t) = constant_p;
    6926      1081621 :   TREE_SIDE_EFFECTS (t) = side_effects_p;
    6927      1081621 :   if (VECTOR_TYPE_P (type))
    6928         4832 :     t = fold (t);
    6929              :   return t;
    6930              : }
    6931              : 
    6932              : /* Subroutine of cxx_eval_constant_expression.
    6933              :    The expression tree T is a VEC_INIT_EXPR which denotes the desired
    6934              :    initialization of a non-static data member of array type.  Reduce it to a
    6935              :    CONSTRUCTOR.
    6936              : 
    6937              :    Note that apart from value-initialization (when VALUE_INIT is true),
    6938              :    this is only intended to support value-initialization and the
    6939              :    initializations done by defaulted constructors for classes with
    6940              :    non-static data members of array type.  In this case, VEC_INIT_EXPR_INIT
    6941              :    will either be NULL_TREE for the default constructor, or a COMPONENT_REF
    6942              :    for the copy/move constructor.  */
    6943              : 
    6944              : static tree
    6945          665 : cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init,
    6946              :                      bool value_init, value_cat lval,
    6947              :                      bool *non_constant_p, bool *overflow_p,
    6948              :                      tree *jump_target)
    6949              : {
    6950          665 :   tree elttype = TREE_TYPE (atype);
    6951          665 :   verify_ctor_sanity (ctx, atype);
    6952          665 :   vec<constructor_elt, va_gc> **p = &CONSTRUCTOR_ELTS (ctx->ctor);
    6953          665 :   bool pre_init = false;
    6954          665 :   unsigned HOST_WIDE_INT i;
    6955          665 :   tsubst_flags_t complain = ctx->quiet ? tf_none : tf_warning_or_error;
    6956              : 
    6957          665 :   if (init && TREE_CODE (init) == CONSTRUCTOR)
    6958            0 :     return cxx_eval_bare_aggregate (ctx, init, lval,
    6959            0 :                                     non_constant_p, overflow_p, jump_target);
    6960              : 
    6961              :   /* We already checked access when building the VEC_INIT_EXPR.  */
    6962          665 :   deferring_access_check_sentinel acs (dk_deferred);
    6963              : 
    6964              :   /* For the default constructor, build up a call to the default
    6965              :      constructor of the element type.  We only need to handle class types
    6966              :      here, as for a constructor to be constexpr, all members must be
    6967              :      initialized, which for a defaulted default constructor means they must
    6968              :      be of a class type with a constexpr default constructor.  */
    6969          665 :   if (TREE_CODE (elttype) == ARRAY_TYPE)
    6970              :     /* We only do this at the lowest level.  */;
    6971          616 :   else if (value_init)
    6972              :     {
    6973          174 :       init = build_value_init (elttype, complain);
    6974          174 :       pre_init = true;
    6975              :     }
    6976          442 :   else if (!init)
    6977              :     {
    6978          332 :       releasing_vec argvec;
    6979          332 :       init = build_special_member_call (NULL_TREE, complete_ctor_identifier,
    6980              :                                         &argvec, elttype, LOOKUP_NORMAL,
    6981              :                                         complain);
    6982          332 :       init = build_aggr_init_expr (elttype, init);
    6983          332 :       pre_init = true;
    6984          332 :     }
    6985              : 
    6986          665 :   bool zeroed_out = false;
    6987          665 :   if (!CONSTRUCTOR_NO_CLEARING (ctx->ctor))
    6988              :     {
    6989              :       /* We're initializing an array object that had been zero-initialized
    6990              :          earlier.  Truncate ctx->ctor, and propagate its zeroed state by
    6991              :          clearing CONSTRUCTOR_NO_CLEARING on each of the aggregate element
    6992              :          initializers we append to it.  */
    6993          156 :       gcc_checking_assert (initializer_zerop (ctx->ctor));
    6994          156 :       zeroed_out = true;
    6995          156 :       vec_safe_truncate (*p, 0);
    6996              :     }
    6997              : 
    6998          665 :   tree nelts = get_array_or_vector_nelts (ctx, atype, non_constant_p,
    6999              :                                           overflow_p, jump_target);
    7000          665 :   if (*jump_target)
    7001              :     return NULL_TREE;
    7002          665 :   unsigned HOST_WIDE_INT max = tree_to_uhwi (nelts);
    7003         6427 :   for (i = 0; i < max; ++i)
    7004              :     {
    7005         6198 :       tree idx = build_int_cst (size_type_node, i);
    7006         6198 :       tree eltinit;
    7007         6198 :       bool reuse = false;
    7008         6198 :       constexpr_ctx new_ctx;
    7009         6655 :       init_subob_ctx (ctx, new_ctx, idx, pre_init ? init : elttype);
    7010         6198 :       bool no_slot = new_ctx.ctor == NULL_TREE;
    7011         6198 :       if (new_ctx.ctor != ctx->ctor && !no_slot)
    7012              :         {
    7013         6061 :           if (zeroed_out)
    7014         5445 :             CONSTRUCTOR_NO_CLEARING (new_ctx.ctor) = false;
    7015         6061 :           CONSTRUCTOR_APPEND_ELT (*p, idx, new_ctx.ctor);
    7016              :         }
    7017         6198 :       if (TREE_CODE (elttype) == ARRAY_TYPE)
    7018              :         {
    7019              :           /* A multidimensional array; recurse.  */
    7020          181 :           if (value_init || init == NULL_TREE)
    7021              :             {
    7022          171 :               eltinit = NULL_TREE;
    7023          171 :               reuse = i == 0;
    7024              :             }
    7025              :           else
    7026           10 :             eltinit = cp_build_array_ref (input_location, init, idx, complain);
    7027          181 :           eltinit = cxx_eval_vec_init_1 (&new_ctx, elttype, eltinit,
    7028              :                                          value_init, lval, non_constant_p,
    7029              :                                          overflow_p, jump_target);
    7030              :         }
    7031         6017 :       else if (pre_init)
    7032              :         {
    7033              :           /* Initializing an element using value or default initialization
    7034              :              we just pre-built above.  */
    7035         5741 :           if (init == void_node)
    7036              :             /* Trivial default-init, don't do anything to the CONSTRUCTOR.  */
    7037            3 :             return ctx->ctor;
    7038         5738 :           eltinit = init;
    7039         5738 :           if (CLASS_TYPE_P (elttype) && new_ctx.object)
    7040              :             /* Clarify what object is being initialized (118285).  */
    7041         5602 :             eltinit = build2 (INIT_EXPR, elttype, new_ctx.object, eltinit);
    7042         5738 :           eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval,
    7043              :                                                   non_constant_p, overflow_p,
    7044              :                                                   jump_target);
    7045         5738 :           reuse = i == 0;
    7046              :         }
    7047              :       else
    7048              :         {
    7049              :           /* Copying an element.  */
    7050          276 :           eltinit = cp_build_array_ref (input_location, init, idx, complain);
    7051          276 :           if (!lvalue_p (init))
    7052          232 :             eltinit = move (eltinit);
    7053          276 :           eltinit = (perform_implicit_conversion_flags
    7054          276 :                      (elttype, eltinit, complain,
    7055              :                       LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING));
    7056          269 :           if (CLASS_TYPE_P (elttype)
    7057          269 :               && new_ctx.object
    7058          522 :               && !error_operand_p (eltinit))
    7059              :             /* Clarify what object is being initialized (118285).  */
    7060          244 :             eltinit = build2 (INIT_EXPR, elttype, new_ctx.object, eltinit);
    7061          276 :           eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval,
    7062              :                                                   non_constant_p, overflow_p,
    7063              :                                                   jump_target);
    7064              :         }
    7065         6195 :       if (*jump_target)
    7066              :         return NULL_TREE;
    7067         6195 :       if (*non_constant_p)
    7068              :         break;
    7069         6070 :       if (no_slot)
    7070              :         {
    7071              :           /* This is an initializer for an empty subobject; now that we've
    7072              :              checked that it's constant, we can ignore it.  */
    7073            0 :           gcc_checking_assert (i == 0);
    7074              :           break;
    7075              :         }
    7076         6070 :       else if (new_ctx.ctor != ctx->ctor)
    7077              :         {
    7078              :           /* We appended this element above; update the value.  */
    7079         5940 :           gcc_assert ((*p)->last().index == idx);
    7080         5940 :           (*p)->last().value = eltinit;
    7081              :         }
    7082              :       else
    7083          130 :         CONSTRUCTOR_APPEND_ELT (*p, idx, eltinit);
    7084              :       /* Reuse the result of cxx_eval_constant_expression call
    7085              :          from the first iteration to all others if it is a constant
    7086              :          initializer that doesn't require relocations.  */
    7087         6070 :       if (reuse
    7088         6070 :           && max > 1
    7089         6070 :           && (eltinit == NULL_TREE
    7090          461 :               || (initializer_constant_valid_p (eltinit, TREE_TYPE (eltinit))
    7091          461 :                   == null_pointer_node)))
    7092              :         {
    7093          308 :           if (new_ctx.ctor != ctx->ctor)
    7094          184 :             eltinit = new_ctx.ctor;
    7095          308 :           tree range = build2 (RANGE_EXPR, size_type_node,
    7096              :                                build_int_cst (size_type_node, 1),
    7097          308 :                                build_int_cst (size_type_node, max - 1));
    7098          308 :           CONSTRUCTOR_APPEND_ELT (*p, range, unshare_constructor (eltinit));
    7099          308 :           break;
    7100              :         }
    7101         5762 :       else if (i == 0)
    7102          226 :         vec_safe_reserve (*p, max);
    7103              :     }
    7104              : 
    7105          662 :   if (!*non_constant_p)
    7106              :     {
    7107          537 :       init = ctx->ctor;
    7108          537 :       CONSTRUCTOR_NO_CLEARING (init) = false;
    7109              :     }
    7110          662 :   return init;
    7111              : }
    7112              : 
    7113              : static tree
    7114          547 : cxx_eval_vec_init (const constexpr_ctx *ctx, tree t,
    7115              :                    value_cat lval,
    7116              :                    bool *non_constant_p, bool *overflow_p, tree *jump_target)
    7117              : {
    7118          547 :   tree atype = TREE_TYPE (t);
    7119          547 :   tree init = VEC_INIT_EXPR_INIT (t);
    7120          547 :   bool value_init = VEC_INIT_EXPR_VALUE_INIT (t);
    7121          547 :   if (!init || !BRACE_ENCLOSED_INITIALIZER_P (init))
    7122              :     ;
    7123           74 :   else if (CONSTRUCTOR_NELTS (init) == 0
    7124           74 :            && !CP_AGGREGATE_TYPE_P (strip_array_types (atype)))
    7125              :     {
    7126              :       /* Handle {} as value-init.  */
    7127              :       init = NULL_TREE;
    7128              :       value_init = true;
    7129              :     }
    7130              :   else
    7131              :     {
    7132              :       /* This is a more complicated case, like needing to loop over trailing
    7133              :          elements; call build_vec_init and evaluate the result.  */
    7134           63 :       tsubst_flags_t complain = ctx->quiet ? tf_none : tf_warning_or_error;
    7135           63 :       constexpr_ctx new_ctx = *ctx;
    7136           63 :       if (!ctx->object)
    7137              :         {
    7138              :           /* We want to have an initialization target for an VEC_INIT_EXPR.
    7139              :              If we don't already have one in CTX, use the VEC_INIT_EXPR_SLOT.  */
    7140           51 :           new_ctx.object = VEC_INIT_EXPR_SLOT (t);
    7141           51 :           tree ctor = new_ctx.ctor = build_constructor (atype, NULL);
    7142           51 :           CONSTRUCTOR_NO_CLEARING (ctor) = true;
    7143           51 :           ctx->global->put_value (new_ctx.object, ctor);
    7144           51 :           ctx = &new_ctx;
    7145              :         }
    7146           63 :       init = expand_vec_init_expr (ctx->object, t, complain);
    7147           63 :       return cxx_eval_constant_expression (ctx, init, lval, non_constant_p,
    7148              :                                            overflow_p, jump_target);
    7149              :     }
    7150          484 :   tree r = cxx_eval_vec_init_1 (ctx, atype, init, value_init,
    7151              :                                 lval, non_constant_p, overflow_p, jump_target);
    7152          484 :   if (*non_constant_p)
    7153              :     return t;
    7154              :   else
    7155          382 :     return r;
    7156              : }
    7157              : 
    7158              : /* Like same_type_ignoring_top_level_qualifiers_p, but also handle the case
    7159              :    where the desired type is an array of unknown bounds because the variable
    7160              :    has had its bounds deduced since the wrapping expression was created.  */
    7161              : 
    7162              : static bool
    7163    256189364 : same_type_ignoring_tlq_and_bounds_p (tree type1, tree type2)
    7164              : {
    7165    256189364 :   while (TREE_CODE (type1) == ARRAY_TYPE
    7166        54418 :          && TREE_CODE (type2) == ARRAY_TYPE
    7167    256189368 :          && (!TYPE_DOMAIN (type1) || !TYPE_DOMAIN (type2)))
    7168              :     {
    7169            2 :       type1 = TREE_TYPE (type1);
    7170            2 :       type2 = TREE_TYPE (type2);
    7171              :     }
    7172    256189364 :   return same_type_ignoring_top_level_qualifiers_p (type1, type2);
    7173              : }
    7174              : 
    7175              : /* Try to determine the currently active union member for an expression
    7176              :    with UNION_TYPE.  If it can be determined, return the FIELD_DECL,
    7177              :    otherwise return NULL_TREE.  */
    7178              : 
    7179              : static tree
    7180           76 : cxx_union_active_member (const constexpr_ctx *ctx, tree t, tree *jump_target)
    7181              : {
    7182           76 :   constexpr_ctx new_ctx = *ctx;
    7183           76 :   new_ctx.quiet = true;
    7184           76 :   bool non_constant_p = false, overflow_p = false;
    7185           76 :   tree ctor = cxx_eval_constant_expression (&new_ctx, t, vc_prvalue,
    7186              :                                             &non_constant_p,
    7187              :                                             &overflow_p, jump_target);
    7188           76 :   if (*jump_target)
    7189              :     return NULL_TREE;
    7190           76 :   if (TREE_CODE (ctor) == CONSTRUCTOR
    7191           28 :       && CONSTRUCTOR_NELTS (ctor) == 1
    7192           16 :       && CONSTRUCTOR_ELT (ctor, 0)->index
    7193           92 :       && TREE_CODE (CONSTRUCTOR_ELT (ctor, 0)->index) == FIELD_DECL)
    7194              :     return CONSTRUCTOR_ELT (ctor, 0)->index;
    7195              :   return NULL_TREE;
    7196              : }
    7197              : 
    7198              : /* Helper function for cxx_fold_indirect_ref_1, called recursively.  */
    7199              : 
    7200              : static tree
    7201      8656469 : cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type,
    7202              :                          tree op, unsigned HOST_WIDE_INT off, bool *empty_base,
    7203              :                          tree *jump_target)
    7204              : {
    7205     13704871 :   tree optype = TREE_TYPE (op);
    7206     13704871 :   unsigned HOST_WIDE_INT const_nunits;
    7207     13704871 :   if (off == 0 && similar_type_p (optype, type))
    7208              :     return op;
    7209      8653940 :   else if (cxx_dialect >= cxx26
    7210      3326127 :            && VAR_P (op)
    7211      1418475 :            && DECL_VTABLE_OR_VTT_P (op)
    7212         8829 :            && same_type_ignoring_top_level_qualifiers_p (type,
    7213              :                                                          ptrdiff_type_node)
    7214      8654922 :            && POINTER_TYPE_P (strip_array_types (optype)))
    7215              :     {
    7216              :       /* We often read some virtual table elements using ptrdiff_t rather
    7217              :          than pointer type.  */
    7218          982 :       if (tree ret = cxx_fold_indirect_ref_1 (ctx, loc,
    7219              :                                               strip_array_types (optype),
    7220              :                                               op, off, empty_base,
    7221              :                                               jump_target))
    7222          982 :         return fold_convert (type, ret);
    7223              :     }
    7224      8652958 :   else if (TREE_CODE (optype) == COMPLEX_TYPE
    7225      8652958 :            && similar_type_p (type, TREE_TYPE (optype)))
    7226              :     {
    7227              :       /* *(foo *)&complexfoo => __real__ complexfoo */
    7228            0 :       if (off == 0)
    7229            0 :         return build1_loc (loc, REALPART_EXPR, type, op);
    7230              :       /* ((foo*)&complexfoo)[1] => __imag__ complexfoo */
    7231            0 :       else if (tree_to_uhwi (TYPE_SIZE_UNIT (type)) == off)
    7232            0 :         return build1_loc (loc, IMAGPART_EXPR, type, op);
    7233              :     }
    7234              :   /* ((foo*)&vectorfoo)[x] => BIT_FIELD_REF<vectorfoo,...> */
    7235      8652958 :   else if (VECTOR_TYPE_P (optype)
    7236            0 :            && similar_type_p (type, TREE_TYPE (optype))
    7237      8652958 :            && TYPE_VECTOR_SUBPARTS (optype).is_constant (&const_nunits))
    7238              :     {
    7239            0 :       unsigned HOST_WIDE_INT part_width = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    7240            0 :       unsigned HOST_WIDE_INT max_offset = part_width * const_nunits;
    7241            0 :       if (off < max_offset && off % part_width == 0)
    7242              :         {
    7243            0 :           tree index = bitsize_int (off * BITS_PER_UNIT);
    7244            0 :           return build3_loc (loc, BIT_FIELD_REF, type, op,
    7245            0 :                              TYPE_SIZE (type), index);
    7246              :         }
    7247              :     }
    7248              :   /* ((foo *)&fooarray)[x] => fooarray[x] */
    7249      8652958 :   else if (TREE_CODE (optype) == ARRAY_TYPE
    7250      5048402 :            && tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (optype)))
    7251     13701360 :            && !integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (optype))))
    7252              :     {
    7253      5048402 :       tree type_domain = TYPE_DOMAIN (optype);
    7254      5048402 :       tree min_val = size_zero_node;
    7255      5048402 :       if (type_domain && TYPE_MIN_VALUE (type_domain))
    7256      5048263 :         min_val = TYPE_MIN_VALUE (type_domain);
    7257      5048402 :       unsigned HOST_WIDE_INT el_sz
    7258      5048402 :         = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (optype)));
    7259      5048402 :       unsigned HOST_WIDE_INT idx = off / el_sz;
    7260      5048402 :       unsigned HOST_WIDE_INT rem = off % el_sz;
    7261      5048402 :       if (tree_fits_uhwi_p (min_val))
    7262              :         {
    7263      5048402 :           tree index = size_int (idx + tree_to_uhwi (min_val));
    7264      5048402 :           op = build4_loc (loc, ARRAY_REF, TREE_TYPE (optype), op, index,
    7265              :                            NULL_TREE, NULL_TREE);
    7266      5048402 :           return cxx_fold_indirect_ref_1 (ctx, loc, type, op, rem,
    7267      5048402 :                                           empty_base, jump_target);
    7268              :         }
    7269              :     }
    7270              :   /* ((foo *)&struct_with_foo_field)[x] => COMPONENT_REF */
    7271      3604556 :   else if (TREE_CODE (optype) == RECORD_TYPE
    7272      3604556 :            || TREE_CODE (optype) == UNION_TYPE)
    7273              :     {
    7274      3601141 :       if (TREE_CODE (optype) == UNION_TYPE)
    7275              :         /* For unions prefer the currently active member.  */
    7276           76 :         if (tree field = cxx_union_active_member (ctx, op, jump_target))
    7277              :           {
    7278           16 :             unsigned HOST_WIDE_INT el_sz
    7279           16 :               = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (field)));
    7280           16 :             if (off < el_sz)
    7281              :               {
    7282           16 :                 tree cop = build3 (COMPONENT_REF, TREE_TYPE (field),
    7283              :                                    op, field, NULL_TREE);
    7284           16 :                 if (tree ret = cxx_fold_indirect_ref_1 (ctx, loc, type, cop,
    7285              :                                                         off, empty_base,
    7286              :                                                         jump_target))
    7287              :                   return ret;
    7288              :               }
    7289              :           }
    7290              : 
    7291              :       /* Handle conversion to "as base" type.  */
    7292      3601131 :       if (CLASS_TYPE_P (optype)
    7293      7202098 :           && CLASSTYPE_AS_BASE (optype) == type)
    7294              :         return op;
    7295              : 
    7296              :       /* Handle conversion to an empty base class, which is represented with a
    7297              :          NOP_EXPR.  Do this before spelunking into the non-empty subobjects,
    7298              :          which is likely to be a waste of time (109678).  */
    7299      3598554 :       if (is_empty_class (type)
    7300      3428654 :           && CLASS_TYPE_P (optype)
    7301      7027202 :           && lookup_base (optype, type, ba_any, NULL, tf_none, off))
    7302              :         {
    7303      1786635 :           if (empty_base)
    7304      1786635 :             *empty_base = true;
    7305      1786635 :           return op;
    7306              :         }
    7307              : 
    7308      1811919 :       for (tree field = TYPE_FIELDS (optype);
    7309     24440461 :            field; field = DECL_CHAIN (field))
    7310     24425018 :         if (TREE_CODE (field) == FIELD_DECL
    7311      1817703 :             && TREE_TYPE (field) != error_mark_node
    7312     26242721 :             && tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (field))))
    7313              :           {
    7314      1817699 :             tree pos = byte_position (field);
    7315      1817699 :             if (!tree_fits_uhwi_p (pos))
    7316            0 :               continue;
    7317      1817699 :             unsigned HOST_WIDE_INT upos = tree_to_uhwi (pos);
    7318      1817699 :             unsigned HOST_WIDE_INT el_sz;
    7319      1817699 :             if (DECL_FIELD_IS_BASE (field)
    7320       392741 :                 && CLASS_TYPE_P (optype)
    7321      2210440 :                 && CLASSTYPE_VBASECLASSES (optype))
    7322         6189 :               el_sz = tree_to_uhwi (DECL_SIZE_UNIT (field));
    7323              :             else
    7324      1811510 :               el_sz = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (field)));
    7325      1817699 :             if (upos <= off && off < upos + el_sz)
    7326              :               {
    7327      1811816 :                 tree cop = build3 (COMPONENT_REF, TREE_TYPE (field),
    7328              :                                    op, field, NULL_TREE);
    7329      1811816 :                 if (tree ret = cxx_fold_indirect_ref_1 (ctx, loc, type, cop,
    7330              :                                                         off - upos,
    7331              :                                                         empty_base,
    7332              :                                                         jump_target))
    7333              :                   return ret;
    7334              :               }
    7335              :           }
    7336              :     }
    7337              : 
    7338              :   return NULL_TREE;
    7339              : }
    7340              : 
    7341              : /* A less strict version of fold_indirect_ref_1, which requires cv-quals to
    7342              :    match.  We want to be less strict for simple *& folding; if we have a
    7343              :    non-const temporary that we access through a const pointer, that should
    7344              :    work.  We handle this here rather than change fold_indirect_ref_1
    7345              :    because we're dealing with things like ADDR_EXPR of INTEGER_CST which
    7346              :    don't really make sense outside of constant expression evaluation.  Also
    7347              :    we want to allow folding to COMPONENT_REF, which could cause trouble
    7348              :    with TBAA in fold_indirect_ref_1.  */
    7349              : 
    7350              : static tree
    7351    108975502 : cxx_fold_indirect_ref (const constexpr_ctx *ctx, location_t loc, tree type,
    7352              :                        tree op0, bool *empty_base, tree *jump_target)
    7353              : {
    7354    108975502 :   tree sub = op0;
    7355    108975502 :   tree subtype;
    7356              : 
    7357              :   /* STRIP_NOPS, but stop if REINTERPRET_CAST_P.  */
    7358    226111386 :   while (CONVERT_EXPR_P (sub) || TREE_CODE (sub) == NON_LVALUE_EXPR
    7359    298451656 :          || TREE_CODE (sub) == VIEW_CONVERT_EXPR)
    7360              :     {
    7361     78563915 :       if (TREE_CODE (sub) == NOP_EXPR
    7362     78563915 :           && REINTERPRET_CAST_P (sub))
    7363              :         return NULL_TREE;
    7364     78563915 :       sub = TREE_OPERAND (sub, 0);
    7365              :     }
    7366              : 
    7367    108975502 :   subtype = TREE_TYPE (sub);
    7368    108975502 :   if (!INDIRECT_TYPE_P (subtype))
    7369              :     return NULL_TREE;
    7370              : 
    7371              :   /* Canonicalizes the given OBJ/OFF pair by iteratively absorbing
    7372              :      the innermost component into the offset until it would make the
    7373              :      offset positive, so that cxx_fold_indirect_ref_1 can identify
    7374              :      more folding opportunities.  */
    7375    115819105 :   auto canonicalize_obj_off = [] (tree& obj, tree& off) {
    7376      6843655 :     if (cxx_dialect >= cxx26)
    7377              :       {
    7378              :         /* For C++26, we need to fold *(B *)(&x.D.1234 + 32) used
    7379              :            to access virtual base members.  */
    7380      2312956 :         tree nobj = obj;
    7381      2312956 :         while (TREE_CODE (nobj) == COMPONENT_REF
    7382      2332603 :                && DECL_FIELD_IS_BASE (TREE_OPERAND (nobj, 1)))
    7383        19647 :           nobj = TREE_OPERAND (nobj, 0);
    7384      2312956 :         if (nobj != obj
    7385        15695 :             && CLASS_TYPE_P (TREE_TYPE (nobj))
    7386      2328651 :             && CLASSTYPE_VBASECLASSES (TREE_TYPE (nobj)))
    7387         2039 :           while (obj != nobj)
    7388              :             {
    7389         1174 :               tree field = TREE_OPERAND (obj, 1);
    7390         1174 :               tree pos = byte_position (field);
    7391         1174 :               off = int_const_binop (PLUS_EXPR, off, pos);
    7392         1174 :               obj = TREE_OPERAND (obj, 0);
    7393              :             }
    7394              :       }
    7395      8663193 :     while (TREE_CODE (obj) == COMPONENT_REF
    7396              :            /* We need to preserve union member accesses so that we can
    7397              :               later properly diagnose accessing the wrong member.  */
    7398      4555725 :            && TREE_CODE (TREE_TYPE (TREE_OPERAND (obj, 0))) == RECORD_TYPE
    7399     13091858 :            && (tree_int_cst_sign_bit (off) || integer_zerop (off)))
    7400              :       {
    7401      1895874 :         tree field = TREE_OPERAND (obj, 1);
    7402      1895874 :         tree pos = byte_position (field);
    7403      1895874 :         if (integer_zerop (off) && integer_nonzerop (pos))
    7404              :           /* If the offset is already 0, keep going as long as the
    7405              :              component is at position 0.  */
    7406              :           break;
    7407      1819538 :         off = int_const_binop (PLUS_EXPR, off, pos);
    7408      1819538 :         obj = TREE_OPERAND (obj, 0);
    7409              :       }
    7410      6843655 :   };
    7411              : 
    7412    108975450 :   if (TREE_CODE (sub) == ADDR_EXPR)
    7413              :     {
    7414     47514827 :       tree op = TREE_OPERAND (sub, 0);
    7415     47514827 :       tree optype = TREE_TYPE (op);
    7416              : 
    7417              :       /* *&CONST_DECL -> to the value of the const decl.  */
    7418     47514827 :       if (TREE_CODE (op) == CONST_DECL)
    7419            0 :         return DECL_INITIAL (op);
    7420              :       /* *&p => p;  make sure to handle *&"str"[cst] here.  */
    7421     47514827 :       if (similar_type_p (optype, type))
    7422              :         {
    7423     44957595 :           tree fop = fold_read_from_constant_string (op);
    7424     44957595 :           if (fop)
    7425              :             return fop;
    7426              :           else
    7427     44855869 :             return op;
    7428              :         }
    7429              :       else
    7430              :         {
    7431      2557232 :           tree off = integer_zero_node;
    7432      2557232 :           canonicalize_obj_off (op, off);
    7433      2557232 :           return cxx_fold_indirect_ref_1 (ctx, loc, type, op,
    7434              :                                           tree_to_uhwi (off), empty_base,
    7435              :                                           jump_target);
    7436              :         }
    7437              :     }
    7438     61460623 :   else if (TREE_CODE (sub) == POINTER_PLUS_EXPR
    7439     61460623 :            && tree_fits_uhwi_p (TREE_OPERAND (sub, 1)))
    7440              :     {
    7441      4615059 :       tree op00 = TREE_OPERAND (sub, 0);
    7442      4615059 :       tree off = TREE_OPERAND (sub, 1);
    7443              : 
    7444      4615059 :       STRIP_NOPS (op00);
    7445      4615059 :       if (TREE_CODE (op00) == ADDR_EXPR)
    7446              :         {
    7447      4286423 :           tree obj = TREE_OPERAND (op00, 0);
    7448      4286423 :           canonicalize_obj_off (obj, off);
    7449      4286423 :           return cxx_fold_indirect_ref_1 (ctx, loc, type, obj,
    7450              :                                           tree_to_uhwi (off), empty_base,
    7451              :                                           jump_target);
    7452              :         }
    7453              :     }
    7454              :   /* *(foo *)fooarrptr => (*fooarrptr)[0] */
    7455     56845564 :   else if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE
    7456     56845564 :            && similar_type_p (type, TREE_TYPE (TREE_TYPE (subtype))))
    7457              :     {
    7458            0 :       tree type_domain;
    7459            0 :       tree min_val = size_zero_node;
    7460            0 :       tree newsub
    7461            0 :         = cxx_fold_indirect_ref (ctx, loc, TREE_TYPE (subtype), sub, NULL,
    7462              :                                  jump_target);
    7463            0 :       if (*jump_target)
    7464              :         return NULL_TREE;
    7465            0 :       if (newsub)
    7466              :         sub = newsub;
    7467              :       else
    7468            0 :         sub = build1_loc (loc, INDIRECT_REF, TREE_TYPE (subtype), sub);
    7469            0 :       type_domain = TYPE_DOMAIN (TREE_TYPE (sub));
    7470            0 :       if (type_domain && TYPE_MIN_VALUE (type_domain))
    7471            0 :         min_val = TYPE_MIN_VALUE (type_domain);
    7472            0 :       return build4_loc (loc, ARRAY_REF, type, sub, min_val, NULL_TREE,
    7473            0 :                          NULL_TREE);
    7474              :     }
    7475              : 
    7476              :   return NULL_TREE;
    7477              : }
    7478              : 
    7479              : static tree
    7480     58965055 : cxx_eval_indirect_ref (const constexpr_ctx *ctx, tree t,
    7481              :                        value_cat lval,
    7482              :                        bool *non_constant_p, bool *overflow_p,
    7483              :                        tree *jump_target)
    7484              : {
    7485     58965055 :   tree orig_op0 = TREE_OPERAND (t, 0);
    7486     58965055 :   bool empty_base = false;
    7487              : 
    7488              :   /* We can handle a MEM_REF like an INDIRECT_REF, if MEM_REF's second
    7489              :      operand is an integer-zero.  Otherwise reject the MEM_REF for now.  */
    7490              : 
    7491     58965055 :   if (TREE_CODE (t) == MEM_REF
    7492     58965055 :       && (!TREE_OPERAND (t, 1) || !integer_zerop (TREE_OPERAND (t, 1))))
    7493              :     {
    7494            9 :       gcc_assert (ctx->quiet);
    7495            9 :       *non_constant_p = true;
    7496            9 :       return t;
    7497              :     }
    7498              : 
    7499              :   /* First try to simplify it directly.  */
    7500     58965046 :   tree r = cxx_fold_indirect_ref (ctx, EXPR_LOCATION (t), TREE_TYPE (t),
    7501              :                                   orig_op0, &empty_base, jump_target);
    7502     58965046 :   if (*jump_target)
    7503              :     return NULL_TREE;
    7504     58965046 :   if (!r)
    7505              :     {
    7506              :       /* If that didn't work, evaluate the operand first.  */
    7507     56538955 :       tree op0 = cxx_eval_constant_expression (ctx, orig_op0,
    7508              :                                                vc_prvalue, non_constant_p,
    7509              :                                                overflow_p, jump_target);
    7510     56538955 :       if (*jump_target)
    7511              :         return NULL_TREE;
    7512              :       /* Don't VERIFY_CONSTANT here.  */
    7513     56538946 :       if (*non_constant_p)
    7514              :         return t;
    7515              : 
    7516     40353222 :       if (!lval && integer_zerop (op0))
    7517              :         {
    7518           70 :           if (!ctx->quiet)
    7519           12 :             error ("dereferencing a null pointer");
    7520           70 :           *non_constant_p = true;
    7521           70 :           return t;
    7522              :         }
    7523              : 
    7524     40353152 :       r = cxx_fold_indirect_ref (ctx, EXPR_LOCATION (t), TREE_TYPE (t), op0,
    7525              :                                  &empty_base, jump_target);
    7526     40353152 :       if (*jump_target)
    7527              :         return NULL_TREE;
    7528     40353152 :       if (r == NULL_TREE)
    7529              :         {
    7530              :           /* We couldn't fold to a constant value.  Make sure it's not
    7531              :              something we should have been able to fold.  */
    7532       638760 :           tree sub = op0;
    7533       638760 :           STRIP_NOPS (sub);
    7534       638760 :           if (TREE_CODE (sub) == ADDR_EXPR)
    7535              :             {
    7536         1675 :               gcc_assert (!similar_type_p
    7537              :                           (TREE_TYPE (TREE_TYPE (sub)), TREE_TYPE (t)));
    7538              :               /* DR 1188 says we don't have to deal with this.  */
    7539         1675 :               if (!ctx->quiet)
    7540              :                 {
    7541            8 :                   auto_diagnostic_group d;
    7542           13 :                   error_at (cp_expr_loc_or_input_loc (t),
    7543              :                             "accessing value of %qT object through a %qT "
    7544              :                             "glvalue in a constant expression",
    7545            8 :                             TREE_TYPE (TREE_TYPE (sub)), TREE_TYPE (t));
    7546            8 :                   tree ob = build_fold_indirect_ref (sub);
    7547            8 :                   if (DECL_P (ob))
    7548              :                     {
    7549            8 :                       if (DECL_ARTIFICIAL (ob))
    7550            1 :                         inform (DECL_SOURCE_LOCATION (ob),
    7551            1 :                                 "%qT object created here", TREE_TYPE (ob));
    7552              :                       else
    7553            7 :                         inform (DECL_SOURCE_LOCATION (ob),
    7554              :                                 "%q#D declared here", ob);
    7555              :                     }
    7556            8 :                 }
    7557         1675 :               *non_constant_p = true;
    7558         1675 :               return t;
    7559              :             }
    7560              : 
    7561       637085 :           if (lval == vc_glvalue && op0 != orig_op0)
    7562        76418 :             return build1 (INDIRECT_REF, TREE_TYPE (t), op0);
    7563       560667 :           if (!lval)
    7564       469594 :             VERIFY_CONSTANT (t);
    7565       560667 :           return t;
    7566              :         }
    7567              :     }
    7568              : 
    7569     42140483 :   r = cxx_eval_constant_expression (ctx, r,
    7570              :                                     lval, non_constant_p, overflow_p,
    7571              :                                     jump_target);
    7572     42140482 :   if (*jump_target)
    7573              :     return NULL_TREE;
    7574     42140482 :   if (*non_constant_p)
    7575              :     return t;
    7576              : 
    7577              :   /* If we're pulling out the value of an empty base, just return an empty
    7578              :      CONSTRUCTOR.  */
    7579     35867761 :   if (empty_base && !lval)
    7580              :     {
    7581        16853 :       r = build_constructor (TREE_TYPE (t), NULL);
    7582        16853 :       TREE_CONSTANT (r) = true;
    7583              :     }
    7584              : 
    7585              :   return r;
    7586              : }
    7587              : 
    7588              : /* Complain about R, a DECL that is accessed outside its lifetime.  */
    7589              : 
    7590              : static void
    7591           36 : outside_lifetime_error (location_t loc, tree r)
    7592              : {
    7593           36 :   auto_diagnostic_group d;
    7594           36 :   if (DECL_NAME (r) == heap_deleted_identifier)
    7595              :     {
    7596              :       /* Provide a more accurate message for deleted variables.  */
    7597            6 :       error_at (loc, "use of allocated storage after deallocation "
    7598              :                 "in a constant expression");
    7599            6 :       inform (DECL_SOURCE_LOCATION (r), "allocated here");
    7600              :     }
    7601              :   else
    7602              :     {
    7603           30 :       error_at (loc, "accessing %qE outside its lifetime", r);
    7604           30 :       inform (DECL_SOURCE_LOCATION (r), "declared here");
    7605              :     }
    7606           36 : }
    7607              : 
    7608              : /* Complain about R, a VAR_DECL, not being usable in a constant expression.
    7609              :    FUNDEF_P is true if we're checking a constexpr function body.
    7610              :    Shared between potential_constant_expression and
    7611              :    cxx_eval_constant_expression.  */
    7612              : 
    7613              : static void
    7614          343 : non_const_var_error (location_t loc, tree r, bool fundef_p)
    7615              : {
    7616          343 :   auto_diagnostic_group d;
    7617          343 :   tree type = TREE_TYPE (r);
    7618          343 :   if (DECL_NAME (r) == heap_uninit_identifier
    7619          343 :       || DECL_NAME (r) == heap_identifier
    7620          340 :       || DECL_NAME (r) == heap_vec_uninit_identifier
    7621          683 :       || DECL_NAME (r) == heap_vec_identifier)
    7622              :     {
    7623            3 :       if (constexpr_error (loc, fundef_p, "the content of uninitialized "
    7624              :                            "storage is not usable in a constant expression"))
    7625            3 :         inform (DECL_SOURCE_LOCATION (r), "allocated here");
    7626            3 :       return;
    7627              :     }
    7628          340 :   if (DECL_NAME (r) == heap_deleted_identifier)
    7629              :     {
    7630            0 :       if (constexpr_error (loc, fundef_p, "use of allocated storage after "
    7631              :                            "deallocation in a constant expression"))
    7632            0 :         inform (DECL_SOURCE_LOCATION (r), "allocated here");
    7633            0 :       return;
    7634              :     }
    7635          340 :   if (!constexpr_error (loc, fundef_p, "the value of %qD is not usable in "
    7636              :                         "a constant expression", r))
    7637              :     return;
    7638              :   /* Avoid error cascade.  */
    7639          337 :   if (DECL_INITIAL (r) == error_mark_node)
    7640              :     return;
    7641          323 :   if (DECL_DECLARED_CONSTEXPR_P (r))
    7642            3 :     inform (DECL_SOURCE_LOCATION (r),
    7643              :             "%qD used in its own initializer", r);
    7644          320 :   else if (INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    7645              :     {
    7646          219 :       if (!CP_TYPE_CONST_P (type))
    7647          190 :         inform (DECL_SOURCE_LOCATION (r),
    7648              :                 "%q#D is not const", r);
    7649           29 :       else if (CP_TYPE_VOLATILE_P (type))
    7650            0 :         inform (DECL_SOURCE_LOCATION (r),
    7651              :                 "%q#D is volatile", r);
    7652           29 :       else if (!DECL_INITIAL (r)
    7653            9 :                || !TREE_CONSTANT (DECL_INITIAL (r))
    7654           37 :                || !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (r))
    7655           29 :         inform (DECL_SOURCE_LOCATION (r),
    7656              :                 "%qD was not initialized with a constant "
    7657              :                 "expression", r);
    7658              :       else
    7659            0 :         gcc_unreachable ();
    7660              :     }
    7661          101 :   else if (TYPE_REF_P (type))
    7662            9 :     inform (DECL_SOURCE_LOCATION (r),
    7663              :             "%qD was not initialized with a constant "
    7664              :             "expression", r);
    7665              :   else
    7666              :     {
    7667           92 :       if (cxx_dialect >= cxx11 && !DECL_DECLARED_CONSTEXPR_P (r))
    7668           92 :         inform (DECL_SOURCE_LOCATION (r),
    7669              :                 "%qD was not declared %<constexpr%>", r);
    7670              :       else
    7671            0 :         inform (DECL_SOURCE_LOCATION (r),
    7672              :                 "%qD does not have integral or enumeration type",
    7673              :                 r);
    7674              :     }
    7675          343 : }
    7676              : 
    7677              : /* Subroutine of cxx_eval_constant_expression.
    7678              :    Like cxx_eval_unary_expression, except for trinary expressions.  */
    7679              : 
    7680              : static tree
    7681        14887 : cxx_eval_trinary_expression (const constexpr_ctx *ctx, tree t,
    7682              :                              value_cat lval,
    7683              :                              bool *non_constant_p, bool *overflow_p,
    7684              :                              tree *jump_target)
    7685              : {
    7686        14887 :   int i;
    7687        14887 :   tree args[3];
    7688        14887 :   tree val;
    7689              : 
    7690        58078 :   for (i = 0; i < 3; i++)
    7691              :     {
    7692        43681 :       args[i] = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, i),
    7693              :                                               lval,
    7694              :                                               non_constant_p, overflow_p,
    7695              :                                               jump_target);
    7696        43681 :       if (*jump_target)
    7697              :         return NULL_TREE;
    7698        43681 :       VERIFY_CONSTANT (args[i]);
    7699              :     }
    7700              : 
    7701        14397 :   val = fold_ternary_loc (EXPR_LOCATION (t), TREE_CODE (t), TREE_TYPE (t),
    7702              :                           args[0], args[1], args[2]);
    7703        14397 :   if (val == NULL_TREE)
    7704              :     return t;
    7705        14397 :   VERIFY_CONSTANT (val);
    7706              :   return val;
    7707              : }
    7708              : 
    7709              : /* True if T was declared in a function declared to be constexpr, and
    7710              :    therefore potentially constant in C++14.  */
    7711              : 
    7712              : bool
    7713     84996553 : var_in_constexpr_fn (tree t)
    7714              : {
    7715     84996553 :   tree ctx = DECL_CONTEXT (t);
    7716     84996553 :   return (ctx && TREE_CODE (ctx) == FUNCTION_DECL
    7717    161872038 :           && DECL_DECLARED_CONSTEXPR_P (ctx));
    7718              : }
    7719              : 
    7720              : /* True if a function might be constexpr: either a function that was
    7721              :    declared constexpr, or a C++17 lambda op().  */
    7722              : 
    7723              : bool
    7724    587456720 : maybe_constexpr_fn (tree t)
    7725              : {
    7726    587456720 :   return (DECL_DECLARED_CONSTEXPR_P (t)
    7727    186249770 :           || (cxx_dialect >= cxx17 && LAMBDA_FUNCTION_P (t))
    7728    765915505 :           || (flag_implicit_constexpr
    7729           86 :               && DECL_DECLARED_INLINE_P (STRIP_TEMPLATE (t))));
    7730              : }
    7731              : 
    7732              : /* True if T was declared in a function that might be constexpr: either a
    7733              :    function that was declared constexpr, or a C++17 lambda op().  */
    7734              : 
    7735              : bool
    7736     60367737 : var_in_maybe_constexpr_fn (tree t)
    7737              : {
    7738    120734864 :   return (DECL_FUNCTION_SCOPE_P (t)
    7739    109827737 :           && maybe_constexpr_fn (DECL_CONTEXT (t)));
    7740              : }
    7741              : 
    7742              : /* We're assigning INIT to TARGET.  In do_build_copy_constructor and
    7743              :    build_over_call we implement trivial copy of a class with tail padding using
    7744              :    assignment of character arrays, which is valid in normal code, but not in
    7745              :    constexpr evaluation.  We don't need to worry about clobbering tail padding
    7746              :    in constexpr evaluation, so strip the type punning.  */
    7747              : 
    7748              : static void
    7749     58518346 : maybe_simplify_trivial_copy (tree &target, tree &init)
    7750              : {
    7751     58518346 :   if (TREE_CODE (target) == MEM_REF
    7752         3707 :       && TREE_CODE (init) == MEM_REF
    7753         3543 :       && TREE_TYPE (target) == TREE_TYPE (init)
    7754         3543 :       && TREE_CODE (TREE_TYPE (target)) == ARRAY_TYPE
    7755     58521889 :       && TREE_TYPE (TREE_TYPE (target)) == unsigned_char_type_node)
    7756              :     {
    7757         3543 :       target = build_fold_indirect_ref (TREE_OPERAND (target, 0));
    7758         3543 :       init = build_fold_indirect_ref (TREE_OPERAND (init, 0));
    7759              :     }
    7760     58518346 : }
    7761              : 
    7762              : /* Returns true if REF, which is a COMPONENT_REF, has any fields
    7763              :    of constant type.  This does not check for 'mutable', so the
    7764              :    caller is expected to be mindful of that.  */
    7765              : 
    7766              : static bool
    7767          419 : cref_has_const_field (tree ref)
    7768              : {
    7769          488 :   while (TREE_CODE (ref) == COMPONENT_REF)
    7770              :     {
    7771          479 :       if (CP_TYPE_CONST_P (TREE_TYPE (TREE_OPERAND (ref, 1))))
    7772              :        return true;
    7773           69 :       ref = TREE_OPERAND (ref, 0);
    7774              :     }
    7775              :   return false;
    7776              : }
    7777              : 
    7778              : /* Return true if we are modifying something that is const during constant
    7779              :    expression evaluation.  CODE is the code of the statement, OBJ is the
    7780              :    object in question, MUTABLE_P is true if one of the subobjects were
    7781              :    declared mutable.  */
    7782              : 
    7783              : static bool
    7784     58603412 : modifying_const_object_p (tree_code code, tree obj, bool mutable_p)
    7785              : {
    7786              :   /* If this is initialization, there's no problem.  */
    7787     58603412 :   if (code != MODIFY_EXPR)
    7788              :     return false;
    7789              : 
    7790              :   /* [basic.type.qualifier] "A const object is an object of type
    7791              :      const T or a non-mutable subobject of a const object."  */
    7792     18053387 :   if (mutable_p)
    7793              :     return false;
    7794              : 
    7795     18052651 :   if (TREE_READONLY (obj))
    7796              :     return true;
    7797              : 
    7798     18048479 :   if (CP_TYPE_CONST_P (TREE_TYPE (obj)))
    7799              :     {
    7800              :       /* Although a COMPONENT_REF may have a const type, we should
    7801              :          only consider it modifying a const object when any of the
    7802              :          field components is const.  This can happen when using
    7803              :          constructs such as const_cast<const T &>(m), making something
    7804              :          const even though it wasn't declared const.  */
    7805        30618 :       if (TREE_CODE (obj) == COMPONENT_REF)
    7806          419 :         return cref_has_const_field (obj);
    7807              :       else
    7808              :         return true;
    7809              :     }
    7810              : 
    7811              :   return false;
    7812              : }
    7813              : 
    7814              : /* Evaluate an INIT_EXPR or MODIFY_EXPR.  */
    7815              : 
    7816              : static tree
    7817     58518346 : cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
    7818              :                            value_cat lval,
    7819              :                            bool *non_constant_p, bool *overflow_p,
    7820              :                            tree *jump_target)
    7821              : {
    7822     58518346 :   constexpr_ctx new_ctx = *ctx;
    7823              : 
    7824     58518346 :   tree init = TREE_OPERAND (t, 1);
    7825              : 
    7826              :   /* First we figure out where we're storing to.  */
    7827     58518346 :   tree target = TREE_OPERAND (t, 0);
    7828              : 
    7829     58518346 :   maybe_simplify_trivial_copy (target, init);
    7830              : 
    7831     58518346 :   tree type = TREE_TYPE (target);
    7832     58518346 :   bool preeval = SCALAR_TYPE_P (type) || TREE_CODE (t) == MODIFY_EXPR;
    7833     43944162 :   if (preeval && !TREE_CLOBBER_P (init))
    7834              :     {
    7835              :       /* Ignore var = .DEFERRED_INIT (); for now, until PR121965 is fixed.  */
    7836     43451919 :       if (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    7837     15141585 :           && TREE_CODE (init) == CALL_EXPR
    7838      2086500 :           && CALL_EXPR_FN (init) == NULL_TREE
    7839     43451923 :           && CALL_EXPR_IFN (init) == IFN_DEFERRED_INIT)
    7840            4 :         return void_node;
    7841              : 
    7842              :       /* Evaluate the value to be stored without knowing what object it will be
    7843              :          stored in, so that any side-effects happen first.  */
    7844     43451915 :       if (!SCALAR_TYPE_P (type))
    7845        90474 :         new_ctx.ctor = new_ctx.object = NULL_TREE;
    7846     43451915 :       init = cxx_eval_constant_expression (&new_ctx, init, vc_prvalue,
    7847              :                                            non_constant_p, overflow_p,
    7848              :                                            jump_target);
    7849     43451913 :       if (*jump_target)
    7850              :         return NULL_TREE;
    7851     43451790 :       if (*non_constant_p)
    7852              :         return t;
    7853              :     }
    7854              : 
    7855     50716743 :   bool evaluated = false;
    7856     50716743 :   if (lval == vc_glvalue)
    7857              :     {
    7858              :       /* If we want to return a reference to the target, we need to evaluate it
    7859              :          as a whole; otherwise, only evaluate the innermost piece to avoid
    7860              :          building up unnecessary *_REFs.  */
    7861            0 :       target = cxx_eval_constant_expression (ctx, target, lval,
    7862              :                                              non_constant_p, overflow_p,
    7863              :                                              jump_target);
    7864            0 :       evaluated = true;
    7865            0 :       if (*jump_target)
    7866              :         return NULL_TREE;
    7867            0 :       if (*non_constant_p)
    7868              :         return t;
    7869              :     }
    7870              : 
    7871              :   /* Find the underlying variable.  */
    7872     50716743 :   releasing_vec refs;
    7873     50716743 :   tree object = NULL_TREE;
    7874              :   /* If we're modifying a const object, save it.  */
    7875     50716743 :   tree const_object_being_modified = NULL_TREE;
    7876     50716743 :   bool mutable_p = false;
    7877              :   /* If we see a union, we can't ignore clobbers.  */
    7878     50716743 :   int seen_union = 0;
    7879    174531076 :   for (tree probe = target; object == NULL_TREE; )
    7880              :     {
    7881    123814665 :       switch (TREE_CODE (probe))
    7882              :         {
    7883     22381456 :         case BIT_FIELD_REF:
    7884     22381456 :         case COMPONENT_REF:
    7885     22381456 :         case ARRAY_REF:
    7886     22381456 :           {
    7887     22381456 :             tree ob = TREE_OPERAND (probe, 0);
    7888     22381456 :             tree elt = TREE_OPERAND (probe, 1);
    7889     22381456 :             if (TREE_CODE (elt) == FIELD_DECL && DECL_MUTABLE_P (elt))
    7890              :               mutable_p = true;
    7891     22381456 :             if (TREE_CODE (probe) == ARRAY_REF)
    7892              :               {
    7893      4216152 :                 elt = eval_and_check_array_index (ctx, probe, false,
    7894              :                                                   non_constant_p, overflow_p,
    7895              :                                                   jump_target);
    7896      4216152 :                 if (*jump_target)
    7897           66 :                   return NULL_TREE;
    7898      4216152 :                 if (*non_constant_p)
    7899              :                   return t;
    7900              :               }
    7901              :             /* We don't check modifying_const_object_p for ARRAY_REFs.  Given
    7902              :                "int a[10]", an ARRAY_REF "a[2]" can be "const int", even though
    7903              :                the array isn't const.  Instead, check "a" in the next iteration;
    7904              :                that will detect modifying "const int a[10]".  */
    7905     18165304 :             else if (evaluated
    7906      7887001 :                      && modifying_const_object_p (TREE_CODE (t), probe,
    7907              :                                                   mutable_p)
    7908     18165816 :                      && const_object_being_modified == NULL_TREE)
    7909              :               const_object_being_modified = probe;
    7910              : 
    7911              :             /* Track named member accesses for unions to validate modifications
    7912              :                that change active member.  */
    7913     22381390 :             if (!evaluated && TREE_CODE (probe) == COMPONENT_REF)
    7914     10278303 :               vec_safe_push (refs, probe);
    7915              :             else
    7916     12103087 :               vec_safe_push (refs, NULL_TREE);
    7917              : 
    7918     22381390 :             vec_safe_push (refs, elt);
    7919     22381390 :             vec_safe_push (refs, TREE_TYPE (probe));
    7920     22381390 :             probe = ob;
    7921     22381390 :             if (TREE_CODE (TREE_TYPE (ob)) == UNION_TYPE)
    7922       296707 :               ++seen_union;
    7923              :           }
    7924     22381390 :           break;
    7925              : 
    7926           16 :         case REALPART_EXPR:
    7927           16 :           gcc_assert (refs->is_empty ());
    7928           16 :           vec_safe_push (refs, NULL_TREE);
    7929           16 :           vec_safe_push (refs, probe);
    7930           16 :           vec_safe_push (refs, TREE_TYPE (probe));
    7931           16 :           probe = TREE_OPERAND (probe, 0);
    7932           16 :           break;
    7933              : 
    7934           17 :         case IMAGPART_EXPR:
    7935           17 :           gcc_assert (refs->is_empty ());
    7936           17 :           vec_safe_push (refs, NULL_TREE);
    7937           17 :           vec_safe_push (refs, probe);
    7938           17 :           vec_safe_push (refs, TREE_TYPE (probe));
    7939           17 :           probe = TREE_OPERAND (probe, 0);
    7940           17 :           break;
    7941              : 
    7942    101433176 :         default:
    7943    101433176 :           if (evaluated)
    7944              :             object = probe;
    7945              :           else
    7946              :             {
    7947     50716765 :               tree pvar = tree_strip_any_location_wrapper (probe);
    7948     50716765 :               if (VAR_P (pvar) && DECL_ANON_UNION_VAR_P (pvar))
    7949              :                 {
    7950              :                   /* Stores to DECL_ANON_UNION_VAR_P var are allowed to change
    7951              :                      active union member.  */
    7952           55 :                   probe = DECL_VALUE_EXPR (pvar);
    7953           55 :                   break;
    7954              :                 }
    7955     50716710 :               probe = cxx_eval_constant_expression (ctx, probe, vc_glvalue,
    7956              :                                                     non_constant_p, overflow_p,
    7957              :                                                     jump_target);
    7958     50716710 :               evaluated = true;
    7959     50716710 :               if (*jump_target)
    7960              :                 return NULL_TREE;
    7961     50716710 :               if (*non_constant_p)
    7962              :                 return t;
    7963              :             }
    7964              :           break;
    7965              :         }
    7966              :     }
    7967              : 
    7968     50716411 :   if (modifying_const_object_p (TREE_CODE (t), object, mutable_p)
    7969     50716411 :       && const_object_being_modified == NULL_TREE)
    7970     50716411 :     const_object_being_modified = object;
    7971              : 
    7972     50716411 :   if (DECL_P (object)
    7973     50715450 :       && TREE_CLOBBER_P (init)
    7974     51216379 :       && DECL_NAME (object) == heap_deleted_identifier)
    7975              :     /* Ignore clobbers of deleted allocations for now; we'll get a better error
    7976              :        message later when operator delete is called.  */
    7977           15 :     return void_node;
    7978              : 
    7979              :   /* And then find/build up our initializer for the path to the subobject
    7980              :      we're initializing.  */
    7981     50716396 :   tree *valp;
    7982     50716396 :   if (DECL_P (object))
    7983     50715435 :     valp = ctx->global->get_value_ptr (object, TREE_CODE (t) == INIT_EXPR);
    7984              :   else
    7985          961 :     valp = NULL;
    7986     50716396 :   if (!valp)
    7987              :     {
    7988              :       /* A constant-expression cannot modify objects from outside the
    7989              :          constant-expression.  */
    7990         6282 :       if (!ctx->quiet)
    7991              :         {
    7992           29 :           auto_diagnostic_group d;
    7993           29 :           if (DECL_P (object) && DECL_NAME (object) == heap_deleted_identifier)
    7994              :             {
    7995            0 :               error ("modification of allocated storage after deallocation "
    7996              :                      "is not a constant expression");
    7997            0 :               inform (DECL_SOURCE_LOCATION (object), "allocated here");
    7998              :             }
    7999           29 :           else if (DECL_P (object) && ctx->global->is_outside_lifetime (object))
    8000              :             {
    8001           14 :               if (TREE_CLOBBER_P (init))
    8002            6 :                 error ("destroying %qE outside its lifetime", object);
    8003              :               else
    8004            8 :                 error ("modification of %qE outside its lifetime "
    8005              :                        "is not a constant expression", object);
    8006           14 :               inform (DECL_SOURCE_LOCATION (object), "declared here");
    8007              :             }
    8008              :           else
    8009              :             {
    8010           15 :               if (TREE_CLOBBER_P (init))
    8011            6 :                 error ("destroying %qE from outside current evaluation "
    8012              :                        "is not a constant expression", object);
    8013              :               else
    8014            9 :                 error ("modification of %qE from outside current evaluation "
    8015              :                        "is not a constant expression", object);
    8016              :             }
    8017           29 :         }
    8018         6282 :       *non_constant_p = true;
    8019         6282 :       return t;
    8020              :     }
    8021              : 
    8022              :   /* Handle explicit end-of-lifetime.  */
    8023     50710114 :   if (TREE_CLOBBER_P (init))
    8024              :     {
    8025       499903 :       if (CLOBBER_KIND (init) >= CLOBBER_OBJECT_END
    8026       499903 :           && refs->is_empty ())
    8027              :         {
    8028       115909 :           ctx->global->destroy_value (object);
    8029       115909 :           return void_node;
    8030              :         }
    8031              : 
    8032       379058 :       if (!seen_union && !*valp
    8033       387332 :           && CLOBBER_KIND (init) < CLOBBER_OBJECT_END)
    8034         3304 :         return void_node;
    8035              : 
    8036              :       /* Ending the lifetime of a const object is OK.  */
    8037              :       const_object_being_modified = NULL_TREE;
    8038              :     }
    8039              : 
    8040     50590901 :   type = TREE_TYPE (object);
    8041     50590901 :   bool no_zero_init = true;
    8042     50590901 :   bool zero_padding_bits = false;
    8043              : 
    8044    101181802 :   auto_vec<tree *> ctors;
    8045    101181802 :   releasing_vec indexes;
    8046    101181802 :   auto_vec<int> index_pos_hints;
    8047     50590901 :   bool activated_union_member_p = false;
    8048     50590901 :   bool empty_base = false;
    8049     72834527 :   while (!refs->is_empty ())
    8050              :     {
    8051     22366577 :       if (*valp == NULL_TREE)
    8052              :         {
    8053      1944458 :           *valp = build_constructor (type, NULL);
    8054      1944458 :           CONSTRUCTOR_NO_CLEARING (*valp) = no_zero_init;
    8055      1944458 :           CONSTRUCTOR_ZERO_PADDING_BITS (*valp) = zero_padding_bits;
    8056              :         }
    8057     20422119 :       else if (STRIP_ANY_LOCATION_WRAPPER (*valp),
    8058     20422119 :                TREE_CODE (*valp) == STRING_CST)
    8059              :         {
    8060              :           /* An array was initialized with a string constant, and now
    8061              :              we're writing into one of its elements.  Explode the
    8062              :              single initialization into a set of element
    8063              :              initializations.  */
    8064        10587 :           gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    8065              : 
    8066        10587 :           tree string = *valp;
    8067        10587 :           tree elt_type = TREE_TYPE (type);
    8068        10587 :           unsigned chars_per_elt = (TYPE_PRECISION (elt_type)
    8069        10587 :                                     / TYPE_PRECISION (char_type_node));
    8070        10587 :           unsigned num_elts = TREE_STRING_LENGTH (string) / chars_per_elt;
    8071        10587 :           tree ary_ctor = build_constructor (type, NULL);
    8072              : 
    8073        10587 :           vec_safe_reserve (CONSTRUCTOR_ELTS (ary_ctor), num_elts);
    8074        21328 :           for (unsigned ix = 0; ix != num_elts; ix++)
    8075              :             {
    8076        10741 :               constructor_elt elt =
    8077              :                 {
    8078        10741 :                   build_int_cst (size_type_node, ix),
    8079        10741 :                   extract_string_elt (string, chars_per_elt, ix)
    8080        10741 :                 };
    8081        10741 :               CONSTRUCTOR_ELTS (ary_ctor)->quick_push (elt);
    8082              :             }
    8083              : 
    8084        10587 :           *valp = ary_ctor;
    8085              :         }
    8086              : 
    8087     22366577 :       enum tree_code code = TREE_CODE (type);
    8088     22366577 :       tree reftype = refs->pop();
    8089     22366577 :       tree index = refs->pop();
    8090     22366577 :       bool is_access_expr = refs->pop() != NULL_TREE;
    8091              : 
    8092     22366577 :       if (code == COMPLEX_TYPE)
    8093              :         {
    8094           33 :           if (TREE_CODE (*valp) == COMPLEX_CST)
    8095           29 :             *valp = build2 (COMPLEX_EXPR, type, TREE_REALPART (*valp),
    8096           29 :                             TREE_IMAGPART (*valp));
    8097            4 :           else if (TREE_CODE (*valp) == CONSTRUCTOR
    8098            2 :                    && CONSTRUCTOR_NELTS (*valp) == 0
    8099            6 :                    && CONSTRUCTOR_NO_CLEARING (*valp))
    8100              :             {
    8101            2 :               tree r = build_constructor (reftype, NULL);
    8102            2 :               CONSTRUCTOR_NO_CLEARING (r) = 1;
    8103            2 :               *valp = build2 (COMPLEX_EXPR, type, r, r);
    8104              :             }
    8105           33 :           gcc_assert (TREE_CODE (*valp) == COMPLEX_EXPR);
    8106           33 :           ctors.safe_push (valp);
    8107           33 :           vec_safe_push (indexes, index);
    8108           33 :           valp = &TREE_OPERAND (*valp, TREE_CODE (index) == IMAGPART_EXPR);
    8109           33 :           gcc_checking_assert (refs->is_empty ());
    8110              :           type = reftype;
    8111       120825 :           break;
    8112              :         }
    8113              : 
    8114              :       /* If the value of object is already zero-initialized, any new ctors for
    8115              :          subobjects will also be zero-initialized.  Similarly with zeroing of
    8116              :          padding bits.  */
    8117     22366544 :       no_zero_init = CONSTRUCTOR_NO_CLEARING (*valp);
    8118     22366544 :       zero_padding_bits = CONSTRUCTOR_ZERO_PADDING_BITS (*valp);
    8119              : 
    8120     22366544 :       if (code == RECORD_TYPE && is_empty_field (index))
    8121              :         /* Don't build a sub-CONSTRUCTOR for an empty base or field, as they
    8122              :            have no data and might have an offset lower than previously declared
    8123              :            fields, which confuses the middle-end.  The code below will notice
    8124              :            that we don't have a CONSTRUCTOR for our inner target and just
    8125              :            return init.  */
    8126              :         {
    8127              :           empty_base = true;
    8128              :           break;
    8129              :         }
    8130              : 
    8131              :       /* If a union is zero-initialized, its first non-static named data member
    8132              :          is zero-initialized (and therefore active).  */
    8133     22245752 :       if (code == UNION_TYPE
    8134     22245752 :           && !no_zero_init
    8135     22245752 :           && CONSTRUCTOR_NELTS (*valp) == 0)
    8136         2281 :         if (tree first = next_aggregate_field (TYPE_FIELDS (type)))
    8137         2281 :           CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (*valp), first, NULL_TREE);
    8138              : 
    8139              :       /* Check for implicit change of active member for a union.  */
    8140              : 
    8141              :       /* LWG3436, CWG2675, c++/121068: The array object model is confused.  For
    8142              :          now allow initializing an array element to activate the array.  */
    8143     22281323 :       auto only_array_refs = [](const releasing_vec &refs)
    8144              :       {
    8145        35575 :         for (unsigned i = 1; i < refs->length(); i += 3)
    8146           34 :           if (TREE_CODE ((*refs)[i]) != INTEGER_CST)
    8147              :             return false;
    8148              :         return true;
    8149              :       };
    8150              : 
    8151     22245752 :       if (code == UNION_TYPE
    8152       295937 :           && (CONSTRUCTOR_NELTS (*valp) == 0
    8153       149858 :               || CONSTRUCTOR_ELT (*valp, 0)->index != index)
    8154              :           /* An INIT_EXPR of the last member in an access chain is always OK,
    8155              :              but still check implicit change of members earlier on; see
    8156              :              cpp2a/constexpr-union6.C.  */
    8157     22396323 :           && !(TREE_CODE (t) == INIT_EXPR && only_array_refs (refs)))
    8158              :         {
    8159       115030 :           bool has_active_member = CONSTRUCTOR_NELTS (*valp) != 0;
    8160       115030 :           tree inner = strip_array_types (reftype);
    8161              : 
    8162       115030 :           if (has_active_member && cxx_dialect < cxx20)
    8163              :             {
    8164           58 :               if (!ctx->quiet)
    8165           19 :                 error_at (cp_expr_loc_or_input_loc (t),
    8166              :                           "change of the active member of a union "
    8167              :                           "from %qD to %qD is not a constant expression "
    8168              :                           "before C++20",
    8169           19 :                           CONSTRUCTOR_ELT (*valp, 0)->index,
    8170              :                           index);
    8171           58 :               *non_constant_p = true;
    8172              :             }
    8173       114972 :           else if (!is_access_expr
    8174        26219 :                    || (TREE_CLOBBER_P (init)
    8175            0 :                        && CLOBBER_KIND (init) >= CLOBBER_OBJECT_END)
    8176       141191 :                    || (TREE_CODE (t) == MODIFY_EXPR
    8177        26207 :                        && CLASS_TYPE_P (inner)
    8178           17 :                        && !type_has_non_deleted_trivial_default_ctor (inner)))
    8179              :             {
    8180              :               /* Diagnose changing active union member after initialization
    8181              :                  without a valid member access expression, as described in
    8182              :                  [class.union.general] p5.  */
    8183        88762 :               if (!ctx->quiet)
    8184              :                 {
    8185           33 :                   auto_diagnostic_group d;
    8186           33 :                   if (has_active_member)
    8187           24 :                     error_at (cp_expr_loc_or_input_loc (t),
    8188              :                               "accessing %qD member instead of initialized "
    8189              :                               "%qD member in constant expression",
    8190           24 :                               index, CONSTRUCTOR_ELT (*valp, 0)->index);
    8191              :                   else
    8192            9 :                     error_at (cp_expr_loc_or_input_loc (t),
    8193              :                               "accessing uninitialized member %qD",
    8194              :                               index);
    8195           33 :                   if (is_access_expr)
    8196            3 :                     inform (DECL_SOURCE_LOCATION (index),
    8197              :                             "%qD does not implicitly begin its lifetime "
    8198              :                             "because %qT does not have a non-deleted "
    8199              :                             "trivial default constructor, use "
    8200              :                             "%<std::construct_at%> instead",
    8201              :                             index, inner);
    8202              :                   else
    8203           30 :                     inform (DECL_SOURCE_LOCATION (index),
    8204              :                             "initializing %qD requires a member access "
    8205              :                             "expression as the left operand of the assignment",
    8206              :                             index);
    8207           33 :                 }
    8208        88762 :               *non_constant_p = true;
    8209              :             }
    8210        26210 :           else if (has_active_member && CONSTRUCTOR_NO_CLEARING (*valp))
    8211              :             {
    8212              :               /* Diagnose changing the active union member while the union
    8213              :                  is in the process of being initialized.  */
    8214           18 :               if (!ctx->quiet)
    8215            6 :                 error_at (cp_expr_loc_or_input_loc (t),
    8216              :                           "change of the active member of a union "
    8217              :                           "from %qD to %qD during initialization",
    8218            6 :                           CONSTRUCTOR_ELT (*valp, 0)->index,
    8219              :                           index);
    8220           18 :               *non_constant_p = true;
    8221              :             }
    8222              :           no_zero_init = true;
    8223              :         }
    8224              : 
    8225              :       /* Ending the lifetime of the active union member means the union no
    8226              :          longer has an active member.  */
    8227       295937 :       if (code == UNION_TYPE && refs->is_empty ()
    8228        62342 :           && TREE_CLOBBER_P (init)
    8229     22248284 :           && CLOBBER_KIND (init) >= CLOBBER_OBJECT_END)
    8230              :         {
    8231         1204 :           vec_safe_truncate (CONSTRUCTOR_ELTS (*valp), 0);
    8232         2126 :           return void_node;
    8233              :         }
    8234              : 
    8235     22244548 :       ctors.safe_push (valp);
    8236     22244548 :       vec_safe_push (indexes, index);
    8237              : 
    8238              :       /* Avoid adding an _elt for a clobber when the whole CONSTRUCTOR is
    8239              :          uninitialized.  */
    8240     21295206 :       int pos = (!seen_union && TREE_CLOBBER_P (init)
    8241       880600 :                  && CONSTRUCTOR_NO_CLEARING (*valp)
    8242     23028839 :                  && CLOBBER_KIND (init) < CLOBBER_OBJECT_END) ? -2 : -1;
    8243     22244548 :       constructor_elt *cep
    8244     22244548 :         = get_or_insert_ctor_field (*valp, index, pos);
    8245     22244548 :       if (cep == nullptr)
    8246          922 :         return void_node;
    8247     22243626 :       index_pos_hints.safe_push (cep - CONSTRUCTOR_ELTS (*valp)->begin());
    8248              : 
    8249     22243626 :       if (code == UNION_TYPE)
    8250              :         {
    8251       294733 :           activated_union_member_p = true;
    8252       294733 :           --seen_union;
    8253              :         }
    8254              : 
    8255     22243626 :       valp = &cep->value;
    8256     22243626 :       type = reftype;
    8257              :     }
    8258              : 
    8259              :   /* Change an "as-base" clobber to the real type;
    8260              :      we don't need to worry about padding in constexpr.  */
    8261     50588775 :   tree itype = initialized_type (init);
    8262     50588775 :   if (IS_FAKE_BASE_TYPE (itype))
    8263         2204 :     itype = TYPE_CONTEXT (itype);
    8264              : 
    8265              :   /* For initialization of an empty base, the original target will be
    8266              :      *(base*)this, evaluation of which resolves to the object
    8267              :      argument, which has the derived type rather than the base type.  */
    8268    101056758 :   if (!empty_base && !(same_type_ignoring_top_level_qualifiers_p
    8269     50467983 :                        (itype, type)))
    8270              :     {
    8271        11971 :       gcc_assert (is_empty_class (TREE_TYPE (target)));
    8272              :       empty_base = true;
    8273              :     }
    8274              : 
    8275              :   /* Detect modifying a constant object in constexpr evaluation.
    8276              :      We have found a const object that is being modified.  Figure out
    8277              :      if we need to issue an error.  Consider
    8278              : 
    8279              :      struct A {
    8280              :        int n;
    8281              :        constexpr A() : n(1) { n = 2; } // #1
    8282              :      };
    8283              :      struct B {
    8284              :        const A a;
    8285              :        constexpr B() { a.n = 3; } // #2
    8286              :      };
    8287              :     constexpr B b{};
    8288              : 
    8289              :     #1 is OK, since we're modifying an object under construction, but
    8290              :     #2 is wrong, since "a" is const and has been fully constructed.
    8291              :     To track it, we use the TREE_READONLY bit in the object's CONSTRUCTOR
    8292              :     which means that the object is read-only.  For the example above, the
    8293              :     *ctors stack at the point of #2 will look like:
    8294              : 
    8295              :       ctors[0] = {.a={.n=2}}  TREE_READONLY = 0
    8296              :       ctors[1] = {.n=2}       TREE_READONLY = 1
    8297              : 
    8298              :     and we're modifying "b.a", so we search the stack and see if the
    8299              :     constructor for "b.a" has already run.  */
    8300     50588775 :   if (const_object_being_modified)
    8301              :     {
    8302        33629 :       bool fail = false;
    8303        33629 :       tree const_objtype
    8304        33629 :         = strip_array_types (TREE_TYPE (const_object_being_modified));
    8305        33629 :       if (!CLASS_TYPE_P (const_objtype))
    8306              :         fail = true;
    8307              :       else
    8308              :         {
    8309              :           /* [class.ctor]p5 "A constructor can be invoked for a const,
    8310              :              volatile, or const volatile object.  const and volatile
    8311              :              semantics are not applied on an object under construction.
    8312              :              They come into effect when the constructor for the most
    8313              :              derived object ends."  */
    8314       100984 :           for (tree *elt : ctors)
    8315        33936 :             if (same_type_ignoring_top_level_qualifiers_p
    8316        33936 :                 (TREE_TYPE (const_object_being_modified), TREE_TYPE (*elt)))
    8317              :               {
    8318        33524 :                 fail = TREE_READONLY (*elt);
    8319        33524 :                 break;
    8320              :               }
    8321              :         }
    8322        33524 :       if (fail)
    8323              :         {
    8324          198 :           if (!ctx->quiet)
    8325           63 :             modifying_const_object_error (t, const_object_being_modified);
    8326          198 :           *non_constant_p = true;
    8327          198 :           return t;
    8328              :         }
    8329              :     }
    8330              : 
    8331     50588577 :   if (!preeval)
    8332              :     {
    8333              :       /* We're handling an INIT_EXPR of class type, so the value of the
    8334              :          initializer can depend on the object it's initializing.  */
    8335              : 
    8336              :       /* Create a new CONSTRUCTOR in case evaluation of the initializer
    8337              :          wants to modify it.  */
    8338     14565901 :       if (*valp == NULL_TREE)
    8339              :         {
    8340     13990687 :           *valp = build_constructor (type, NULL);
    8341     13990687 :           CONSTRUCTOR_NO_CLEARING (*valp) = no_zero_init;
    8342     13990687 :           CONSTRUCTOR_ZERO_PADDING_BITS (*valp) = zero_padding_bits;
    8343              :         }
    8344     14565901 :       new_ctx.ctor = empty_base ? NULL_TREE : *valp;
    8345     14565901 :       new_ctx.object = target;
    8346              :       /* Avoid temporary materialization when initializing from a TARGET_EXPR.
    8347              :          We don't need to mess with AGGR_EXPR_SLOT/VEC_INIT_EXPR_SLOT because
    8348              :          expansion of those trees uses ctx instead.  */
    8349     14565901 :       if (TREE_CODE (init) == TARGET_EXPR)
    8350      2342353 :         if (tree tinit = TARGET_EXPR_INITIAL (init))
    8351      2342353 :           init = tinit;
    8352     14565901 :       init = cxx_eval_constant_expression (&new_ctx, init, vc_prvalue,
    8353              :                                            non_constant_p, overflow_p,
    8354              :                                            jump_target);
    8355     14565901 :       if (*jump_target)
    8356              :         return NULL_TREE;
    8357              :       /* The hash table might have moved since the get earlier, and the
    8358              :          initializer might have mutated the underlying CONSTRUCTORs, so we must
    8359              :          recompute VALP. */
    8360     14565837 :       valp = ctx->global->get_value_ptr (object, TREE_CODE (t) == INIT_EXPR);
    8361     16746080 :       for (unsigned i = 0; i < vec_safe_length (indexes); i++)
    8362              :         {
    8363      2180243 :           ctors[i] = valp;
    8364      2180243 :           constructor_elt *cep
    8365      2180243 :             = get_or_insert_ctor_field (*valp, indexes[i], index_pos_hints[i]);
    8366      2180243 :           valp = &cep->value;
    8367              :         }
    8368              :     }
    8369              : 
    8370     50588513 :   if (*non_constant_p)
    8371              :     return t;
    8372              : 
    8373              :   /* Don't share a CONSTRUCTOR that might be changed later.  */
    8374     49094665 :   init = unshare_constructor (init);
    8375              : 
    8376     49094665 :   gcc_checking_assert (!*valp
    8377              :                        || *valp == void_node
    8378              :                        || (same_type_ignoring_top_level_qualifiers_p
    8379              :                            (TREE_TYPE (*valp), type)));
    8380     49094665 :   if (empty_base)
    8381              :     {
    8382              :       /* Just evaluate the initializer and return, since there's no actual data
    8383              :          to store, and we didn't build a CONSTRUCTOR.  */
    8384       125602 :       if (!*valp)
    8385              :         {
    8386              :           /* But do make sure we have something in *valp.  */
    8387            0 :           *valp = build_constructor (type, nullptr);
    8388            0 :           CONSTRUCTOR_NO_CLEARING (*valp) = no_zero_init;
    8389            0 :           CONSTRUCTOR_ZERO_PADDING_BITS (*valp) = zero_padding_bits;
    8390              :         }
    8391              :     }
    8392     48969063 :   else if (TREE_CLOBBER_P (init))
    8393              :     {
    8394       378564 :       if (AGGREGATE_TYPE_P (type))
    8395              :         {
    8396       265701 :           if (*valp && TREE_CODE (*valp) == CONSTRUCTOR)
    8397       265678 :             CONSTRUCTOR_ELTS (*valp) = nullptr;
    8398              :           else
    8399           23 :             *valp = build_constructor (type, nullptr);
    8400       265701 :           TREE_CONSTANT (*valp) = true;
    8401       265701 :           TREE_SIDE_EFFECTS (*valp) = false;
    8402       265701 :           CONSTRUCTOR_NO_CLEARING (*valp) = true;
    8403       265701 :           CONSTRUCTOR_ZERO_PADDING_BITS (*valp) = zero_padding_bits;
    8404              :         }
    8405              :       else
    8406       112863 :         *valp = void_node;
    8407              :     }
    8408     48590499 :   else if (*valp && TREE_CODE (*valp) == CONSTRUCTOR
    8409     13115297 :            && TREE_CODE (init) == CONSTRUCTOR)
    8410              :     {
    8411              :       /* An outer ctx->ctor might be pointing to *valp, so replace
    8412              :          its contents.  */
    8413      2983233 :       CONSTRUCTOR_ELTS (*valp) = CONSTRUCTOR_ELTS (init);
    8414      2983233 :       TREE_CONSTANT (*valp) = TREE_CONSTANT (init);
    8415      2983233 :       TREE_SIDE_EFFECTS (*valp) = TREE_SIDE_EFFECTS (init);
    8416      8949699 :       CONSTRUCTOR_NO_CLEARING (*valp)
    8417      2983233 :         = CONSTRUCTOR_NO_CLEARING (init);
    8418      8949699 :       CONSTRUCTOR_ZERO_PADDING_BITS (*valp)
    8419      2983233 :         = CONSTRUCTOR_ZERO_PADDING_BITS (init);
    8420              :     }
    8421              :   else
    8422     45607266 :     *valp = init;
    8423              : 
    8424              :   /* After initialization, 'const' semantics apply to the value of the
    8425              :      object.  Make a note of this fact by marking the CONSTRUCTOR
    8426              :      TREE_READONLY.  */
    8427     49094665 :   if (TREE_CODE (t) == INIT_EXPR
    8428     35713889 :       && !empty_base
    8429     35588287 :       && TREE_CODE (*valp) == CONSTRUCTOR
    8430     51997842 :       && TYPE_READONLY (type))
    8431              :     {
    8432        27379 :       tree target_type = TREE_TYPE (target);
    8433        27379 :       if (IS_FAKE_BASE_TYPE (target_type))
    8434            0 :         target_type = TYPE_CONTEXT (target_type);
    8435        27379 :       if (INDIRECT_REF_P (target)
    8436        42442 :           && (is_this_parameter
    8437        15063 :               (tree_strip_nop_conversions (TREE_OPERAND (target, 0)))))
    8438              :         /* We've just initialized '*this' (perhaps via the target
    8439              :            constructor of a delegating constructor).  Leave it up to the
    8440              :            caller that set 'this' to set TREE_READONLY appropriately.  */
    8441           23 :         gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p
    8442              :                              (target_type, type) || empty_base);
    8443              :       else
    8444        27356 :         TREE_READONLY (*valp) = true;
    8445              :     }
    8446              : 
    8447              :   /* Update TREE_CONSTANT and TREE_SIDE_EFFECTS on enclosing
    8448              :      CONSTRUCTORs, if any.  */
    8449     49094665 :   bool c = TREE_CONSTANT (init);
    8450     49094665 :   bool s = TREE_SIDE_EFFECTS (init);
    8451     49094665 :   if (!indexes->is_empty ())
    8452              :     {
    8453     12762822 :       tree last = indexes->last ();
    8454     12762822 :       if (TREE_CODE (last) == REALPART_EXPR
    8455     12762822 :           || TREE_CODE (last) == IMAGPART_EXPR)
    8456              :         {
    8457              :           /* And canonicalize COMPLEX_EXPR into COMPLEX_CST if
    8458              :              possible.  */
    8459           33 :           tree *cexpr = ctors.last ();
    8460           33 :           if (tree c = const_binop (COMPLEX_EXPR, TREE_TYPE (*cexpr),
    8461           33 :                                     TREE_OPERAND (*cexpr, 0),
    8462           33 :                                     TREE_OPERAND (*cexpr, 1)))
    8463           31 :             *cexpr = c;
    8464              :           else
    8465              :             {
    8466            4 :               TREE_CONSTANT (*cexpr)
    8467            2 :                 = (TREE_CONSTANT (TREE_OPERAND (*cexpr, 0))
    8468            2 :                    & TREE_CONSTANT (TREE_OPERAND (*cexpr, 1)));
    8469            4 :               TREE_SIDE_EFFECTS (*cexpr)
    8470            4 :                 = (TREE_SIDE_EFFECTS (TREE_OPERAND (*cexpr, 0))
    8471            2 :                    | TREE_SIDE_EFFECTS (TREE_OPERAND (*cexpr, 1)));
    8472              :             }
    8473           33 :           c = TREE_CONSTANT (*cexpr);
    8474           33 :           s = TREE_SIDE_EFFECTS (*cexpr);
    8475              :         }
    8476              :     }
    8477     49094665 :   if (!c || s || activated_union_member_p)
    8478     30950268 :     for (tree *elt : ctors)
    8479              :       {
    8480      5831800 :         if (TREE_CODE (*elt) != CONSTRUCTOR)
    8481            0 :           continue;
    8482      5831800 :         if (!c)
    8483      4980714 :           TREE_CONSTANT (*elt) = false;
    8484      5831800 :         if (s)
    8485            0 :           TREE_SIDE_EFFECTS (*elt) = true;
    8486              :         /* Clear CONSTRUCTOR_NO_CLEARING since we've activated a member of
    8487              :            this union.  */
    8488      5831800 :         if (TREE_CODE (TREE_TYPE (*elt)) == UNION_TYPE)
    8489       205716 :           CONSTRUCTOR_NO_CLEARING (*elt) = false;
    8490              :       }
    8491              : 
    8492     49094665 :   if (lval)
    8493              :     return target;
    8494              :   else
    8495       281717 :     return init;
    8496     50716743 : }
    8497              : 
    8498              : /* Evaluate a ++ or -- expression.  */
    8499              : 
    8500              : static tree
    8501      4964165 : cxx_eval_increment_expression (const constexpr_ctx *ctx, tree t,
    8502              :                               value_cat lval,
    8503              :                               bool *non_constant_p, bool *overflow_p,
    8504              :                               tree *jump_target)
    8505              : {
    8506      4964165 :   enum tree_code code = TREE_CODE (t);
    8507      4964165 :   tree type = TREE_TYPE (t);
    8508      4964165 :   tree op = TREE_OPERAND (t, 0);
    8509      4964165 :   tree offset = TREE_OPERAND (t, 1);
    8510      4964165 :   gcc_assert (TREE_CONSTANT (offset));
    8511              : 
    8512              :   /* OFFSET is constant, but perhaps not constant enough.  We need to
    8513              :      e.g. bash FLOAT_EXPRs to REAL_CSTs.  */
    8514      4964165 :   offset = fold_simple (offset);
    8515              : 
    8516              :   /* The operand as an lvalue.  */
    8517      4964165 :   op = cxx_eval_constant_expression (ctx, op, vc_glvalue,
    8518              :                                      non_constant_p, overflow_p,
    8519              :                                      jump_target);
    8520      4964165 :   if (*jump_target)
    8521              :     return NULL_TREE;
    8522              : 
    8523              :   /* The operand as an rvalue.  */
    8524      4964165 :   tree val
    8525      4964165 :     = cxx_eval_constant_expression (ctx, op, vc_prvalue,
    8526              :                                     non_constant_p, overflow_p,
    8527              :                                     jump_target);
    8528      4964165 :   if (*jump_target)
    8529              :     return NULL_TREE;
    8530              :   /* Don't VERIFY_CONSTANT if this might be dealing with a pointer to
    8531              :      a local array in a constexpr function.  */
    8532      4964165 :   bool ptr = INDIRECT_TYPE_P (TREE_TYPE (val));
    8533      1915976 :   if (!ptr)
    8534      1915976 :     VERIFY_CONSTANT (val);
    8535              : 
    8536              :   /* The modified value.  */
    8537      4911787 :   bool inc = (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR);
    8538      4911787 :   tree mod;
    8539      4911787 :   if (INDIRECT_TYPE_P (type))
    8540              :     {
    8541              :       /* The middle end requires pointers to use POINTER_PLUS_EXPR.  */
    8542      3048189 :       offset = convert_to_ptrofftype (offset);
    8543      3048189 :       if (!inc)
    8544        52967 :         offset = fold_build1 (NEGATE_EXPR, TREE_TYPE (offset), offset);
    8545      3048189 :       mod = fold_build2 (POINTER_PLUS_EXPR, type, val, offset);
    8546              :     }
    8547      1863598 :   else if (c_promoting_integer_type_p (type)
    8548         5086 :            && !TYPE_UNSIGNED (type)
    8549      1863723 :            && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
    8550              :     {
    8551          125 :       offset = fold_convert (integer_type_node, offset);
    8552          125 :       mod = fold_convert (integer_type_node, val);
    8553          155 :       tree t = fold_build2 (inc ? PLUS_EXPR : MINUS_EXPR, integer_type_node,
    8554              :                             mod, offset);
    8555          125 :       mod = fold_convert (type, t);
    8556          125 :       if (TREE_OVERFLOW_P (mod) && !TREE_OVERFLOW_P (t))
    8557            9 :         TREE_OVERFLOW (mod) = false;
    8558              :     }
    8559              :   else
    8560      2107164 :     mod = fold_build2 (inc ? PLUS_EXPR : MINUS_EXPR, type, val, offset);
    8561      4911787 :   if (!ptr)
    8562      1863598 :     VERIFY_CONSTANT (mod);
    8563              : 
    8564              :   /* Storing the modified value.  */
    8565      7189113 :   tree store = build2_loc (cp_expr_loc_or_loc (t, input_location),
    8566              :                            MODIFY_EXPR, type, op, mod);
    8567      4911787 :   mod = cxx_eval_constant_expression (ctx, store, lval,
    8568              :                                       non_constant_p, overflow_p,
    8569              :                                       jump_target);
    8570      4911787 :   ggc_free (store);
    8571      4911787 :   if (*jump_target)
    8572              :     return NULL_TREE;
    8573      4911787 :   if (*non_constant_p)
    8574              :     return t;
    8575              : 
    8576              :   /* And the value of the expression.  */
    8577      4866875 :   if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
    8578              :     /* Prefix ops are lvalues, but the caller might want an rvalue;
    8579              :        lval has already been taken into account in the store above.  */
    8580              :     return mod;
    8581              :   else
    8582              :     /* Postfix ops are rvalues.  */
    8583       275716 :     return val;
    8584              : }
    8585              : 
    8586              : /* Subroutine of cxx_eval_statement_list.  Determine whether the statement
    8587              :    STMT matches *jump_target.  If we're looking for a case label and we see
    8588              :    the default label, note it in ctx->css_state.  */
    8589              : 
    8590              : static bool
    8591       308515 : label_matches (const constexpr_ctx *ctx, tree *jump_target, tree stmt)
    8592              : {
    8593       308515 :   switch (TREE_CODE (*jump_target))
    8594              :     {
    8595           45 :     case LABEL_DECL:
    8596           45 :       if (TREE_CODE (stmt) == LABEL_EXPR
    8597           45 :           && LABEL_EXPR_LABEL (stmt) == *jump_target)
    8598              :         return true;
    8599              :       break;
    8600              : 
    8601       306553 :     case INTEGER_CST:
    8602       306553 :       if (TREE_CODE (stmt) == CASE_LABEL_EXPR)
    8603              :         {
    8604       306537 :           gcc_assert (ctx->css_state != NULL);
    8605       306537 :           if (!CASE_LOW (stmt))
    8606              :             {
    8607              :               /* default: should appear just once in a SWITCH_EXPR
    8608              :                  body (excluding nested SWITCH_EXPR).  */
    8609        50432 :               gcc_assert (*ctx->css_state != css_default_seen);
    8610              :               /* When evaluating SWITCH_EXPR body for the second time,
    8611              :                  return true for the default: label.  */
    8612        50432 :               if (*ctx->css_state == css_default_processing)
    8613              :                 return true;
    8614        25228 :               *ctx->css_state = css_default_seen;
    8615              :             }
    8616       256105 :           else if (CASE_HIGH (stmt))
    8617              :             {
    8618           20 :               if (tree_int_cst_le (CASE_LOW (stmt), *jump_target)
    8619           31 :                   && tree_int_cst_le (*jump_target, CASE_HIGH (stmt)))
    8620              :                 return true;
    8621              :             }
    8622       256085 :           else if (tree_int_cst_equal (*jump_target, CASE_LOW (stmt)))
    8623              :             return true;
    8624              :         }
    8625              :       break;
    8626              : 
    8627              :     case BREAK_STMT:
    8628              :     case CONTINUE_STMT:
    8629              :       /* These two are handled directly in cxx_eval_loop_expr by testing
    8630              :          breaks (jump_target) or continues (jump_target).  */
    8631              :       break;
    8632              : 
    8633              :     case VAR_DECL:
    8634              :       /* Uncaught exception.  This is handled by TRY_BLOCK evaluation
    8635              :          and other places by testing throws (jump_target).  */
    8636              :       break;
    8637              : 
    8638            0 :     default:
    8639            0 :       gcc_unreachable ();
    8640              :     }
    8641              :   return false;
    8642              : }
    8643              : 
    8644              : /* Evaluate a STATEMENT_LIST for side-effects.  Handles various jump
    8645              :    semantics, for switch, break, continue, and return.  */
    8646              : 
    8647              : static tree
    8648     31011958 : cxx_eval_statement_list (const constexpr_ctx *ctx, tree t,
    8649              :                          bool *non_constant_p, bool *overflow_p,
    8650              :                          tree *jump_target)
    8651              : {
    8652              :   /* In a statement-expression we want to return the last value.
    8653              :      For empty statement expression return void_node.  */
    8654     31011958 :   tree r = void_node;
    8655     74807720 :   for (tree_stmt_iterator i = tsi_start (t); !tsi_end_p (i); ++i)
    8656              :     {
    8657     60543081 :       tree stmt = *i;
    8658              : 
    8659              :       /* We've found a continue, so skip everything until we reach
    8660              :          the label its jumping to.  */
    8661     60543081 :       if (continues (jump_target))
    8662              :         {
    8663         1962 :           if (label_matches (ctx, jump_target, stmt))
    8664              :             /* Found it.  */
    8665            9 :             *jump_target = NULL_TREE;
    8666              :           else
    8667         1953 :             continue;
    8668              :         }
    8669     60541128 :       if (TREE_CODE (stmt) == DEBUG_BEGIN_STMT)
    8670      8542233 :         continue;
    8671              : 
    8672     51998895 :       value_cat lval = vc_discard;
    8673              :       /* The result of a statement-expression is not wrapped in EXPR_STMT.  */
    8674     75039103 :       if (tsi_one_before_end_p (i)
    8675     23041417 :           && !VOID_TYPE_P (TREE_TYPE (stmt)))
    8676              :         lval = vc_prvalue;
    8677              : 
    8678     51998895 :       r = cxx_eval_constant_expression (ctx, stmt, lval,
    8679              :                                         non_constant_p, overflow_p,
    8680              :                                         jump_target);
    8681     51998893 :       if (*non_constant_p)
    8682              :         break;
    8683     43658576 :       if (returns (jump_target)
    8684     35273192 :           || breaks (jump_target)
    8685     43795762 :           || throws (jump_target))
    8686              :         break;
    8687              :     }
    8688     31011956 :   return r;
    8689              : }
    8690              : 
    8691              : /* Evaluate a LOOP_EXPR for side-effects.  Handles break and return
    8692              :    semantics; continue semantics are covered by cxx_eval_statement_list.  */
    8693              : 
    8694              : static tree
    8695      3302508 : cxx_eval_loop_expr (const constexpr_ctx *ctx, tree t,
    8696              :                     bool *non_constant_p, bool *overflow_p,
    8697              :                     tree *jump_target)
    8698              : {
    8699      3302508 :   tree body, cond = NULL_TREE, expr = NULL_TREE;
    8700      3302508 :   tree cond_prep = NULL_TREE, cond_cleanup = NULL_TREE;
    8701      3302508 :   unsigned cond_cleanup_depth = 0;
    8702      3302508 :   int count = 0;
    8703      3302508 :   switch (TREE_CODE (t))
    8704              :     {
    8705         1634 :     case LOOP_EXPR:
    8706         1634 :       body = LOOP_EXPR_BODY (t);
    8707         1634 :       break;
    8708      2670761 :     case DO_STMT:
    8709      2670761 :       body = DO_BODY (t);
    8710      2670761 :       cond = DO_COND (t);
    8711      2670761 :       break;
    8712       131714 :     case WHILE_STMT:
    8713       131714 :       body = WHILE_BODY (t);
    8714       131714 :       cond = WHILE_COND (t);
    8715       131714 :       cond_prep = WHILE_COND_PREP (t);
    8716       131714 :       cond_cleanup = WHILE_COND_CLEANUP (t);
    8717       131714 :       count = -1;
    8718       131714 :       break;
    8719       498399 :     case FOR_STMT:
    8720       498399 :       if (FOR_INIT_STMT (t))
    8721            0 :         cxx_eval_constant_expression (ctx, FOR_INIT_STMT (t), vc_discard,
    8722              :                                       non_constant_p, overflow_p, jump_target);
    8723       498399 :       if (*non_constant_p)
    8724              :         return NULL_TREE;
    8725       498399 :       body = FOR_BODY (t);
    8726       498399 :       cond = FOR_COND (t);
    8727       498399 :       expr = FOR_EXPR (t);
    8728       498399 :       cond_prep = FOR_COND_PREP (t);
    8729       498399 :       cond_cleanup = FOR_COND_CLEANUP (t);
    8730       498399 :       count = -1;
    8731       498399 :       break;
    8732            0 :     default:
    8733            0 :       gcc_unreachable ();
    8734              :     }
    8735      3302508 :   if (cond_prep)
    8736           12 :     gcc_assert (TREE_CODE (cond_prep) == BIND_EXPR);
    8737     18358030 :   auto cleanup_cond = [&] {
    8738              :     /* Clean up the condition variable after each iteration.  */
    8739     15055522 :     if (cond_cleanup_depth && !*non_constant_p)
    8740              :       {
    8741          105 :         auto_vec<tree, 4> cleanups (cond_cleanup_depth);
    8742          105 :         tree s = BIND_EXPR_BODY (cond_prep);
    8743          105 :         unsigned i;
    8744          210 :         for (i = cond_cleanup_depth; i; --i)
    8745              :           {
    8746          105 :             tree_stmt_iterator iter = tsi_last (s);
    8747          105 :             s = tsi_stmt (iter);
    8748          105 :             cleanups.quick_push (CLEANUP_EXPR (s));
    8749          105 :             s = CLEANUP_BODY (s);
    8750              :           }
    8751          105 :         tree c;
    8752          420 :         FOR_EACH_VEC_ELT_REVERSE (cleanups, i, c)
    8753          105 :           cxx_eval_constant_expression (ctx, c, vc_discard, non_constant_p,
    8754              :                                         overflow_p, jump_target);
    8755          105 :       }
    8756     15055522 :     if (cond_prep)
    8757          111 :       for (tree decl = BIND_EXPR_VARS (cond_prep);
    8758          222 :            decl; decl = DECL_CHAIN (decl))
    8759          111 :         destroy_value_checked (ctx, decl, non_constant_p);
    8760      3302508 :   };
    8761     12385179 :   do
    8762              :     {
    8763     12385179 :       if (count != -1)
    8764              :         {
    8765     11755066 :           if (body)
    8766     11755066 :             cxx_eval_constant_expression (ctx, body, vc_discard,
    8767              :                                           non_constant_p, overflow_p,
    8768              :                                           jump_target);
    8769     11755066 :           if (breaks (jump_target))
    8770              :             {
    8771         2052 :               *jump_target = NULL_TREE;
    8772         2052 :               break;
    8773              :             }
    8774              : 
    8775     11753014 :           if (TREE_CODE (t) != LOOP_EXPR && continues (jump_target))
    8776          570 :             *jump_target = NULL_TREE;
    8777              : 
    8778     11753014 :           if (expr)
    8779      3964968 :             cxx_eval_constant_expression (ctx, expr, vc_discard,
    8780              :                                           non_constant_p, overflow_p,
    8781              :                                           jump_target);
    8782     11753014 :           cleanup_cond ();
    8783              :         }
    8784              : 
    8785     12383127 :       if (cond_prep)
    8786              :         {
    8787          111 :           for (tree decl = BIND_EXPR_VARS (cond_prep);
    8788          222 :                decl; decl = DECL_CHAIN (decl))
    8789          111 :             ctx->global->clear_value (decl);
    8790          111 :           if (cond_cleanup)
    8791              :             {
    8792              :               /* If COND_CLEANUP is non-NULL, we need to evaluate DEPTH
    8793              :                  nested STATEMENT_LISTs from inside of BIND_EXPR_BODY,
    8794              :                  but defer the evaluation of CLEANUP_EXPRs of CLEANUP_STMT
    8795              :                  at the end of those STATEMENT_LISTs.  */
    8796          111 :               cond_cleanup_depth = 0;
    8797          111 :               tree s = BIND_EXPR_BODY (cond_prep);
    8798          111 :               for (unsigned depth = tree_to_uhwi (cond_cleanup);
    8799          222 :                    depth; --depth)
    8800              :                 {
    8801          111 :                   for (tree_stmt_iterator i = tsi_start (s);
    8802          321 :                        !tsi_end_p (i); ++i)
    8803              :                     {
    8804          321 :                       tree stmt = *i;
    8805          321 :                       if (TREE_CODE (stmt) == DEBUG_BEGIN_STMT)
    8806            0 :                         continue;
    8807          321 :                       if (tsi_one_before_end_p (i))
    8808              :                         {
    8809              :                           /* The last statement in the STATEMENT_LIST
    8810              :                              has to be a CLEANUP_STMT (verified in
    8811              :                              finish_loop_cond_prep).  We want to
    8812              :                              evaluate just its CLEANUP_BODY part but not
    8813              :                              CLEANUP_EXPR part just yet.  */
    8814          105 :                           gcc_assert (TREE_CODE (stmt) == CLEANUP_STMT);
    8815              :                           /* If the CLEANUP_STMT is not actually to be
    8816              :                              evaluated, don't increment cond_cleanup_depth
    8817              :                              so that we don't evaluate the CLEANUP_EXPR
    8818              :                              for it later either.  */
    8819          105 :                           if (*jump_target)
    8820              :                             {
    8821              :                               depth = 1;
    8822              :                               break;
    8823              :                             }
    8824          105 :                           ++cond_cleanup_depth;
    8825              :                           /* If not in the innermost one, next iteration
    8826              :                              will handle CLEANUP_BODY similarly.  */
    8827          105 :                           if (depth > 1)
    8828              :                             {
    8829            0 :                               s = CLEANUP_BODY (stmt);
    8830            0 :                               break;
    8831              :                             }
    8832              :                           /* The innermost one can be evaluated normally.  */
    8833          105 :                           cxx_eval_constant_expression (ctx,
    8834          105 :                                                         CLEANUP_BODY (stmt),
    8835              :                                                         vc_discard,
    8836              :                                                         non_constant_p,
    8837              :                                                         overflow_p,
    8838              :                                                         jump_target);
    8839          105 :                           break;
    8840              :                         }
    8841              :                       /* And so should be evaluated statements which aren't
    8842              :                          last in the STATEMENT_LIST.  */
    8843          216 :                       cxx_eval_constant_expression (ctx, stmt, vc_discard,
    8844              :                                                     non_constant_p, overflow_p,
    8845              :                                                     jump_target);
    8846          216 :                       if (*non_constant_p
    8847          210 :                           || returns (jump_target)
    8848          210 :                           || breaks (jump_target)
    8849          210 :                           || continues (jump_target)
    8850          531 :                           || throws (jump_target))
    8851              :                         {
    8852              :                           depth = 1;
    8853              :                           break;
    8854              :                         }
    8855              :                     }
    8856              :                 }
    8857              :             }
    8858              :           else
    8859            0 :             cxx_eval_constant_expression (ctx, BIND_EXPR_BODY (cond_prep),
    8860              :                                           vc_discard, non_constant_p,
    8861              :                                           overflow_p, jump_target);
    8862              :         }
    8863              : 
    8864     12383127 :       if (cond)
    8865              :         {
    8866     12380722 :           tree res
    8867     12380722 :             = cxx_eval_constant_expression (ctx, cond, vc_prvalue,
    8868              :                                             non_constant_p, overflow_p,
    8869              :                                             jump_target);
    8870     12380722 :           if (res)
    8871              :             {
    8872     12336904 :               if (verify_constant (res, ctx->quiet, non_constant_p,
    8873              :                                    overflow_p))
    8874              :                 break;
    8875     12209806 :               if (integer_zerop (res))
    8876              :                 break;
    8877              :             }
    8878              :           else
    8879        43818 :             gcc_assert (*jump_target);
    8880              :         }
    8881              : 
    8882      9126733 :       if (++count >= constexpr_loop_limit)
    8883              :         {
    8884           27 :           if (!ctx->quiet)
    8885            9 :             error_at (cp_expr_loc_or_input_loc (t),
    8886              :                       "%<constexpr%> loop iteration count exceeds limit of %d "
    8887              :                       "(use %<-fconstexpr-loop-limit=%> to increase the limit)",
    8888              :                       constexpr_loop_limit);
    8889           27 :           *non_constant_p = true;
    8890           27 :           break;
    8891              :         }
    8892              :     }
    8893     27336271 :   while (!returns (jump_target)
    8894      9082859 :          && !breaks (jump_target)
    8895      9082859 :          && !continues (jump_target)
    8896      9082952 :          && (!switches (jump_target) || count == 0)
    8897      9082829 :          && !throws (jump_target)
    8898     18253563 :          && !*non_constant_p);
    8899              : 
    8900      3302508 :   cleanup_cond ();
    8901              : 
    8902      3302508 :   return NULL_TREE;
    8903              : }
    8904              : 
    8905              : /* Evaluate a SWITCH_EXPR for side-effects.  Handles switch and break jump
    8906              :    semantics.  */
    8907              : 
    8908              : static tree
    8909        30978 : cxx_eval_switch_expr (const constexpr_ctx *ctx, tree t,
    8910              :                       bool *non_constant_p, bool *overflow_p,
    8911              :                       tree *jump_target)
    8912              : {
    8913        30978 :   tree cond
    8914        30978 :     = TREE_CODE (t) == SWITCH_STMT ? SWITCH_STMT_COND (t) : SWITCH_COND (t);
    8915        30978 :   cond = cxx_eval_constant_expression (ctx, cond, vc_prvalue,
    8916              :                                        non_constant_p, overflow_p,
    8917              :                                        jump_target);
    8918        30978 :   if (*jump_target)
    8919              :     return NULL_TREE;
    8920        30978 :   VERIFY_CONSTANT (cond);
    8921        30735 :   if (TREE_CODE (cond) != INTEGER_CST)
    8922              :     {
    8923              :       /* If the condition doesn't reduce to an INTEGER_CST it isn't a usable
    8924              :          switch condition even if it's constant enough for other things
    8925              :          (c++/113545).  */
    8926            0 :       gcc_checking_assert (ctx->quiet);
    8927            0 :       *non_constant_p = true;
    8928            0 :       return t;
    8929              :     }
    8930              : 
    8931        30735 :   *jump_target = cond;
    8932              : 
    8933        30735 :   tree body
    8934        30735 :     = TREE_CODE (t) == SWITCH_STMT ? SWITCH_STMT_BODY (t) : SWITCH_BODY (t);
    8935        30735 :   constexpr_ctx new_ctx = *ctx;
    8936        30735 :   constexpr_switch_state css = css_default_not_seen;
    8937        30735 :   new_ctx.css_state = &css;
    8938        30735 :   cxx_eval_constant_expression (&new_ctx, body, vc_discard,
    8939              :                                 non_constant_p, overflow_p, jump_target);
    8940        55974 :   if (switches (jump_target) && css == css_default_seen)
    8941              :     {
    8942              :       /* If the SWITCH_EXPR body has default: label, process it once again,
    8943              :          this time instructing label_matches to return true for default:
    8944              :          label on switches (jump_target).  */
    8945        25204 :       css = css_default_processing;
    8946        25204 :       cxx_eval_constant_expression (&new_ctx, body, vc_discard,
    8947              :                                     non_constant_p, overflow_p, jump_target);
    8948              :     }
    8949        30735 :   if (breaks (jump_target) || switches (jump_target))
    8950        19597 :     *jump_target = NULL_TREE;
    8951              :   return NULL_TREE;
    8952              : }
    8953              : 
    8954              : /* Find the object of TYPE under initialization in CTX.  */
    8955              : 
    8956              : static tree
    8957        16669 : lookup_placeholder (const constexpr_ctx *ctx, value_cat lval, tree type)
    8958              : {
    8959        16669 :   if (!ctx)
    8960              :     return NULL_TREE;
    8961              : 
    8962              :   /* Prefer the outermost matching object, but don't cross
    8963              :      CONSTRUCTOR_PLACEHOLDER_BOUNDARY constructors.  */
    8964        16294 :   if (ctx->ctor && !CONSTRUCTOR_PLACEHOLDER_BOUNDARY (ctx->ctor))
    8965          553 :     if (tree outer_ob = lookup_placeholder (ctx->parent, lval, type))
    8966              :       return outer_ob;
    8967              : 
    8968              :   /* We could use ctx->object unconditionally, but using ctx->ctor when we
    8969              :      can is a minor optimization.  */
    8970        16116 :   if (!lval && ctx->ctor && same_type_p (TREE_TYPE (ctx->ctor), type))
    8971          300 :     return ctx->ctor;
    8972              : 
    8973        15816 :   if (!ctx->object)
    8974              :     return NULL_TREE;
    8975              : 
    8976              :   /* Since an object cannot have a field of its own type, we can search outward
    8977              :      from ctx->object to find the unique containing object of TYPE.  */
    8978              :   tree ob = ctx->object;
    8979        15804 :   while (ob)
    8980              :     {
    8981        15804 :       if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (ob), type))
    8982              :         break;
    8983          219 :       if (handled_component_p (ob))
    8984          217 :         ob = TREE_OPERAND (ob, 0);
    8985              :       else
    8986              :         ob = NULL_TREE;
    8987              :     }
    8988              : 
    8989              :   return ob;
    8990              : }
    8991              : 
    8992              : /* Complain about an attempt to evaluate inline assembly.  If FUNDEF_P is
    8993              :    true, we're checking a constexpr function body.  */
    8994              : 
    8995              : static void
    8996           34 : inline_asm_in_constexpr_error (location_t loc, bool fundef_p)
    8997              : {
    8998           34 :   auto_diagnostic_group d;
    8999           34 :   if (constexpr_error (loc, fundef_p, "inline assembly is not a "
    9000              :                        "constant expression"))
    9001           34 :     inform (loc, "only unevaluated inline assembly is allowed in a "
    9002              :             "%<constexpr%> function in C++20");
    9003           34 : }
    9004              : 
    9005              : /* We're getting the constant value of DECL in a manifestly constant-evaluated
    9006              :    context; maybe complain about that.  */
    9007              : 
    9008              : static void
    9009     82855877 : maybe_warn_about_constant_value (location_t loc, tree decl)
    9010              : {
    9011     82855877 :   static bool explained = false;
    9012     82855877 :   if (cxx_dialect >= cxx17
    9013     82688826 :       && warn_interference_size
    9014     82688826 :       && !OPTION_SET_P (param_destruct_interfere_size)
    9015     82688826 :       && DECL_CONTEXT (decl) == std_node
    9016     17209109 :       && DECL_NAME (decl)
    9017     17209103 :       && id_equal (DECL_NAME (decl), "hardware_destructive_interference_size")
    9018           16 :       && (LOCATION_FILE (input_location) != main_input_filename
    9019           10 :           || module_exporting_p ())
    9020     82855880 :       && warning_at (loc, OPT_Winterference_size, "use of %qD", decl)
    9021     82855886 :       && !explained)
    9022              :     {
    9023            6 :       explained = true;
    9024            6 :       inform (loc, "its value can vary between compiler versions or "
    9025              :               "with different %<-mtune%> or %<-mcpu%> flags");
    9026            6 :       inform (loc, "if this use is part of a public ABI, change it to "
    9027              :               "instead use a constant variable you define");
    9028            6 :       inform (loc, "the default value for the current CPU tuning "
    9029              :               "is %d bytes", param_destruct_interfere_size);
    9030            6 :       inform (loc, "you can stabilize this value with %<--param "
    9031              :               "hardware_destructive_interference_size=%d%>, or disable "
    9032              :               "this warning with %<-Wno-interference-size%>",
    9033              :               param_destruct_interfere_size);
    9034              :     }
    9035     82855877 : }
    9036              : 
    9037              : /* For element type ELT_TYPE, return the appropriate type of the heap object
    9038              :    containing such element(s).  COOKIE_SIZE is NULL or the size of cookie
    9039              :    in bytes.  If COOKIE_SIZE is NULL, return array type
    9040              :    ELT_TYPE[FULL_SIZE / sizeof(ELT_TYPE)], otherwise return
    9041              :    struct { size_t[COOKIE_SIZE/sizeof(size_t)]; ELT_TYPE[N]; }
    9042              :    where N is computed such that the size of the struct fits into FULL_SIZE.
    9043              :    If ARG_SIZE is non-NULL, it is the first argument to the new operator.
    9044              :    It should be passed if ELT_TYPE is zero sized type in which case FULL_SIZE
    9045              :    will be also 0 and so it is not possible to determine the actual array
    9046              :    size.  CTX, NON_CONSTANT_P and OVERFLOW_P are used during constant
    9047              :    expression evaluation of subexpressions of ARG_SIZE.  */
    9048              : 
    9049              : static tree
    9050        64073 : build_new_constexpr_heap_type (const constexpr_ctx *ctx, tree elt_type,
    9051              :                                tree cookie_size, tree full_size, tree arg_size,
    9052              :                                bool *non_constant_p, bool *overflow_p,
    9053              :                                tree *jump_target)
    9054              : {
    9055        64073 :   gcc_assert (cookie_size == NULL_TREE || tree_fits_uhwi_p (cookie_size));
    9056        64073 :   gcc_assert (tree_fits_uhwi_p (full_size));
    9057        64073 :   unsigned HOST_WIDE_INT csz = cookie_size ? tree_to_uhwi (cookie_size) : 0;
    9058        64073 :   if (arg_size)
    9059              :     {
    9060            9 :       STRIP_NOPS (arg_size);
    9061            9 :       if (cookie_size)
    9062              :         {
    9063            0 :           if (TREE_CODE (arg_size) != PLUS_EXPR)
    9064              :             arg_size = NULL_TREE;
    9065            0 :           else if (TREE_CODE (TREE_OPERAND (arg_size, 0)) == INTEGER_CST
    9066            0 :                    && tree_int_cst_equal (cookie_size,
    9067            0 :                                           TREE_OPERAND (arg_size, 0)))
    9068              :             {
    9069            0 :               arg_size = TREE_OPERAND (arg_size, 1);
    9070            0 :               STRIP_NOPS (arg_size);
    9071              :             }
    9072            0 :           else if (TREE_CODE (TREE_OPERAND (arg_size, 1)) == INTEGER_CST
    9073            0 :                    && tree_int_cst_equal (cookie_size,
    9074            0 :                                           TREE_OPERAND (arg_size, 1)))
    9075              :             {
    9076            0 :               arg_size = TREE_OPERAND (arg_size, 0);
    9077            0 :               STRIP_NOPS (arg_size);
    9078              :             }
    9079              :           else
    9080              :             arg_size = NULL_TREE;
    9081              :         }
    9082            9 :       if (arg_size && TREE_CODE (arg_size) == MULT_EXPR)
    9083              :         {
    9084            9 :           tree op0 = TREE_OPERAND (arg_size, 0);
    9085            9 :           tree op1 = TREE_OPERAND (arg_size, 1);
    9086            9 :           if (integer_zerop (op0))
    9087            9 :             arg_size
    9088            9 :               = cxx_eval_constant_expression (ctx, op1, vc_prvalue,
    9089              :                                               non_constant_p, overflow_p,
    9090              :                                               jump_target);
    9091            0 :           else if (integer_zerop (op1))
    9092            0 :             arg_size
    9093            0 :               = cxx_eval_constant_expression (ctx, op0, vc_prvalue,
    9094              :                                               non_constant_p, overflow_p,
    9095              :                                               jump_target);
    9096              :           else
    9097              :             arg_size = NULL_TREE;
    9098            9 :           if (*jump_target)
    9099              :             return NULL_TREE;
    9100              :         }
    9101              :       else
    9102              :         arg_size = NULL_TREE;
    9103              :     }
    9104              : 
    9105            9 :   unsigned HOST_WIDE_INT fsz = tree_to_uhwi (arg_size ? arg_size : full_size);
    9106        64073 :   if (!arg_size)
    9107              :     {
    9108        64064 :       unsigned HOST_WIDE_INT esz = int_size_in_bytes (elt_type);
    9109        64064 :       gcc_assert (fsz >= csz);
    9110        64064 :       fsz -= csz;
    9111        64064 :       if (esz)
    9112        64064 :         fsz /= esz;
    9113              :     }
    9114        64073 :   tree itype2 = build_index_type (size_int (fsz - 1));
    9115        64073 :   if (!cookie_size)
    9116        64064 :     return build_cplus_array_type (elt_type, itype2);
    9117            9 :   return build_new_constexpr_heap_type (elt_type, cookie_size, itype2);
    9118              : }
    9119              : 
    9120              : /* Handle the case when a cleanup of some expression throws.  JMP_TARGET
    9121              :    indicates whether the cleanup threw or not, *JUMP_TARGET indicates whether
    9122              :    the expression which needed the cleanup threw.  If both threw, diagnose
    9123              :    it and return NULL, otherwise return R.  If only the cleanup threw, set
    9124              :    *JUMP_TARGET to the exception object from the cleanup.  */
    9125              : 
    9126              : static tree
    9127       800561 : merge_jump_target (location_t loc, const constexpr_ctx *ctx, tree r,
    9128              :                    bool *non_constant_p, tree *jump_target, tree jmp_target)
    9129              : {
    9130       800562 :   if (!throws (&jmp_target))
    9131              :     return r;
    9132            7 :   if (throws (jump_target))
    9133              :     {
    9134              :       /* [except.throw]/9 - If the exception handling mechanism
    9135              :          handling an uncaught exception directly invokes a function
    9136              :          that exits via an exception, the function std::terminate is
    9137              :          invoked.  */
    9138            6 :       if (!ctx->quiet)
    9139              :         {
    9140            2 :           auto_diagnostic_group d;
    9141            2 :           diagnose_std_terminate (loc, ctx, *jump_target);
    9142            2 :           inform (loc, "destructor exited with an exception");
    9143            2 :         }
    9144            6 :       *non_constant_p = true;
    9145            6 :       *jump_target = NULL_TREE;
    9146            6 :       return NULL_TREE;
    9147              :     }
    9148            1 :   *jump_target = jmp_target;
    9149            1 :   return r;
    9150              : }
    9151              : 
    9152              : /* Attempt to reduce the expression T to a constant value.
    9153              :    On failure, issue diagnostic and return error_mark_node.  */
    9154              : /* FIXME unify with c_fully_fold */
    9155              : /* FIXME overflow_p is too global */
    9156              : 
    9157              : tree
    9158   1956250137 : cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
    9159              :                               value_cat lval,
    9160              :                               bool *non_constant_p, bool *overflow_p,
    9161              :                               tree *jump_target)
    9162              : {
    9163   1956250137 :   if (*jump_target)
    9164              :     {
    9165              :       /* If we are jumping, ignore all statements/expressions except those
    9166              :          that could have LABEL_EXPR or CASE_LABEL_EXPR in their bodies.  */
    9167      1226476 :       switch (TREE_CODE (t))
    9168              :         {
    9169              :         case BIND_EXPR:
    9170              :         case STATEMENT_LIST:
    9171              :         case LOOP_EXPR:
    9172              :         case COND_EXPR:
    9173              :         case IF_STMT:
    9174              :         case DO_STMT:
    9175              :         case WHILE_STMT:
    9176              :         case FOR_STMT:
    9177              :           break;
    9178       306553 :         case LABEL_EXPR:
    9179       306553 :         case CASE_LABEL_EXPR:
    9180       306553 :           if (label_matches (ctx, jump_target, t))
    9181              :             /* Found it.  */
    9182        30700 :             *jump_target = NULL_TREE;
    9183       306553 :           return NULL_TREE;
    9184              :         default:
    9185              :           return NULL_TREE;
    9186              :         }
    9187              :     }
    9188   1955234154 :   if (error_operand_p (t))
    9189              :     {
    9190          132 :       *non_constant_p = true;
    9191          132 :       return t;
    9192              :     }
    9193              : 
    9194              :   /* Change the input location to the currently processed expression for
    9195              :      better error messages when a subexpression has no location.  */
    9196   1955234022 :   location_t loc = cp_expr_loc_or_input_loc (t);
    9197   3910462631 :   iloc_sentinel sentinel (loc);
    9198              : 
    9199   1955234022 :   STRIP_ANY_LOCATION_WRAPPER (t);
    9200              : 
    9201   1955234022 :   if (CONSTANT_CLASS_P (t))
    9202              :     {
    9203    371545584 :       if (TREE_OVERFLOW (t))
    9204              :         {
    9205           62 :           if (!ctx->quiet)
    9206           15 :             permerror (input_location, "overflow in constant expression");
    9207           62 :           if (!flag_permissive || ctx->quiet)
    9208           59 :             *overflow_p = true;
    9209              :         }
    9210              : 
    9211    371545584 :       if (TREE_CODE (t) == INTEGER_CST
    9212    357386500 :           && TYPE_PTR_P (TREE_TYPE (t))
    9213              :           /* INTEGER_CST with pointer-to-method type is only used
    9214              :              for a virtual method in a pointer to member function.
    9215              :              Don't reject those.  */
    9216      1557485 :           && TREE_CODE (TREE_TYPE (TREE_TYPE (t))) != METHOD_TYPE
    9217    373102799 :           && !integer_zerop (t))
    9218              :         {
    9219            5 :           if (!ctx->quiet)
    9220            0 :             error ("value %qE of type %qT is not a constant expression",
    9221            0 :                    t, TREE_TYPE (t));
    9222            5 :           *non_constant_p = true;
    9223              :         }
    9224              : 
    9225    371545584 :       return t;
    9226              :     }
    9227              : 
    9228              :   /* Avoid excessively long constexpr evaluations.  */
    9229   1583688438 :   if (++ctx->global->constexpr_ops_count >= constexpr_ops_limit)
    9230              :     {
    9231            9 :       if (!ctx->quiet)
    9232            3 :         error_at (loc,
    9233              :                   "%<constexpr%> evaluation operation count exceeds limit of "
    9234              :                   "%wd (use %<-fconstexpr-ops-limit=%> to increase the limit)",
    9235              :                   constexpr_ops_limit);
    9236            9 :       ctx->global->constexpr_ops_count = INTTYPE_MINIMUM (HOST_WIDE_INT);
    9237            9 :       *non_constant_p = true;
    9238            9 :       return t;
    9239              :     }
    9240              : 
    9241   1583688429 :   constexpr_ctx new_ctx;
    9242   1583688429 :   tree r = t;
    9243              : 
    9244   1583688429 :   tree_code tcode = TREE_CODE (t);
    9245   1583688429 :   switch (tcode)
    9246              :     {
    9247     28925840 :     case RESULT_DECL:
    9248     28925840 :       if (lval)
    9249              :         return t;
    9250              :       /* We ask for an rvalue for the RESULT_DECL when indirecting
    9251              :          through an invisible reference, or in named return value
    9252              :          optimization.  */
    9253        31765 :       if (tree v = ctx->global->get_value (t))
    9254              :         return v;
    9255              :       else
    9256              :         {
    9257            3 :           if (!ctx->quiet)
    9258            0 :             error ("%qE is not a constant expression", t);
    9259            3 :           *non_constant_p = true;
    9260              :         }
    9261            3 :       break;
    9262              : 
    9263    217384900 :     case VAR_DECL:
    9264    217384900 :       if (DECL_HAS_VALUE_EXPR_P (t))
    9265              :         {
    9266      4522429 :           if (is_normal_capture_proxy (t)
    9267      4522429 :               && current_function_decl == DECL_CONTEXT (t))
    9268              :             {
    9269              :               /* Function parms aren't constexpr within the function
    9270              :                  definition, so don't try to look at the closure.  But if the
    9271              :                  captured variable is constant, try to evaluate it directly. */
    9272       326793 :               r = DECL_CAPTURED_VARIABLE (t);
    9273              :             }
    9274              :           else
    9275      4195636 :             r = DECL_VALUE_EXPR (t);
    9276              : 
    9277      4522429 :           tree type = TREE_TYPE (t);
    9278      4522429 :           if (TYPE_REF_P (type) != TYPE_REF_P (TREE_TYPE (r)))
    9279              :             {
    9280              :               /* Adjust r to match the reference-ness of t.  */
    9281       144237 :               if (TYPE_REF_P (type))
    9282       141936 :                 r = build_address (r);
    9283              :               else
    9284         2301 :                 r = convert_from_reference (r);
    9285              :             }
    9286      4522429 :           return cxx_eval_constant_expression (ctx, r, lval, non_constant_p,
    9287      4522429 :                                                overflow_p, jump_target);
    9288              :         }
    9289              :       /* fall through */
    9290    221603001 :     case CONST_DECL:
    9291              :       /* We used to not check lval for CONST_DECL, but darwin.cc uses
    9292              :          CONST_DECL for aggregate constants.  */
    9293    221603001 :       if (lval)
    9294              :         return t;
    9295    166795851 :       else if (t == ctx->object)
    9296       949889 :         return ctx->ctor;
    9297    165845962 :       if (VAR_P (t))
    9298              :         {
    9299    157105432 :           if (tree v = ctx->global->get_value (t))
    9300              :             {
    9301              :               r = v;
    9302              :               break;
    9303              :             }
    9304    121672296 :           if (ctx->global->is_outside_lifetime (t))
    9305              :             {
    9306          103 :               if (!ctx->quiet)
    9307           30 :                 outside_lifetime_error (loc, t);
    9308          103 :               *non_constant_p = true;
    9309          103 :               break;
    9310              :             }
    9311              :         }
    9312    130412723 :       if (ctx->manifestly_const_eval == mce_true)
    9313     82855877 :         maybe_warn_about_constant_value (loc, t);
    9314    130412723 :       if (COMPLETE_TYPE_P (TREE_TYPE (t))
    9315    130412723 :           && is_really_empty_class (TREE_TYPE (t), /*ignore_vptr*/false))
    9316              :         {
    9317              :           /* If the class is empty, we aren't actually loading anything.  */
    9318       136729 :           r = build_constructor (TREE_TYPE (t), NULL);
    9319       136729 :           TREE_CONSTANT (r) = true;
    9320              :         }
    9321    130275994 :       else if (ctx->strict)
    9322    129998089 :         r = decl_really_constant_value (t, /*unshare_p=*/false);
    9323              :       else
    9324       277905 :         r = decl_constant_value (t, /*unshare_p=*/false);
    9325    130410026 :       if (TREE_CODE (r) == TARGET_EXPR
    9326    130410026 :           && TREE_CODE (TARGET_EXPR_INITIAL (r)) == CONSTRUCTOR)
    9327            0 :         r = TARGET_EXPR_INITIAL (r);
    9328    130410026 :       if (DECL_P (r)
    9329              :           /* P2280 allows references to unknown.  */
    9330    130671599 :           && !(p2280_active_p (ctx) && VAR_P (t) && TYPE_REF_P (TREE_TYPE (t))))
    9331              :         {
    9332     28623243 :           if (!ctx->quiet)
    9333          180 :             non_const_var_error (loc, r, /*fundef_p*/false);
    9334     28623243 :           *non_constant_p = true;
    9335              :         }
    9336              :       break;
    9337              : 
    9338              :     case DEBUG_BEGIN_STMT:
    9339              :       /* ??? It might be nice to retain this information somehow, so
    9340              :          as to be able to step into a constexpr function call.  */
    9341              :       /* Fall through.  */
    9342              : 
    9343              :     case FUNCTION_DECL:
    9344              :     case TEMPLATE_DECL:
    9345              :     case LABEL_DECL:
    9346              :     case LABEL_EXPR:
    9347              :     case CASE_LABEL_EXPR:
    9348              :     case PREDICT_EXPR:
    9349              :     case OMP_DECLARE_MAPPER:
    9350              :     case REFLECT_EXPR:
    9351              :       return t;
    9352              : 
    9353    174554771 :     case PARM_DECL:
    9354    174554771 :       if (lval && !TYPE_REF_P (TREE_TYPE (t)))
    9355              :         {
    9356              :           /* glvalue use.  */
    9357      8888840 :           if (TREE_ADDRESSABLE (TREE_TYPE (t)))
    9358       143283 :             if (tree v = ctx->global->get_value (t))
    9359   1258739450 :               r = v;
    9360              :         }
    9361    165665931 :       else if (tree v = ctx->global->get_value (t))
    9362              :         {
    9363     76090877 :           r = v;
    9364     76090877 :           if (TREE_ADDRESSABLE (TREE_TYPE (t)))
    9365         5353 :             r = cxx_eval_constant_expression (ctx, r, vc_prvalue,
    9366              :                                               non_constant_p, overflow_p,
    9367              :                                               jump_target);
    9368     76090877 :           if (*jump_target)
    9369              :             return NULL_TREE;
    9370              :         }
    9371     89575054 :       else if (lval)
    9372              :         /* Defer in case this is only used for its type.  */;
    9373     89575054 :       else if (ctx->global->is_outside_lifetime (t))
    9374              :         {
    9375           18 :           if (!ctx->quiet)
    9376            6 :             outside_lifetime_error (loc, t);
    9377           18 :           *non_constant_p = true;
    9378           18 :           break;
    9379              :         }
    9380     89575036 :       else if (COMPLETE_TYPE_P (TREE_TYPE (t))
    9381     89575036 :                && is_really_empty_class (TREE_TYPE (t), /*ignore_vptr*/false))
    9382              :         {
    9383              :           /* If the class is empty, we aren't actually loading anything.  */
    9384        25189 :           r = build_constructor (TREE_TYPE (t), NULL);
    9385        25189 :           TREE_CONSTANT (r) = true;
    9386              :         }
    9387     89549847 :       else if (p2280_active_p (ctx) && TYPE_REF_P (TREE_TYPE (t)))
    9388              :         /* P2280 allows references to unknown...  */;
    9389     89296206 :       else if (p2280_active_p (ctx) && is_this_parameter (t))
    9390              :         /* ...as well as the this pointer.  */;
    9391              :       else
    9392              :         {
    9393     88884536 :           if (!ctx->quiet)
    9394          195 :             error ("%qE is not a constant expression", t);
    9395     88884536 :           *non_constant_p = true;
    9396              :         }
    9397              :       break;
    9398              : 
    9399    138424437 :     case CALL_EXPR:
    9400    138424437 :     case AGGR_INIT_EXPR:
    9401    138424437 :       r = cxx_eval_call_expression (ctx, t, lval,
    9402              :                                     non_constant_p, overflow_p, jump_target);
    9403    138424437 :       break;
    9404              : 
    9405     11178497 :     case DECL_EXPR:
    9406     11178497 :       {
    9407     11178497 :         r = DECL_EXPR_DECL (t);
    9408     11178497 :         if (TREE_CODE (r) == USING_DECL)
    9409              :           {
    9410         9080 :             r = void_node;
    9411         9080 :             break;
    9412              :           }
    9413              : 
    9414     11169417 :         if (VAR_P (r)
    9415     11169417 :             && (TREE_STATIC (r)
    9416     11046462 :                 || (CP_DECL_THREAD_LOCAL_P (r) && !DECL_REALLY_EXTERN (r)))
    9417              :             /* Allow __FUNCTION__ etc.  */
    9418       122955 :             && !DECL_ARTIFICIAL (r)
    9419     11169459 :             && !decl_constant_var_p (r))
    9420              :           {
    9421            7 :             if (!ctx->quiet)
    9422              :               {
    9423            2 :                 if (CP_DECL_THREAD_LOCAL_P (r))
    9424            1 :                   error_at (loc, "control passes through definition of %qD "
    9425              :                                  "with thread storage duration", r);
    9426              :                 else
    9427            1 :                   error_at (loc, "control passes through definition of %qD "
    9428              :                                  "with static storage duration", r);
    9429              :               }
    9430            7 :             *non_constant_p = true;
    9431            7 :             break;
    9432              :           }
    9433              : 
    9434              :         /* make_rtl_for_nonlocal_decl could have deferred emission of
    9435              :            a local static var, but if it appears in a statement expression
    9436              :            which is constant expression evaluated to e.g. just the address
    9437              :            of the variable, its DECL_EXPR will never be seen during
    9438              :            gimple lowering's record_vars_into as the statement expression
    9439              :            will not be in the IL at all.  */
    9440     11169410 :         if (VAR_P (r)
    9441     11169410 :             && TREE_STATIC (r)
    9442       122948 :             && !DECL_REALLY_EXTERN (r)
    9443       122937 :             && DECL_FUNCTION_SCOPE_P (r)
    9444       122937 :             && !var_in_maybe_constexpr_fn (r)
    9445     11169413 :             && decl_constant_var_p (r))
    9446              :           {
    9447            3 :             varpool_node *node = varpool_node::get (r);
    9448            3 :             if (node == NULL || !node->definition)
    9449            3 :               rest_of_decl_compilation (r, 0, at_eof);
    9450              :           }
    9451              : 
    9452     22182640 :         if (AGGREGATE_TYPE_P (TREE_TYPE (r))
    9453     20980766 :             || VECTOR_TYPE_P (TREE_TYPE (r)))
    9454              :           {
    9455      1359160 :             new_ctx = *ctx;
    9456      1359160 :             new_ctx.object = r;
    9457      1359160 :             new_ctx.ctor = build_constructor (TREE_TYPE (r), NULL);
    9458      1359160 :             CONSTRUCTOR_NO_CLEARING (new_ctx.ctor) = true;
    9459      1359160 :             ctx->global->put_value (r, new_ctx.ctor);
    9460      1359160 :             ctx = &new_ctx;
    9461              :           }
    9462              : 
    9463     11169410 :         if (tree init = DECL_INITIAL (r))
    9464              :           {
    9465      6207530 :             init = cxx_eval_constant_expression (ctx, init, vc_prvalue,
    9466              :                                                  non_constant_p, overflow_p,
    9467              :                                                  jump_target);
    9468      6207530 :             if (*jump_target)
    9469              :               return NULL_TREE;
    9470              :             /* Don't share a CONSTRUCTOR that might be changed.  */
    9471      6207530 :             init = unshare_constructor (init);
    9472              :             /* Remember that a constant object's constructor has already
    9473              :                run.  */
    9474     12415060 :             if (CLASS_TYPE_P (TREE_TYPE (r))
    9475      6501271 :                 && CP_TYPE_CONST_P (TREE_TYPE (r)))
    9476        35600 :               TREE_READONLY (init) = true;
    9477      6207530 :             ctx->global->put_value (r, init);
    9478              :           }
    9479      4961880 :         else if (ctx == &new_ctx)
    9480              :           /* We gave it a CONSTRUCTOR above.  */;
    9481              :         else
    9482      3929652 :           ctx->global->put_value (r, NULL_TREE);
    9483              :       }
    9484              :       break;
    9485              : 
    9486     16915351 :     case TARGET_EXPR:
    9487     16915351 :       {
    9488     16915351 :         tree type = TREE_TYPE (t);
    9489              : 
    9490     16915351 :         if (!literal_type_p (type))
    9491              :           {
    9492         5141 :             if (!ctx->quiet)
    9493              :               {
    9494            0 :                 auto_diagnostic_group d;
    9495            0 :                 error ("temporary of non-literal type %qT in a "
    9496              :                        "constant expression", type);
    9497            0 :                 explain_non_literal_class (type);
    9498            0 :               }
    9499         5141 :             *non_constant_p = true;
    9500      7878403 :             break;
    9501              :           }
    9502     16910210 :         gcc_checking_assert (!TARGET_EXPR_DIRECT_INIT_P (t));
    9503              :         /* Avoid evaluating a TARGET_EXPR more than once.  */
    9504     16910210 :         tree slot = TARGET_EXPR_SLOT (t);
    9505     16910210 :         if (tree v = ctx->global->get_value (slot))
    9506              :           {
    9507         1817 :             if (lval)
    9508      7265496 :               return slot;
    9509              :             r = v;
    9510              :             break;
    9511              :           }
    9512     16908393 :         if ((AGGREGATE_TYPE_P (type) || VECTOR_TYPE_P (type)))
    9513              :           {
    9514              :             /* We're being expanded without an explicit target, so start
    9515              :                initializing a new object; expansion with an explicit target
    9516              :                strips the TARGET_EXPR before we get here.  */
    9517     13354429 :             new_ctx = *ctx;
    9518              :             /* Link CTX to NEW_CTX so that lookup_placeholder can resolve
    9519              :                any PLACEHOLDER_EXPR within the initializer that refers to the
    9520              :                former object under construction.  */
    9521     13354429 :             new_ctx.parent = ctx;
    9522     13354429 :             new_ctx.ctor = build_constructor (type, NULL);
    9523     13354429 :             CONSTRUCTOR_NO_CLEARING (new_ctx.ctor) = true;
    9524     13354429 :             new_ctx.object = slot;
    9525     13354429 :             ctx->global->put_value (new_ctx.object, new_ctx.ctor);
    9526     13354429 :             ctx = &new_ctx;
    9527              :           }
    9528              : 
    9529              :         /* If the initializer is complex, evaluate it to initialize slot.  */
    9530     16908393 :         bool is_complex = target_expr_needs_replace (t);
    9531     16908393 :         if (is_complex)
    9532              :           /* In case no initialization actually happens, clear out any
    9533              :              void_node from a previous evaluation.  */
    9534          267 :           ctx->global->put_value (slot, NULL_TREE);
    9535              : 
    9536              :         /* Pass vc_prvalue because this indicates
    9537              :            initialization of a temporary.  */
    9538     16908393 :         r = cxx_eval_constant_expression (ctx, TARGET_EXPR_INITIAL (t),
    9539              :                                           vc_prvalue, non_constant_p,
    9540              :                                           overflow_p, jump_target);
    9541     16908393 :         if (*non_constant_p)
    9542              :           break;
    9543      9036114 :         if (ctx->save_exprs)
    9544      4557515 :           ctx->save_exprs->safe_push (slot);
    9545      9036114 :         if (*jump_target)
    9546              :           {
    9547          255 :             if (!is_complex
    9548          255 :                 && !(AGGREGATE_TYPE_P (type) || VECTOR_TYPE_P (type)))
    9549              :               /* If TARGET_EXPR_INITIAL throws exception and slot's value
    9550              :                  has not been changed yet, CLEANUP_POINT_EXPR handling
    9551              :                  could see there void_node from a previous evaluation
    9552              :                  and complain.  */
    9553            3 :               ctx->global->put_value (slot, NULL_TREE);
    9554          255 :             return NULL_TREE;
    9555              :           }
    9556      9035859 :         if (!is_complex)
    9557              :           {
    9558      9035638 :             r = unshare_constructor (r);
    9559              :             /* Adjust the type of the result to the type of the temporary.  */
    9560      9035638 :             r = adjust_temp_type (type, r);
    9561      9035638 :             ctx->global->put_value (slot, r);
    9562              :           }
    9563      9035859 :         if (TARGET_EXPR_CLEANUP (t)
    9564      9035859 :             && (!CLEANUP_EH_ONLY (t) || cxx_dialect >= cxx26))
    9565              :           {
    9566       718250 :             ctx->global->cleanups->safe_push (TARGET_EXPR_CLEANUP (t));
    9567              :             /* Mark CLEANUP_EH_ONLY cleanups by pushing NULL_TREE after
    9568              :                them.  */
    9569       718250 :             if (CLEANUP_EH_ONLY (t))
    9570          971 :               ctx->global->cleanups->safe_push (NULL_TREE);
    9571              :           }
    9572      9035859 :         if (lval)
    9573              :           return slot;
    9574      1771452 :         if (is_complex)
    9575            0 :           r = ctx->global->get_value (slot);
    9576              :       }
    9577      1771452 :       break;
    9578              : 
    9579     58518346 :     case INIT_EXPR:
    9580     58518346 :     case MODIFY_EXPR:
    9581     58518346 :       gcc_assert (jump_target == NULL || *jump_target == NULL_TREE);
    9582     58518346 :       r = cxx_eval_store_expression (ctx, t, lval,
    9583              :                                      non_constant_p, overflow_p, jump_target);
    9584     58518346 :       break;
    9585              : 
    9586            0 :     case SCOPE_REF:
    9587            0 :       r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1),
    9588              :                                         lval,
    9589              :                                         non_constant_p, overflow_p,
    9590              :                                         jump_target);
    9591            0 :       break;
    9592              : 
    9593     35216004 :     case RETURN_EXPR:
    9594     35216004 :       if (TREE_OPERAND (t, 0) != NULL_TREE)
    9595     35041616 :         r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
    9596              :                                           lval,
    9597              :                                           non_constant_p, overflow_p,
    9598              :                                           jump_target);
    9599     35216002 :       if (!throws (jump_target))
    9600     35215864 :         *jump_target = t;
    9601              :       break;
    9602        20592 :     case BREAK_STMT:
    9603        20592 :     case CONTINUE_STMT:
    9604        20592 :       *jump_target = t;
    9605        20592 :       break;
    9606              : 
    9607       604136 :     case SAVE_EXPR:
    9608              :       /* Avoid evaluating a SAVE_EXPR more than once.  */
    9609       604136 :       if (tree v = ctx->global->get_value (t))
    9610              :         r = v;
    9611              :       else
    9612              :         {
    9613       591976 :           r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
    9614              :                                             vc_prvalue, non_constant_p,
    9615              :                                             overflow_p, jump_target);
    9616       591976 :           if (*non_constant_p || *jump_target)
    9617              :             break;
    9618         8435 :           ctx->global->put_value (t, r);
    9619         8435 :           if (ctx->save_exprs)
    9620         6297 :             ctx->save_exprs->safe_push (t);
    9621              :         }
    9622              :       break;
    9623              : 
    9624     35309017 :     case NON_LVALUE_EXPR:
    9625     35309017 :     case EXPR_STMT:
    9626     35309017 :     case EH_SPEC_BLOCK:
    9627     35309017 :       r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
    9628              :                                         lval,
    9629              :                                         non_constant_p, overflow_p,
    9630              :                                         jump_target);
    9631     35309017 :       break;
    9632              : 
    9633         2263 :     case TRY_BLOCK:
    9634         2263 :       r = cxx_eval_constant_expression (ctx, TRY_STMTS (t), lval,
    9635              :                                         non_constant_p, overflow_p,
    9636              :                                         jump_target);
    9637         2263 :       if (!*non_constant_p && throws (jump_target))
    9638         1749 :         if (tree h = TRY_HANDLERS (t))
    9639              :           {
    9640         1749 :             tree type = strip_array_types (TREE_TYPE (*jump_target));
    9641         1749 :             if (TREE_CODE (h) == STATEMENT_LIST)
    9642              :               {
    9643          468 :                 for (tree stmt : tsi_range (h))
    9644          451 :                   if (TREE_CODE (stmt) == HANDLER
    9645          451 :                       && handler_match_for_exception_type (stmt, type))
    9646              :                     {
    9647              :                       h = stmt;
    9648              :                       break;
    9649              :                     }
    9650          230 :                 if (TREE_CODE (h) == STATEMENT_LIST)
    9651              :                   h = NULL_TREE;
    9652              :               }
    9653         1519 :             else if (TREE_CODE (h) != HANDLER
    9654         1519 :                      || !handler_match_for_exception_type (h, type))
    9655              :               h = NULL_TREE;
    9656              :             if (h)
    9657              :               {
    9658         1732 :                 gcc_assert (VAR_P (*jump_target));
    9659         1732 :                 ctx->global->caught_exceptions.safe_push (*jump_target);
    9660         1732 :                 ctx->global->caught_exceptions.safe_push (HANDLER_TYPE (h));
    9661         1732 :                 *jump_target = NULL_TREE;
    9662         1732 :                 r = cxx_eval_constant_expression (ctx, HANDLER_BODY (h),
    9663              :                                                   vc_discard, non_constant_p,
    9664              :                                                   overflow_p, jump_target);
    9665              :               }
    9666              :           }
    9667              :       break;
    9668              : 
    9669     51445244 :     case CLEANUP_POINT_EXPR:
    9670     51445244 :       {
    9671     51445244 :         auto_vec<tree, 2> cleanups;
    9672     51445244 :         vec<tree> *prev_cleanups = ctx->global->cleanups;
    9673     51445244 :         ctx->global->cleanups = &cleanups;
    9674              : 
    9675     51445244 :         auto_vec<tree, 10> save_exprs;
    9676     51445244 :         constexpr_ctx new_ctx = *ctx;
    9677     51445244 :         new_ctx.save_exprs = &save_exprs;
    9678              : 
    9679     51445244 :         r = cxx_eval_constant_expression (&new_ctx, TREE_OPERAND (t, 0),
    9680              :                                           lval,
    9681              :                                           non_constant_p, overflow_p,
    9682              :                                           jump_target);
    9683              : 
    9684     51445243 :         ctx->global->cleanups = prev_cleanups;
    9685     51445243 :         unsigned int i;
    9686     51445243 :         tree cleanup, jmp_target = NULL_TREE;
    9687     51445243 :         bool eh = throws (jump_target);
    9688              :         /* Evaluate the cleanups.  */
    9689    103527789 :         FOR_EACH_VEC_ELT_REVERSE (cleanups, i, cleanup)
    9690       637303 :           if (cleanup == NULL_TREE)
    9691              :             {
    9692              :               /* NULL_TREE cleanup is a marker that before it is
    9693              :                  CLEANUP_EH_ONLY cleanup.  Skip the cleanup before it
    9694              :                  if the body didn't throw.  */
    9695          948 :               if (!eh)
    9696          947 :                 --i;
    9697              :             }
    9698              :           else
    9699       636355 :             cxx_eval_constant_expression (&new_ctx, cleanup, vc_discard,
    9700              :                                           non_constant_p, overflow_p,
    9701              :                                           &jmp_target);
    9702              : 
    9703              :         /* Forget SAVE_EXPRs and TARGET_EXPRs created by this
    9704              :            full-expression.  */
    9705    158899541 :         for (tree save_expr : save_exprs)
    9706      4563812 :           destroy_value_checked (ctx, save_expr, non_constant_p);
    9707     51445243 :         if (throws (&jmp_target))
    9708            0 :           *jump_target = jmp_target;
    9709     51445243 :       }
    9710     51445243 :       break;
    9711              : 
    9712     34096044 :     case MUST_NOT_THROW_EXPR:
    9713     34096044 :       r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
    9714              :                                         lval,
    9715              :                                         non_constant_p, overflow_p,
    9716              :                                         jump_target);
    9717     34096043 :       if (throws (jump_target))
    9718              :         {
    9719              :           /* [except.handle]/7 - If the search for a handler exits the
    9720              :              function body of a function with a non-throwing exception
    9721              :              specification, the function std::terminate is invoked.  */
    9722           27 :           if (!ctx->quiet)
    9723              :             {
    9724            9 :               auto_diagnostic_group d;
    9725            9 :               diagnose_std_terminate (loc, ctx, *jump_target);
    9726            9 :               if (MUST_NOT_THROW_NOEXCEPT_P (t)
    9727            7 :                   && ctx->call
    9728           16 :                   && ctx->call->fundef)
    9729            7 :                 inform (loc, "uncaught exception exited from %<noexcept%> "
    9730              :                              "function %qD",
    9731              :                         ctx->call->fundef->decl);
    9732            2 :               else if (MUST_NOT_THROW_THROW_P (t))
    9733            1 :                 inform (loc, "destructor exited with an exception after "
    9734              :                              "initializing the exception object");
    9735            1 :               else if (MUST_NOT_THROW_CATCH_P (t))
    9736            1 :                 inform (loc, "constructor exited with another exception while "
    9737              :                              "entering handler");
    9738            9 :             }
    9739           27 :           *non_constant_p = true;
    9740           27 :           *jump_target = NULL_TREE;
    9741           27 :           r = NULL_TREE;
    9742              :         }
    9743              :       break;
    9744              : 
    9745            0 :     case TRY_CATCH_EXPR:
    9746            0 :       if (TREE_OPERAND (t, 0) == NULL_TREE)
    9747              :         {
    9748            0 :           r = void_node;
    9749            0 :           break;
    9750              :         }
    9751            0 :       r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval,
    9752              :                                         non_constant_p, overflow_p,
    9753              :                                         jump_target);
    9754            0 :       if (!*non_constant_p && throws (jump_target))
    9755              :         {
    9756            0 :           tree jmp_target = NULL_TREE;
    9757            0 :           cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1), vc_discard,
    9758              :                                         non_constant_p, overflow_p,
    9759              :                                         &jmp_target);
    9760            0 :           r = merge_jump_target (loc, ctx, r, non_constant_p, jump_target,
    9761              :                                  jmp_target);
    9762              :         }
    9763              :       break;
    9764              : 
    9765          623 :     case TRY_FINALLY_EXPR:
    9766          623 :       r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval,
    9767              :                                         non_constant_p, overflow_p,
    9768              :                                         jump_target);
    9769          623 :       if (!*non_constant_p)
    9770              :         {
    9771          608 :           tree jmp_target = NULL_TREE;
    9772              :           /* Also evaluate the cleanup.  */
    9773          608 :           if (TREE_CODE (TREE_OPERAND (t, 1)) == EH_ELSE_EXPR
    9774          608 :               && throws (jump_target))
    9775            0 :             cxx_eval_constant_expression (ctx,
    9776            0 :                                           TREE_OPERAND (TREE_OPERAND (t, 1),
    9777              :                                                         1), vc_discard,
    9778              :                                           non_constant_p, overflow_p,
    9779              :                                           &jmp_target);
    9780              :           else
    9781          608 :             cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1), vc_discard,
    9782              :                                           non_constant_p, overflow_p,
    9783              :                                           &jmp_target);
    9784          608 :           r = merge_jump_target (loc, ctx, r, non_constant_p, jump_target,
    9785              :                                  jmp_target);
    9786              :         }
    9787              :       break;
    9788              : 
    9789            0 :     case EH_ELSE_EXPR:
    9790              :       /* Evaluate any cleanup that applies to non-EH exits.  */
    9791            0 :       cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), vc_discard,
    9792              :                                     non_constant_p, overflow_p,
    9793              :                                     jump_target);
    9794              : 
    9795              :       /* The EH path is handled in TRY_FINALLY_EXPR handling above.  */
    9796            0 :       break;
    9797              : 
    9798      2197566 :     case CLEANUP_STMT:
    9799      2197566 :       r = cxx_eval_constant_expression (ctx, CLEANUP_BODY (t), lval,
    9800              :                                         non_constant_p, overflow_p,
    9801              :                                         jump_target);
    9802      2197565 :       if ((!CLEANUP_EH_ONLY (t) || throws (jump_target)) && !*non_constant_p)
    9803              :         {
    9804       799953 :           iloc_sentinel ils (loc);
    9805       799953 :           tree jmp_target = NULL_TREE;
    9806              :           /* Also evaluate the cleanup.  */
    9807       799953 :           cxx_eval_constant_expression (ctx, CLEANUP_EXPR (t), vc_discard,
    9808              :                                         non_constant_p, overflow_p,
    9809              :                                         &jmp_target);
    9810       799953 :           r = merge_jump_target (loc, ctx, r, non_constant_p, jump_target,
    9811              :                                  jmp_target);
    9812       799953 :         }
    9813              :       break;
    9814              : 
    9815              :       /* These differ from cxx_eval_unary_expression in that this doesn't
    9816              :          check for a constant operand or result; an address can be
    9817              :          constant without its operand being, and vice versa.  */
    9818     58965055 :     case MEM_REF:
    9819     58965055 :     case INDIRECT_REF:
    9820     58965055 :       r = cxx_eval_indirect_ref (ctx, t, lval,
    9821              :                                  non_constant_p, overflow_p,
    9822              :                                  jump_target);
    9823     58965055 :       break;
    9824              : 
    9825     65337730 :     case ADDR_EXPR:
    9826     65337730 :       {
    9827     65337730 :         tree oldop = TREE_OPERAND (t, 0);
    9828     65337730 :         tree op = cxx_eval_constant_expression (ctx, oldop, vc_glvalue,
    9829              :                                                 non_constant_p, overflow_p,
    9830              :                                                 jump_target);
    9831     65337730 :         if (*jump_target)
    9832              :           return NULL_TREE;
    9833              :         /* Don't VERIFY_CONSTANT here.  */
    9834     65337726 :         if (*non_constant_p)
    9835              :           return t;
    9836     50374273 :         gcc_checking_assert (TREE_CODE (op) != CONSTRUCTOR);
    9837              :         /* This function does more aggressive folding than fold itself.  */
    9838     50374273 :         r = build_fold_addr_expr_with_type (op, TREE_TYPE (t));
    9839     50374273 :         if (TREE_CODE (r) == ADDR_EXPR && TREE_OPERAND (r, 0) == oldop)
    9840              :           {
    9841     36113208 :             ggc_free (r);
    9842     36113208 :             return t;
    9843              :           }
    9844              :         break;
    9845              :       }
    9846              : 
    9847       476649 :     case REALPART_EXPR:
    9848       476649 :     case IMAGPART_EXPR:
    9849       476649 :       if (lval)
    9850              :         {
    9851          614 :           r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval,
    9852              :                                             non_constant_p, overflow_p,
    9853              :                                             jump_target);
    9854          614 :           if (*jump_target)
    9855              :             return NULL_TREE;
    9856          614 :           if (r == error_mark_node)
    9857              :             ;
    9858          614 :           else if (r == TREE_OPERAND (t, 0) || lval == vc_discard)
    9859              :             r = t;
    9860              :           else
    9861          568 :             r = fold_build1 (TREE_CODE (t), TREE_TYPE (t), r);
    9862              :           break;
    9863              :         }
    9864              :       /* FALLTHRU */
    9865     21106779 :     case CONJ_EXPR:
    9866     21106779 :     case FIX_TRUNC_EXPR:
    9867     21106779 :     case FLOAT_EXPR:
    9868     21106779 :     case NEGATE_EXPR:
    9869     21106779 :     case ABS_EXPR:
    9870     21106779 :     case ABSU_EXPR:
    9871     21106779 :     case BIT_NOT_EXPR:
    9872     21106779 :     case TRUTH_NOT_EXPR:
    9873     21106779 :     case FIXED_CONVERT_EXPR:
    9874     21106779 :     case VEC_DUPLICATE_EXPR:
    9875     21106779 :       r = cxx_eval_unary_expression (ctx, t, lval,
    9876              :                                      non_constant_p, overflow_p,
    9877              :                                      jump_target);
    9878     21106779 :       break;
    9879              : 
    9880      8636745 :     case SIZEOF_EXPR:
    9881      8636745 :       r = fold_sizeof_expr (t);
    9882              :       /* In a template, fold_sizeof_expr may merely create a new SIZEOF_EXPR,
    9883              :          which could lead to an infinite recursion.  */
    9884      8636745 :       if (TREE_CODE (r) != SIZEOF_EXPR)
    9885      8636745 :         r = cxx_eval_constant_expression (ctx, r, lval,
    9886              :                                           non_constant_p, overflow_p,
    9887              :                                           jump_target);
    9888              :       else
    9889              :         {
    9890            0 :           *non_constant_p = true;
    9891            0 :           gcc_assert (ctx->quiet);
    9892              :         }
    9893              : 
    9894              :       break;
    9895              : 
    9896      6828939 :     case COMPOUND_EXPR:
    9897      6828939 :       {
    9898              :         /* check_return_expr sometimes wraps a TARGET_EXPR in a
    9899              :            COMPOUND_EXPR; don't get confused.  Also handle EMPTY_CLASS_EXPR
    9900              :            introduced by build_call_a.  */
    9901      6828939 :         tree op0 = TREE_OPERAND (t, 0);
    9902      6828939 :         tree op1 = TREE_OPERAND (t, 1);
    9903      6828939 :         STRIP_NOPS (op1);
    9904      2101912 :         if ((TREE_CODE (op0) == TARGET_EXPR && op1 == TARGET_EXPR_SLOT (op0))
    9905      7888547 :             || TREE_CODE (op1) == EMPTY_CLASS_EXPR)
    9906      3851599 :           r = cxx_eval_constant_expression (ctx, op0,
    9907              :                                             lval, non_constant_p, overflow_p,
    9908              :                                             jump_target);
    9909              :         else
    9910              :           {
    9911              :             /* Check that the LHS is constant and then discard it.  */
    9912      2977340 :             cxx_eval_constant_expression (ctx, op0, vc_discard,
    9913              :                                           non_constant_p, overflow_p,
    9914              :                                           jump_target);
    9915      2977340 :             if (*jump_target)
    9916              :               return NULL_TREE;
    9917      2973834 :             if (*non_constant_p)
    9918              :               return t;
    9919      2731331 :             op1 = TREE_OPERAND (t, 1);
    9920      2731331 :             r = cxx_eval_constant_expression (ctx, op1,
    9921              :                                               lval, non_constant_p, overflow_p,
    9922              :                                               jump_target);
    9923              :           }
    9924              :       }
    9925              :       break;
    9926              : 
    9927     76858611 :     case POINTER_PLUS_EXPR:
    9928     76858611 :     case POINTER_DIFF_EXPR:
    9929     76858611 :     case PLUS_EXPR:
    9930     76858611 :     case MINUS_EXPR:
    9931     76858611 :     case MULT_EXPR:
    9932     76858611 :     case TRUNC_DIV_EXPR:
    9933     76858611 :     case CEIL_DIV_EXPR:
    9934     76858611 :     case FLOOR_DIV_EXPR:
    9935     76858611 :     case ROUND_DIV_EXPR:
    9936     76858611 :     case TRUNC_MOD_EXPR:
    9937     76858611 :     case CEIL_MOD_EXPR:
    9938     76858611 :     case ROUND_MOD_EXPR:
    9939     76858611 :     case RDIV_EXPR:
    9940     76858611 :     case EXACT_DIV_EXPR:
    9941     76858611 :     case MIN_EXPR:
    9942     76858611 :     case MAX_EXPR:
    9943     76858611 :     case LSHIFT_EXPR:
    9944     76858611 :     case RSHIFT_EXPR:
    9945     76858611 :     case LROTATE_EXPR:
    9946     76858611 :     case RROTATE_EXPR:
    9947     76858611 :     case BIT_IOR_EXPR:
    9948     76858611 :     case BIT_XOR_EXPR:
    9949     76858611 :     case BIT_AND_EXPR:
    9950     76858611 :     case TRUTH_XOR_EXPR:
    9951     76858611 :     case LT_EXPR:
    9952     76858611 :     case LE_EXPR:
    9953     76858611 :     case GT_EXPR:
    9954     76858611 :     case GE_EXPR:
    9955     76858611 :     case EQ_EXPR:
    9956     76858611 :     case NE_EXPR:
    9957     76858611 :     case SPACESHIP_EXPR:
    9958     76858611 :     case UNORDERED_EXPR:
    9959     76858611 :     case ORDERED_EXPR:
    9960     76858611 :     case UNLT_EXPR:
    9961     76858611 :     case UNLE_EXPR:
    9962     76858611 :     case UNGT_EXPR:
    9963     76858611 :     case UNGE_EXPR:
    9964     76858611 :     case UNEQ_EXPR:
    9965     76858611 :     case LTGT_EXPR:
    9966     76858611 :     case RANGE_EXPR:
    9967     76858611 :     case COMPLEX_EXPR:
    9968     76858611 :       r = cxx_eval_binary_expression (ctx, t, lval,
    9969              :                                       non_constant_p, overflow_p,
    9970              :                                       jump_target);
    9971     76858611 :       break;
    9972              : 
    9973              :       /* fold can introduce non-IF versions of these; still treat them as
    9974              :          short-circuiting.  */
    9975      8742114 :     case TRUTH_AND_EXPR:
    9976      8742114 :     case TRUTH_ANDIF_EXPR:
    9977      8742114 :       r = cxx_eval_logical_expression (ctx, t, boolean_false_node,
    9978              :                                        boolean_true_node,
    9979              :                                        non_constant_p, overflow_p,
    9980              :                                        jump_target);
    9981      8742114 :       break;
    9982              : 
    9983      1956500 :     case TRUTH_OR_EXPR:
    9984      1956500 :     case TRUTH_ORIF_EXPR:
    9985      1956500 :       r = cxx_eval_logical_expression (ctx, t, boolean_true_node,
    9986              :                                        boolean_false_node,
    9987              :                                        non_constant_p, overflow_p,
    9988              :                                        jump_target);
    9989      1956500 :       break;
    9990              : 
    9991      8289696 :     case ARRAY_REF:
    9992      8289696 :       r = cxx_eval_array_reference (ctx, t, lval,
    9993              :                                     non_constant_p, overflow_p,
    9994              :                                     jump_target);
    9995      8289696 :       break;
    9996              : 
    9997     65538768 :     case COMPONENT_REF:
    9998     65538768 :       if (is_overloaded_fn (t))
    9999              :         {
   10000              :           /* We can only get here in checking mode via
   10001              :              build_non_dependent_expr,  because any expression that
   10002              :              calls or takes the address of the function will have
   10003              :              pulled a FUNCTION_DECL out of the COMPONENT_REF.  */
   10004            6 :           gcc_checking_assert (ctx->quiet || errorcount);
   10005            6 :           *non_constant_p = true;
   10006            6 :           return t;
   10007              :         }
   10008     65538762 :       r = cxx_eval_component_reference (ctx, t, lval,
   10009              :                                         non_constant_p, overflow_p,
   10010              :                                         jump_target);
   10011     65538762 :       break;
   10012              : 
   10013        15766 :     case BIT_FIELD_REF:
   10014        15766 :       r = cxx_eval_bit_field_ref (ctx, t, lval,
   10015              :                                   non_constant_p, overflow_p,
   10016              :                                   jump_target);
   10017        15766 :       break;
   10018              : 
   10019     18517176 :     case COND_EXPR:
   10020     18517176 :     case IF_STMT:
   10021     18517176 :       if (*jump_target)
   10022              :         {
   10023       150852 :           tree orig_jump = *jump_target;
   10024       150852 :           tree arg = ((TREE_CODE (t) != IF_STMT || TREE_OPERAND (t, 1))
   10025       301704 :                       ? TREE_OPERAND (t, 1) : void_node);
   10026              :           /* When jumping to a label, the label might be either in the
   10027              :              then or else blocks, so process then block first in skipping
   10028              :              mode first, and if we are still in the skipping mode at its end,
   10029              :              process the else block too.  */
   10030       150852 :           r = cxx_eval_constant_expression (ctx, arg, lval, non_constant_p,
   10031              :                                             overflow_p, jump_target);
   10032              :           /* It's possible that we found the label in the then block.  But
   10033              :              it could have been followed by another jumping statement, e.g.
   10034              :              say we're looking for case 1:
   10035              :               if (cond)
   10036              :                 {
   10037              :                   // skipped statements
   10038              :                   case 1:; // clears up *jump_target
   10039              :                   return 1; // and sets it to a RETURN_EXPR
   10040              :                 }
   10041              :               else { ... }
   10042              :              in which case we need not go looking to the else block.
   10043              :              (goto is not allowed in a constexpr function.)  */
   10044       150852 :           if (*jump_target == orig_jump)
   10045              :             {
   10046       150900 :               arg = ((TREE_CODE (t) != IF_STMT || TREE_OPERAND (t, 2))
   10047       150900 :                      ? TREE_OPERAND (t, 2) : void_node);
   10048       150818 :               r = cxx_eval_constant_expression (ctx, arg, lval, non_constant_p,
   10049              :                                                 overflow_p, jump_target);
   10050              :             }
   10051              :           break;
   10052              :         }
   10053     18366324 :       r = cxx_eval_conditional_expression (ctx, t, lval,
   10054              :                                            non_constant_p, overflow_p,
   10055              :                                            jump_target);
   10056     18366324 :       break;
   10057         4582 :     case VEC_COND_EXPR:
   10058         4582 :       r = cxx_eval_vector_conditional_expression (ctx, t, non_constant_p,
   10059              :                                                   overflow_p, jump_target);
   10060         4582 :       break;
   10061              : 
   10062     17899265 :     case CONSTRUCTOR:
   10063     17899265 :       if (TREE_CONSTANT (t) && reduced_constant_expression_p (t))
   10064              :         {
   10065              :           /* Don't re-process a constant CONSTRUCTOR.  */
   10066     16289777 :           verify_constructor_flags (t);
   10067     16289777 :           if (TREE_CONSTANT (t))
   10068              :             return t;
   10069              :         }
   10070      1609488 :       if (TREE_CLOBBER_P (t))
   10071              :         {
   10072              :           /* Assignment from a clobber is handled in cxx_eval_store_expression;
   10073              :              a clobber by itself isn't a constant-expression.  */
   10074            0 :           gcc_assert (ctx->quiet);
   10075            0 :           *non_constant_p = true;
   10076            0 :           break;
   10077              :         }
   10078      1609488 :       r = cxx_eval_bare_aggregate (ctx, t, lval,
   10079              :                                    non_constant_p, overflow_p, jump_target);
   10080      1609488 :       break;
   10081              : 
   10082          547 :     case VEC_INIT_EXPR:
   10083              :       /* We can get this in a defaulted constructor for a class with a
   10084              :          non-static data member of array type.  Either the initializer will
   10085              :          be NULL, meaning default-initialization, or it will be an lvalue
   10086              :          or xvalue of the same type, meaning direct-initialization from the
   10087              :          corresponding member.  */
   10088          547 :       r = cxx_eval_vec_init (ctx, t, lval,
   10089              :                              non_constant_p, overflow_p, jump_target);
   10090          547 :       break;
   10091              : 
   10092        14887 :     case VEC_PERM_EXPR:
   10093        14887 :       r = cxx_eval_trinary_expression (ctx, t, lval,
   10094              :                                        non_constant_p, overflow_p,
   10095              :                                        jump_target);
   10096        14887 :       break;
   10097              : 
   10098            4 :     case PAREN_EXPR:
   10099            4 :       gcc_assert (!REF_PARENTHESIZED_P (t));
   10100              :       /* A PAREN_EXPR resulting from __builtin_assoc_barrier has no effect in
   10101              :          constant expressions since it's unaffected by -fassociative-math.  */
   10102            4 :       r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval,
   10103              :                                         non_constant_p, overflow_p,
   10104              :                                         jump_target);
   10105            4 :       break;
   10106              : 
   10107    286016026 :     case NOP_EXPR:
   10108    286016026 :       if (REINTERPRET_CAST_P (t))
   10109              :         {
   10110           73 :           if (!ctx->quiet)
   10111            6 :             error_at (loc,
   10112              :                       "%<reinterpret_cast%> is not a constant expression");
   10113           73 :           *non_constant_p = true;
   10114           73 :           return t;
   10115              :         }
   10116              :       /* FALLTHROUGH.  */
   10117    346781266 :     case CONVERT_EXPR:
   10118    346781266 :     case VIEW_CONVERT_EXPR:
   10119    346781266 :     case UNARY_PLUS_EXPR:
   10120    346781266 :       {
   10121    346781266 :         tree oldop = TREE_OPERAND (t, 0);
   10122              : 
   10123    346781266 :         tree op = cxx_eval_constant_expression (ctx, oldop,
   10124    346781266 :                                                 VOID_TYPE_P (TREE_TYPE (t))
   10125              :                                                 ? vc_discard
   10126              :                                                 : tcode == VIEW_CONVERT_EXPR
   10127    325838998 :                                                 ? lval : vc_prvalue,
   10128              :                                                 non_constant_p, overflow_p,
   10129              :                                                 jump_target);
   10130    346778568 :         if (*jump_target)
   10131              :           return NULL_TREE;
   10132    346776529 :         if (*non_constant_p)
   10133              :           return t;
   10134    265427042 :         tree type = TREE_TYPE (t);
   10135              : 
   10136    265427042 :         if (VOID_TYPE_P (type))
   10137     20098246 :           return void_node;
   10138              : 
   10139    245328796 :         if (TREE_CODE (t) == CONVERT_EXPR
   10140     26164569 :             && ARITHMETIC_TYPE_P (type)
   10141      4158504 :             && INDIRECT_TYPE_P (TREE_TYPE (op))
   10142    245352254 :             && ctx->strict)
   10143              :           {
   10144        23366 :             if (!ctx->quiet)
   10145           54 :               error_at (loc,
   10146              :                         "conversion from pointer type %qT to arithmetic type "
   10147           54 :                         "%qT in a constant expression", TREE_TYPE (op), type);
   10148        23366 :             *non_constant_p = true;
   10149        23366 :             return t;
   10150              :           }
   10151              : 
   10152              :         /* [expr.const]: a conversion from type cv void* to a pointer-to-object
   10153              :            type cannot be part of a core constant expression as a resolution to
   10154              :            DR 1312.  */
   10155     77160680 :         if (TYPE_PTROB_P (type)
   10156     75027288 :             && TYPE_PTR_P (TREE_TYPE (op))
   10157     52909660 :             && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (op)))
   10158              :             /* Inside a call to std::construct_at,
   10159              :                std::allocator<T>::{,de}allocate, or
   10160              :                std::source_location::current, we permit casting from void*
   10161              :                because that is compiler-generated code.  */
   10162       750285 :             && !is_std_construct_at (ctx->call)
   10163        83054 :             && !is_std_allocator_allocate (ctx->call)
   10164    245347800 :             && !is_std_source_location_current (ctx->call))
   10165              :           {
   10166              :             /* Likewise, don't error when casting from void* when OP is
   10167              :                &heap uninit and similar.  */
   10168        42211 :             tree sop = tree_strip_nop_conversions (op);
   10169        42211 :             tree decl = NULL_TREE;
   10170        42211 :             if (TREE_CODE (sop) == ADDR_EXPR)
   10171        32502 :               decl = TREE_OPERAND (sop, 0);
   10172        32502 :             if (decl
   10173        32502 :                 && VAR_P (decl)
   10174        32123 :                 && DECL_ARTIFICIAL (decl)
   10175        64586 :                 && (DECL_NAME (decl) == heap_identifier
   10176        24726 :                     || DECL_NAME (decl) == heap_uninit_identifier
   10177         2867 :                     || DECL_NAME (decl) == heap_vec_identifier
   10178         1546 :                     || DECL_NAME (decl) == heap_vec_uninit_identifier))
   10179              :               /* OK */;
   10180              :             /* P2738 (C++26): a conversion from a prvalue P of type "pointer to
   10181              :                cv void" to a pointer-to-object type T unless P is a null
   10182              :                pointer value or points to an object whose type is similar to
   10183              :                T.  */
   10184        10143 :             else if (cxx_dialect > cxx23)
   10185              :               {
   10186         9994 :                 if (integer_zerop (sop))
   10187           28 :                   return build_int_cst (type, 0);
   10188         9966 :                 r = cxx_fold_indirect_ref (ctx, loc, TREE_TYPE (type), sop,
   10189              :                                            NULL, jump_target);
   10190         9966 :                 if (*jump_target)
   10191              :                   return NULL_TREE;
   10192         9966 :                 if (r)
   10193              :                   {
   10194         9931 :                     r = build1 (ADDR_EXPR, type, r);
   10195         9931 :                     break;
   10196              :                   }
   10197           35 :                 if (!ctx->quiet)
   10198              :                   {
   10199            3 :                     gcc_assert (TREE_CODE (sop) == ADDR_EXPR);
   10200            3 :                     auto_diagnostic_group d;
   10201            3 :                     error_at (loc, "cast from %qT is not allowed in a "
   10202              :                               "constant expression because "
   10203              :                               "pointed-to type %qT is not similar to %qT",
   10204            3 :                               TREE_TYPE (op), TREE_TYPE (TREE_TYPE (sop)),
   10205            3 :                               TREE_TYPE (type));
   10206            3 :                     tree obj = build_fold_indirect_ref (sop);
   10207            3 :                     if (TREE_CODE (obj) == COMPONENT_REF)
   10208            2 :                       obj = TREE_OPERAND (obj, 1);
   10209            3 :                     if (DECL_P (obj))
   10210            3 :                       inform (DECL_SOURCE_LOCATION (obj),
   10211              :                               "pointed-to object declared here");
   10212            3 :                   }
   10213           35 :                 *non_constant_p = true;
   10214           35 :                 return t;
   10215              :               }
   10216              :             else
   10217              :               {
   10218          149 :                 if (!ctx->quiet)
   10219           26 :                   error_at (loc, "cast from %qT is not allowed in a "
   10220              :                             "constant expression before C++26",
   10221           26 :                             TREE_TYPE (op));
   10222          149 :                 *non_constant_p = true;
   10223          149 :                 return t;
   10224              :               }
   10225              :           }
   10226              : 
   10227    245295287 :         if (TREE_CODE (op) == PTRMEM_CST && !TYPE_PTRMEM_P (type))
   10228              :           {
   10229          981 :             op = cplus_expand_constant (op);
   10230          981 :             if (TREE_CODE (op) == PTRMEM_CST)
   10231              :               {
   10232           21 :                 if (!ctx->quiet)
   10233            3 :                   error_at (loc, "%qE is not a constant expression when the "
   10234              :                             "class %qT is still incomplete", op,
   10235            3 :                             PTRMEM_CST_CLASS (op));
   10236           21 :                 *non_constant_p = true;
   10237           21 :                 return t;
   10238              :               }
   10239              :           }
   10240              : 
   10241    245295266 :         if (TREE_CODE (op) == PTRMEM_CST && tcode == NOP_EXPR)
   10242              :           {
   10243          643 :             if (!same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (op))
   10244          643 :                 && !can_convert_qual (type, op))
   10245            6 :               op = cplus_expand_constant (op);
   10246          643 :             return cp_fold_convert (type, op);
   10247              :           }
   10248              : 
   10249    245294623 :         if (INDIRECT_TYPE_P (type) && TREE_CODE (op) == INTEGER_CST)
   10250              :           {
   10251       554647 :             if (integer_zerop (op))
   10252              :               {
   10253       499645 :                 if (TYPE_REF_P (type))
   10254              :                   {
   10255           35 :                     if (!ctx->quiet)
   10256            4 :                       error_at (loc, "dereferencing a null pointer");
   10257           35 :                     *non_constant_p = true;
   10258           35 :                     return t;
   10259              :                   }
   10260              :               }
   10261        55002 :             else if (TYPE_PTR_P (type)
   10262        55002 :                     && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE)
   10263              :               /* INTEGER_CST with pointer-to-method type is only used
   10264              :                  for a virtual method in a pointer to member function.
   10265              :                  Don't reject those.  */
   10266              :               ;
   10267              :             else
   10268              :               {
   10269              :                 /* This detects for example:
   10270              :                      reinterpret_cast<void*>(sizeof 0)
   10271              :                 */
   10272        54999 :                 if (!ctx->quiet)
   10273           15 :                   error_at (loc, "%<reinterpret_cast<%T>(%E)%> is not "
   10274              :                             "a constant expression",
   10275              :                             type, op);
   10276        54999 :                 *non_constant_p = true;
   10277        54999 :                 return t;
   10278              :               }
   10279              :           }
   10280              : 
   10281    245239589 :         if (INDIRECT_TYPE_P (type)
   10282    122509185 :             && TREE_CODE (op) == NOP_EXPR
   10283     61677248 :             && TREE_TYPE (op) == ptr_type_node
   10284       262648 :             && TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR
   10285       259736 :             && VAR_P (TREE_OPERAND (TREE_OPERAND (op, 0), 0))
   10286    245446446 :             && (DECL_NAME (TREE_OPERAND (TREE_OPERAND (op, 0),
   10287       206857 :                                          0)) == heap_uninit_identifier
   10288       144314 :                 || DECL_NAME (TREE_OPERAND (TREE_OPERAND (op, 0),
   10289       144314 :                                             0)) == heap_vec_uninit_identifier))
   10290              :           {
   10291        64073 :             tree var = TREE_OPERAND (TREE_OPERAND (op, 0), 0);
   10292        64073 :             tree var_size = TYPE_SIZE_UNIT (TREE_TYPE (var));
   10293        64073 :             tree elt_type = TREE_TYPE (type);
   10294        64073 :             tree cookie_size = NULL_TREE;
   10295        64073 :             tree arg_size = NULL_TREE;
   10296        64073 :             if (TREE_CODE (elt_type) == RECORD_TYPE
   10297        64073 :                 && TYPE_IDENTIFIER (elt_type) == heap_identifier)
   10298              :               {
   10299            9 :                 tree fld1 = TYPE_FIELDS (elt_type);
   10300            9 :                 tree fld2 = DECL_CHAIN (fld1);
   10301            9 :                 elt_type = TREE_TYPE (TREE_TYPE (fld2));
   10302            9 :                 cookie_size = TYPE_SIZE_UNIT (TREE_TYPE (fld1));
   10303              :               }
   10304        64073 :             DECL_NAME (var)
   10305        64073 :               = (DECL_NAME (var) == heap_uninit_identifier
   10306        64073 :                  ? heap_identifier : heap_vec_identifier);
   10307              :             /* For zero sized elt_type, try to recover how many outer_nelts
   10308              :                it should have.  */
   10309        64073 :             if ((cookie_size ? tree_int_cst_equal (var_size, cookie_size)
   10310        64064 :                              : integer_zerop (var_size))
   10311           89 :                 && !int_size_in_bytes (elt_type)
   10312            9 :                 && TREE_CODE (oldop) == CALL_EXPR
   10313        64091 :                 && call_expr_nargs (oldop) >= 1)
   10314            9 :               if (tree fun = get_function_named_in_call (oldop))
   10315            9 :                 if (cxx_replaceable_global_alloc_fn (fun)
   10316            9 :                     && IDENTIFIER_NEW_OP_P (DECL_NAME (fun)))
   10317            9 :                   arg_size = CALL_EXPR_ARG (oldop, 0);
   10318        64073 :             tree new_type
   10319        64073 :               = build_new_constexpr_heap_type (ctx, elt_type, cookie_size,
   10320              :                                                var_size, arg_size,
   10321              :                                                non_constant_p, overflow_p,
   10322              :                                                jump_target);
   10323        64073 :             if (*jump_target)
   10324              :               return NULL_TREE;
   10325        64073 :             TREE_TYPE (var) = new_type;
   10326        64073 :             TREE_TYPE (TREE_OPERAND (op, 0))
   10327       128146 :               = build_pointer_type (TREE_TYPE (var));
   10328              :           }
   10329              : 
   10330              :         /* This can happen for std::meta::info(^^int) where the cast has no
   10331              :            meaning.  */
   10332    245239589 :         if (REFLECTION_TYPE_P (type) && REFLECT_EXPR_P (op))
   10333              :           {
   10334              :             r = op;
   10335              :             break;
   10336              :           }
   10337              : 
   10338    245190646 :         if (op == oldop && tcode != UNARY_PLUS_EXPR)
   10339              :           /* We didn't fold at the top so we could check for ptr-int
   10340              :              conversion.  */
   10341     19304220 :           return fold (t);
   10342              : 
   10343    225886426 :         tree sop;
   10344              : 
   10345              :         /* Handle an array's bounds having been deduced after we built
   10346              :            the wrapping expression.  */
   10347    225886426 :         if (same_type_ignoring_tlq_and_bounds_p (type, TREE_TYPE (op)))
   10348              :           r = op;
   10349     76720155 :         else if (sop = tree_strip_nop_conversions (op),
   10350    107023093 :                  sop != op && (same_type_ignoring_tlq_and_bounds_p
   10351     30302938 :                                (type, TREE_TYPE (sop))))
   10352              :           r = sop;
   10353     62591794 :         else if (tcode == UNARY_PLUS_EXPR)
   10354            0 :           r = fold_convert (TREE_TYPE (t), op);
   10355              :         else
   10356     62591794 :           r = fold_build1 (tcode, type, op);
   10357              : 
   10358              :         /* Conversion of an out-of-range value has implementation-defined
   10359              :            behavior; the language considers it different from arithmetic
   10360              :            overflow, which is undefined.  */
   10361    225886426 :         if (TREE_OVERFLOW_P (r) && !TREE_OVERFLOW_P (op))
   10362        12198 :           TREE_OVERFLOW (r) = false;
   10363              :       }
   10364              :       break;
   10365              : 
   10366         6582 :     case EXCESS_PRECISION_EXPR:
   10367         6582 :       {
   10368         6582 :         tree oldop = TREE_OPERAND (t, 0);
   10369              : 
   10370         6582 :         tree op = cxx_eval_constant_expression (ctx, oldop,
   10371              :                                                 lval,
   10372              :                                                 non_constant_p, overflow_p,
   10373              :                                                 jump_target);
   10374         6582 :         if (*jump_target)
   10375              :           return NULL_TREE;
   10376         6582 :         if (*non_constant_p)
   10377              :           return t;
   10378         6578 :         r = fold_convert (TREE_TYPE (t), op);
   10379         6578 :         break;
   10380              :       }
   10381              : 
   10382        39796 :     case EMPTY_CLASS_EXPR:
   10383              :       /* Handle EMPTY_CLASS_EXPR produced by build_call_a by lowering
   10384              :          it to an appropriate CONSTRUCTOR.  */
   10385        39796 :       return build_constructor (TREE_TYPE (t), NULL);
   10386              : 
   10387     31011958 :     case STATEMENT_LIST:
   10388     31011958 :       new_ctx = *ctx;
   10389     31011958 :       new_ctx.ctor = new_ctx.object = NULL_TREE;
   10390     31011958 :       return cxx_eval_statement_list (&new_ctx, t,
   10391     31011956 :                                       non_constant_p, overflow_p, jump_target);
   10392              : 
   10393     18947995 :     case BIND_EXPR:
   10394              :       /* Pre-emptively clear the vars declared by this BIND_EXPR from the value
   10395              :          map, so that when checking whether they're already destroyed later we
   10396              :          don't get confused by remnants of previous calls.  */
   10397     27777666 :       for (tree decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
   10398      8829671 :         ctx->global->clear_value (decl);
   10399     18947995 :       r = cxx_eval_constant_expression (ctx, BIND_EXPR_BODY (t),
   10400              :                                         lval,
   10401              :                                         non_constant_p, overflow_p,
   10402              :                                         jump_target);
   10403     27777664 :       for (tree decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
   10404      8829670 :         destroy_value_checked (ctx, decl, non_constant_p);
   10405              :       break;
   10406              : 
   10407      4964165 :     case PREINCREMENT_EXPR:
   10408      4964165 :     case POSTINCREMENT_EXPR:
   10409      4964165 :     case PREDECREMENT_EXPR:
   10410      4964165 :     case POSTDECREMENT_EXPR:
   10411      4964165 :       return cxx_eval_increment_expression (ctx, t,
   10412              :                                             lval, non_constant_p, overflow_p,
   10413      4964165 :                                             jump_target);
   10414              : 
   10415         1131 :     case THROW_EXPR:
   10416         1131 :       if (cxx_dialect >= cxx26)
   10417          804 :         return cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval,
   10418              :                                              non_constant_p, overflow_p,
   10419          804 :                                              jump_target);
   10420              :       /* FALLTHROUGH */
   10421          335 :     case LAMBDA_EXPR:
   10422          335 :     case NEW_EXPR:
   10423          335 :     case VEC_NEW_EXPR:
   10424          335 :     case DELETE_EXPR:
   10425          335 :     case VEC_DELETE_EXPR:
   10426          335 :     case MODOP_EXPR:
   10427              :       /* GCC internal stuff.  */
   10428          335 :     case VA_ARG_EXPR:
   10429          335 :     case BASELINK:
   10430          335 :     case OFFSET_REF:
   10431          335 :       if (!ctx->quiet)
   10432           86 :         error_at (loc, "expression %qE is not a constant expression", t);
   10433          335 :       *non_constant_p = true;
   10434          335 :       break;
   10435              : 
   10436       209243 :     case OBJ_TYPE_REF:
   10437              :       /* Virtual function lookup.  We don't need to do anything fancy.  */
   10438       209243 :       return cxx_eval_constant_expression (ctx, OBJ_TYPE_REF_EXPR (t),
   10439              :                                            lval, non_constant_p, overflow_p,
   10440       209243 :                                            jump_target);
   10441              : 
   10442        16116 :     case PLACEHOLDER_EXPR:
   10443              :       /* Use of the value or address of the current object.  */
   10444        16116 :       if (tree ctor = lookup_placeholder (ctx, lval, TREE_TYPE (t)))
   10445              :         {
   10446        15885 :           if (TREE_CODE (ctor) == CONSTRUCTOR)
   10447              :             return ctor;
   10448              :           else
   10449        15585 :             return cxx_eval_constant_expression (ctx, ctor, lval,
   10450              :                                                  non_constant_p, overflow_p,
   10451        15585 :                                                  jump_target);
   10452              :         }
   10453              :       /* A placeholder without a referent.  We can get here when
   10454              :          checking whether NSDMIs are noexcept, or in massage_init_elt;
   10455              :          just say it's non-constant for now.  */
   10456          231 :       gcc_assert (ctx->quiet);
   10457          231 :       *non_constant_p = true;
   10458          231 :       break;
   10459              : 
   10460         3351 :     case EXIT_EXPR:
   10461         3351 :       {
   10462         3351 :         tree cond = TREE_OPERAND (t, 0);
   10463         3351 :         cond = cxx_eval_constant_expression (ctx, cond, vc_prvalue,
   10464              :                                              non_constant_p, overflow_p,
   10465              :                                              jump_target);
   10466         3351 :         if (*jump_target)
   10467              :           return NULL_TREE;
   10468         3351 :         VERIFY_CONSTANT (cond);
   10469         3351 :         if (integer_nonzerop (cond))
   10470         1616 :           *jump_target = t;
   10471              :       }
   10472              :       break;
   10473              : 
   10474           21 :     case GOTO_EXPR:
   10475           21 :       if (breaks (&TREE_OPERAND (t, 0))
   10476           21 :           || continues (&TREE_OPERAND (t, 0)))
   10477            9 :         *jump_target = TREE_OPERAND (t, 0);
   10478              :       else
   10479              :         {
   10480           12 :           if (!ctx->quiet)
   10481            1 :             error_at (loc, "%<goto%> is not a constant expression");
   10482           12 :           *non_constant_p = true;
   10483              :         }
   10484              :       break;
   10485              : 
   10486      3302508 :     case LOOP_EXPR:
   10487      3302508 :     case DO_STMT:
   10488      3302508 :     case WHILE_STMT:
   10489      3302508 :     case FOR_STMT:
   10490      3302508 :       cxx_eval_loop_expr (ctx, t,
   10491              :                           non_constant_p, overflow_p, jump_target);
   10492      3302508 :       break;
   10493              : 
   10494        30978 :     case SWITCH_EXPR:
   10495        30978 :     case SWITCH_STMT:
   10496        30978 :       cxx_eval_switch_expr (ctx, t,
   10497              :                             non_constant_p, overflow_p, jump_target);
   10498        30978 :       break;
   10499              : 
   10500          120 :     case REQUIRES_EXPR:
   10501              :       /* It's possible to get a requires-expression in a constant
   10502              :          expression. For example:
   10503              : 
   10504              :              template<typename T> concept bool C() {
   10505              :                return requires (T t) { t; };
   10506              :              }
   10507              : 
   10508              :              template<typename T> requires !C<T>() void f(T);
   10509              : 
   10510              :          Normalization leaves f with the associated constraint
   10511              :          '!requires (T t) { ... }' which is not transformed into
   10512              :          a constraint.  */
   10513          120 :       if (!processing_template_decl)
   10514          120 :         return evaluate_requires_expr (t);
   10515              :       else
   10516            0 :         *non_constant_p = true;
   10517            0 :       return t;
   10518              : 
   10519        16327 :     case ANNOTATE_EXPR:
   10520        16327 :       r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
   10521              :                                         lval,
   10522              :                                         non_constant_p, overflow_p,
   10523              :                                         jump_target);
   10524        16327 :       break;
   10525              : 
   10526        11718 :     case USING_STMT:
   10527        11718 :       r = void_node;
   10528        11718 :       break;
   10529              : 
   10530           20 :     case ASSERTION_STMT:
   10531           20 :     case PRECONDITION_STMT:
   10532           20 :     case POSTCONDITION_STMT:
   10533           20 :       {
   10534           20 :         r = void_node;
   10535              :         /* Only record the first fail, and do not go further is the semantic
   10536              :            is 'ignore'.  */
   10537           20 :         if (*non_constant_p || ctx->global->contract_statement
   10538           40 :             || contract_ignored_p (t))
   10539              :           break;
   10540              : 
   10541           20 :         tree cond = CONTRACT_CONDITION (t);
   10542           20 :         if (!potential_rvalue_constant_expression (cond))
   10543              :           {
   10544            4 :             ctx->global->contract_statement = t;
   10545            4 :             ctx->global->contract_condition_non_const = true;
   10546            4 :             break;
   10547              :           }
   10548              : 
   10549              :         /* We need to evaluate and stash the result of this here, since whether
   10550              :            it needs to be reported (and how) depends on whether the containing
   10551              :            expression is otherwise const.  */
   10552           16 :         bool ctrct_non_const_p = false;
   10553           16 :         bool ctrct_overflow_p = false;
   10554           16 :         tree jmp_target = NULL_TREE;
   10555           16 :         constexpr_ctx new_ctx = *ctx;
   10556           16 :         new_ctx.quiet = true;
   10557              :         /* Avoid modification of existing values.  */
   10558           16 :         modifiable_tracker ms (new_ctx.global);
   10559           16 :         tree eval =
   10560           16 :           cxx_eval_constant_expression (&new_ctx, cond, vc_prvalue,
   10561              :                                         &ctrct_non_const_p,
   10562              :                                         &ctrct_overflow_p, &jmp_target);
   10563              :         /* Not a constant.  */
   10564           16 :         if (ctrct_non_const_p)
   10565              :           {
   10566            0 :             ctx->global->contract_statement = t;
   10567            0 :             ctx->global->contract_condition_non_const = true;
   10568            0 :             break;
   10569              :           }
   10570              :         /* Constant, but check failed.  */
   10571           16 :         if (integer_zerop (eval))
   10572           16 :           ctx->global->contract_statement = t;
   10573           16 :       }
   10574           16 :       break;
   10575              : 
   10576      2310994 :     case TEMPLATE_ID_EXPR:
   10577      2310994 :       {
   10578              :         /* We can evaluate template-id that refers to a concept only if
   10579              :            the template arguments are non-dependent.  */
   10580      2310994 :         gcc_assert (concept_check_p (t));
   10581              : 
   10582      2310994 :         if (!value_dependent_expression_p (t)
   10583      2310994 :             && !uid_sensitive_constexpr_evaluation_p ())
   10584      2310555 :           r = evaluate_concept_check (t);
   10585              :         else
   10586          439 :           *non_constant_p = true;
   10587              : 
   10588              :         break;
   10589              :       }
   10590              : 
   10591           51 :     case ASM_EXPR:
   10592           51 :       if (!ctx->quiet)
   10593           29 :         inline_asm_in_constexpr_error (loc, /*constexpr_fundef_p*/false);
   10594           51 :       *non_constant_p = true;
   10595           51 :       return t;
   10596              : 
   10597         1125 :     case BIT_CAST_EXPR:
   10598         1125 :       if (lval)
   10599              :         {
   10600            0 :           if (!ctx->quiet)
   10601            0 :             error_at (EXPR_LOCATION (t),
   10602              :                       "address of a call to %qs is not a constant expression",
   10603              :                       "__builtin_bit_cast");
   10604            0 :           *non_constant_p = true;
   10605            0 :           return t;
   10606              :         }
   10607         1125 :       r = cxx_eval_bit_cast (ctx, t, non_constant_p, overflow_p, jump_target);
   10608         1125 :       break;
   10609              : 
   10610            0 :     case OMP_PARALLEL:
   10611            0 :     case OMP_TASK:
   10612            0 :     case OMP_FOR:
   10613            0 :     case OMP_SIMD:
   10614            0 :     case OMP_DISTRIBUTE:
   10615            0 :     case OMP_TASKLOOP:
   10616            0 :     case OMP_LOOP:
   10617            0 :     case OMP_TEAMS:
   10618            0 :     case OMP_TARGET_DATA:
   10619            0 :     case OMP_TARGET:
   10620            0 :     case OMP_SECTIONS:
   10621            0 :     case OMP_ORDERED:
   10622            0 :     case OMP_CRITICAL:
   10623            0 :     case OMP_SINGLE:
   10624            0 :     case OMP_SCAN:
   10625            0 :     case OMP_SCOPE:
   10626            0 :     case OMP_SECTION:
   10627            0 :     case OMP_STRUCTURED_BLOCK:
   10628            0 :     case OMP_MASTER:
   10629            0 :     case OMP_MASKED:
   10630            0 :     case OMP_TASKGROUP:
   10631            0 :     case OMP_TARGET_UPDATE:
   10632            0 :     case OMP_TARGET_ENTER_DATA:
   10633            0 :     case OMP_TARGET_EXIT_DATA:
   10634            0 :     case OMP_ATOMIC:
   10635            0 :     case OMP_ATOMIC_READ:
   10636            0 :     case OMP_ATOMIC_CAPTURE_OLD:
   10637            0 :     case OMP_ATOMIC_CAPTURE_NEW:
   10638            0 :     case OMP_DEPOBJ:
   10639            0 :     case OACC_PARALLEL:
   10640            0 :     case OACC_KERNELS:
   10641            0 :     case OACC_SERIAL:
   10642            0 :     case OACC_DATA:
   10643            0 :     case OACC_HOST_DATA:
   10644            0 :     case OACC_LOOP:
   10645            0 :     case OACC_CACHE:
   10646            0 :     case OACC_DECLARE:
   10647            0 :     case OACC_ENTER_DATA:
   10648            0 :     case OACC_EXIT_DATA:
   10649            0 :     case OACC_UPDATE:
   10650            0 :       if (!ctx->quiet)
   10651            0 :         error_at (EXPR_LOCATION (t),
   10652              :                   "statement is not a constant expression");
   10653            0 :       *non_constant_p = true;
   10654            0 :       break;
   10655              : 
   10656            0 :     default:
   10657            0 :       if (STATEMENT_CODE_P (TREE_CODE (t)))
   10658              :         {
   10659              :           /* This function doesn't know how to deal with pre-genericize
   10660              :              statements; this can only happen with statement-expressions,
   10661              :              so for now just fail.  */
   10662            0 :           if (!ctx->quiet)
   10663            0 :             error_at (EXPR_LOCATION (t),
   10664              :                       "statement is not a constant expression");
   10665              :         }
   10666            0 :       else if (flag_checking)
   10667            0 :         internal_error ("unexpected expression %qE of kind %s", t,
   10668              :                         get_tree_code_name (TREE_CODE (t)));
   10669            0 :       *non_constant_p = true;
   10670            0 :       break;
   10671              :     }
   10672              : 
   10673   1258739450 :   if (r == error_mark_node)
   10674     11862084 :     *non_constant_p = true;
   10675              : 
   10676     73853206 :   if (r == void_node && lval != vc_discard && !*jump_target
   10677   1258751753 :       && !VOID_TYPE_P (TREE_TYPE (t)))
   10678              :     {
   10679              :       /* For diagnostic quality we should have handled this sooner, where we
   10680              :          can be more specific about the out-of-lifetime object.  But here we
   10681              :          can still be correct.  */
   10682            1 :       gcc_checking_assert (false);
   10683              :       if (!ctx->quiet)
   10684              :         error_at (EXPR_LOCATION (t),
   10685              :                   "%qE accesses an object outside its lifetime", t);
   10686              :       *non_constant_p = true;
   10687              :     }
   10688              : 
   10689   1258739449 :   if (*non_constant_p)
   10690    325034259 :     return t;
   10691              :   else
   10692              :     return r;
   10693              : }
   10694              : 
   10695              : /* P0859: A function is needed for constant evaluation if it is a constexpr
   10696              :    function that is named by an expression ([basic.def.odr]) that is
   10697              :    potentially constant evaluated.
   10698              : 
   10699              :    So we need to instantiate any constexpr functions mentioned by the
   10700              :    expression even if the definition isn't needed for evaluating the
   10701              :    expression.  */
   10702              : 
   10703              : static tree
   10704    546702141 : instantiate_cx_fn_r (tree *tp, int *walk_subtrees, void */*data*/)
   10705              : {
   10706    546702141 :   if (TREE_CODE (*tp) == FUNCTION_DECL
   10707     11458313 :       && DECL_DECLARED_CONSTEXPR_P (*tp)
   10708     11332467 :       && !DECL_INITIAL (*tp)
   10709      2878578 :       && !trivial_fn_p (*tp)
   10710      2878522 :       && (DECL_TEMPLOID_INSTANTIATION (*tp) || DECL_DEFAULTED_FN (*tp))
   10711    546702141 :       && !uid_sensitive_constexpr_evaluation_p ())
   10712              :     {
   10713      2864055 :       ++function_depth;
   10714      2864055 :       if (DECL_TEMPLOID_INSTANTIATION (*tp))
   10715      2864043 :         instantiate_decl (*tp, /*defer_ok*/false, /*expl_inst*/false);
   10716              :       else
   10717           12 :         synthesize_method (*tp);
   10718      2864055 :       --function_depth;
   10719              :     }
   10720    543838086 :   else if (TREE_CODE (*tp) == CALL_EXPR
   10721    532842101 :            || TREE_CODE (*tp) == AGGR_INIT_EXPR)
   10722              :     {
   10723     11519768 :       if (EXPR_HAS_LOCATION (*tp))
   10724     11516312 :         input_location = EXPR_LOCATION (*tp);
   10725              :     }
   10726              : 
   10727    546702141 :   if (!EXPR_P (*tp))
   10728    309994856 :     *walk_subtrees = 0;
   10729              : 
   10730    546702141 :   return NULL_TREE;
   10731              : }
   10732              : 
   10733              : static void
   10734    263332927 : instantiate_constexpr_fns (tree t)
   10735              : {
   10736    263332927 :   location_t loc = input_location;
   10737    263332927 :   cp_walk_tree_without_duplicates (&t, instantiate_cx_fn_r, NULL);
   10738    263332927 :   input_location = loc;
   10739    263332927 : }
   10740              : 
   10741              : /* Look for heap variables in the expression *TP.  */
   10742              : 
   10743              : static tree
   10744       326945 : find_heap_var_refs (tree *tp, int *walk_subtrees, void */*data*/)
   10745              : {
   10746       326945 :   if (VAR_P (*tp)
   10747       326945 :       && (DECL_NAME (*tp) == heap_uninit_identifier
   10748         5939 :           || DECL_NAME (*tp) == heap_identifier
   10749         2474 :           || DECL_NAME (*tp) == heap_vec_uninit_identifier
   10750         1744 :           || DECL_NAME (*tp) == heap_vec_identifier
   10751          555 :           || DECL_NAME (*tp) == heap_deleted_identifier))
   10752              :     return *tp;
   10753              : 
   10754       225825 :   if (TYPE_P (*tp))
   10755           83 :     *walk_subtrees = 0;
   10756              :   return NULL_TREE;
   10757              : }
   10758              : 
   10759              : /* Find immediate function decls in *TP if any.  */
   10760              : 
   10761              : static tree
   10762    568024153 : find_immediate_fndecl (tree *tp, int *walk_subtrees, void */*data*/)
   10763              : {
   10764    571667699 :   if (TREE_CODE (*tp) == FUNCTION_DECL && DECL_IMMEDIATE_FUNCTION_P (*tp))
   10765              :     return *tp;
   10766    568019309 :   if (TREE_CODE (*tp) == PTRMEM_CST
   10767        28895 :       && TREE_CODE (PTRMEM_CST_MEMBER (*tp)) == FUNCTION_DECL
   10768    568047351 :       && DECL_IMMEDIATE_FUNCTION_P (PTRMEM_CST_MEMBER (*tp)))
   10769              :     return PTRMEM_CST_MEMBER (*tp);
   10770    568019204 :   if (REFLECT_EXPR_P (*tp))
   10771        50228 :     *walk_subtrees = 0;
   10772              :   return NULL_TREE;
   10773              : }
   10774              : 
   10775              : /* T has TREE_CONSTANT set but has been deemed not a valid C++ constant
   10776              :    expression.  Return a version of T that has TREE_CONSTANT cleared.  */
   10777              : 
   10778              : static tree
   10779       143059 : mark_non_constant (tree t)
   10780              : {
   10781       143059 :   gcc_checking_assert (TREE_CONSTANT (t));
   10782              : 
   10783              :   /* This isn't actually constant, so unset TREE_CONSTANT.
   10784              :      Don't clear TREE_CONSTANT on ADDR_EXPR, as the middle-end requires
   10785              :      it to be set if it is invariant address, even when it is not
   10786              :      a valid C++ constant expression.  Wrap it with a NOP_EXPR
   10787              :      instead.  */
   10788       143059 :   if (EXPR_P (t) && TREE_CODE (t) != ADDR_EXPR)
   10789       141393 :     t = copy_node (t);
   10790         1666 :   else if (TREE_CODE (t) == CONSTRUCTOR)
   10791          233 :     t = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (t), t);
   10792              :   else
   10793         1433 :     t = build_nop (TREE_TYPE (t), t);
   10794       143059 :   TREE_CONSTANT (t) = false;
   10795       143059 :   return t;
   10796              : }
   10797              : 
   10798              : /* If we have a successful constant evaluation, now check whether there is
   10799              :    a failed or non-constant contract that would invalidate this.  */
   10800              : 
   10801              : static bool
   10802    499891496 : check_for_failed_contracts (constexpr_ctx *ctx)
   10803              : {
   10804    499891496 :   constexpr_global_ctx *const global_ctx = ctx->global;
   10805    499891496 :   if (!flag_contracts || !global_ctx->contract_statement)
   10806              :     return false;
   10807              : 
   10808           20 :   location_t loc = EXPR_LOCATION (global_ctx->contract_statement);
   10809           20 :   enum diagnostics::kind kind;
   10810           20 :   bool error = false;
   10811              :   /* [intro.compliance.general]/2.3.4. */
   10812              :   /* [basic.contract.eval]/8. */
   10813           20 :   if (ctx->manifestly_const_eval != mce_true)
   10814              :     {
   10815              :       /* When !MCE, silently return not constant.  */
   10816              :       return true;
   10817              :     }
   10818           18 :   else if (contract_terminating_p (global_ctx->contract_statement))
   10819              :     {
   10820              :       kind = diagnostics::kind::error;
   10821              :       error = true;
   10822              :     }
   10823              :   else
   10824            4 :     kind = diagnostics::kind::warning;
   10825              : 
   10826              :   /* [basic.contract.eval]/7.3 */
   10827           18 :   if (global_ctx->contract_condition_non_const)
   10828              :     {
   10829            4 :       emit_diagnostic (kind, loc, 0, "contract condition is not constant");
   10830            4 :       return error;
   10831              :     }
   10832              : 
   10833              :   /* Otherwise, the evaluation was const, but determined to be false.  */
   10834           14 :   emit_diagnostic (kind, loc, 0,
   10835              :                    "contract predicate is false in constant expression");
   10836           14 :   return error;
   10837              : }
   10838              : 
   10839              : /* ALLOW_NON_CONSTANT is false if T is required to be a constant expression.
   10840              :    STRICT has the same sense as for constant_value_1: true if we only allow
   10841              :    conforming C++ constant expressions, or false if we want a constant value
   10842              :    even if it doesn't conform.
   10843              :    MANIFESTLY_CONST_EVAL is true if T is manifestly const-evaluated as
   10844              :    per P0595 even when ALLOW_NON_CONSTANT is true.
   10845              :    CONSTEXPR_DTOR is true when evaluating the dtor of a constexpr variable.
   10846              :    OBJECT must be non-NULL in that case.  */
   10847              : 
   10848              : static tree
   10849    509072041 : cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant,
   10850              :                                   bool strict = true,
   10851              :                                   mce_value manifestly_const_eval = mce_unknown,
   10852              :                                   bool constexpr_dtor = false,
   10853              :                                   tree object = NULL_TREE)
   10854              : {
   10855    509072041 :   auto_timevar time (TV_CONSTEXPR);
   10856              : 
   10857    509072041 :   bool non_constant_p = false;
   10858    509072041 :   bool overflow_p = false;
   10859              : 
   10860    509072041 :   if (BRACE_ENCLOSED_INITIALIZER_P (t))
   10861              :     {
   10862            0 :       gcc_checking_assert (allow_non_constant);
   10863              :       return t;
   10864              :     }
   10865              : 
   10866    509072041 :   constexpr_global_ctx global_ctx;
   10867    509072041 :   constexpr_ctx ctx = { &global_ctx, NULL, NULL, NULL, NULL, NULL, NULL,
   10868              :                         allow_non_constant, strict,
   10869    509072041 :                         !allow_non_constant ? mce_true : manifestly_const_eval };
   10870              : 
   10871              :   /* Turn off -frounding-math for manifestly constant evaluation.  */
   10872    509072041 :   warning_sentinel rm (flag_rounding_math,
   10873    509072041 :                        ctx.manifestly_const_eval == mce_true);
   10874    509072041 :   tree type = (object
   10875    509072041 :                ? cv_unqualified (TREE_TYPE (object))
   10876    468596313 :                : initialized_type (t));
   10877    509072041 :   tree r = t;
   10878    509072041 :   bool is_consteval = false;
   10879    509072041 :   if (VOID_TYPE_P (type))
   10880              :     {
   10881      9174130 :       if (!constexpr_dtor)
   10882              :         {
   10883      9174130 :           if (cxx_dialect < cxx20)
   10884              :             return t;
   10885              :           /* We could have a COMPOUND_EXPR here coming from
   10886              :              keep_unused_object_arg.  */
   10887      9163108 :           tree x = extract_call_expr (t);
   10888      9163108 :           if (x == NULL_TREE || x == error_mark_node)
   10889              :             return t;
   10890              :           /* Calls to immediate functions returning void need to be
   10891              :              evaluated.  */
   10892      9163068 :           tree fndecl = cp_get_callee_fndecl_nofold (x);
   10893     18326136 :           if (fndecl == NULL_TREE || !DECL_IMMEDIATE_FUNCTION_P (fndecl))
   10894              :             return t;
   10895              :           else
   10896          584 :             is_consteval = true;
   10897          584 :           tree lam;
   10898          584 :           if (manifestly_const_eval == mce_true
   10899          844 :               && LAMBDA_FUNCTION_P (fndecl)
   10900          254 :               && (lam = CLASSTYPE_LAMBDA_EXPR (CP_DECL_CONTEXT (fndecl)))
   10901          838 :               && LAMBDA_EXPR_CONSTEVAL_BLOCK_P (lam))
   10902          244 :             global_ctx.consteval_block = fndecl;
   10903              :         }
   10904              :     }
   10905    499897911 :   else if (cxx_dialect >= cxx20
   10906    491722412 :            && (TREE_CODE (t) == CALL_EXPR
   10907    426714136 :                || TREE_CODE (t) == AGGR_INIT_EXPR
   10908    422602642 :                || TREE_CODE (t) == TARGET_EXPR))
   10909              :     {
   10910     74017759 :       tree x = t;
   10911     74017759 :       if (TREE_CODE (x) == TARGET_EXPR)
   10912      4897989 :         x = TARGET_EXPR_INITIAL (x);
   10913     74017759 :       tree fndecl = cp_get_callee_fndecl_nofold (x);
   10914    145657596 :       if (fndecl && DECL_IMMEDIATE_FUNCTION_P (fndecl))
   10915              :         is_consteval = true;
   10916              :       /* Don't try to evaluate a std::vector constructor taking an integer, it
   10917              :          will fail in the 'if (heap_var)' block below after doing all the work
   10918              :          (c++/113835).  This will need adjustment if P3554 is accepted.  Note
   10919              :          that evaluation of e.g. the vector default constructor can succeed, so
   10920              :          we don't shortcut all vector constructors.  */
   10921    143279674 :       if (fndecl && DECL_CONSTRUCTOR_P (fndecl) && allow_non_constant
   10922     10034491 :           && is_std_class (type, "vector") && call_expr_nargs (x) > 1
   10923     74038875 :           && TREE_CODE (TREE_TYPE (get_nth_callarg (x, 1))) == INTEGER_TYPE)
   10924              :         return t;
   10925              :     }
   10926    499897143 :   if (AGGREGATE_TYPE_P (type) || VECTOR_TYPE_P (type))
   10927              :     {
   10928              :       /* In C++14 an NSDMI can participate in aggregate initialization,
   10929              :          and can refer to the address of the object being initialized, so
   10930              :          we need to pass in the relevant VAR_DECL if we want to do the
   10931              :          evaluation in a single pass.  The evaluation will dynamically
   10932              :          update ctx.values for the VAR_DECL.  We use the same strategy
   10933              :          for C++11 constexpr constructors that refer to the object being
   10934              :          initialized.  */
   10935     38627233 :       if (constexpr_dtor)
   10936              :         {
   10937          161 :           gcc_assert (object && VAR_P (object));
   10938          161 :           gcc_assert (DECL_DECLARED_CONSTEXPR_P (object));
   10939          161 :           gcc_assert (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (object));
   10940          161 :           if (error_operand_p (DECL_INITIAL (object)))
   10941              :             return t;
   10942          149 :           ctx.ctor = unshare_expr (DECL_INITIAL (object));
   10943          149 :           TREE_READONLY (ctx.ctor) = false;
   10944              :           /* Temporarily force decl_really_constant_value to return false
   10945              :              for it, we want to use ctx.ctor for the current value instead.  */
   10946          149 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (object) = false;
   10947              :         }
   10948              :       else
   10949              :         {
   10950     38627072 :           ctx.ctor = build_constructor (type, NULL);
   10951     38627072 :           CONSTRUCTOR_NO_CLEARING (ctx.ctor) = true;
   10952              :         }
   10953     38627221 :       if (!object)
   10954              :         {
   10955     19939594 :           if (TREE_CODE (t) == CALL_EXPR)
   10956              :             {
   10957              :               /* If T is calling a constructor to initialize an object, reframe
   10958              :                  it as an AGGR_INIT_EXPR to avoid trying to modify an object
   10959              :                  from outside the constant evaluation, which will fail even if
   10960              :                  the value is actually constant (is_constant_evaluated3.C).  */
   10961      9063647 :               tree fn = cp_get_callee_fndecl_nofold (t);
   10962     18127198 :               if (fn && DECL_CONSTRUCTOR_P (fn))
   10963              :                 {
   10964      3779101 :                   object = CALL_EXPR_ARG (t, 0);
   10965      3779101 :                   object = build_fold_indirect_ref (object);
   10966      3779101 :                   r = build_aggr_init_expr (type, r);
   10967              :                 }
   10968              :             }
   10969     10875947 :           else if (TREE_CODE (t) == TARGET_EXPR)
   10970      4809473 :             object = TARGET_EXPR_SLOT (t);
   10971      6066474 :           else if (TREE_CODE (t) == AGGR_INIT_EXPR)
   10972       670485 :             object = AGGR_INIT_EXPR_SLOT (t);
   10973              :         }
   10974     38627221 :       ctx.object = object;
   10975     38627221 :       if (object)
   10976     27946686 :         gcc_assert (same_type_ignoring_top_level_qualifiers_p
   10977              :                     (type, TREE_TYPE (object)));
   10978     27946686 :       if (object && DECL_P (object))
   10979     23837004 :         global_ctx.put_value (object, ctx.ctor);
   10980     38627221 :       if (TREE_CODE (r) == TARGET_EXPR)
   10981              :         /* Avoid creating another CONSTRUCTOR when we expand the
   10982              :            TARGET_EXPR.  */
   10983      4934676 :         r = TARGET_EXPR_INITIAL (r);
   10984              :     }
   10985              : 
   10986              :   /* uid_sensitive_constexpr_evaluation_value restricts warning-dependent
   10987              :      constexpr evaluation to avoid unnecessary template instantiation, and is
   10988              :      always done with mce_unknown.  But due to gaps in the restriction logic
   10989              :      we may still end up taking an evaluation path that in turn requires
   10990              :      manifestly constant evaluation, and such evaluation must not be
   10991              :      restricted since it likely has semantic consequences.
   10992              :      TODO: Remove/replace the mechanism in GCC 17.  */
   10993    499897131 :   auto uids = make_temp_override (uid_sensitive_constexpr_evaluation_value);
   10994    499897131 :   if (ctx.manifestly_const_eval == mce_true)
   10995    263332927 :     uid_sensitive_constexpr_evaluation_value = false;
   10996              : 
   10997    499897131 :   auto_vec<tree, 16> cleanups;
   10998    499897131 :   global_ctx.cleanups = &cleanups;
   10999              : 
   11000    499897131 :   if (manifestly_const_eval == mce_true)
   11001    263332927 :     instantiate_constexpr_fns (r);
   11002    499897131 :   tree jmp_target = NULL_TREE;
   11003    499897131 :   r = cxx_eval_constant_expression (&ctx, r, vc_prvalue,
   11004              :                                     &non_constant_p, &overflow_p,
   11005              :                                     &jmp_target);
   11006    499895170 :   if (throws (&jmp_target) && !non_constant_p)
   11007              :     {
   11008          737 :       if (!ctx.quiet)
   11009          217 :         diagnose_uncaught_exception (input_location, &ctx, jmp_target);
   11010          737 :       non_constant_p = true;
   11011          737 :       jmp_target = NULL_TREE;
   11012          737 :       r = t;
   11013              :     }
   11014    499893696 :   else if (!non_constant_p && jmp_target)
   11015              :     {
   11016           24 :       non_constant_p = true;
   11017           24 :       if (!ctx.quiet)
   11018              :         {
   11019            3 :           if (breaks (&jmp_target))
   11020            3 :             error ("%<break%> outside of a loop or %<switch%>");
   11021            0 :           else if (continues (&jmp_target))
   11022            0 :             error ("%<continue%> outside of a loop");
   11023            0 :           else if (returns (&jmp_target))
   11024            0 :             error ("%<return%> in a statement expression");
   11025              :           else
   11026            0 :             gcc_unreachable ();
   11027              :         }
   11028           24 :       r = t;
   11029              :     }
   11030              : 
   11031              :   /* If we got a non-simple TARGET_EXPR, the initializer was a sequence
   11032              :      of statements, and the result ought to be stored in ctx.ctor.  */
   11033    499894433 :   if (r == void_node && !constexpr_dtor && ctx.ctor)
   11034            0 :     r = ctx.ctor;
   11035              : 
   11036    499894433 :   unsigned int i;
   11037    499894433 :   tree cleanup;
   11038    499894433 :   jmp_target = NULL_TREE;
   11039              :   /* Evaluate the cleanups.  */
   11040    999869814 :   FOR_EACH_VEC_ELT_REVERSE (cleanups, i, cleanup)
   11041        80948 :     if (cleanup == NULL_TREE)
   11042              :       /* NULL_TREE cleanup is a marker that before it is
   11043              :          CLEANUP_EH_ONLY cleanup.  Skip the cleanup before it.  */
   11044           23 :       --i;
   11045              :     else
   11046        80925 :       cxx_eval_constant_expression (&ctx, cleanup, vc_discard,
   11047              :                                     &non_constant_p, &overflow_p,
   11048              :                                     &jmp_target);
   11049    499894433 :   if (throws (&jmp_target) && !non_constant_p)
   11050              :     {
   11051            0 :       if (!ctx.quiet)
   11052            0 :         diagnose_uncaught_exception (input_location, &ctx, jmp_target);
   11053            0 :       non_constant_p = true;
   11054            0 :       r = t;
   11055              :     }
   11056              : 
   11057              :   /* Mutable logic is a bit tricky: we want to allow initialization of
   11058              :      constexpr variables with mutable members, but we can't copy those
   11059              :      members to another constexpr variable.  */
   11060    499894433 :   if (!non_constant_p
   11061    380478008 :       && TREE_CODE (r) == CONSTRUCTOR
   11062    514929287 :       && CONSTRUCTOR_MUTABLE_POISON (r))
   11063              :     {
   11064           89 :       if (!allow_non_constant)
   11065            6 :         error ("%qE is not a constant expression because it refers to "
   11066              :                "mutable subobjects of %qT", t, type);
   11067           89 :       non_constant_p = true;
   11068              :     }
   11069              : 
   11070    380477919 :   if (!non_constant_p && cxx_dialect >= cxx20
   11071    880372352 :       && !global_ctx.heap_vars.is_empty ())
   11072              :     {
   11073       106526 :       tree heap_var = cp_walk_tree_without_duplicates (&r, find_heap_var_refs,
   11074              :                                                        NULL);
   11075       106526 :       unsigned int i;
   11076       106526 :       if (heap_var)
   11077              :         {
   11078       101120 :           if (!allow_non_constant && !non_constant_p)
   11079              :             {
   11080           12 :               if (DECL_LANG_SPECIFIC (heap_var))
   11081            2 :                 error ("%qE is not a constant expression because it refers to "
   11082              :                        "exception object allocated with "
   11083              :                        "%<__cxa_allocate_exception%>", t);
   11084              :               else
   11085           10 :                 error ("%qE is not a constant expression because it refers to "
   11086              :                        "a result of %<operator new%>", t);
   11087           12 :               inform (DECL_SOURCE_LOCATION (heap_var), "allocated here");
   11088              :             }
   11089       101120 :           r = t;
   11090       101120 :           non_constant_p = true;
   11091              :         }
   11092       249459 :       FOR_EACH_VEC_ELT (global_ctx.heap_vars, i, heap_var)
   11093              :         {
   11094       142933 :           if (DECL_NAME (heap_var) != heap_deleted_identifier)
   11095              :             {
   11096       101175 :               if (!allow_non_constant && !non_constant_p)
   11097              :                 {
   11098           16 :                   error ("%qE is not a constant expression because allocated "
   11099              :                          "storage has not been deallocated", t);
   11100           16 :                   inform (DECL_SOURCE_LOCATION (heap_var), "allocated here");
   11101              :                 }
   11102       101175 :               r = t;
   11103       101175 :               non_constant_p = true;
   11104              :             }
   11105              :         }
   11106              :     }
   11107              : 
   11108              :   /* Check that immediate invocation does not return an expression referencing
   11109              :      any immediate function decls.  */
   11110    499894433 :   if (!non_constant_p && cxx_dialect >= cxx20)
   11111    749402294 :     if (tree immediate_fndecl
   11112    374701147 :         = cp_walk_tree_without_duplicates (&r, find_immediate_fndecl,
   11113              :                                            NULL))
   11114              :     {
   11115         4949 :       if (!allow_non_constant && !non_constant_p)
   11116              :         {
   11117           73 :           if (is_consteval)
   11118           36 :             error_at (cp_expr_loc_or_input_loc (t),
   11119              :                       "immediate evaluation returns address of immediate "
   11120              :                       "function %qD", immediate_fndecl);
   11121              :           else
   11122           56 :             error_at (cp_expr_loc_or_input_loc (t),
   11123              :                       "constant evaluation returns address of immediate "
   11124              :                       "function %qD", immediate_fndecl);
   11125              :         }
   11126         4949 :       r = t;
   11127         4949 :       non_constant_p = true;
   11128              :     }
   11129              : 
   11130              :   /* Detect consteval-only smuggling: turning a consteval-only object
   11131              :      into one that is not.  For instance, in
   11132              :        struct B { };
   11133              :        struct D : B { info r; };
   11134              :        constexpr D d{^^::};
   11135              :        constexpr const B &b = d; // #1
   11136              :      #1 is wrong because D is a consteval-only type but B is not.  */
   11137    499894433 :   if (flag_reflection
   11138      5295033 :       && !non_constant_p
   11139      4265247 :       && object
   11140       479012 :       && POINTER_TYPE_P (TREE_TYPE (object))
   11141          859 :       && !consteval_only_p (object)
   11142    499895235 :       && check_out_of_consteval_use (r, /*complain=*/false))
   11143              :     {
   11144           15 :       if (!allow_non_constant)
   11145              :         {
   11146            5 :           if (TYPE_REF_P (TREE_TYPE (object)))
   11147            6 :             error_at (cp_expr_loc_or_input_loc (t),
   11148              :                       "reference into an object of consteval-only type is "
   11149              :                       "not a constant expression unless it also has "
   11150              :                       "consteval-only type");
   11151              :           else
   11152            2 :             error_at (cp_expr_loc_or_input_loc (t),
   11153              :                       "pointer into an object of consteval-only type is "
   11154              :                       "not a constant expression unless it also has "
   11155              :                       "consteval-only type");
   11156              :         }
   11157           15 :       r = t;
   11158           15 :       non_constant_p = true;
   11159              :     }
   11160              : 
   11161    499894433 :   if (!non_constant_p && !constexpr_dtor)
   11162    380371636 :     verify_constant (r, allow_non_constant, &non_constant_p, &overflow_p);
   11163              : 
   11164              :   /* After verify_constant because reduced_constant_expression_p can unset
   11165              :      CONSTRUCTOR_NO_CLEARING.  */
   11166    499894433 :   if (TREE_CODE (r) == CONSTRUCTOR && CONSTRUCTOR_NO_CLEARING (r))
   11167              :     {
   11168        59412 :       if (!allow_non_constant)
   11169           43 :         error ("%qE is not a constant expression because it refers to "
   11170              :                "an incompletely initialized variable", t);
   11171        59412 :       TREE_CONSTANT (r) = false;
   11172        59412 :       non_constant_p = true;
   11173              :     }
   11174              : 
   11175    499894433 :   if (non_constant_p)
   11176              :     /* If we saw something bad, go back to our argument.  The wrapping below is
   11177              :        only for the cases of TREE_CONSTANT argument or overflow.  */
   11178    121493160 :     r = t;
   11179              : 
   11180    499894433 :   if (!non_constant_p && overflow_p)
   11181          215 :     non_constant_p = true;
   11182              : 
   11183              :   /* Unshare the result.  */
   11184    499894433 :   bool should_unshare = true;
   11185    499894433 :   if (r == t || (TREE_CODE (t) == TARGET_EXPR
   11186      1369968 :                  && TARGET_EXPR_INITIAL (t) == r))
   11187              :     should_unshare = false;
   11188              : 
   11189    499894433 :   if (non_constant_p && !allow_non_constant)
   11190         2937 :     return error_mark_node;
   11191    499891496 :   else if (check_for_failed_contracts (&ctx))
   11192              :     {
   11193           16 :       if (manifestly_const_eval == mce_true)
   11194              :         /* If MCE, we gave a hard error and return error_mark_node.  */
   11195           14 :         return error_mark_node;
   11196              :       else
   11197              :         {
   11198              :           /* Otherwise treat it as non-constant so the violation is still
   11199              :              detectable at run-time.  */
   11200            2 :           gcc_checking_assert (allow_non_constant);
   11201              :           return t;
   11202              :         }
   11203              :     }
   11204    499891480 :   else if (non_constant_p && TREE_CONSTANT (r))
   11205       138569 :     r = mark_non_constant (r);
   11206    499752911 :   else if (non_constant_p)
   11207              :     return t;
   11208              : 
   11209    378539611 :   if (constexpr_dtor)
   11210              :     {
   11211          131 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (object) = true;
   11212          131 :       return r;
   11213              :     }
   11214              : 
   11215              :   /* Check we are not trying to return the wrong type.  */
   11216    378539480 :   if (!same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (r)))
   11217              :     {
   11218              :       /* If so, this is not a constant expression.  */
   11219          151 :       if (!allow_non_constant)
   11220            2 :         error ("%qE is not a constant expression because it initializes "
   11221            2 :                "a %qT rather than %qT", t, TREE_TYPE (t), type);
   11222          151 :       return t;
   11223              :     }
   11224              : 
   11225    378539329 :   if (should_unshare)
   11226    217178748 :     r = unshare_expr (r);
   11227              : 
   11228    378539329 :   if (TREE_CODE (r) == CONSTRUCTOR && CLASS_TYPE_P (TREE_TYPE (r)))
   11229              :     {
   11230     14227470 :       r = adjust_temp_type (type, r);
   11231     14227470 :       if (TREE_CODE (t) == TARGET_EXPR
   11232     14227470 :           && TARGET_EXPR_INITIAL (t) == r)
   11233              :         return t;
   11234     13331994 :       else if (TREE_CODE (t) == CONSTRUCTOR || TREE_CODE (t) == CALL_EXPR
   11235      2305763 :                || TREE_CODE (t) == AGGR_INIT_EXPR)
   11236              :         /* Don't add a TARGET_EXPR if our argument didn't have one.  */;
   11237       563731 :       else if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_CLEANUP (t))
   11238          497 :         r = get_target_expr (r);
   11239              :       else
   11240              :         {
   11241       563234 :           r = get_target_expr (r, tf_warning_or_error | tf_no_cleanup);
   11242       563234 :           TREE_CONSTANT (r) = true;
   11243              :         }
   11244              :     }
   11245              : 
   11246    377643853 :   if (TREE_CODE (t) == TARGET_EXPR
   11247       474492 :       && TREE_CODE (r) == TARGET_EXPR)
   11248              :     {
   11249              :       /* Preserve this flag for potential_constant_expression, and the others
   11250              :          for good measure.  */
   11251       474391 :       TARGET_EXPR_ELIDING_P (r) = TARGET_EXPR_ELIDING_P (t);
   11252       474391 :       TARGET_EXPR_IMPLICIT_P (r) = TARGET_EXPR_IMPLICIT_P (t);
   11253       474391 :       TARGET_EXPR_LIST_INIT_P (r) = TARGET_EXPR_LIST_INIT_P (t);
   11254       474391 :       TARGET_EXPR_DIRECT_INIT_P (r) = TARGET_EXPR_DIRECT_INIT_P (t);
   11255              :     }
   11256              : 
   11257              :   /* Remember the original location if that wouldn't need a wrapper.  */
   11258    377643853 :   if (location_t loc = EXPR_LOCATION (t))
   11259    177100451 :     protected_set_expr_location (r, loc);
   11260              : 
   11261    377643853 :   return r;
   11262    509069343 : }
   11263              : 
   11264              : /* If T represents a constant expression returns its reduced value.
   11265              :    Otherwise return error_mark_node.  */
   11266              : 
   11267              : tree
   11268    141104764 : cxx_constant_value (tree t, tree decl /* = NULL_TREE */,
   11269              :                     tsubst_flags_t complain /* = tf_error */)
   11270              : {
   11271    141104764 :   bool sfinae = !(complain & tf_error);
   11272    141104764 :   tree r = cxx_eval_outermost_constant_expr (t, sfinae, true, mce_true, false, decl);
   11273    141104764 :   if (sfinae && !TREE_CONSTANT (r))
   11274         1653 :     r = error_mark_node;
   11275    141104764 :   return r;
   11276              : }
   11277              : 
   11278              : /* Like cxx_constant_value, but used for evaluation of constexpr destructors
   11279              :    of constexpr variables.  The actual initializer of DECL is not modified.  */
   11280              : 
   11281              : void
   11282          161 : cxx_constant_dtor (tree t, tree decl)
   11283              : {
   11284          161 :   cxx_eval_outermost_constant_expr (t, false, true, mce_true, true, decl);
   11285          161 : }
   11286              : 
   11287              : /* Helper routine for fold_simple function.  Either return simplified
   11288              :    expression T, otherwise NULL_TREE.
   11289              :    In contrast to cp_fully_fold, and to maybe_constant_value, we try to fold
   11290              :    even if we are within template-declaration.  So be careful on call, as in
   11291              :    such case types can be undefined.  */
   11292              : 
   11293              : static tree
   11294    156622201 : fold_simple_1 (tree t)
   11295              : {
   11296    156622201 :   tree op1;
   11297    156622201 :   enum tree_code code = TREE_CODE (t);
   11298              : 
   11299    156622201 :   switch (code)
   11300              :     {
   11301              :     case INTEGER_CST:
   11302              :     case REAL_CST:
   11303              :     case VECTOR_CST:
   11304              :     case FIXED_CST:
   11305              :     case COMPLEX_CST:
   11306              :       return t;
   11307              : 
   11308      1377156 :     case SIZEOF_EXPR:
   11309      1377156 :       return fold_sizeof_expr (t);
   11310              : 
   11311     35869856 :     case ABS_EXPR:
   11312     35869856 :     case ABSU_EXPR:
   11313     35869856 :     case CONJ_EXPR:
   11314     35869856 :     case REALPART_EXPR:
   11315     35869856 :     case IMAGPART_EXPR:
   11316     35869856 :     case NEGATE_EXPR:
   11317     35869856 :     case BIT_NOT_EXPR:
   11318     35869856 :     case TRUTH_NOT_EXPR:
   11319     35869856 :     case VIEW_CONVERT_EXPR:
   11320     35869856 :     CASE_CONVERT:
   11321     35869856 :     case FLOAT_EXPR:
   11322     35869856 :     case FIX_TRUNC_EXPR:
   11323     35869856 :     case FIXED_CONVERT_EXPR:
   11324     35869856 :     case ADDR_SPACE_CONVERT_EXPR:
   11325              : 
   11326     35869856 :       op1 = TREE_OPERAND (t, 0);
   11327              : 
   11328     35869856 :       t = const_unop (code, TREE_TYPE (t), op1);
   11329     35869856 :       if (!t)
   11330              :         return NULL_TREE;
   11331              : 
   11332      3942414 :       if (CONVERT_EXPR_CODE_P (code)
   11333      3942414 :           && TREE_OVERFLOW_P (t) && !TREE_OVERFLOW_P (op1))
   11334            0 :         TREE_OVERFLOW (t) = false;
   11335              :       return t;
   11336              : 
   11337              :     default:
   11338              :       return NULL_TREE;
   11339              :     }
   11340              : }
   11341              : 
   11342              : /* If T is a simple constant expression, returns its simplified value.
   11343              :    Otherwise returns T.  In contrast to maybe_constant_value we
   11344              :    simplify only few operations on constant-expressions, and we don't
   11345              :    try to simplify constexpressions.  */
   11346              : 
   11347              : tree
   11348    157359201 : fold_simple (tree t)
   11349              : {
   11350    157359201 :   if (processing_template_decl)
   11351              :     return t;
   11352              : 
   11353    156622201 :   tree r = fold_simple_1 (t);
   11354    156622201 :   if (r)
   11355              :     return r;
   11356              : 
   11357              :   return t;
   11358              : }
   11359              : 
   11360              : /* Try folding the expression T to a simple constant.
   11361              :    Returns that constant, otherwise returns T.  */
   11362              : 
   11363              : tree
   11364      1549513 : fold_to_constant (tree t)
   11365              : {
   11366      1549513 :   if (processing_template_decl)
   11367              :     return t;
   11368              : 
   11369      1455925 :   tree r = fold (t);
   11370      1455925 :   if (CONSTANT_CLASS_P (r) && !TREE_OVERFLOW (r))
   11371              :     return r;
   11372              :   else
   11373              :     return t;
   11374              : }
   11375              : 
   11376              : /* If T is a constant expression, returns its reduced value.
   11377              :    Otherwise, if T does not have TREE_CONSTANT set, returns T.
   11378              :    Otherwise, returns a version of T without TREE_CONSTANT.
   11379              :    MANIFESTLY_CONST_EVAL is true if T is manifestly const-evaluated
   11380              :    as per P0595.  */
   11381              : 
   11382              : static GTY((deletable)) hash_map<tree, tree> *cv_cache;
   11383              : 
   11384              : tree
   11385    802416058 : maybe_constant_value (tree t, tree decl /* = NULL_TREE */,
   11386              :                       mce_value manifestly_const_eval /* = mce_unknown */)
   11387              : {
   11388    802416058 :   tree orig_t = t;
   11389    802416058 :   tree r;
   11390              : 
   11391    802416058 :   if (EXPR_P (t) && manifestly_const_eval == mce_unknown)
   11392              :     {
   11393              :       /* Look up each operand in the cv_cache first to see if we've already
   11394              :          reduced it, and reuse that result to avoid quadratic behavior if
   11395              :          we're called when building up a large expression.  */
   11396    232922079 :       int n = cp_tree_operand_length (t);
   11397    232922079 :       tree *ops = XALLOCAVEC (tree, n);
   11398    232922079 :       bool rebuild = false;
   11399    653553993 :       for (int i = 0; i < n; ++i)
   11400              :         {
   11401    420631914 :           ops[i] = TREE_OPERAND (t, i);
   11402   1261268875 :           if (tree *cached = hash_map_safe_get (cv_cache, ops[i]))
   11403     29032308 :             if (*cached != ops[i])
   11404              :               {
   11405      9028457 :                 ops[i] = *cached;
   11406      9028457 :                 rebuild = true;
   11407              :               }
   11408              :         }
   11409    232922079 :       if (rebuild)
   11410              :         {
   11411      7610107 :           t = copy_node (t);
   11412     24739093 :           for (int i = 0; i < n; ++i)
   11413     17128986 :             TREE_OPERAND (t, i) = ops[i];
   11414              :         }
   11415              :     }
   11416              : 
   11417    802416058 :   if (!is_nondependent_constant_expression (t))
   11418              :     {
   11419            0 :       if (TREE_OVERFLOW_P (t)
   11420    120801111 :           || (!processing_template_decl && TREE_CONSTANT (t)))
   11421         4490 :         t = mark_non_constant (t);
   11422    120801111 :       return t;
   11423              :     }
   11424    681614947 :   else if (CONSTANT_CLASS_P (t))
   11425              :     /* No caching or evaluation needed.  */
   11426              :     return t;
   11427              : 
   11428              :   /* Don't constant evaluate an unevaluated non-manifestly-constant operand,
   11429              :      but at least try folding it to a simple constant.  */
   11430    311992034 :   if (cp_unevaluated_operand && manifestly_const_eval != mce_true)
   11431       492056 :     return fold_to_constant (t);
   11432              : 
   11433    296550320 :   if (manifestly_const_eval != mce_unknown)
   11434              :     /* TODO: Extend the cache to be mce_value aware.  And if we have a
   11435              :        previously cached mce_unknown result that's TREE_CONSTANT, it means
   11436              :        the reduced value is independent of mce_value and so we should
   11437              :        be able to reuse it in the mce_true/false case.  */
   11438    161332208 :     return cxx_eval_outermost_constant_expr (t, true, true,
   11439    161329510 :                                              manifestly_const_eval, false, decl);
   11440              : 
   11441    150167770 :   if (cv_cache == NULL)
   11442       141242 :     cv_cache = hash_map<tree, tree>::create_ggc (101);
   11443    150167770 :   if (tree *cached = cv_cache->get (t))
   11444              :     {
   11445     12623380 :       r = *cached;
   11446     12623380 :       if (r != t)
   11447              :         {
   11448              :           /* Clear processing_template_decl for sake of break_out_target_exprs;
   11449              :              entries in the cv_cache are non-templated.  */
   11450      4318845 :           processing_template_decl_sentinel ptds;
   11451              : 
   11452      4318845 :           r = break_out_target_exprs (r, /*clear_loc*/true);
   11453      4318845 :           protected_set_expr_location (r, EXPR_LOCATION (t));
   11454      4318845 :         }
   11455     12623380 :       return r;
   11456              :     }
   11457              : 
   11458    137544390 :   uid_sensitive_constexpr_evaluation_checker c;
   11459    137544390 :   r = cxx_eval_outermost_constant_expr (t, true, true,
   11460              :                                         manifestly_const_eval, false, decl);
   11461    137544390 :   gcc_checking_assert (r == t
   11462              :                        || CONVERT_EXPR_P (t)
   11463              :                        || TREE_CODE (t) == VIEW_CONVERT_EXPR
   11464              :                        || (TREE_CONSTANT (t) && !TREE_CONSTANT (r))
   11465              :                        || !cp_tree_equal (r, t));
   11466    137544390 :   if (!c.evaluation_restricted_p ())
   11467    137317292 :     cv_cache->put (orig_t, r);
   11468              :   return r;
   11469              : }
   11470              : 
   11471              : /* Dispose of the whole CV_CACHE.  */
   11472              : 
   11473              : static void
   11474     38332523 : clear_cv_cache (void)
   11475              : {
   11476     38332523 :   if (cv_cache != NULL)
   11477     38085481 :     cv_cache->empty ();
   11478     38332523 : }
   11479              : 
   11480              : /* Dispose of the whole CV_CACHE and FOLD_CACHE.  */
   11481              : 
   11482              : void
   11483     38332523 : clear_cv_and_fold_caches ()
   11484              : {
   11485     38332523 :   clear_cv_cache ();
   11486     38332523 :   clear_fold_cache ();
   11487     38332523 : }
   11488              : 
   11489              : /* Internal function handling expressions in templates for
   11490              :    fold_non_dependent_expr and fold_non_dependent_init.
   11491              : 
   11492              :    If we're in a template, but T isn't value dependent, simplify
   11493              :    it.  We're supposed to treat:
   11494              : 
   11495              :      template <typename T> void f(T[1 + 1]);
   11496              :      template <typename T> void f(T[2]);
   11497              : 
   11498              :    as two declarations of the same function, for example.  */
   11499              : 
   11500              : static tree
   11501     29746429 : fold_non_dependent_expr_template (tree t, tsubst_flags_t complain,
   11502              :                                   bool manifestly_const_eval,
   11503              :                                   tree object)
   11504              : {
   11505     29746429 :   gcc_assert (processing_template_decl);
   11506              : 
   11507     29746429 :   if (is_nondependent_constant_expression (t))
   11508              :     {
   11509     16458351 :       processing_template_decl_sentinel s;
   11510     16458351 :       t = instantiate_non_dependent_expr_internal (t, complain);
   11511              : 
   11512     16458351 :       if (type_unknown_p (t) || BRACE_ENCLOSED_INITIALIZER_P (t))
   11513              :         {
   11514            0 :           if (TREE_OVERFLOW_P (t))
   11515              :             {
   11516            0 :               t = build_nop (TREE_TYPE (t), t);
   11517            0 :               TREE_CONSTANT (t) = false;
   11518              :             }
   11519            0 :           return t;
   11520              :         }
   11521     16458351 :       else if (CONSTANT_CLASS_P (t))
   11522              :         /* No evaluation needed.  */
   11523              :         return t;
   11524              : 
   11525              :       /* Don't constant evaluate an unevaluated non-manifestly-constant operand,
   11526              :          but at least try folding it to a simple constant.  */
   11527      4352981 :       if (cp_unevaluated_operand && !manifestly_const_eval)
   11528           89 :         return fold_to_constant (t);
   11529              : 
   11530      4352892 :       tree r = cxx_eval_outermost_constant_expr (t, true, true,
   11531              :                                                  mce_value (manifestly_const_eval),
   11532              :                                                  false, object);
   11533              :       /* cp_tree_equal looks through NOPs, so allow them.  */
   11534      4352892 :       gcc_checking_assert (r == t
   11535              :                            || CONVERT_EXPR_P (t)
   11536              :                            || TREE_CODE (t) == VIEW_CONVERT_EXPR
   11537              :                            || (TREE_CONSTANT (t) && !TREE_CONSTANT (r))
   11538              :                            || !cp_tree_equal (r, t));
   11539      4352892 :       return r;
   11540     16458351 :     }
   11541     13288078 :   else if (TREE_OVERFLOW_P (t))
   11542              :     {
   11543            0 :       t = build_nop (TREE_TYPE (t), t);
   11544            0 :       TREE_CONSTANT (t) = false;
   11545              :     }
   11546              : 
   11547              :   return t;
   11548              : }
   11549              : 
   11550              : /* Like maybe_constant_value but first fully instantiate the argument.
   11551              : 
   11552              :    Note: this is equivalent to instantiate_non_dependent_expr (t, complain)
   11553              :    followed by maybe_constant_value but is more efficient,
   11554              :    because it calls instantiation_dependent_expression_p and
   11555              :    potential_constant_expression at most once.
   11556              :    The manifestly_const_eval argument is passed to maybe_constant_value.
   11557              : 
   11558              :    Callers should generally pass their active complain, or if they are in a
   11559              :    non-template, diagnosing context, they can use the default of
   11560              :    tf_warning_or_error.  Callers that might be within a template context, don't
   11561              :    have a complain parameter, and aren't going to remember the result for long
   11562              :    (e.g. null_ptr_cst_p), can pass tf_none and deal with error_mark_node
   11563              :    appropriately.  */
   11564              : 
   11565              : tree
   11566    247451907 : fold_non_dependent_expr (tree t,
   11567              :                          tsubst_flags_t complain /* = tf_warning_or_error */,
   11568              :                          bool manifestly_const_eval /* = false */,
   11569              :                          tree object /* = NULL_TREE */)
   11570              : {
   11571    247451907 :   if (t == NULL_TREE)
   11572              :     return NULL_TREE;
   11573              : 
   11574    246400572 :   if (processing_template_decl)
   11575     28707166 :     return fold_non_dependent_expr_template (t, complain,
   11576     28707166 :                                              manifestly_const_eval, object);
   11577              : 
   11578    217693406 :   return maybe_constant_value (t, object, mce_value (manifestly_const_eval));
   11579              : }
   11580              : 
   11581              : /* Like fold_non_dependent_expr, but if EXPR couldn't be folded to a constant,
   11582              :    return the original expression.  */
   11583              : 
   11584              : tree
   11585      2239719 : maybe_fold_non_dependent_expr (tree expr,
   11586              :                                tsubst_flags_t complain/*=tf_warning_or_error*/)
   11587              : {
   11588      2239719 :   tree t = fold_non_dependent_expr (expr, complain);
   11589      2239719 :   if (t && TREE_CONSTANT (t))
   11590      1056215 :     return t;
   11591              : 
   11592              :   return expr;
   11593              : }
   11594              : 
   11595              : /* Like maybe_constant_init but first fully instantiate the argument.  */
   11596              : 
   11597              : tree
   11598     59190583 : fold_non_dependent_init (tree t,
   11599              :                          tsubst_flags_t complain /*=tf_warning_or_error*/,
   11600              :                          bool manifestly_const_eval /*=false*/,
   11601              :                          tree object /* = NULL_TREE */)
   11602              : {
   11603     59190583 :   if (t == NULL_TREE)
   11604              :     return NULL_TREE;
   11605              : 
   11606     59190583 :   if (processing_template_decl)
   11607              :     {
   11608      1039263 :       t = fold_non_dependent_expr_template (t, complain,
   11609              :                                             manifestly_const_eval, object);
   11610              :       /* maybe_constant_init does this stripping, so do it here too.  */
   11611      1039263 :       if (TREE_CODE (t) == TARGET_EXPR)
   11612              :         {
   11613          934 :           tree init = TARGET_EXPR_INITIAL (t);
   11614          934 :           if (TREE_CODE (init) == CONSTRUCTOR)
   11615      1039263 :             t = init;
   11616              :         }
   11617      1039263 :       return t;
   11618              :     }
   11619              : 
   11620     58151320 :   return maybe_constant_init (t, object, manifestly_const_eval);
   11621              : }
   11622              : 
   11623              : /* Like maybe_constant_value, but returns a CONSTRUCTOR directly, rather
   11624              :    than wrapped in a TARGET_EXPR.
   11625              :    ALLOW_NON_CONSTANT is false if T is required to be a constant expression.
   11626              :    MANIFESTLY_CONST_EVAL is true if T is manifestly const-evaluated as
   11627              :    per P0595 even when ALLOW_NON_CONSTANT is true.  */
   11628              : 
   11629              : static tree
   11630    113098852 : maybe_constant_init_1 (tree t, tree decl, bool allow_non_constant,
   11631              :                        mce_value manifestly_const_eval)
   11632              : {
   11633    113098852 :   if (!t)
   11634              :     return t;
   11635    113098852 :   if (TREE_CODE (t) == EXPR_STMT)
   11636        24510 :     t = TREE_OPERAND (t, 0);
   11637    113098852 :   if (TREE_CODE (t) == CONVERT_EXPR
   11638    113098852 :       && VOID_TYPE_P (TREE_TYPE (t)))
   11639        26439 :     t = TREE_OPERAND (t, 0);
   11640              :   /* If the types don't match, the INIT_EXPR is initializing a subobject of
   11641              :      DECL and losing that information would cause mischief later.  */
   11642    113098852 :   if (TREE_CODE (t) == INIT_EXPR
   11643    113098852 :       && (!decl
   11644         1945 :           || same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (decl),
   11645         1945 :                                                         TREE_TYPE (t))))
   11646        25758 :     t = TREE_OPERAND (t, 1);
   11647    113098852 :   if (TREE_CODE (t) == TARGET_EXPR)
   11648       518052 :     t = TARGET_EXPR_INITIAL (t);
   11649    113098852 :   if (!is_nondependent_static_init_expression (t))
   11650              :     /* Don't try to evaluate it.  */;
   11651    104978680 :   else if (CONSTANT_CLASS_P (t) && TREE_CODE (t) != PTRMEM_CST)
   11652              :     /* No evaluation needed.  PTRMEM_CST needs the immediate fn check.  */;
   11653              :   else
   11654              :     {
   11655              :       /* [basic.start.static] allows constant-initialization of variables with
   11656              :          static or thread storage duration even if it isn't required, but we
   11657              :          shouldn't bend the rules the same way for automatic variables.
   11658              : 
   11659              :          But still enforce the requirements of constexpr/constinit.
   11660              :          [dcl.constinit] "If a variable declared with the constinit specifier
   11661              :          has dynamic initialization, the program is ill-formed, even if the
   11662              :          implementation would perform that initialization as a static
   11663              :          initialization."  */
   11664     18825081 :       bool is_static = (decl && DECL_P (decl)
   11665     61188493 :                         && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)));
   11666      3260396 :       bool strict = (!is_static
   11667              :                      || (decl && DECL_P (decl)
   11668      3260396 :                          && (DECL_DECLARED_CONSTEXPR_P (decl)
   11669       946052 :                              || DECL_DECLARED_CONSTINIT_P (decl))));
   11670              :       if (is_static)
   11671              :         manifestly_const_eval = mce_true;
   11672              : 
   11673     43063408 :       if (cp_unevaluated_operand && manifestly_const_eval != mce_true)
   11674        51417 :         return fold_to_constant (t);
   11675              : 
   11676     43011991 :       t = cxx_eval_outermost_constant_expr (t, allow_non_constant, strict,
   11677              :                                             manifestly_const_eval,
   11678              :                                             false, decl);
   11679              :     }
   11680    113047435 :   if (TREE_CODE (t) == TARGET_EXPR)
   11681              :     {
   11682        88870 :       tree init = TARGET_EXPR_INITIAL (t);
   11683        88870 :       if (TREE_CODE (init) == CONSTRUCTOR)
   11684    113098852 :         t = init;
   11685              :     }
   11686              :   return t;
   11687              : }
   11688              : 
   11689              : /* Wrapper for maybe_constant_init_1 which permits non constants.  */
   11690              : 
   11691              : tree
   11692     93409551 : maybe_constant_init (tree t, tree decl, bool manifestly_const_eval)
   11693              : {
   11694     93409551 :   return maybe_constant_init_1 (t, decl, true, mce_value (manifestly_const_eval));
   11695              : }
   11696              : 
   11697              : tree
   11698     19687745 : maybe_constant_init (tree t, tree decl, mce_value manifestly_const_eval)
   11699              : {
   11700     19687745 :   return maybe_constant_init_1 (t, decl, true, manifestly_const_eval);
   11701              : }
   11702              : 
   11703              : /* Wrapper for maybe_constant_init_1 which does not permit non constants.  */
   11704              : 
   11705              : tree
   11706         1556 : cxx_constant_init (tree t, tree decl)
   11707              : {
   11708         1556 :   return maybe_constant_init_1 (t, decl, false, mce_true);
   11709              : }
   11710              : 
   11711              : /* Return true if CALL_EXPR T might throw during constant evaluation.  */
   11712              : 
   11713              : static bool
   11714    195625824 : callee_might_throw (tree t)
   11715              : {
   11716    195625824 :   if (cxx_dialect < cxx26 || !flag_exceptions)
   11717              :     return false;
   11718     19461003 :   tree callee = cp_get_callee (t);
   11719     19461003 :   if (callee == NULL_TREE)
   11720              :     return false;
   11721     19425503 :   tree callee_fn = cp_get_fndecl_from_callee (callee, false);
   11722     19425503 :   return (!flag_enforce_eh_specs
   11723     19425503 :           || type_dependent_expression_p (callee)
   11724     17518092 :           || !POINTER_TYPE_P (TREE_TYPE (callee))
   11725     35630994 :           || (!type_noexcept_p (TREE_TYPE (TREE_TYPE (callee)))
   11726      6925112 :               && (callee_fn == NULL_TREE || !TREE_NOTHROW (callee_fn))));
   11727              : }
   11728              : 
   11729              : #if 0
   11730              : /* FIXME see ADDR_EXPR section in potential_constant_expression_1.  */
   11731              : /* Return true if the object referred to by REF has automatic or thread
   11732              :    local storage.  */
   11733              : 
   11734              : enum { ck_ok, ck_bad, ck_unknown };
   11735              : static int
   11736              : check_automatic_or_tls (tree ref)
   11737              : {
   11738              :   machine_mode mode;
   11739              :   poly_int64 bitsize, bitpos;
   11740              :   tree offset;
   11741              :   int volatilep = 0, unsignedp = 0;
   11742              :   tree decl = get_inner_reference (ref, &bitsize, &bitpos, &offset,
   11743              :                                    &mode, &unsignedp, &volatilep, false);
   11744              :   duration_kind dk;
   11745              : 
   11746              :   /* If there isn't a decl in the middle, we don't know the linkage here,
   11747              :      and this isn't a constant expression anyway.  */
   11748              :   if (!DECL_P (decl))
   11749              :     return ck_unknown;
   11750              :   dk = decl_storage_duration (decl);
   11751              :   return (dk == dk_auto || dk == dk_thread) ? ck_bad : ck_ok;
   11752              : }
   11753              : #endif
   11754              : 
   11755              : /* Data structure for passing data from potential_constant_expression_1
   11756              :    to check_for_return_continue via cp_walk_tree.  */
   11757              : struct check_for_return_continue_data {
   11758              :   hash_set<tree> *pset;
   11759              :   tree continue_stmt;
   11760              :   tree break_stmt;
   11761              :   bool could_throw;
   11762              : };
   11763              : 
   11764              : /* Helper function for potential_constant_expression_1 SWITCH_STMT handling,
   11765              :    called through cp_walk_tree.  Return the first RETURN_EXPR found, or note
   11766              :    the first CONTINUE_STMT and/or BREAK_STMT if RETURN_EXPR is not found.
   11767              :    For C++26 also note presence of possibly throwing calls.  */
   11768              : static tree
   11769     46026875 : check_for_return_continue (tree *tp, int *walk_subtrees, void *data)
   11770              : {
   11771     46026875 :   tree t = *tp, s, b;
   11772     46026875 :   check_for_return_continue_data *d = (check_for_return_continue_data *) data;
   11773     46026875 :   switch (TREE_CODE (t))
   11774              :     {
   11775              :     case RETURN_EXPR:
   11776              :       return t;
   11777              : 
   11778           28 :     case CONTINUE_STMT:
   11779           28 :       if (d->continue_stmt == NULL_TREE)
   11780           28 :         d->continue_stmt = t;
   11781              :       break;
   11782              : 
   11783         3018 :     case BREAK_STMT:
   11784         3018 :       if (d->break_stmt == NULL_TREE)
   11785         1303 :         d->break_stmt = t;
   11786              :       break;
   11787              : 
   11788              : #define RECUR(x) \
   11789              :       if (tree r = cp_walk_tree (&x, check_for_return_continue, data,       \
   11790              :                                  d->pset))                           \
   11791              :         return r
   11792              : 
   11793              :       /* For loops, walk subtrees manually, so that continue stmts found
   11794              :          inside of the bodies of the loops are ignored.  */
   11795        39540 :     case DO_STMT:
   11796        39540 :       *walk_subtrees = 0;
   11797        39540 :       RECUR (DO_COND (t));
   11798        39540 :       s = d->continue_stmt;
   11799        39540 :       b = d->break_stmt;
   11800        39540 :       RECUR (DO_BODY (t));
   11801        39540 :       d->continue_stmt = s;
   11802        39540 :       d->break_stmt = b;
   11803        39540 :       break;
   11804              : 
   11805          117 :     case WHILE_STMT:
   11806          117 :       *walk_subtrees = 0;
   11807          117 :       RECUR (WHILE_COND_PREP (t));
   11808          117 :       RECUR (WHILE_COND (t));
   11809          117 :       s = d->continue_stmt;
   11810          117 :       b = d->break_stmt;
   11811          117 :       RECUR (WHILE_BODY (t));
   11812          105 :       d->continue_stmt = s;
   11813          105 :       d->break_stmt = b;
   11814          105 :       break;
   11815              : 
   11816          277 :     case FOR_STMT:
   11817          277 :       *walk_subtrees = 0;
   11818          277 :       RECUR (FOR_INIT_STMT (t));
   11819          277 :       RECUR (FOR_COND_PREP (t));
   11820          277 :       RECUR (FOR_COND (t));
   11821          277 :       RECUR (FOR_EXPR (t));
   11822          277 :       s = d->continue_stmt;
   11823          277 :       b = d->break_stmt;
   11824          277 :       RECUR (FOR_BODY (t));
   11825          247 :       d->continue_stmt = s;
   11826          247 :       d->break_stmt = b;
   11827          247 :       break;
   11828              : 
   11829            0 :     case RANGE_FOR_STMT:
   11830            0 :       *walk_subtrees = 0;
   11831            0 :       RECUR (RANGE_FOR_EXPR (t));
   11832            0 :       s = d->continue_stmt;
   11833            0 :       b = d->break_stmt;
   11834            0 :       RECUR (RANGE_FOR_BODY (t));
   11835            0 :       d->continue_stmt = s;
   11836            0 :       d->break_stmt = b;
   11837            0 :       break;
   11838              : 
   11839          207 :     case SWITCH_STMT:
   11840          207 :       *walk_subtrees = 0;
   11841          207 :       RECUR (SWITCH_STMT_COND (t));
   11842          207 :       b = d->break_stmt;
   11843          207 :       RECUR (SWITCH_STMT_BODY (t));
   11844          187 :       d->break_stmt = b;
   11845          187 :       break;
   11846              : #undef RECUR
   11847              : 
   11848              :     case STATEMENT_LIST:
   11849              :     case CONSTRUCTOR:
   11850              :       break;
   11851              : 
   11852      2419373 :     case AGGR_INIT_EXPR:
   11853      2419373 :     case CALL_EXPR:
   11854              :       /* In C++26 a function could throw.  */
   11855      2419373 :       if (callee_might_throw (t))
   11856        66697 :         d->could_throw = true;
   11857              :       break;
   11858              : 
   11859     42272486 :     default:
   11860     42272486 :       if (!EXPR_P (t))
   11861     13078122 :         *walk_subtrees = 0;
   11862              :       break;
   11863              :     }
   11864              : 
   11865              :   return NULL_TREE;
   11866              : }
   11867              : 
   11868              : /* Return true if T denotes a potentially constant expression.  Issue
   11869              :    diagnostic as appropriate under control of FLAGS.  If WANT_RVAL is true,
   11870              :    an lvalue-rvalue conversion is implied.  If NOW is true, we want to
   11871              :    consider the expression in the current context, independent of constexpr
   11872              :    substitution.  If FUNDEF_P is true, we're checking a constexpr function body
   11873              :    and hard errors should not be reported by constexpr_error.
   11874              : 
   11875              :    C++0x [expr.const] used to say
   11876              : 
   11877              :    6 An expression is a potential constant expression if it is
   11878              :      a constant expression where all occurrences of function
   11879              :      parameters are replaced by arbitrary constant expressions
   11880              :      of the appropriate type.
   11881              : 
   11882              :    2  A conditional expression is a constant expression unless it
   11883              :       involves one of the following as a potentially evaluated
   11884              :       subexpression (3.2), but subexpressions of logical AND (5.14),
   11885              :       logical OR (5.15), and conditional (5.16) operations that are
   11886              :       not evaluated are not considered.   */
   11887              : 
   11888              : static bool
   11889   4364937682 : potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
   11890              :                                  bool fundef_p, tsubst_flags_t flags,
   11891              :                                  tree *jump_target)
   11892              : {
   11893              : #define RECUR(T,RV) \
   11894              :   potential_constant_expression_1 ((T), (RV), strict, now, fundef_p, flags, \
   11895              :                                    jump_target)
   11896              : 
   11897   4364937682 :   enum { any = false, rval = true };
   11898   4364937682 :   int i;
   11899   4364937682 :   tree tmp;
   11900              : 
   11901   4364937682 :   if (t == error_mark_node)
   11902              :     return false;
   11903   4364926481 :   if (t == NULL_TREE)
   11904              :     return true;
   11905   4357733901 :   location_t loc = cp_expr_loc_or_input_loc (t);
   11906   4357733901 :   iloc_sentinel ils = loc;
   11907              : 
   11908   4357733901 :   if (*jump_target)
   11909              :     /* If we are jumping, ignore everything.  This is simpler than the
   11910              :        cxx_eval_constant_expression handling because we only need to be
   11911              :        conservatively correct, and we don't necessarily have a constant value
   11912              :        available, so we don't bother with switch tracking.  */
   11913              :     return true;
   11914              : 
   11915      1614764 :   if (TREE_THIS_VOLATILE (t) && want_rval
   11916      1048084 :       && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (t))
   11917   4350177591 :       && !NULLPTR_TYPE_P (TREE_TYPE (t)))
   11918              :     {
   11919        77853 :       if (TREE_CLOBBER_P (t))
   11920              :         {
   11921              :           /* We should have caught any clobbers in INIT/MODIFY_EXPR.  */
   11922            0 :           gcc_checking_assert (false);
   11923              :           return true;
   11924              :         }
   11925              : 
   11926        77853 :       if (flags & tf_error)
   11927           22 :         constexpr_error (loc, fundef_p, "lvalue-to-rvalue conversion of "
   11928              :                          "a volatile lvalue %qE with type %qT", t,
   11929           22 :                          TREE_TYPE (t));
   11930        77853 :       return false;
   11931              :     }
   11932   4350021859 :   if (CONSTANT_CLASS_P (t))
   11933              :     return true;
   11934   3121199469 :   if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPED)
   11935   3121199469 :       && TREE_TYPE (t) == error_mark_node)
   11936              :     return false;
   11937              : 
   11938   3121199432 :   switch (TREE_CODE (t))
   11939              :     {
   11940              :     case FUNCTION_DECL:
   11941              :     case BASELINK:
   11942              :     case TEMPLATE_DECL:
   11943              :     case OVERLOAD:
   11944              :     case TEMPLATE_ID_EXPR:
   11945              :     case LABEL_DECL:
   11946              :     case CASE_LABEL_EXPR:
   11947              :     case PREDICT_EXPR:
   11948              :     case CONST_DECL:
   11949              :     case SIZEOF_EXPR:
   11950              :     case ALIGNOF_EXPR:
   11951              :     case OFFSETOF_EXPR:
   11952              :     case NOEXCEPT_EXPR:
   11953              :     case TEMPLATE_PARM_INDEX:
   11954              :     case TRAIT_EXPR:
   11955              :     case IDENTIFIER_NODE:
   11956              :     case USERDEF_LITERAL:
   11957              :       /* We can see a FIELD_DECL in a pointer-to-member expression.  */
   11958              :     case FIELD_DECL:
   11959              :     case RESULT_DECL:
   11960              :     case USING_DECL:
   11961              :     case USING_STMT:
   11962              :     case PLACEHOLDER_EXPR:
   11963              :     case REQUIRES_EXPR:
   11964              :     case STATIC_ASSERT:
   11965              :     case DEBUG_BEGIN_STMT:
   11966              :     case REFLECT_EXPR:
   11967              :       return true;
   11968              : 
   11969     23010940 :     case RETURN_EXPR:
   11970     23010940 :       if (!RECUR (TREE_OPERAND (t, 0), any))
   11971              :         return false;
   11972              :       /* FALLTHROUGH */
   11973              : 
   11974     22868728 :     case BREAK_STMT:
   11975     22868728 :     case CONTINUE_STMT:
   11976     22868728 :       *jump_target = t;
   11977     22868728 :       return true;
   11978              : 
   11979    324602785 :     case PARM_DECL:
   11980    324602785 :       if (now && want_rval)
   11981              :         {
   11982     83275590 :           tree type = TREE_TYPE (t);
   11983     83275590 :           if (dependent_type_p (type)
   11984     55630305 :               || !COMPLETE_TYPE_P (processing_template_decl
   11985              :                                    ? type : complete_type (type))
   11986    138905895 :               || is_really_empty_class (type, /*ignore_vptr*/false))
   11987              :             /* An empty class has no data to read.  */
   11988     27645756 :             return true;
   11989     55629834 :           if (flags & tf_error)
   11990           17 :             constexpr_error (input_location, fundef_p,
   11991              :                              "%qE is not a constant expression", t);
   11992     55629834 :           return false;
   11993              :         }
   11994              :       return true;
   11995              : 
   11996    236362854 :     case AGGR_INIT_EXPR:
   11997    236362854 :     case CALL_EXPR:
   11998              :       /* -- an invocation of a function other than a constexpr function
   11999              :             or a constexpr constructor.  */
   12000    236362854 :       {
   12001    236362854 :         tree fun = get_function_named_in_call (t);
   12002    236362854 :         const int nargs = call_expr_nargs (t);
   12003    236362854 :         i = 0;
   12004              : 
   12005    236362854 :         if (fun == NULL_TREE)
   12006              :           {
   12007              :             /* Reset to allow the function to continue past the end
   12008              :                of the block below.  Otherwise return early.  */
   12009       399935 :             bool bail = true;
   12010              : 
   12011       399935 :             if (TREE_CODE (t) == CALL_EXPR
   12012       399935 :                 && CALL_EXPR_FN (t) == NULL_TREE)
   12013       399935 :               switch (CALL_EXPR_IFN (t))
   12014              :                 {
   12015              :                 /* These should be ignored, they are optimized away from
   12016              :                    constexpr functions.  */
   12017              :                 case IFN_UBSAN_NULL:
   12018              :                 case IFN_UBSAN_BOUNDS:
   12019              :                 case IFN_UBSAN_VPTR:
   12020              :                 case IFN_FALLTHROUGH:
   12021              :                 case IFN_ASSUME:
   12022              :                   return true;
   12023              : 
   12024              :                 case IFN_ADD_OVERFLOW:
   12025              :                 case IFN_SUB_OVERFLOW:
   12026              :                 case IFN_MUL_OVERFLOW:
   12027              :                 case IFN_LAUNDER:
   12028              :                 case IFN_VEC_CONVERT:
   12029              :                   bail = false;
   12030              :                   break;
   12031              : 
   12032              :                 default:
   12033              :                   break;
   12034              :                 }
   12035              : 
   12036              :             if (bail)
   12037              :               {
   12038              :                 /* fold_call_expr can't do anything with IFN calls.  */
   12039           66 :                 if (flags & tf_error)
   12040            0 :                   constexpr_error (loc, fundef_p,
   12041              :                                    "call to internal function %qE", t);
   12042           66 :                 return false;
   12043              :               }
   12044              :           }
   12045              : 
   12046    235962919 :         if (fun && is_overloaded_fn (fun))
   12047              :           {
   12048    218475882 :             if (!RECUR (fun, true))
   12049              :               return false;
   12050    218050237 :             fun = get_fns (fun);
   12051              : 
   12052    218050237 :             if (TREE_CODE (fun) == FUNCTION_DECL)
   12053              :               {
   12054    201061271 :                 if (builtin_valid_in_constant_expr_p (fun))
   12055              :                   return true;
   12056    199373997 :                 if (!maybe_constexpr_fn (fun)
   12057              :                     /* Allow any built-in function; if the expansion
   12058              :                        isn't constant, we'll deal with that then.  */
   12059     39359962 :                     && !fndecl_built_in_p (fun)
   12060              :                     /* In C++20, replaceable global allocation functions
   12061              :                        are constant expressions.  */
   12062     27280114 :                     && (!cxx_replaceable_global_alloc_fn (fun)
   12063       698218 :                         || TREE_CODE (t) != CALL_EXPR
   12064       698218 :                         || (!CALL_FROM_NEW_OR_DELETE_P (t)
   12065       264995 :                             && (current_function_decl == NULL_TREE
   12066       264995 :                                 || !is_std_allocator_allocate
   12067       264995 :                                                 (current_function_decl))))
   12068              :                     /* Allow placement new in std::construct_at.  */
   12069     26586033 :                     && (!cxx_placement_new_fn (fun)
   12070       387273 :                         || TREE_CODE (t) != CALL_EXPR
   12071       387273 :                         || current_function_decl == NULL_TREE
   12072       387261 :                         || !is_std_construct_at (current_function_decl))
   12073     26317623 :                     && !cxx_dynamic_cast_fn_p (fun)
   12074    225688817 :                     && !cxx_cxa_builtin_fn_p (fun))
   12075              :                   {
   12076              :                     /* In C++26 evaluation of the function arguments might
   12077              :                        throw and in that case it is irrelevant whether
   12078              :                        fun is constexpr or not.  */
   12079     26283991 :                     if (cxx_dialect >= cxx26)
   12080      4888093 :                       for (; i < nargs; ++i)
   12081              :                         {
   12082      2907667 :                           tree x = get_nth_callarg (t, i);
   12083      2907667 :                           bool rv = processing_template_decl ? any : rval;
   12084      2907667 :                           bool sub_now = false;
   12085      2907667 :                           if (!potential_constant_expression_1 (x, rv, strict,
   12086              :                                                                 sub_now,
   12087              :                                                                 fundef_p,
   12088              :                                                                 flags,
   12089              :                                                                 jump_target))
   12090              :                             return false;
   12091      2667888 :                           if (throws (jump_target))
   12092              :                             return true;
   12093              :                         }
   12094     26003833 :                     if ((flags & tf_error)
   12095     26003833 :                         && constexpr_error (loc, fundef_p,
   12096              :                                             "call to non-%<constexpr%> "
   12097              :                                             "function %qD", fun))
   12098          256 :                       explain_invalid_constexpr_fn (fun);
   12099     26003833 :                     return false;
   12100              :                   }
   12101              :               }
   12102              : 
   12103    190078972 :             fun = OVL_FIRST (fun);
   12104              :             /* Skip initial arguments to base constructors.  */
   12105    190078972 :             if (DECL_BASE_CONSTRUCTOR_P (fun))
   12106      3888900 :               i = num_artificial_parms_for (fun);
   12107              :           }
   12108     17487037 :         else if (fun)
   12109              :           {
   12110     17487037 :             if (TREE_TYPE (fun)
   12111     17487037 :                 && FUNCTION_POINTER_TYPE_P (TREE_TYPE (fun)))
   12112              :               want_rval = rval;
   12113              :             else
   12114              :               want_rval = any;
   12115     17487037 :             if (RECUR (fun, want_rval))
   12116              :               /* Might end up being a constant function pointer.  But it
   12117              :                  could also be a function object with constexpr op(), so
   12118              :                  we pass 'any' so that the underlying VAR_DECL is deemed
   12119              :                  as potentially-constant even though it wasn't declared
   12120              :                  constexpr.  */;
   12121              :             else
   12122              :               return false;
   12123              :           }
   12124    452832426 :         for (; i < nargs; ++i)
   12125              :           {
   12126    259590332 :             tree x = get_nth_callarg (t, i);
   12127              :             /* In a template, reference arguments haven't been converted to
   12128              :                REFERENCE_TYPE and we might not even know if the parameter
   12129              :                is a reference, so accept lvalue constants too.  */
   12130    259590332 :             bool rv = processing_template_decl ? any : rval;
   12131              :             /* Don't require an immediately constant value, as constexpr
   12132              :                substitution might not use the value of the argument.  */
   12133    259590332 :             bool sub_now = false;
   12134    259590332 :             if (!potential_constant_expression_1 (x, rv, strict,
   12135              :                                                   sub_now, fundef_p, flags,
   12136              :                                                   jump_target))
   12137              :               return false;
   12138   2847486600 :             if (throws (jump_target))
   12139              :               return true;
   12140              :           }
   12141              :         /* In C++26 a function could throw.  */
   12142    193242094 :         if (*jump_target == NULL_TREE && callee_might_throw (t))
   12143      6156392 :           *jump_target = void_node;
   12144              :         return true;
   12145              :       }
   12146              : 
   12147    188751795 :     case NON_LVALUE_EXPR:
   12148              :       /* -- an lvalue-to-rvalue conversion (4.1) unless it is applied to
   12149              :             -- an lvalue of integral type that refers to a non-volatile
   12150              :                const variable or static data member initialized with
   12151              :                constant expressions, or
   12152              : 
   12153              :             -- an lvalue of literal type that refers to non-volatile
   12154              :                object defined with constexpr, or that refers to a
   12155              :                sub-object of such an object;  */
   12156    188751795 :       return RECUR (TREE_OPERAND (t, 0), rval);
   12157              : 
   12158        27565 :     case EXCESS_PRECISION_EXPR:
   12159        27565 :       return RECUR (TREE_OPERAND (t, 0), rval);
   12160              : 
   12161    285826110 :     case VAR_DECL:
   12162    285826110 :       if (DECL_HAS_VALUE_EXPR_P (t))
   12163              :         {
   12164      3867900 :           if (now && is_normal_capture_proxy (t))
   12165              :             {
   12166              :               /* -- in a lambda-expression, a reference to this or to a
   12167              :                  variable with automatic storage duration defined outside that
   12168              :                  lambda-expression, where the reference would be an
   12169              :                  odr-use.  */
   12170              : 
   12171       357481 :               if (want_rval)
   12172              :                 /* Since we're doing an lvalue-rvalue conversion, this might
   12173              :                    not be an odr-use, so evaluate the variable directly. */
   12174       356378 :                 return RECUR (DECL_CAPTURED_VARIABLE (t), rval);
   12175              : 
   12176         1103 :               if (flags & tf_error)
   12177              :                 {
   12178            3 :                   tree cap = DECL_CAPTURED_VARIABLE (t);
   12179            3 :                   auto_diagnostic_group d;
   12180            3 :                   if (constexpr_error (input_location, fundef_p,
   12181              :                                        "lambda capture of %qE is not a "
   12182              :                                        "constant expression", cap)
   12183            3 :                       && decl_constant_var_p (cap))
   12184            3 :                     inform (input_location, "because it is used as a glvalue");
   12185            3 :                 }
   12186         1103 :               return false;
   12187              :             }
   12188      3510419 :           tree ve = DECL_VALUE_EXPR (t);
   12189              :           /* Treat __PRETTY_FUNCTION__ inside a template function as
   12190              :              potentially-constant.  */
   12191      3510419 :           if (DECL_PRETTY_FUNCTION_P (t) && ve == error_mark_node)
   12192              :             return true;
   12193      3510414 :           if (DECL_DECOMPOSITION_P (t) && TREE_CODE (ve) == TREE_VEC)
   12194         2736 :             return RECUR (TREE_VEC_ELT (ve, 0), rval);
   12195      3507678 :           return RECUR (ve, rval);
   12196              :         }
   12197    281958210 :       if (want_rval
   12198    201450052 :           && (now || !var_in_maybe_constexpr_fn (t))
   12199    185069726 :           && !type_dependent_expression_p (t)
   12200    154400109 :           && !decl_maybe_constant_var_p (t)
   12201     49347811 :           && !is_local_temp (t)
   12202     48837955 :           && (strict
   12203      1203719 :               || !CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (t))
   12204       602966 :               || (DECL_INITIAL (t)
   12205       597498 :                   && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (t)))
   12206     48831843 :           && COMPLETE_TYPE_P (TREE_TYPE (t))
   12207    330789903 :           && !is_really_empty_class (TREE_TYPE (t), /*ignore_vptr*/false))
   12208              :         {
   12209     48827017 :           if (flags & tf_error)
   12210          163 :             non_const_var_error (loc, t, fundef_p);
   12211     48827017 :           return false;
   12212              :         }
   12213              :       return true;
   12214              : 
   12215    375115056 :     case NOP_EXPR:
   12216    375115056 :       if (REINTERPRET_CAST_P (t))
   12217              :         {
   12218       156058 :           if (flags & tf_error)
   12219           46 :             constexpr_error (loc, fundef_p, "%<reinterpret_cast%> is not a "
   12220              :                              "constant expression");
   12221       156058 :           return false;
   12222              :         }
   12223              :       /* FALLTHRU */
   12224    785528231 :     case CONVERT_EXPR:
   12225    785528231 :     case VIEW_CONVERT_EXPR:
   12226              :       /* -- a reinterpret_cast.  FIXME not implemented, and this rule
   12227              :          may change to something more specific to type-punning (DR 1312).  */
   12228    785528231 :       {
   12229    785528231 :         tree from = TREE_OPERAND (t, 0);
   12230    785528231 :         if (location_wrapper_p (t))
   12231    341418471 :           return (RECUR (from, want_rval));
   12232    444109760 :         if (INDIRECT_TYPE_P (TREE_TYPE (t)))
   12233              :           {
   12234    245642868 :             STRIP_ANY_LOCATION_WRAPPER (from);
   12235    245642868 :             if (TREE_CODE (from) == INTEGER_CST
   12236    245642868 :                 && !integer_zerop (from))
   12237              :               {
   12238         1536 :                 if (flags & tf_error)
   12239           25 :                   constexpr_error (loc, fundef_p,
   12240              :                                    "%<reinterpret_cast%> from integer to "
   12241              :                                    "pointer");
   12242         1536 :                 return false;
   12243              :               }
   12244              :           }
   12245    444108224 :         return (RECUR (from, TREE_CODE (t) != VIEW_CONVERT_EXPR));
   12246              :       }
   12247              : 
   12248        11990 :     case ADDRESSOF_EXPR:
   12249              :       /* This is like ADDR_EXPR, except it won't form pointer-to-member.  */
   12250        11990 :       t = TREE_OPERAND (t, 0);
   12251        11990 :       goto handle_addr_expr;
   12252              : 
   12253     80668871 :     case ADDR_EXPR:
   12254              :       /* -- a unary operator & that is applied to an lvalue that
   12255              :             designates an object with thread or automatic storage
   12256              :             duration;  */
   12257     80668871 :       t = TREE_OPERAND (t, 0);
   12258              : 
   12259     80668871 :       if (TREE_CODE (t) == OFFSET_REF && PTRMEM_OK_P (t))
   12260              :         /* A pointer-to-member constant.  */
   12261              :         return true;
   12262              : 
   12263     80680623 :     handle_addr_expr:
   12264              : #if 0
   12265              :       /* FIXME adjust when issue 1197 is fully resolved.  For now don't do
   12266              :          any checking here, as we might dereference the pointer later.  If
   12267              :          we remove this code, also remove check_automatic_or_tls.  */
   12268              :       i = check_automatic_or_tls (t);
   12269              :       if (i == ck_ok)
   12270              :         return true;
   12271              :       if (i == ck_bad)
   12272              :         {
   12273              :           if (flags & tf_error)
   12274              :             error ("address-of an object %qE with thread local or "
   12275              :                    "automatic storage is not a constant expression", t);
   12276              :           return false;
   12277              :         }
   12278              : #endif
   12279     80680623 :       return RECUR (t, any);
   12280              : 
   12281     91594698 :     case COMPONENT_REF:
   12282     91594698 :     case ARROW_EXPR:
   12283     91594698 :     case OFFSET_REF:
   12284              :       /* -- a class member access unless its postfix-expression is
   12285              :             of literal type or of pointer to literal type.  */
   12286              :       /* This test would be redundant, as it follows from the
   12287              :          postfix-expression being a potential constant expression.  */
   12288     91594698 :       if (type_unknown_p (t))
   12289              :         return true;
   12290     84102732 :       if (is_overloaded_fn (t))
   12291              :         /* In a template, a COMPONENT_REF of a function expresses ob.fn(),
   12292              :            which uses ob as an lvalue.  */
   12293     85667711 :         want_rval = false;
   12294     85667711 :       gcc_fallthrough ();
   12295              : 
   12296     85667711 :     case REALPART_EXPR:
   12297     85667711 :     case IMAGPART_EXPR:
   12298     85667711 :     case BIT_FIELD_REF:
   12299     85667711 :       return RECUR (TREE_OPERAND (t, 0), want_rval);
   12300              : 
   12301       254386 :     case EXPR_PACK_EXPANSION:
   12302       254386 :       return RECUR (PACK_EXPANSION_PATTERN (t), want_rval);
   12303              : 
   12304              :     case PACK_INDEX_EXPR:
   12305              :       return true;
   12306              : 
   12307     92814442 :     case INDIRECT_REF:
   12308     92814442 :       return RECUR (TREE_OPERAND (t, 0), rval);
   12309              : 
   12310     23639580 :     case STATEMENT_LIST:
   12311   4450480262 :       for (tree stmt : tsi_range (t))
   12312     69631519 :         if (!RECUR (stmt, any))
   12313    253445417 :           return false;
   12314              :       return true;
   12315              : 
   12316      4308247 :     case MODIFY_EXPR:
   12317      4308247 :       if (cxx_dialect < cxx14)
   12318         1973 :         goto fail;
   12319      4306274 :       if (!RECUR (TREE_OPERAND (t, 0), any))
   12320              :         return false;
   12321              :       /* Just ignore clobbers.  */
   12322      3879995 :       if (TREE_CLOBBER_P (TREE_OPERAND (t, 1)))
   12323              :         return true;
   12324      3433995 :       if (!RECUR (TREE_OPERAND (t, 1), rval))
   12325              :         return false;
   12326              :       return true;
   12327              : 
   12328       878089 :     case MODOP_EXPR:
   12329       878089 :       if (cxx_dialect < cxx14)
   12330           98 :         goto fail;
   12331       877991 :       if (!RECUR (TREE_OPERAND (t, 0), rval))
   12332              :         return false;
   12333       867992 :       if (!RECUR (TREE_OPERAND (t, 2), rval))
   12334              :         return false;
   12335              :       return true;
   12336              : 
   12337       515595 :     case DO_STMT:
   12338       515595 :       if (!RECUR (DO_COND (t), rval))
   12339              :         return false;
   12340       515595 :       if (!RECUR (DO_BODY (t), any))
   12341              :         return false;
   12342       515306 :       if (breaks (jump_target) || continues (jump_target))
   12343            2 :         *jump_target = NULL_TREE;
   12344              :       return true;
   12345              : 
   12346       419111 :     case FOR_STMT:
   12347       419111 :       if (!RECUR (FOR_INIT_STMT (t), any))
   12348              :         return false;
   12349       419111 :       if (!RECUR (FOR_COND_PREP (t), any))
   12350              :         return false;
   12351       419111 :       tmp = FOR_COND (t);
   12352       419111 :       if (!RECUR (tmp, rval))
   12353              :         return false;
   12354       419043 :       if (tmp)
   12355              :         {
   12356       374027 :           if (!processing_template_decl)
   12357       370805 :             tmp = cxx_eval_outermost_constant_expr (tmp, true);
   12358              :           /* If we couldn't evaluate the condition, it might not ever be
   12359              :              true.  */
   12360       374027 :           if (!integer_onep (tmp))
   12361              :             {
   12362              :               /* Before returning true, check if the for body can contain
   12363              :                  a return.  */
   12364       374027 :               hash_set<tree> pset;
   12365       374027 :               check_for_return_continue_data data = { &pset, NULL_TREE,
   12366       374027 :                                                       NULL_TREE, false };
   12367       374027 :               if (tree ret_expr
   12368       374027 :                   = cp_walk_tree (&FOR_BODY (t), check_for_return_continue,
   12369              :                                   &data, &pset))
   12370       131830 :                 *jump_target = ret_expr;
   12371       374027 :               if (data.could_throw)
   12372         9601 :                 *jump_target = void_node;
   12373       374027 :               return true;
   12374       374027 :             }
   12375              :         }
   12376        45016 :       if (!RECUR (FOR_EXPR (t), any))
   12377              :         return false;
   12378        45016 :       if (!RECUR (FOR_BODY (t), any))
   12379              :         return false;
   12380        45016 :       if (!RECUR (FOR_COND_CLEANUP (t), any))
   12381              :         return false;
   12382        45016 :       if (breaks (jump_target) || continues (jump_target))
   12383           12 :         *jump_target = NULL_TREE;
   12384              :       return true;
   12385              : 
   12386          469 :     case RANGE_FOR_STMT:
   12387          469 :       if (!RECUR (RANGE_FOR_INIT_STMT (t), any))
   12388              :         return false;
   12389          469 :       if (!RECUR (RANGE_FOR_EXPR (t), any))
   12390              :         return false;
   12391          469 :       if (!RECUR (RANGE_FOR_BODY (t), any))
   12392              :         return false;
   12393          467 :       if (breaks (jump_target) || continues (jump_target))
   12394            0 :         *jump_target = NULL_TREE;
   12395              :       return true;
   12396              : 
   12397       157161 :     case WHILE_STMT:
   12398       157161 :       if (!RECUR (WHILE_COND_PREP (t), any))
   12399              :         return false;
   12400       157161 :       tmp = WHILE_COND (t);
   12401       157161 :       if (!RECUR (tmp, rval))
   12402              :         return false;
   12403       157097 :       if (!processing_template_decl)
   12404       157073 :         tmp = cxx_eval_outermost_constant_expr (tmp, true);
   12405              :       /* If we couldn't evaluate the condition, it might not ever be true.  */
   12406       157097 :       if (!integer_onep (tmp))
   12407              :         {
   12408              :           /* Before returning true, check if the while body can contain
   12409              :              a return.  */
   12410       147340 :           hash_set<tree> pset;
   12411       147340 :           check_for_return_continue_data data = { &pset, NULL_TREE,
   12412       147340 :                                                   NULL_TREE, false };
   12413       147340 :           if (tree ret_expr
   12414       147340 :               = cp_walk_tree (&WHILE_BODY (t), check_for_return_continue,
   12415              :                               &data, &pset))
   12416          421 :             *jump_target = ret_expr;
   12417       147340 :           if (data.could_throw)
   12418         3186 :             *jump_target = void_node;
   12419       147340 :           return true;
   12420       147340 :         }
   12421         9757 :       if (!RECUR (WHILE_BODY (t), any))
   12422              :         return false;
   12423         9746 :       if (!RECUR (WHILE_COND_CLEANUP (t), any))
   12424              :         return false;
   12425         9746 :       if (breaks (jump_target) || continues (jump_target))
   12426           24 :         *jump_target = NULL_TREE;
   12427              :       return true;
   12428              : 
   12429        24606 :     case SWITCH_STMT:
   12430        24606 :       if (!RECUR (SWITCH_STMT_COND (t), rval))
   12431              :         return false;
   12432              :       /* FIXME we don't check SWITCH_STMT_BODY currently, because even
   12433              :          unreachable labels would be checked and it is enough if there is
   12434              :          a single switch cond value for which it is a valid constant
   12435              :          expression.  We need to check if there are any RETURN_EXPRs
   12436              :          or CONTINUE_STMTs inside of the body though, as in that case
   12437              :          we need to set *jump_target.  */
   12438              :       else
   12439              :         {
   12440        24600 :           hash_set<tree> pset;
   12441        24600 :           check_for_return_continue_data data = { &pset, NULL_TREE,
   12442        24600 :                                                   NULL_TREE, false };
   12443        24600 :           if (tree ret_expr
   12444        24600 :               = cp_walk_tree (&SWITCH_STMT_BODY (t), check_for_return_continue,
   12445              :                               &data, &pset))
   12446              :             /* The switch might return.  */
   12447        24220 :             *jump_target = ret_expr;
   12448          380 :           else if (data.continue_stmt)
   12449              :             /* The switch can't return, but might continue.  */
   12450            3 :             *jump_target = data.continue_stmt;
   12451        24600 :           if (data.could_throw)
   12452           25 :             *jump_target = void_node;
   12453        24600 :         }
   12454        24600 :       return true;
   12455              : 
   12456           50 :     case STMT_EXPR:
   12457           50 :       return RECUR (STMT_EXPR_STMT (t), rval);
   12458              : 
   12459       542279 :     case LAMBDA_EXPR:
   12460       542279 :       if (cxx_dialect >= cxx17)
   12461              :         /* In C++17 lambdas can be constexpr, don't give up yet.  */
   12462              :         return true;
   12463          449 :       else if (flags & tf_error)
   12464            0 :         constexpr_error (loc, fundef_p, "lambda-expression is not a "
   12465              :                          "constant expression before C++17");
   12466              :       return false;
   12467              : 
   12468       109816 :     case NEW_EXPR:
   12469       109816 :     case VEC_NEW_EXPR:
   12470       109816 :     case DELETE_EXPR:
   12471       109816 :     case VEC_DELETE_EXPR:
   12472       109816 :       if (cxx_dialect >= cxx20)
   12473              :         /* In C++20, new-expressions are potentially constant.  */
   12474              :         return true;
   12475         1077 :       else if (flags & tf_error)
   12476            0 :         constexpr_error (loc, fundef_p, "new-expression is not a "
   12477              :                          "constant expression before C++20");
   12478              :       return false;
   12479              : 
   12480        80076 :     case DYNAMIC_CAST_EXPR:
   12481        80076 :     case PSEUDO_DTOR_EXPR:
   12482        80076 :     case OMP_PARALLEL:
   12483        80076 :     case OMP_TASK:
   12484        80076 :     case OMP_FOR:
   12485        80076 :     case OMP_SIMD:
   12486        80076 :     case OMP_DISTRIBUTE:
   12487        80076 :     case OMP_TASKLOOP:
   12488        80076 :     case OMP_LOOP:
   12489        80076 :     case OMP_TEAMS:
   12490        80076 :     case OMP_TARGET_DATA:
   12491        80076 :     case OMP_TARGET:
   12492        80076 :     case OMP_SECTIONS:
   12493        80076 :     case OMP_ORDERED:
   12494        80076 :     case OMP_CRITICAL:
   12495        80076 :     case OMP_SINGLE:
   12496        80076 :     case OMP_SCAN:
   12497        80076 :     case OMP_SCOPE:
   12498        80076 :     case OMP_SECTION:
   12499        80076 :     case OMP_MASTER:
   12500        80076 :     case OMP_MASKED:
   12501        80076 :     case OMP_TASKGROUP:
   12502        80076 :     case OMP_TARGET_UPDATE:
   12503        80076 :     case OMP_TARGET_ENTER_DATA:
   12504        80076 :     case OMP_TARGET_EXIT_DATA:
   12505        80076 :     case OMP_ATOMIC:
   12506        80076 :     case OMP_ATOMIC_READ:
   12507        80076 :     case OMP_ATOMIC_CAPTURE_OLD:
   12508        80076 :     case OMP_ATOMIC_CAPTURE_NEW:
   12509        80076 :     case OMP_DEPOBJ:
   12510        80076 :     case OACC_PARALLEL:
   12511        80076 :     case OACC_KERNELS:
   12512        80076 :     case OACC_SERIAL:
   12513        80076 :     case OACC_DATA:
   12514        80076 :     case OACC_HOST_DATA:
   12515        80076 :     case OACC_LOOP:
   12516        80076 :     case OACC_CACHE:
   12517        80076 :     case OACC_DECLARE:
   12518        80076 :     case OACC_ENTER_DATA:
   12519        80076 :     case OACC_EXIT_DATA:
   12520        80076 :     case OACC_UPDATE:
   12521        80076 :     case OMP_ARRAY_SECTION:
   12522              :       /* GCC internal stuff.  */
   12523        80076 :     case VA_ARG_EXPR:
   12524        80076 :     case TRANSACTION_EXPR:
   12525        80076 :     case AT_ENCODE_EXPR:
   12526        80076 :     fail:
   12527        80076 :       if (flags & tf_error)
   12528           23 :          constexpr_error (loc, fundef_p, "expression %qE is not a constant "
   12529              :                           "expression", t);
   12530              :       return false;
   12531              : 
   12532              :     case OMP_DECLARE_MAPPER:
   12533              :       /* This can be used to initialize VAR_DECLs: it's treated as a magic
   12534              :          constant.  */
   12535              :       return true;
   12536              : 
   12537        15929 :     case THROW_EXPR:
   12538        15929 :       if (cxx_dialect < cxx26)
   12539          278 :         goto fail;
   12540        15651 :       return RECUR (TREE_OPERAND (t, 0), rval);
   12541              : 
   12542          517 :     case ASM_EXPR:
   12543          517 :       if (flags & tf_error)
   12544            5 :         inline_asm_in_constexpr_error (loc, fundef_p);
   12545              :       return false;
   12546              : 
   12547       305387 :     case OBJ_TYPE_REF:
   12548       305387 :       if (cxx_dialect >= cxx20)
   12549              :         /* In C++20 virtual calls can be constexpr, don't give up yet.  */
   12550              :         return true;
   12551         5582 :       else if (flags & tf_error)
   12552            0 :         constexpr_error (loc, fundef_p, "virtual functions cannot be "
   12553              :                          "%<constexpr%> before C++20");
   12554              :       return false;
   12555              : 
   12556         4560 :     case TYPEID_EXPR:
   12557              :       /* In C++20, a typeid expression whose operand is of polymorphic
   12558              :          class type can be constexpr.  */
   12559         4560 :       {
   12560         4560 :         tree e = TREE_OPERAND (t, 0);
   12561         4560 :         if (cxx_dialect < cxx20
   12562           26 :             && strict
   12563           26 :             && !TYPE_P (e)
   12564           19 :             && !type_dependent_expression_p (e)
   12565            7 :             && CLASS_TYPE_P (TREE_TYPE (e))
   12566         4565 :             && TYPE_POLYMORPHIC_P (TREE_TYPE (e)))
   12567              :           {
   12568            4 :             if (flags & tf_error)
   12569            1 :               constexpr_error (loc, fundef_p, "%<typeid%> is not a "
   12570              :                                "constant expression because %qE is "
   12571              :                                "of polymorphic type", e);
   12572            4 :             return false;
   12573              :           }
   12574              :         return true;
   12575              :       }
   12576              : 
   12577     28643450 :     case POINTER_DIFF_EXPR:
   12578     28643450 :     case MINUS_EXPR:
   12579     28643450 :       want_rval = true;
   12580     28643450 :       goto binary;
   12581              : 
   12582     74542968 :     case LT_EXPR:
   12583     74542968 :     case LE_EXPR:
   12584     74542968 :     case GT_EXPR:
   12585     74542968 :     case GE_EXPR:
   12586     74542968 :     case EQ_EXPR:
   12587     74542968 :     case NE_EXPR:
   12588     74542968 :     case SPACESHIP_EXPR:
   12589     74542968 :       want_rval = true;
   12590     74542968 :       goto binary;
   12591              : 
   12592      1768010 :     case PREINCREMENT_EXPR:
   12593      1768010 :     case POSTINCREMENT_EXPR:
   12594      1768010 :     case PREDECREMENT_EXPR:
   12595      1768010 :     case POSTDECREMENT_EXPR:
   12596      1768010 :       if (cxx_dialect < cxx14)
   12597         8730 :         goto fail;
   12598      1759280 :       goto unary;
   12599              : 
   12600      1037622 :     case BIT_NOT_EXPR:
   12601              :       /* A destructor.  */
   12602      1037622 :       if (TYPE_P (TREE_OPERAND (t, 0)))
   12603              :         return true;
   12604              :       /* fall through.  */
   12605              : 
   12606     42726264 :     case CONJ_EXPR:
   12607     42726264 :     case SAVE_EXPR:
   12608     42726264 :     case FIX_TRUNC_EXPR:
   12609     42726264 :     case FLOAT_EXPR:
   12610     42726264 :     case NEGATE_EXPR:
   12611     42726264 :     case ABS_EXPR:
   12612     42726264 :     case ABSU_EXPR:
   12613     42726264 :     case TRUTH_NOT_EXPR:
   12614     42726264 :     case FIXED_CONVERT_EXPR:
   12615     42726264 :     case UNARY_PLUS_EXPR:
   12616     42726264 :     case UNARY_LEFT_FOLD_EXPR:
   12617     42726264 :     case UNARY_RIGHT_FOLD_EXPR:
   12618     42726264 :     case VEC_DUPLICATE_EXPR:
   12619      1037622 :     unary:
   12620     42726264 :       return RECUR (TREE_OPERAND (t, 0), rval);
   12621              : 
   12622     30199734 :     case CAST_EXPR:
   12623     30199734 :     case CONST_CAST_EXPR:
   12624     30199734 :     case STATIC_CAST_EXPR:
   12625     30199734 :     case REINTERPRET_CAST_EXPR:
   12626     30199734 :     case IMPLICIT_CONV_EXPR:
   12627     30199734 :       if (!cast_valid_in_integral_constant_expression_p (TREE_TYPE (t)))
   12628              :         /* In C++98, a conversion to non-integral type can't be part of a
   12629              :            constant expression.  */
   12630              :         {
   12631          331 :           if (flags & tf_error)
   12632            0 :             constexpr_error (loc, fundef_p,
   12633              :                              "cast to non-integral type %qT in a constant "
   12634            0 :                              "expression", TREE_TYPE (t));
   12635          331 :           return false;
   12636              :         }
   12637              :       /* This might be a conversion from a class to a (potentially) literal
   12638              :          type.  Let's consider it potentially constant since the conversion
   12639              :          might be a constexpr user-defined conversion.  */
   12640     30199403 :       else if (cxx_dialect >= cxx11
   12641     30178309 :                && (dependent_type_p (TREE_TYPE (t))
   12642     10567299 :                    || !COMPLETE_TYPE_P (TREE_TYPE (t))
   12643     10554046 :                    || literal_type_p (TREE_TYPE (t)))
   12644     30141403 :                && TREE_OPERAND (t, 0)
   12645     60107996 :                && (TREE_CODE (t) != CAST_EXPR
   12646     22633939 :                    || !TREE_CHAIN (TREE_OPERAND (t, 0))))
   12647              :         {
   12648     29867995 :           tree from = TREE_OPERAND (t, 0);
   12649     29867995 :           if (TREE_CODE (t) == CAST_EXPR)
   12650     22593341 :             from = TREE_VALUE (from);
   12651     29867995 :           tree type = TREE_TYPE (from);
   12652              :           /* If this is a dependent type, it could end up being a class
   12653              :              with conversions.  */
   12654     29867995 :           if (type == NULL_TREE || WILDCARD_TYPE_P (type))
   12655              :             return true;
   12656              :           /* Or a non-dependent class which has conversions.  */
   12657       601304 :           else if (CLASS_TYPE_P (type)
   12658       601304 :                    && (TYPE_HAS_CONVERSION (type) || dependent_scope_p (type)))
   12659       260524 :             return true;
   12660              :         }
   12661              : 
   12662     23996774 :       return (RECUR (TREE_OPERAND (t, 0),
   12663     23996774 :                      !TYPE_REF_P (TREE_TYPE (t))));
   12664              : 
   12665     12969399 :     case BIND_EXPR:
   12666     12969399 :       return RECUR (BIND_EXPR_BODY (t), want_rval);
   12667              : 
   12668     66085810 :     case CLEANUP_POINT_EXPR:
   12669     66085810 :     case MUST_NOT_THROW_EXPR:
   12670     66085810 :     case TRY_CATCH_EXPR:
   12671              :       /* Even for C++26 handle TRY_BLOCK conservatively, if we detect the
   12672              :          body could throw, even with catch (...) among handlers we'd need
   12673              :          to analyze them in detail if they couldn't rethrow it.  More
   12674              :          importantly though, throws (jump_target) is just conservative,
   12675              :          and there could be e.g.
   12676              :            try
   12677              :              {
   12678              :                possibly_throwing_fn (args);
   12679              :                break;
   12680              :              }
   12681              :            catch (...)
   12682              :              {
   12683              :              }
   12684              :          or continue or return instead of break.  So, clearing *jump_target
   12685              :          because we see catch (...) handler might mean we missed break
   12686              :          etc.  */
   12687     66085810 :     case TRY_BLOCK:
   12688     66085810 :     case EH_SPEC_BLOCK:
   12689     66085810 :     case EXPR_STMT:
   12690     66085810 :     case PAREN_EXPR:
   12691              :       /* For convenience.  */
   12692     66085810 :     case LOOP_EXPR:
   12693     66085810 :     case EXIT_EXPR:
   12694     66085810 :       return RECUR (TREE_OPERAND (t, 0), want_rval);
   12695              : 
   12696     11814124 :     case DECL_EXPR:
   12697     11814124 :       tmp = DECL_EXPR_DECL (t);
   12698      7600068 :       if (VAR_P (tmp) && !DECL_ARTIFICIAL (tmp)
   12699     17417394 :           && (processing_template_decl
   12700      5144922 :               ? !decl_maybe_constant_var_p (tmp)
   12701      4686574 :               : !decl_constant_var_p (tmp)))
   12702              :         {
   12703      4561606 :           if (CP_DECL_THREAD_LOCAL_P (tmp) && !DECL_REALLY_EXTERN (tmp))
   12704              :             {
   12705            8 :               if (flags & tf_error)
   12706            3 :                 constexpr_error (DECL_SOURCE_LOCATION (tmp), fundef_p,
   12707              :                                  "%qD defined %<thread_local%> in "
   12708              :                                  "%<constexpr%> context", tmp);
   12709            8 :               return false;
   12710              :             }
   12711      4561598 :           else if (TREE_STATIC (tmp))
   12712              :             {
   12713          114 :               if (flags & tf_error)
   12714           25 :                 constexpr_error (DECL_SOURCE_LOCATION (tmp), fundef_p,
   12715              :                                  "%qD defined %<static%> in %<constexpr%> "
   12716              :                                  "context", tmp);
   12717          114 :               return false;
   12718              :             }
   12719      4561484 :           else if (!check_for_uninitialized_const_var
   12720      4561484 :                    (tmp, /*constexpr_context_p=*/true, flags))
   12721              :             return false;
   12722              :         }
   12723     11810267 :       if (VAR_P (tmp))
   12724      7596211 :         return RECUR (DECL_INITIAL (tmp), want_rval);
   12725              :       return true;
   12726              : 
   12727        27979 :     case TRY_FINALLY_EXPR:
   12728        27979 :       return (RECUR (TREE_OPERAND (t, 0), want_rval)
   12729        27979 :               && RECUR (TREE_OPERAND (t, 1), any));
   12730              : 
   12731            0 :     case EH_ELSE_EXPR:
   12732              :       /* maybe_apply_function_contracts uses this to check postconditions only
   12733              :          on normal return.  */
   12734            0 :       return (RECUR (TREE_OPERAND (t, 1), any)
   12735            0 :               || RECUR (TREE_OPERAND (t, 0), any));
   12736              : 
   12737     23842447 :     case SCOPE_REF:
   12738     23842447 :       return RECUR (TREE_OPERAND (t, 1), want_rval);
   12739              : 
   12740     40246067 :     case TARGET_EXPR:
   12741     40246067 :       if (!TARGET_EXPR_DIRECT_INIT_P (t)
   12742     40058342 :           && !TARGET_EXPR_ELIDING_P (t)
   12743     72506344 :           && !literal_type_p (TREE_TYPE (t)))
   12744              :         {
   12745       781283 :           if (flags & tf_error)
   12746              :             {
   12747           23 :               auto_diagnostic_group d;
   12748           23 :               if (constexpr_error (loc, fundef_p,
   12749              :                                    "temporary of non-literal type %qT in a "
   12750           23 :                                    "constant expression", TREE_TYPE (t)))
   12751           23 :                 explain_non_literal_class (TREE_TYPE (t));
   12752           23 :             }
   12753       781283 :           return false;
   12754              :         }
   12755              :       /* FALLTHRU */
   12756     65938607 :     case INIT_EXPR:
   12757     65938607 :       if (TREE_CLOBBER_P (TREE_OPERAND (t, 1)))
   12758              :         return true;
   12759     65873991 :       return RECUR (TREE_OPERAND (t, 1), rval);
   12760              : 
   12761     33748089 :     case CONSTRUCTOR:
   12762     33748089 :       {
   12763     33748089 :         vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
   12764     33748089 :         constructor_elt *ce;
   12765   4606009616 :         for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
   12766    215483142 :           if (!RECUR (ce->value, want_rval))
   12767              :             return false;
   12768              :         return true;
   12769              :       }
   12770              : 
   12771     20351862 :     case TREE_LIST:
   12772     20351862 :       {
   12773     20351862 :         gcc_assert (TREE_PURPOSE (t) == NULL_TREE
   12774              :                     || DECL_P (TREE_PURPOSE (t)));
   12775     20351862 :         if (!RECUR (TREE_VALUE (t), want_rval))
   12776              :           return false;
   12777     18233284 :         if (TREE_CHAIN (t) == NULL_TREE)
   12778              :           return true;
   12779        51795 :         return RECUR (TREE_CHAIN (t), want_rval);
   12780              :       }
   12781              : 
   12782     14768939 :     case TRUNC_DIV_EXPR:
   12783     14768939 :     case CEIL_DIV_EXPR:
   12784     14768939 :     case FLOOR_DIV_EXPR:
   12785     14768939 :     case ROUND_DIV_EXPR:
   12786     14768939 :     case TRUNC_MOD_EXPR:
   12787     14768939 :     case CEIL_MOD_EXPR:
   12788     14768939 :     case ROUND_MOD_EXPR:
   12789     14768939 :       {
   12790     14768939 :         tree denom = TREE_OPERAND (t, 1);
   12791     14768939 :         if (!RECUR (denom, rval))
   12792              :           return false;
   12793              :         /* We can't call cxx_eval_outermost_constant_expr on an expression
   12794              :            that hasn't been through instantiate_non_dependent_expr yet.  */
   12795     14326324 :         if (!processing_template_decl)
   12796      7557380 :           denom = cxx_eval_outermost_constant_expr (denom, true);
   12797     14326324 :         if (integer_zerop (denom))
   12798              :           {
   12799          337 :             if (flags & tf_error)
   12800           35 :               constexpr_error (input_location, fundef_p,
   12801              :                                "division by zero is not a constant expression");
   12802          337 :             return false;
   12803              :           }
   12804              :         else
   12805              :           {
   12806     14325987 :             want_rval = true;
   12807     14325987 :             return RECUR (TREE_OPERAND (t, 0), want_rval);
   12808              :           }
   12809              :       }
   12810              : 
   12811      6510555 :     case COMPOUND_EXPR:
   12812      6510555 :       {
   12813              :         /* check_return_expr sometimes wraps a TARGET_EXPR in a
   12814              :            COMPOUND_EXPR; don't get confused.  */
   12815      6510555 :         tree op0 = TREE_OPERAND (t, 0);
   12816      6510555 :         tree op1 = TREE_OPERAND (t, 1);
   12817      6510555 :         STRIP_NOPS (op1);
   12818      6510555 :         if (TREE_CODE (op0) == TARGET_EXPR && op1 == TARGET_EXPR_SLOT (op0))
   12819      1208630 :           return RECUR (op0, want_rval);
   12820              :         else
   12821      5301925 :           goto binary;
   12822              :       }
   12823              : 
   12824              :       /* If the first operand is the non-short-circuit constant, look at
   12825              :          the second operand; otherwise we only care about the first one for
   12826              :          potentiality.  */
   12827     17080170 :     case TRUTH_AND_EXPR:
   12828     17080170 :     case TRUTH_ANDIF_EXPR:
   12829     17080170 :       tmp = boolean_true_node;
   12830     17080170 :       goto truth;
   12831      6846968 :     case TRUTH_OR_EXPR:
   12832      6846968 :     case TRUTH_ORIF_EXPR:
   12833      6846968 :       tmp = boolean_false_node;
   12834     23927138 :     truth:
   12835     23927138 :       {
   12836     23927138 :         tree op0 = TREE_OPERAND (t, 0);
   12837     23927138 :         tree op1 = TREE_OPERAND (t, 1);
   12838     23927138 :         if (!RECUR (op0, rval))
   12839              :           return false;
   12840     16367120 :         if (!(flags & tf_error) && RECUR (op1, rval))
   12841              :           /* When quiet, try to avoid expensive trial evaluation by first
   12842              :              checking potentiality of the second operand.  */
   12843              :           return true;
   12844      1695504 :         if (!processing_template_decl)
   12845      1302141 :           op0 = cxx_eval_outermost_constant_expr (op0, true);
   12846      1695504 :         if (tree_int_cst_equal (op0, tmp))
   12847         5147 :           return (flags & tf_error) ? RECUR (op1, rval) : false;
   12848              :         else
   12849              :           return true;
   12850              :       }
   12851              : 
   12852              :     case PLUS_EXPR:
   12853              :     case MULT_EXPR:
   12854              :     case POINTER_PLUS_EXPR:
   12855              :     case RDIV_EXPR:
   12856              :     case EXACT_DIV_EXPR:
   12857              :     case MIN_EXPR:
   12858              :     case MAX_EXPR:
   12859              :     case LSHIFT_EXPR:
   12860              :     case RSHIFT_EXPR:
   12861              :     case LROTATE_EXPR:
   12862              :     case RROTATE_EXPR:
   12863              :     case BIT_IOR_EXPR:
   12864              :     case BIT_XOR_EXPR:
   12865              :     case BIT_AND_EXPR:
   12866              :     case TRUTH_XOR_EXPR:
   12867              :     case UNORDERED_EXPR:
   12868              :     case ORDERED_EXPR:
   12869              :     case UNLT_EXPR:
   12870              :     case UNLE_EXPR:
   12871              :     case UNGT_EXPR:
   12872              :     case UNGE_EXPR:
   12873              :     case UNEQ_EXPR:
   12874              :     case LTGT_EXPR:
   12875              :     case RANGE_EXPR:
   12876              :     case COMPLEX_EXPR:
   12877    220066414 :       want_rval = true;
   12878              :       /* Fall through.  */
   12879    220066414 :     case ARRAY_REF:
   12880    220066414 :     case ARRAY_RANGE_REF:
   12881    220066414 :     case MEMBER_REF:
   12882    220066414 :     case DOTSTAR_EXPR:
   12883    220066414 :     case MEM_REF:
   12884    220066414 :     case BINARY_LEFT_FOLD_EXPR:
   12885    220066414 :     case BINARY_RIGHT_FOLD_EXPR:
   12886    220066414 :     binary:
   12887    486383052 :       for (i = 0; i < 2; ++i)
   12888    359687986 :         if (!RECUR (TREE_OPERAND (t, i), want_rval))
   12889              :           return false;
   12890              :       return true;
   12891              : 
   12892              :     case VEC_PERM_EXPR:
   12893       106204 :      for (i = 0; i < 3; ++i)
   12894       105806 :       if (!RECUR (TREE_OPERAND (t, i), true))
   12895              :         return false;
   12896              :      return true;
   12897              : 
   12898      6197110 :     case COND_EXPR:
   12899      6197110 :       if (COND_EXPR_IS_VEC_DELETE (t) && cxx_dialect < cxx20)
   12900              :         {
   12901            8 :           if (flags & tf_error)
   12902            2 :             constexpr_error (loc, fundef_p, "%<delete[]%> is not a "
   12903              :                              "constant expression");
   12904            8 :           return false;
   12905              :         }
   12906              :       /* Fall through.  */
   12907     15772515 :     case IF_STMT:
   12908     15772515 :     case VEC_COND_EXPR:
   12909              :       /* If the condition is a known constant, we know which of the legs we
   12910              :          care about; otherwise we only require that the condition and
   12911              :          either of the legs be potentially constant.  */
   12912     15772515 :       tmp = TREE_OPERAND (t, 0);
   12913     15772515 :       if (!RECUR (tmp, rval))
   12914              :         return false;
   12915     14256771 :       if (!processing_template_decl)
   12916     12338236 :         tmp = cxx_eval_outermost_constant_expr (tmp, true);
   12917              :       /* potential_constant_expression* isn't told if it is called for
   12918              :          manifestly_const_eval or not, so for consteval if always
   12919              :          process both branches as if the condition is not a known
   12920              :          constant.  */
   12921     14256771 :       if (TREE_CODE (t) != IF_STMT || !IF_STMT_CONSTEVAL_P (t))
   12922              :         {
   12923     14206833 :           if (integer_zerop (tmp))
   12924      3010150 :             return RECUR (TREE_OPERAND (t, 2), want_rval);
   12925     11196683 :           else if (TREE_CODE (tmp) == INTEGER_CST)
   12926      3435786 :             return RECUR (TREE_OPERAND (t, 1), want_rval);
   12927              :         }
   12928      7810835 :       tmp = *jump_target;
   12929      8946684 :       for (i = 1; i < 3; ++i)
   12930              :         {
   12931      8873586 :           tree this_jump_target = tmp;
   12932      8873586 :           if (potential_constant_expression_1 (TREE_OPERAND (t, i),
   12933              :                                                want_rval, strict, now, fundef_p,
   12934              :                                                tf_none, &this_jump_target))
   12935              :             {
   12936      7905982 :               if (returns (&this_jump_target) || throws (&this_jump_target))
   12937      2153080 :                 *jump_target = this_jump_target;
   12938      5584657 :               else if (!returns (jump_target) && !throws (jump_target))
   12939              :                 {
   12940      5584657 :                   if (breaks (&this_jump_target)
   12941      5584657 :                       || continues (&this_jump_target))
   12942           42 :                     *jump_target = this_jump_target;
   12943      5584657 :                   if (i == 1)
   12944              :                     {
   12945              :                       /* If the then branch is potentially constant, but
   12946              :                          does not return, check if the else branch
   12947              :                          couldn't return, break or continue.  */
   12948      4597402 :                       hash_set<tree> pset;
   12949      4597402 :                       check_for_return_continue_data data = { &pset, NULL_TREE,
   12950              :                                                               NULL_TREE,
   12951      4597402 :                                                               false };
   12952      9194804 :                       if (tree ret_expr
   12953      4597402 :                         = cp_walk_tree (&TREE_OPERAND (t, 2),
   12954              :                                         check_for_return_continue, &data,
   12955              :                                         &pset))
   12956        69409 :                         *jump_target = ret_expr;
   12957      4527993 :                       else if (*jump_target == NULL_TREE)
   12958              :                         {
   12959      4527954 :                           if (data.continue_stmt)
   12960            0 :                             *jump_target = data.continue_stmt;
   12961      4527954 :                           else if (data.break_stmt)
   12962           13 :                             *jump_target = data.break_stmt;
   12963              :                         }
   12964      4597402 :                       if (data.could_throw)
   12965        28938 :                         *jump_target = void_node;
   12966      4597402 :                     }
   12967              :                 }
   12968      7737737 :               return true;
   12969              :             }
   12970              :         }
   12971        73098 :       if (flags & tf_error)
   12972              :         {
   12973            3 :           if (TREE_CODE (t) == IF_STMT)
   12974            3 :             constexpr_error (loc, fundef_p, "neither branch of %<if%> is a "
   12975              :                              "constant expression");
   12976              :           else
   12977            0 :             constexpr_error (loc, fundef_p, "expression %qE is not a "
   12978              :                              "constant expression", t);
   12979              :         }
   12980              :       return false;
   12981              : 
   12982         1003 :     case VEC_INIT_EXPR:
   12983         1003 :       if (VEC_INIT_EXPR_IS_CONSTEXPR (t))
   12984              :         return true;
   12985          399 :       if (flags & tf_error)
   12986              :         {
   12987            3 :           if (constexpr_error (loc, fundef_p, "non-constant array "
   12988              :                                "initialization"))
   12989            2 :             diagnose_non_constexpr_vec_init (t);
   12990              :         }
   12991              :       return false;
   12992              : 
   12993              :     case TYPE_DECL:
   12994              :     case TAG_DEFN:
   12995              :       /* We can see these in statement-expressions.  */
   12996              :       return true;
   12997              : 
   12998      1345883 :     case CLEANUP_STMT:
   12999      1345883 :       if (!RECUR (CLEANUP_BODY (t), any))
   13000              :         return false;
   13001      1345360 :       if (!CLEANUP_EH_ONLY (t) && !RECUR (CLEANUP_EXPR (t), any))
   13002              :         return false;
   13003              :       return true;
   13004              : 
   13005              :     case EMPTY_CLASS_EXPR:
   13006              :       return true;
   13007              : 
   13008           27 :     case GOTO_EXPR:
   13009           27 :       {
   13010           27 :         tree *target = &TREE_OPERAND (t, 0);
   13011              :         /* Gotos representing break, continue and cdtor return are OK.  */
   13012           27 :         if (breaks (target) || continues (target) || returns (target))
   13013              :           {
   13014            9 :             *jump_target = *target;
   13015            9 :             return true;
   13016              :           }
   13017           18 :         if (TREE_CODE (*target) == LABEL_DECL && DECL_ARTIFICIAL (*target))
   13018              :           /* The user didn't write this goto, this isn't the problem.  */
   13019              :           return true;
   13020           16 :         if (flags & tf_error)
   13021            3 :           constexpr_error (loc, fundef_p, "%<goto%> is not a constant "
   13022              :                            "expression");
   13023              :         return false;
   13024              :       }
   13025              : 
   13026              :     case ASSERTION_STMT:
   13027              :     case PRECONDITION_STMT:
   13028              :     case POSTCONDITION_STMT:
   13029              :       /* Contracts are not supposed to alter this; we have to check that this
   13030              :          is not violated at a later time.  */
   13031              :       return true;
   13032              : 
   13033          223 :     case LABEL_EXPR:
   13034          223 :       t = LABEL_EXPR_LABEL (t);
   13035          223 :       if (DECL_ARTIFICIAL (t) || cxx_dialect >= cxx23)
   13036              :         return true;
   13037           25 :       else if (flags & tf_error)
   13038            5 :         constexpr_error (loc, fundef_p, "label definition in %<constexpr%> "
   13039              :                          "function only available with %<-std=c++23%> or "
   13040              :                          "%<-std=gnu++23%>");
   13041              :       return false;
   13042              : 
   13043         9860 :     case ANNOTATE_EXPR:
   13044         9860 :       return RECUR (TREE_OPERAND (t, 0), rval);
   13045              : 
   13046       131192 :     case BIT_CAST_EXPR:
   13047       131192 :       return RECUR (TREE_OPERAND (t, 0), rval);
   13048              : 
   13049              :     /* Coroutine await, yield and return expressions are not.  */
   13050          718 :     case CO_AWAIT_EXPR:
   13051          718 :     case CO_YIELD_EXPR:
   13052          718 :     case CO_RETURN_EXPR:
   13053          718 :     case TEMPLATE_FOR_STMT:
   13054          718 :       if (flags & tf_error)
   13055            3 :         constexpr_error (cp_expr_loc_or_loc (t, input_location), fundef_p,
   13056              :                          "%qE is not a constant expression", t);
   13057              :       return false;
   13058              : 
   13059              :     /* Assume a TU-local entity is not constant, we'll error later when
   13060              :        instantiating.  */
   13061              :     case TU_LOCAL_ENTITY:
   13062              :       return false;
   13063              : 
   13064              :     /* A splice expression is dependent, but will be constant after
   13065              :        substitution.  */
   13066              :     case SPLICE_EXPR:
   13067              :       return true;
   13068              : 
   13069           30 :     case NONTYPE_ARGUMENT_PACK:
   13070           30 :       {
   13071           30 :         tree args = ARGUMENT_PACK_ARGS (t);
   13072           30 :         int len = TREE_VEC_LENGTH (args);
   13073           90 :         for (int i = 0; i < len; ++i)
   13074           60 :           if (!RECUR (TREE_VEC_ELT (args, i), any))
   13075              :             return false;
   13076              :         return true;
   13077              :       }
   13078              : 
   13079            0 :     default:
   13080            0 :       if (objc_non_constant_expr_p (t))
   13081              :         return false;
   13082              : 
   13083            0 :       sorry ("unexpected AST of kind %s", get_tree_code_name (TREE_CODE (t)));
   13084            0 :       gcc_unreachable ();
   13085              :       return false;
   13086              :     }
   13087              : #undef RECUR
   13088   4357733901 : }
   13089              : 
   13090              : bool
   13091   1591140093 : potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
   13092              :                                  bool fundef_p, tsubst_flags_t flags)
   13093              : {
   13094   1591140093 :   if (flags & tf_error)
   13095              :     {
   13096              :       /* Check potentiality quietly first, as that could be performed more
   13097              :          efficiently in some cases (currently only for TRUTH_*_EXPR).  If
   13098              :          that fails, replay the check noisily to give errors.  */
   13099     10072219 :       flags &= ~tf_error;
   13100     10072219 :       if (potential_constant_expression_1 (t, want_rval, strict, now, fundef_p,
   13101              :                                            flags))
   13102              :         return true;
   13103          986 :       flags |= tf_error;
   13104              :     }
   13105              : 
   13106   1581068860 :   tree target = NULL_TREE;
   13107   1581068860 :   return potential_constant_expression_1 (t, want_rval, strict, now, fundef_p,
   13108   1581068860 :                                           flags, &target);
   13109              : }
   13110              : 
   13111              : /* The main entry point to the above.  */
   13112              : 
   13113              : bool
   13114    413508921 : potential_constant_expression (tree t)
   13115              : {
   13116    413508921 :   return potential_constant_expression_1 (t, /*want_rval*/false, /*strict*/true,
   13117              :                                           /*now*/false, /*fundef_p*/false,
   13118    413508921 :                                           tf_none);
   13119              : }
   13120              : 
   13121              : /* As above, but require a constant rvalue.  */
   13122              : 
   13123              : bool
   13124     32886644 : potential_rvalue_constant_expression (tree t)
   13125              : {
   13126     32886644 :   return potential_constant_expression_1 (t, /*want_rval*/true, /*strict*/true,
   13127              :                                           /*now*/false, /*fundef_p*/false,
   13128     32886644 :                                           tf_none);
   13129              : }
   13130              : 
   13131              : /* Like above, but complain about non-constant expressions.  */
   13132              : 
   13133              : bool
   13134           80 : require_potential_constant_expression (tree t)
   13135              : {
   13136           80 :   return potential_constant_expression_1 (t, /*want_rval*/false, /*strict*/true,
   13137              :                                           /*now*/false, /*fundef_p*/false,
   13138           80 :                                           tf_warning_or_error);
   13139              : }
   13140              : 
   13141              : /* Cross product of the above.  */
   13142              : 
   13143              : bool
   13144       127761 : require_potential_rvalue_constant_expression (tree t)
   13145              : {
   13146       127761 :   return potential_constant_expression_1 (t, /*want_rval*/true, /*strict*/true,
   13147              :                                           /*now*/false, /*fundef_p*/false,
   13148       127761 :                                           tf_warning_or_error);
   13149              : }
   13150              : 
   13151              : /* Like require_potential_rvalue_constant_expression, but fundef_p is true.  */
   13152              : 
   13153              : bool
   13154          257 : require_potential_rvalue_constant_expression_fncheck (tree t)
   13155              : {
   13156          257 :   return potential_constant_expression_1 (t, /*want_rval*/true, /*strict*/true,
   13157              :                                           /*now*/false, /*fundef_p*/true,
   13158          257 :                                           tf_warning_or_error);
   13159              : }
   13160              : 
   13161              : /* Like above, but don't consider PARM_DECL a potential_constant_expression.  */
   13162              : 
   13163              : bool
   13164          780 : require_rvalue_constant_expression (tree t)
   13165              : {
   13166          780 :   return potential_constant_expression_1 (t, /*want_rval*/true, /*strict*/true,
   13167              :                                           /*now*/true, /*fundef_p*/false,
   13168          780 :                                           tf_warning_or_error);
   13169              : }
   13170              : 
   13171              : /* Like potential_constant_expression, but don't consider possible constexpr
   13172              :    substitution of the current function.  That is, PARM_DECL qualifies under
   13173              :    potential_constant_expression, but not here.
   13174              : 
   13175              :    This is basically what you can check when any actual constant values might
   13176              :    be value-dependent.  */
   13177              : 
   13178              : bool
   13179    862105331 : is_constant_expression (tree t)
   13180              : {
   13181    862105331 :   return potential_constant_expression_1 (t, /*want_rval*/false, /*strict*/true,
   13182              :                                           /*now*/true, /*fundef_p*/false,
   13183    862105331 :                                           tf_none);
   13184              : }
   13185              : 
   13186              : /* As above, but expect an rvalue.  */
   13187              : 
   13188              : bool
   13189    149395907 : is_rvalue_constant_expression (tree t)
   13190              : {
   13191    149395907 :   return potential_constant_expression_1 (t, /*want_rval*/true, /*strict*/true,
   13192              :                                           /*now*/true, /*fundef_p*/false,
   13193    149395907 :                                           tf_none);
   13194              : }
   13195              : 
   13196              : /* Like above, but complain about non-constant expressions.  */
   13197              : 
   13198              : bool
   13199      9943341 : require_constant_expression (tree t)
   13200              : {
   13201      9943341 :   return potential_constant_expression_1 (t, /*want_rval*/false, /*strict*/true,
   13202              :                                           /*now*/true, /*fundef_p*/false,
   13203      9943341 :                                           tf_warning_or_error);
   13204              : }
   13205              : 
   13206              : /* Like is_constant_expression, but allow const variables that are not allowed
   13207              :    under constexpr rules.  */
   13208              : 
   13209              : bool
   13210    113098852 : is_static_init_expression (tree t)
   13211              : {
   13212    113098852 :   return potential_constant_expression_1 (t, /*want_rval*/false,
   13213              :                                           /*strict*/false, /*now*/true,
   13214    113098852 :                                           /*fundef_p*/false, tf_none);
   13215              : }
   13216              : 
   13217              : /* Returns true if T is a potential constant expression that is not
   13218              :    instantiation-dependent, and therefore a candidate for constant folding even
   13219              :    in a template.  */
   13220              : 
   13221              : bool
   13222    832511686 : is_nondependent_constant_expression (tree t)
   13223              : {
   13224    832511686 :   return (!type_unknown_p (t)
   13225    832511637 :           && is_constant_expression (t)
   13226   1559247692 :           && !instantiation_dependent_expression_p (t));
   13227              : }
   13228              : 
   13229              : /* Returns true if T is a potential static initializer expression that is not
   13230              :    instantiation-dependent.  */
   13231              : 
   13232              : bool
   13233    113098852 : is_nondependent_static_init_expression (tree t)
   13234              : {
   13235    113098852 :   return (!type_unknown_p (t)
   13236    113098852 :           && is_static_init_expression (t)
   13237    218114855 :           && !instantiation_dependent_expression_p (t));
   13238              : }
   13239              : 
   13240              : /* True iff FN is an implicitly constexpr function.  */
   13241              : 
   13242              : bool
   13243       190732 : decl_implicit_constexpr_p (tree fn)
   13244              : {
   13245       190732 :   if (!(flag_implicit_constexpr
   13246            2 :         && TREE_CODE (fn) == FUNCTION_DECL
   13247            2 :         && DECL_DECLARED_CONSTEXPR_P (fn)))
   13248              :     return false;
   13249              : 
   13250            2 :   if (DECL_CLONED_FUNCTION_P (fn))
   13251            0 :     fn = DECL_CLONED_FUNCTION (fn);
   13252              : 
   13253            2 :   return (DECL_LANG_SPECIFIC (fn)
   13254            2 :           && DECL_LANG_SPECIFIC (fn)->u.fn.implicit_constexpr);
   13255              : }
   13256              : 
   13257              : /* Finalize constexpr processing after parsing.  */
   13258              : 
   13259              : void
   13260        96822 : fini_constexpr (void)
   13261              : {
   13262              :   /* The contexpr call and fundef copies tables are no longer needed.  */
   13263        96822 :   constexpr_call_table = NULL;
   13264        96822 :   fundef_copies_table = NULL;
   13265        96822 : }
   13266              : 
   13267              : #include "gt-cp-constexpr.h"
        

Generated by: LCOV version 2.4-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.