LCOV - code coverage report
Current view: top level - gcc/cp - decl2.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 95.3 % 2921 2783
Test Date: 2026-02-28 14:20:25 Functions: 100.0 % 134 134
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Process declarations and variables for C++ compiler.
       2              :    Copyright (C) 1988-2026 Free Software Foundation, Inc.
       3              :    Hacked by Michael Tiemann (tiemann@cygnus.com)
       4              : 
       5              : This file is part of GCC.
       6              : 
       7              : GCC is free software; you can redistribute it and/or modify
       8              : it under the terms of the GNU General Public License as published by
       9              : the Free Software Foundation; either version 3, or (at your option)
      10              : any later version.
      11              : 
      12              : GCC is distributed in the hope that it will be useful,
      13              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15              : GNU General Public License for more details.
      16              : 
      17              : You should have received a copy of the GNU General Public License
      18              : along with GCC; see the file COPYING3.  If not see
      19              : <http://www.gnu.org/licenses/>.  */
      20              : 
      21              : 
      22              : /* Process declarations and symbol lookup for C++ front end.
      23              :    Also constructs types; the standard scalar types at initialization,
      24              :    and structure, union, array and enum types when they are declared.  */
      25              : 
      26              : /* ??? not all decl nodes are given the most useful possible
      27              :    line numbers.  For example, the CONST_DECLs for enum values.  */
      28              : 
      29              : #include "config.h"
      30              : #include "system.h"
      31              : #include "coretypes.h"
      32              : #include "memmodel.h"
      33              : #include "target.h"
      34              : #include "cp-tree.h"
      35              : #include "c-family/c-common.h"
      36              : #include "timevar.h"
      37              : #include "stringpool.h"
      38              : #include "cgraph.h"
      39              : #include "varasm.h"
      40              : #include "attribs.h"
      41              : #include "stor-layout.h"
      42              : #include "calls.h"
      43              : #include "decl.h"
      44              : #include "toplev.h"
      45              : #include "c-family/c-objc.h"
      46              : #include "c-family/c-pragma.h"
      47              : #include "dumpfile.h"
      48              : #include "intl.h"
      49              : #include "c-family/c-ada-spec.h"
      50              : #include "asan.h"
      51              : #include "optabs-query.h"
      52              : #include "omp-general.h"
      53              : #include "tree-inline.h"
      54              : #include "escaped_string.h"
      55              : #include "gcc-rich-location.h"
      56              : #include "tree-pretty-print-markup.h"
      57              : #include "contracts.h"
      58              : 
      59              : /* Id for dumping the raw trees.  */
      60              : int raw_dump_id;
      61              : 
      62              : extern cpp_reader *parse_in;
      63              : 
      64              : static tree start_objects (bool, unsigned, bool, bool);
      65              : static tree finish_objects (bool, unsigned, tree, bool = true);
      66              : static tree start_partial_init_fini_fn (bool, unsigned, unsigned, bool);
      67              : static void finish_partial_init_fini_fn (tree);
      68              : static tree emit_partial_init_fini_fn (bool, unsigned, tree,
      69              :                                        unsigned, location_t, tree);
      70              : static void one_static_initialization_or_destruction (bool, tree, tree, bool);
      71              : static void generate_ctor_or_dtor_function (bool, unsigned, tree, location_t,
      72              :                                             bool);
      73              : static tree prune_vars_needing_no_initialization (tree *);
      74              : static void write_out_vars (tree);
      75              : static void import_export_class (tree);
      76              : static tree get_guard_bits (tree);
      77              : static void determine_visibility_from_class (tree, tree);
      78              : static bool determine_hidden_inline (tree);
      79              : 
      80              : /* A list of static class variables.  This is needed, because a
      81              :    static class variable can be declared inside the class without
      82              :    an initializer, and then initialized, statically, outside the class.  */
      83              : static GTY(()) vec<tree, va_gc> *pending_statics;
      84              : 
      85              : /* A list of functions which were declared inline, but which we
      86              :    may need to emit outline anyway.  */
      87              : static GTY(()) vec<tree, va_gc> *deferred_fns;
      88              : 
      89              : /* A list of decls that use types with no linkage, which we need to make
      90              :    sure are defined.  */
      91              : static GTY(()) vec<tree, va_gc> *no_linkage_decls;
      92              : 
      93              : /* A vector of alternating decls and identifiers, where the latter
      94              :    is to be an alias for the former if the former is defined.  */
      95              : static GTY(()) vec<tree, va_gc> *mangling_aliases;
      96              : 
      97              : /* hash traits for declarations.  Hashes single decls via
      98              :    DECL_ASSEMBLER_NAME_RAW.  */
      99              : 
     100              : struct mangled_decl_hash : ggc_remove <tree>
     101              : {
     102              :   typedef tree value_type; /* A DECL.  */
     103              :   typedef tree compare_type; /* An identifier.  */
     104              : 
     105    662299479 :   static hashval_t hash (const value_type decl)
     106              :   {
     107    662299479 :     return IDENTIFIER_HASH_VALUE (DECL_ASSEMBLER_NAME_RAW (decl));
     108              :   }
     109    659257856 :   static bool equal (const value_type existing, compare_type candidate)
     110              :   {
     111    659257856 :     tree name = DECL_ASSEMBLER_NAME_RAW (existing);
     112    659257856 :     return candidate == name;
     113              :   }
     114              : 
     115              :   static const bool empty_zero_p = true;
     116           18 :   static inline void mark_empty (value_type &p) {p = NULL_TREE;}
     117              :   static inline bool is_empty (value_type p) {return !p;}
     118              : 
     119    856560207 :   static bool is_deleted (value_type e)
     120              :   {
     121    856560207 :     return e == reinterpret_cast <value_type> (1);
     122              :   }
     123           75 :   static void mark_deleted (value_type &e)
     124              :   {
     125           75 :     e = reinterpret_cast <value_type> (1);
     126              :   }
     127              : };
     128              : 
     129              : /* A hash table of decls keyed by mangled name.  Used to figure out if
     130              :    we need compatibility aliases.  */
     131              : static GTY(()) hash_table<mangled_decl_hash> *mangled_decls;
     132              : 
     133              : // Hash table mapping priority to lists of variables or functions.
     134              : struct priority_map_traits
     135              : {
     136              :   typedef unsigned key_type;
     137              :   typedef tree value_type;
     138              :   static const bool maybe_mx = true;
     139              :   static hashval_t hash (key_type v)
     140              :   {
     141              :     return hashval_t (v);
     142              :   }
     143              :   static bool equal_keys (key_type k1, key_type k2)
     144              :   {
     145              :     return k1 == k2;
     146              :   }
     147              :   template <typename T> static void remove (T &)
     148              :   {
     149              :   }
     150              :   // Zero is not a priority
     151              :   static const bool empty_zero_p = true;
     152       516819 :   template <typename T> static bool is_empty (const T &entry)
     153              :   {
     154       516819 :     return entry.m_key == 0;
     155              :   }
     156            0 :   template <typename T> static void mark_empty (T &entry)
     157              :   {
     158            0 :     entry.m_key = 0;
     159              :   }
     160              :   // Entries are not deleteable
     161              :   template <typename T> static bool is_deleted (const T &)
     162              :   {
     163              :     return false;
     164              :   }
     165              :   template <typename T> static void mark_deleted (T &)
     166              :   {
     167              :     gcc_unreachable ();
     168              :   }
     169              : };
     170              : 
     171              : typedef hash_map<unsigned/*Priority*/, tree/*List*/,
     172              :                  priority_map_traits> priority_map_t;
     173              : 
     174              : /* Two pairs of such hash tables, for the host and an OpenMP offload device.
     175              :    Each pair has one priority map for fini and one for init.  The fini tables
     176              :    are only ever used when !cxa_atexit.  */
     177              : static GTY(()) priority_map_t *static_init_fini_fns[4];
     178              : 
     179              : /* Nonzero if we're done parsing and into end-of-file activities.
     180              :    2 if all templates have been instantiated.
     181              :    3 if we're done with front-end processing.  */
     182              : 
     183              : int at_eof;
     184              : 
     185              : /* True if note_mangling_alias should enqueue mangling aliases for
     186              :    later generation, rather than emitting them right away.  */
     187              : 
     188              : bool defer_mangling_aliases = true;
     189              : 
     190              : 
     191              : /* Return a member function type (a METHOD_TYPE), given FNTYPE (a
     192              :    FUNCTION_TYPE), CTYPE (class type), and QUALS (the cv-qualifiers
     193              :    that apply to the function).  */
     194              : 
     195              : tree
     196    101314445 : build_memfn_type (tree fntype, tree ctype, cp_cv_quals quals,
     197              :                   cp_ref_qualifier rqual)
     198              : {
     199    101314445 :   if (fntype == error_mark_node || ctype == error_mark_node)
     200              :     return error_mark_node;
     201              : 
     202    101314442 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
     203              : 
     204    101314442 :   cp_cv_quals type_quals = quals & ~TYPE_QUAL_RESTRICT;
     205    101314442 :   ctype = cp_build_qualified_type (ctype, type_quals);
     206              : 
     207    101314442 :   tree newtype
     208    101314442 :     = build_method_type_directly (ctype, TREE_TYPE (fntype),
     209    101314442 :                                   (TREE_CODE (fntype) == METHOD_TYPE
     210        58067 :                                    ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
     211    101256375 :                                    : TYPE_ARG_TYPES (fntype)));
     212    101314442 :   if (tree attrs = TYPE_ATTRIBUTES (fntype))
     213           71 :     newtype = cp_build_type_attribute_variant (newtype, attrs);
     214    303943326 :   newtype = build_cp_fntype_variant (newtype, rqual,
     215    101314442 :                                      TYPE_RAISES_EXCEPTIONS (fntype),
     216    101314442 :                                      TYPE_HAS_LATE_RETURN_TYPE (fntype));
     217              : 
     218    101314442 :   return newtype;
     219              : }
     220              : 
     221              : /* Return a variant of FNTYPE, a FUNCTION_TYPE or METHOD_TYPE, with its
     222              :    return type changed to NEW_RET.  */
     223              : 
     224              : tree
     225      2234875 : change_return_type (tree new_ret, tree fntype)
     226              : {
     227      2234875 :   if (new_ret == error_mark_node)
     228              :     return fntype;
     229              : 
     230      2234875 :   if (same_type_p (new_ret, TREE_TYPE (fntype)))
     231              :     return fntype;
     232              : 
     233      2234872 :   tree newtype;
     234      2234872 :   tree args = TYPE_ARG_TYPES (fntype);
     235              : 
     236      2234872 :   if (TREE_CODE (fntype) == FUNCTION_TYPE)
     237              :     {
     238      1221369 :       newtype = build_function_type (new_ret, args,
     239       407123 :                                      TYPE_NO_NAMED_ARGS_STDARG_P (fntype));
     240       407123 :       newtype = apply_memfn_quals (newtype,
     241              :                                    type_memfn_quals (fntype));
     242              :     }
     243              :   else
     244      1827749 :     newtype = build_method_type_directly
     245      1827749 :       (class_of_this_parm (fntype), new_ret, TREE_CHAIN (args));
     246              : 
     247      2234872 :   if (tree attrs = TYPE_ATTRIBUTES (fntype))
     248           92 :     newtype = cp_build_type_attribute_variant (newtype, attrs);
     249      2234872 :   newtype = cxx_copy_lang_qualifiers (newtype, fntype);
     250              : 
     251      2234872 :   return newtype;
     252              : }
     253              : 
     254              : /* Build a PARM_DECL of FN with NAME and TYPE, and set DECL_ARG_TYPE
     255              :    appropriately.  */
     256              : 
     257              : tree
     258    546102905 : cp_build_parm_decl (tree fn, tree name, tree type)
     259              : {
     260    546102905 :   tree parm = build_decl (input_location,
     261              :                           PARM_DECL, name, type);
     262    546102905 :   DECL_CONTEXT (parm) = fn;
     263              : 
     264              :   /* DECL_ARG_TYPE is only used by the back end and the back end never
     265              :      sees templates.  */
     266    546102905 :   if (!processing_template_decl)
     267    195236246 :     DECL_ARG_TYPE (parm) = type_passed_as (type);
     268              : 
     269    546102905 :   return parm;
     270              : }
     271              : 
     272              : /* Returns a PARM_DECL of FN for a parameter of the indicated TYPE, with the
     273              :    indicated NAME.  */
     274              : 
     275              : tree
     276    239115430 : build_artificial_parm (tree fn, tree name, tree type)
     277              : {
     278    239115430 :   tree parm = cp_build_parm_decl (fn, name, type);
     279    239115430 :   DECL_ARTIFICIAL (parm) = 1;
     280              :   /* All our artificial parms are implicitly `const'; they cannot be
     281              :      assigned to.  */
     282    239115430 :   TREE_READONLY (parm) = 1;
     283    239115430 :   return parm;
     284              : }
     285              : 
     286              : /* 'structors for types with virtual baseclasses need an "in-charge" flag
     287              :    saying whether this function is responsible for virtual baseclasses or not.
     288              : 
     289              :    This function adds the "in-charge" flag to member function FN if
     290              :    appropriate.  It is called from grokclassfn and tsubst.
     291              :    FN must be either a constructor or destructor.
     292              : 
     293              :    The in-charge flag follows the 'this' parameter, and is followed by the
     294              :    VTT parm (if any), then the user-written parms.  */
     295              : 
     296              : void
     297     84932036 : maybe_retrofit_in_chrg (tree fn)
     298              : {
     299     84932036 :   tree basetype, arg_types, parms, parm, fntype;
     300              : 
     301              :   /* If we've already add the in-charge parameter don't do it again.  */
     302     84932036 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
     303              :     return;
     304              : 
     305              :   /* When processing templates we can't know, in general, whether or
     306              :      not we're going to have virtual baseclasses.  */
     307     84932036 :   if (processing_template_decl)
     308              :     return;
     309              : 
     310              :   /* We don't need an in-charge parameter for 'structors that don't
     311              :      have virtual bases.  */
     312     56066632 :   if (!CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
     313              :     return;
     314              : 
     315      1122136 :   arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn));
     316      1122136 :   basetype = TREE_TYPE (TREE_VALUE (arg_types));
     317      1122136 :   arg_types = TREE_CHAIN (arg_types);
     318              : 
     319      1122136 :   parms = DECL_CHAIN (DECL_ARGUMENTS (fn));
     320              : 
     321              :   /* If this is a subobject constructor or destructor, our caller will
     322              :      pass us a pointer to our VTT.  */
     323      1122136 :   if (CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
     324              :     {
     325      1122136 :       parm = build_artificial_parm (fn, vtt_parm_identifier, vtt_parm_type);
     326              : 
     327              :       /* First add it to DECL_ARGUMENTS between 'this' and the real args...  */
     328      1122136 :       DECL_CHAIN (parm) = parms;
     329      1122136 :       parms = parm;
     330              : 
     331              :       /* ...and then to TYPE_ARG_TYPES.  */
     332      1122136 :       arg_types = hash_tree_chain (vtt_parm_type, arg_types);
     333              : 
     334      1122136 :       DECL_HAS_VTT_PARM_P (fn) = 1;
     335              :     }
     336              : 
     337              :   /* Then add the in-charge parm (before the VTT parm).  */
     338      1122136 :   parm = build_artificial_parm (fn, in_charge_identifier, integer_type_node);
     339      1122136 :   DECL_CHAIN (parm) = parms;
     340      1122136 :   parms = parm;
     341      1122136 :   arg_types = hash_tree_chain (integer_type_node, arg_types);
     342              : 
     343              :   /* Insert our new parameter(s) into the list.  */
     344      1122136 :   DECL_CHAIN (DECL_ARGUMENTS (fn)) = parms;
     345              : 
     346              :   /* And rebuild the function type.  */
     347      1122136 :   fntype = build_method_type_directly (basetype, TREE_TYPE (TREE_TYPE (fn)),
     348              :                                        arg_types);
     349      1122136 :   if (TYPE_ATTRIBUTES (TREE_TYPE (fn)))
     350            3 :     fntype = (cp_build_type_attribute_variant
     351            3 :               (fntype, TYPE_ATTRIBUTES (TREE_TYPE (fn))));
     352      1122136 :   fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (fn));
     353      1122136 :   TREE_TYPE (fn) = fntype;
     354              : 
     355              :   /* Now we've got the in-charge parameter.  */
     356      1122136 :   DECL_HAS_IN_CHARGE_PARM_P (fn) = 1;
     357              : }
     358              : 
     359              : /* Classes overload their constituent function names automatically.
     360              :    When a function name is declared in a record structure,
     361              :    its name is changed to it overloaded name.  Since names for
     362              :    constructors and destructors can conflict, we place a leading
     363              :    '$' for destructors.
     364              : 
     365              :    CNAME is the name of the class we are grokking for.
     366              : 
     367              :    FUNCTION is a FUNCTION_DECL.  It was created by `grokdeclarator'.
     368              : 
     369              :    FLAGS contains bits saying what's special about today's
     370              :    arguments.  DTOR_FLAG == DESTRUCTOR.
     371              : 
     372              :    If FUNCTION is a destructor, then we must add the `auto-delete' field
     373              :    as a second parameter.  There is some hair associated with the fact
     374              :    that we must "declare" this variable in the manner consistent with the
     375              :    way the rest of the arguments were declared.
     376              : 
     377              :    QUALS are the qualifiers for the this pointer.  */
     378              : 
     379              : void
     380    145247256 : grokclassfn (tree ctype, tree function, enum overload_flags flags)
     381              : {
     382    145247256 :   tree fn_name = DECL_NAME (function);
     383              : 
     384              :   /* Even within an `extern "C"' block, members get C++ linkage.  See
     385              :      [dcl.link] for details.  */
     386    145247256 :   SET_DECL_LANGUAGE (function, lang_cplusplus);
     387              : 
     388    145247256 :   if (fn_name == NULL_TREE)
     389              :     {
     390            0 :       error ("name missing for member function");
     391            0 :       fn_name = get_identifier ("<anonymous>");
     392            0 :       DECL_NAME (function) = fn_name;
     393              :     }
     394              : 
     395    145247256 :   DECL_CONTEXT (function) = ctype;
     396              : 
     397    145247256 :   if (flags == DTOR_FLAG)
     398     12187138 :     DECL_CXX_DESTRUCTOR_P (function) = 1;
     399              : 
     400    278307374 :   if (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))
     401     57425423 :     maybe_retrofit_in_chrg (function);
     402    145247256 : }
     403              : 
     404              : /* Create an ARRAY_REF, checking for the user doing things backwards
     405              :    along the way.
     406              :    If INDEX_EXP is non-NULL, then that is the index expression,
     407              :    otherwise INDEX_EXP_LIST is the list of index expressions.  */
     408              : 
     409              : tree
     410     11350991 : grok_array_decl (location_t loc, tree array_expr, tree index_exp,
     411              :                  vec<tree, va_gc> **index_exp_list, tsubst_flags_t complain)
     412              : {
     413     11350991 :   tree type;
     414     11350991 :   tree expr;
     415     11350991 :   tree orig_array_expr = array_expr;
     416     11350991 :   tree orig_index_exp = index_exp;
     417     11341768 :   vec<tree, va_gc> *orig_index_exp_list
     418     11350991 :     = index_exp_list ? *index_exp_list : NULL;
     419     11350991 :   tree overload = NULL_TREE;
     420              : 
     421     11350991 :   if (error_operand_p (array_expr) || error_operand_p (index_exp))
     422           80 :     return error_mark_node;
     423              : 
     424     11350911 :   if (processing_template_decl)
     425              :     {
     426      9714083 :       if (type_dependent_expression_p (array_expr)
     427      9714109 :           || (index_exp ? type_dependent_expression_p (index_exp)
     428           26 :                         : any_type_dependent_arguments_p (*index_exp_list)))
     429              :         {
     430      7879402 :           if (index_exp == NULL)
     431         1597 :             index_exp = build_min_nt_call_vec (ovl_op_identifier (ARRAY_REF),
     432              :                                                *index_exp_list);
     433      7879402 :           return build_min_nt_loc (loc, ARRAY_REF, array_expr, index_exp,
     434      7879402 :                                    NULL_TREE, NULL_TREE);
     435              :         }
     436      1834681 :       if (!index_exp)
     437           25 :         orig_index_exp_list = make_tree_vector_copy (*index_exp_list);
     438              :     }
     439              : 
     440      3471509 :   type = TREE_TYPE (array_expr);
     441      3471509 :   gcc_assert (type);
     442      3471509 :   type = non_reference (type);
     443              : 
     444              :   /* If they have an `operator[]', use that.  */
     445      3471509 :   if (MAYBE_CLASS_TYPE_P (type)
     446      3147578 :       || (index_exp && MAYBE_CLASS_TYPE_P (TREE_TYPE (index_exp)))
     447              :       || (index_exp == NULL_TREE
     448           56 :           && !(*index_exp_list)->is_empty ()
     449           51 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE ((*index_exp_list)->last ()))))
     450              :     {
     451       323974 :       if (index_exp)
     452       323710 :         expr = build_new_op (loc, ARRAY_REF, LOOKUP_NORMAL, array_expr,
     453              :                              index_exp, NULL_TREE, NULL_TREE,
     454              :                              &overload, complain);
     455          264 :       else if ((*index_exp_list)->is_empty ())
     456           97 :         expr = build_op_subscript (loc, array_expr, index_exp_list, &overload,
     457              :                                    complain);
     458              :       else
     459              :         {
     460          167 :           expr = build_op_subscript (loc, array_expr, index_exp_list,
     461              :                                      &overload, complain & tf_decltype);
     462          167 :           if (expr == error_mark_node
     463              :               /* Don't do the backward compatibility fallback in a SFINAE
     464              :                  context.   */
     465           18 :               && (complain & tf_error))
     466              :             {
     467           10 :               tree idx = build_x_compound_expr_from_vec (*index_exp_list, NULL,
     468              :                                                          tf_none);
     469           10 :               if (idx != error_mark_node)
     470           10 :                 expr = build_new_op (loc, ARRAY_REF, LOOKUP_NORMAL, array_expr,
     471              :                                      idx, NULL_TREE, NULL_TREE, &overload,
     472              :                                      complain & tf_decltype);
     473           10 :               if (expr == error_mark_node)
     474              :                 {
     475            1 :                   overload = NULL_TREE;
     476            1 :                   expr = build_op_subscript (loc, array_expr, index_exp_list,
     477              :                                              &overload, complain);
     478              :                 }
     479              :               else
     480              :                 {
     481              :                   /* If it would be valid albeit deprecated expression in
     482              :                      C++20, just pedwarn on it and treat it as if wrapped
     483              :                      in ().  */
     484            9 :                   pedwarn (loc, OPT_Wcomma_subscript,
     485              :                            "top-level comma expression in array subscript "
     486              :                            "changed meaning in C++23");
     487            9 :                   if (processing_template_decl)
     488              :                     {
     489            2 :                       orig_index_exp
     490            2 :                         = build_x_compound_expr_from_vec (orig_index_exp_list,
     491              :                                                           NULL, complain);
     492            2 :                       if (orig_index_exp == error_mark_node)
     493            0 :                         expr = error_mark_node;
     494            2 :                       release_tree_vector (orig_index_exp_list);
     495              :                     }
     496              :                 }
     497              :             }
     498              :         }
     499              :     }
     500              :   else
     501              :     {
     502      3147535 :       tree p1, p2, i1, i2;
     503      3147535 :       bool swapped = false;
     504              : 
     505              :       /* Otherwise, create an ARRAY_REF for a pointer or array type.
     506              :          It is a little-known fact that, if `a' is an array and `i' is
     507              :          an int, you can write `i[a]', which means the same thing as
     508              :          `a[i]'.  */
     509      3147535 :       if (TREE_CODE (type) == ARRAY_TYPE || VECTOR_TYPE_P (type))
     510              :         p1 = array_expr;
     511              :       else
     512      2010902 :         p1 = build_expr_type_conversion (WANT_POINTER, array_expr, false);
     513              : 
     514      3147535 :       if (index_exp == NULL_TREE)
     515              :         {
     516           56 :           if (!(complain & tf_error))
     517              :             /* Don't do the backward compatibility fallback in a SFINAE
     518              :                context.  */
     519            8 :             return error_mark_node;
     520              : 
     521           48 :           if ((*index_exp_list)->is_empty ())
     522              :             {
     523            1 :               error_at (loc, "built-in subscript operator without expression "
     524              :                              "list");
     525            1 :               return error_mark_node;
     526              :             }
     527           47 :           tree idx = build_x_compound_expr_from_vec (*index_exp_list, NULL,
     528              :                                                      tf_none);
     529           47 :           if (idx != error_mark_node)
     530              :             /* If it would be valid albeit deprecated expression in C++20,
     531              :                just pedwarn on it and treat it as if wrapped in ().  */
     532           47 :             pedwarn (loc, OPT_Wcomma_subscript,
     533              :                      "top-level comma expression in array subscript "
     534              :                      "changed meaning in C++23");
     535              :           else
     536              :             {
     537            0 :               error_at (loc, "built-in subscript operator with more than one "
     538              :                              "expression in expression list");
     539            0 :               return error_mark_node;
     540              :             }
     541           47 :           index_exp = idx;
     542           47 :           if (processing_template_decl)
     543              :             {
     544            1 :               orig_index_exp
     545            1 :                 = build_x_compound_expr_from_vec (orig_index_exp_list,
     546              :                                                   NULL, complain);
     547            1 :               release_tree_vector (orig_index_exp_list);
     548            1 :               if (orig_index_exp == error_mark_node)
     549              :                 return error_mark_node;
     550              :             }
     551              :         }
     552              : 
     553      3147526 :       if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
     554              :         p2 = index_exp;
     555              :       else
     556      3147490 :         p2 = build_expr_type_conversion (WANT_POINTER, index_exp, false);
     557              : 
     558      3147526 :       i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr,
     559              :                                        false);
     560      3147526 :       i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp,
     561              :                                        false);
     562              : 
     563      3147526 :       if ((p1 && i2) && (i1 && p2))
     564            0 :         error ("ambiguous conversion for array subscript");
     565              : 
     566      3147526 :       if (p1 && i2)
     567              :         array_expr = p1, index_exp = i2;
     568           80 :       else if (i1 && p2)
     569              :         swapped = true, array_expr = p2, index_exp = i1;
     570              :       else
     571              :         {
     572           29 :           if (complain & tf_error)
     573           25 :             error_at (loc, "invalid types %<%T[%T]%> for array subscript",
     574           25 :                       type, TREE_TYPE (index_exp));
     575           29 :           return error_mark_node;
     576              :         }
     577              : 
     578      3147497 :       if (array_expr == error_mark_node || index_exp == error_mark_node)
     579            0 :         error ("ambiguous conversion for array subscript");
     580              : 
     581      3147497 :       if (TYPE_PTR_P (TREE_TYPE (array_expr)))
     582      2010854 :         array_expr = mark_rvalue_use (array_expr);
     583              :       else
     584      1136643 :         array_expr = mark_lvalue_use_nonread (array_expr);
     585      3147497 :       index_exp = mark_rvalue_use (index_exp);
     586      3147497 :       if (swapped
     587           51 :           && flag_strong_eval_order == 2
     588      3147541 :           && (TREE_SIDE_EFFECTS (array_expr) || TREE_SIDE_EFFECTS (index_exp)))
     589           18 :         expr = build_array_ref (input_location, index_exp, array_expr);
     590              :       else
     591      3147479 :         expr = build_array_ref (input_location, array_expr, index_exp);
     592              :     }
     593      3471471 :   if (processing_template_decl && expr != error_mark_node)
     594              :     {
     595      1834681 :       if (overload != NULL_TREE)
     596              :         {
     597       263119 :           if (orig_index_exp == NULL_TREE)
     598              :             {
     599           22 :               expr = build_min_non_dep_op_overload (expr, overload,
     600              :                                                     orig_array_expr,
     601              :                                                     orig_index_exp_list);
     602           22 :               release_tree_vector (orig_index_exp_list);
     603           22 :               return expr;
     604              :             }
     605       263097 :           return build_min_non_dep_op_overload (ARRAY_REF, expr, overload,
     606              :                                                 orig_array_expr,
     607       263097 :                                                 orig_index_exp);
     608              :         }
     609              : 
     610      1571562 :       if (orig_index_exp == NULL_TREE)
     611              :         {
     612            0 :           orig_index_exp
     613            0 :             = build_min_nt_call_vec (ovl_op_identifier (ARRAY_REF),
     614              :                                      orig_index_exp_list);
     615            0 :           release_tree_vector (orig_index_exp_list);
     616              :         }
     617              : 
     618      1571562 :       return build_min_non_dep (ARRAY_REF, expr, orig_array_expr,
     619      1571562 :                                 orig_index_exp, NULL_TREE, NULL_TREE);
     620              :     }
     621              :   return expr;
     622              : }
     623              : 
     624              : /* Build an OMP_ARRAY_SECTION expression, handling usage in template
     625              :    definitions, etc.  */
     626              : 
     627              : tree
     628         4800 : grok_omp_array_section (location_t loc, tree array_expr, tree index,
     629              :                         tree length)
     630              : {
     631         4800 :   tree orig_array_expr = array_expr;
     632         4800 :   tree orig_index = index;
     633         4800 :   tree orig_length = length;
     634              : 
     635         4800 :   if (error_operand_p (array_expr)
     636         4791 :       || error_operand_p (index)
     637         9591 :       || error_operand_p (length))
     638            9 :     return error_mark_node;
     639              : 
     640         4791 :   if (processing_template_decl
     641         4791 :       && (type_dependent_expression_p (array_expr)
     642          757 :           || type_dependent_expression_p (index)
     643          741 :           || type_dependent_expression_p (length)))
     644          930 :     return build_min_nt_loc (loc, OMP_ARRAY_SECTION, array_expr, index, length);
     645              : 
     646         3861 :   index = fold_non_dependent_expr (index);
     647         3861 :   length = fold_non_dependent_expr (length);
     648              : 
     649              :   /* NOTE: We can pass through invalidly-typed index/length fields
     650              :      here (e.g. if the user tries to use a floating-point index/length).
     651              :      This is diagnosed later in semantics.cc:handle_omp_array_sections_1.  */
     652              : 
     653         3861 :   tree expr = build_omp_array_section (loc, array_expr, index, length);
     654              : 
     655         3861 :   if (processing_template_decl)
     656          741 :     expr = build_min_non_dep (OMP_ARRAY_SECTION, expr, orig_array_expr,
     657              :                               orig_index, orig_length);
     658              :   return expr;
     659              : }
     660              : 
     661              : /* Given the cast expression EXP, checking out its validity.   Either return
     662              :    an error_mark_node if there was an unavoidable error, return a cast to
     663              :    void for trying to delete a pointer w/ the value 0, or return the
     664              :    call to delete.  If DOING_VEC is true, we handle things differently
     665              :    for doing an array delete.
     666              :    Implements ARM $5.3.4.  This is called from the parser.  */
     667              : 
     668              : tree
     669       559181 : delete_sanity (location_t loc, tree exp, tree size, bool doing_vec,
     670              :                int use_global_delete, tsubst_flags_t complain)
     671              : {
     672       559181 :   tree t, type;
     673              : 
     674       559181 :   if (exp == error_mark_node)
     675              :     return exp;
     676              : 
     677       559064 :   if (processing_template_decl)
     678              :     {
     679       435393 :       t = build_min (DELETE_EXPR, void_type_node, exp, size);
     680       435393 :       DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
     681       435393 :       DELETE_EXPR_USE_VEC (t) = doing_vec;
     682       435393 :       TREE_SIDE_EFFECTS (t) = 1;
     683       435393 :       SET_EXPR_LOCATION (t, loc);
     684       435393 :       return t;
     685              :     }
     686              : 
     687       123671 :   location_t exp_loc = cp_expr_loc_or_loc (exp, loc);
     688              : 
     689              :   /* An array can't have been allocated by new, so complain.  */
     690       123671 :   if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
     691       123671 :       && (complain & tf_warning))
     692           21 :     warning_at (exp_loc, 0, "deleting array %q#E", exp);
     693              : 
     694       123671 :   t = build_expr_type_conversion (WANT_POINTER, exp, true);
     695              : 
     696       123671 :   if (t == NULL_TREE || t == error_mark_node)
     697              :     {
     698           21 :       if (complain & tf_error)
     699           21 :         error_at (exp_loc,
     700              :                   "type %q#T argument given to %<delete%>, expected pointer",
     701           21 :                   TREE_TYPE (exp));
     702           21 :       return error_mark_node;
     703              :     }
     704              : 
     705       123650 :   type = TREE_TYPE (t);
     706              : 
     707              :   /* As of Valley Forge, you can delete a pointer to const.  */
     708              : 
     709              :   /* You can't delete functions.  */
     710       123650 :   if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
     711              :     {
     712            6 :       if (complain & tf_error)
     713            6 :         error_at (exp_loc,
     714              :                   "cannot delete a function.  Only pointer-to-objects are "
     715              :                   "valid arguments to %<delete%>");
     716            6 :       return error_mark_node;
     717              :     }
     718              : 
     719              :   /* Deleting ptr to void is undefined behavior [expr.delete/3].  */
     720       123644 :   if (VOID_TYPE_P (TREE_TYPE (type)))
     721              :     {
     722           19 :       if (complain & tf_warning)
     723           19 :         warning_at (exp_loc, OPT_Wdelete_incomplete,
     724              :                     "deleting %qT is undefined", type);
     725              :       doing_vec = 0;
     726              :     }
     727              : 
     728              :   /* Deleting a pointer with the value zero is valid and has no effect.  */
     729       123644 :   if (integer_zerop (t))
     730            3 :     return build1_loc (loc, NOP_EXPR, void_type_node, t);
     731              : 
     732       123641 :   if (doing_vec)
     733        20983 :     return build_vec_delete (loc, t, /*maxindex=*/NULL_TREE,
     734              :                              sfk_deleting_destructor,
     735        20983 :                              use_global_delete, complain);
     736              :   else
     737       102658 :     return build_delete (loc, type, t, sfk_deleting_destructor,
     738              :                          LOOKUP_NORMAL, use_global_delete,
     739       102658 :                          complain);
     740              : }
     741              : 
     742              : /* Report an error if the indicated template declaration is not the
     743              :    sort of thing that should be a member template.  */
     744              : 
     745              : void
     746     21650711 : check_member_template (tree tmpl)
     747              : {
     748     21650711 :   tree decl;
     749              : 
     750     21650711 :   gcc_assert (TREE_CODE (tmpl) == TEMPLATE_DECL);
     751     21650711 :   decl = DECL_TEMPLATE_RESULT (tmpl);
     752              : 
     753     21650711 :   if (TREE_CODE (decl) == FUNCTION_DECL
     754      2272887 :       || DECL_ALIAS_TEMPLATE_P (tmpl)
     755     22711567 :       || (TREE_CODE (decl) == TYPE_DECL
     756       728653 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE (decl))))
     757              :     {
     758              :       /* The parser rejects template declarations in local classes
     759              :          (with the exception of generic lambdas).  */
     760     21738960 :       gcc_assert (!current_function_decl || LAMBDA_FUNCTION_P (decl));
     761              :       /* The parser rejects any use of virtual in a function template.  */
     762     21318508 :       gcc_assert (!(TREE_CODE (decl) == FUNCTION_DECL
     763              :                     && DECL_VIRTUAL_P (decl)));
     764              : 
     765              :       /* The debug-information generating code doesn't know what to do
     766              :          with member templates.  */
     767     21318508 :       DECL_IGNORED_P (tmpl) = 1;
     768              :     }
     769       332203 :   else if (variable_template_p (tmpl))
     770              :     /* OK */;
     771              :   else
     772            0 :     error ("template declaration of %q#D", decl);
     773     21650711 : }
     774              : 
     775              : /* A struct for conveniently working with the parameter types of a
     776              :    fndecl.  */
     777              : 
     778          276 : struct fndecl_signature
     779              : {
     780          184 :   fndecl_signature (tree fndecl)
     781          184 :   : m_fndecl (fndecl),
     782          184 :     m_num_artificial_parms (num_artificial_parms_for (fndecl)),
     783          184 :     m_variadic (true)
     784              :   {
     785          184 :     function_args_iterator iter;
     786          184 :     tree argtype;
     787          615 :     FOREACH_FUNCTION_ARGS (TREE_TYPE (fndecl), argtype, iter)
     788              :       {
     789              :         /* A trailing "void" type means that FNDECL is non-variadic.  */
     790          603 :         if (VOID_TYPE_P (argtype))
     791              :           {
     792          172 :             gcc_assert (!TREE_CHAIN (iter.next));
     793          172 :             m_variadic = false;
     794          172 :             break;
     795              :           }
     796          431 :         m_parm_types.safe_push (argtype);
     797              :       }
     798          368 :     gcc_assert (m_parm_types.length () >= (size_t)m_num_artificial_parms);
     799          184 :     m_num_user_parms = m_parm_types.length () - m_num_artificial_parms;
     800          184 :   }
     801              : 
     802              :   /* Convert from index within DECL_ARGUMENTS to 0-based user-written
     803              :      parameter, or -1 for "this".  */
     804              :   int
     805           88 :   get_argno_from_idx (size_t idx) const
     806              :   {
     807           88 :     return static_cast<int> (idx) - m_num_artificial_parms;
     808              :   }
     809              : 
     810              :   location_t
     811           88 :   get_argno_location (int argno) const
     812              :   {
     813           88 :     return get_fndecl_argument_location (m_fndecl, argno);
     814              :   }
     815              : 
     816              :   tree m_fndecl;
     817              :   int m_num_artificial_parms;
     818              :   auto_vec<tree> m_parm_types;
     819              :   size_t m_num_user_parms;
     820              :   bool m_variadic;
     821              : };
     822              : 
     823              : /* A rich_location subclass that highlights a given argno
     824              :    within FNDECL_SIG using HIGHLIGHT_COLOR in the quoted source.  */
     825              : 
     826          132 : class parm_rich_location : public gcc_rich_location
     827              : {
     828              : public:
     829           88 :   parm_rich_location (const fndecl_signature &fndecl_sig,
     830              :                       int argno,
     831              :                       const char *highlight_color)
     832           88 :   : gcc_rich_location (fndecl_sig.get_argno_location (argno),
     833              :                        nullptr,
     834           88 :                        highlight_color)
     835              :   {
     836           88 :   }
     837              : };
     838              : 
     839              : /* A class for comparing a pair of fndecls and emitting diagnostic notes
     840              :    about the differences between them, if they are sufficiently close.  */
     841              : 
     842           92 : class fndecl_comparison
     843              : {
     844              : public:
     845           92 :   fndecl_comparison (tree decl_a,
     846              :                      tree decl_b)
     847           92 :   : m_decl_a (decl_a),
     848           92 :     m_decl_b (decl_b)
     849              :   {
     850           92 :     gcc_assert (TREE_CODE (decl_a) == FUNCTION_DECL);
     851           92 :     gcc_assert (TREE_CODE (decl_b) == FUNCTION_DECL);
     852           92 :   }
     853              : 
     854              :   /* Attempt to emit diagnostic notes describing the differences between
     855              :      the fndecls, when they are a sufficiently close match.  */
     856              :   void
     857           92 :   maybe_emit_notes_for_close_match () const
     858              :   {
     859              :     /* If there's a difference in "variadicness", don't attempt to emit
     860              :        any notes.  */
     861           92 :     if (m_decl_a.m_variadic != m_decl_b.m_variadic)
     862           12 :       return;
     863              : 
     864           80 :     auto_vec<parm_difference> differences = get_differences ();
     865          124 :     if (differences.length () == 1)
     866              :       {
     867           44 :         auto_diagnostic_nesting_level sentinel;
     868           44 :         print_parm_type_difference (differences[0]);
     869           44 :       }
     870           80 :   }
     871              : 
     872              : private:
     873              :   struct parm_difference
     874              :   {
     875              :     size_t m_parm_idx_a;
     876              :     size_t m_parm_idx_b;
     877              :   };
     878              : 
     879              :   /* If we have a close match, return the differences between the two
     880              :      fndecls.  Otherwise return an empty vector.  */
     881              :   auto_vec<parm_difference>
     882           80 :   get_differences () const
     883              :   {
     884           80 :     auto_vec<parm_difference> differences;
     885              : 
     886              :     /* For now, just handle the case where the "user parm" count is
     887              :        equal.  */
     888           80 :     if (m_decl_a.m_num_user_parms != m_decl_b.m_num_user_parms)
     889              :       return differences;
     890              : 
     891              :     /* Ideally we'd check the edit distance, and thus report on close
     892              :        matches which are missing a param, have transposed params, etc.
     893              :        For now, just iterate through the params, finding differences
     894              :        elementwise.  */
     895              : 
     896              :     /* Find differences in artificial params, if they are comparable.
     897              :        This should find e.g. const vs non-const differences in "this".  */
     898           65 :     if (m_decl_a.m_num_artificial_parms == m_decl_b.m_num_artificial_parms)
     899           62 :       for (int parm_idx = 0;
     900          124 :            parm_idx < m_decl_a.m_num_artificial_parms;
     901              :            ++parm_idx)
     902           62 :         compare (parm_idx, parm_idx, differences);
     903              : 
     904              :     /* Find differences in user-provided params.  */
     905           74 :     for (size_t user_parm_idx = 0;
     906          139 :          user_parm_idx < m_decl_a.m_num_user_parms;
     907              :          ++user_parm_idx)
     908              :       {
     909           74 :         const size_t idx_a = m_decl_a.m_num_artificial_parms + user_parm_idx;
     910           74 :         const size_t idx_b = m_decl_b.m_num_artificial_parms + user_parm_idx;
     911           74 :         compare (idx_a, idx_b, differences);
     912              :       }
     913              : 
     914              :     return differences;
     915              :   }
     916              : 
     917              :   void
     918          136 :   compare (size_t idx_a, size_t idx_b,
     919              :            auto_vec<parm_difference> &differences) const
     920              :   {
     921          136 :     if (!same_type_p (m_decl_a.m_parm_types[idx_a],
     922              :                       m_decl_b.m_parm_types[idx_b]))
     923           44 :       differences.safe_push (parm_difference {idx_a, idx_b});
     924          136 :   }
     925              : 
     926              :   void
     927           44 :   print_parm_type_difference (const parm_difference &diff) const
     928              :   {
     929           44 :     const char * const highlight_a = "highlight-a";
     930           44 :     pp_markup::element_quoted_type type_of_parm_a
     931           44 :       (m_decl_a.m_parm_types[diff.m_parm_idx_a],
     932           44 :        highlight_a);
     933           44 :     const int argno_a = m_decl_a.get_argno_from_idx (diff.m_parm_idx_a);
     934           44 :     parm_rich_location rich_loc_a (m_decl_a, argno_a, highlight_a);
     935           44 :     inform (&rich_loc_a,
     936              :             "parameter %P of candidate has type %e...",
     937              :             argno_a, &type_of_parm_a);
     938              : 
     939           44 :     const char * const highlight_b = "highlight-b";
     940           44 :     pp_markup::element_quoted_type type_of_parm_b
     941           44 :       (m_decl_b.m_parm_types[diff.m_parm_idx_b],
     942           44 :        highlight_b);
     943           44 :     const int argno_b = m_decl_b.get_argno_from_idx (diff.m_parm_idx_b);
     944           44 :     parm_rich_location rich_loc_b (m_decl_b, argno_b, highlight_b);
     945           44 :     inform (&rich_loc_b,
     946              :             "...which does not match type %e",
     947              :             &type_of_parm_b);
     948           44 :   }
     949              : 
     950              :   fndecl_signature m_decl_a;
     951              :   fndecl_signature m_decl_b;
     952              : };
     953              : 
     954           78 : class decl_mismatch_context : public candidate_context
     955              : {
     956              : public:
     957           78 :   decl_mismatch_context (tree function)
     958           78 :   : m_function (function)
     959              :   {
     960           78 :     gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
     961           78 :   }
     962              : 
     963              :   void
     964          101 :   emit_any_notes_for_candidate (tree cand) final override
     965              :   {
     966          101 :     if (TREE_CODE (cand) == FUNCTION_DECL)
     967              :       {
     968           92 :         fndecl_comparison diff (cand, m_function);
     969           92 :         diff.maybe_emit_notes_for_close_match ();
     970           92 :       }
     971          101 :   }
     972              : private:
     973              :   tree m_function;
     974              : };
     975              : 
     976              : /* Sanity check: report error if this function FUNCTION is not
     977              :    really a member of the class (CTYPE) it is supposed to belong to.
     978              :    TEMPLATE_PARMS is used to specify the template parameters of a member
     979              :    template passed as FUNCTION_DECL. If the member template is passed as a
     980              :    TEMPLATE_DECL, it can be NULL since the parameters can be extracted
     981              :    from the declaration. If the function is not a function template, it
     982              :    must be NULL.
     983              :    It returns the original declaration for the function, NULL_TREE if
     984              :    no declaration was found, error_mark_node if an error was emitted.  */
     985              : 
     986              : tree
     987      9130504 : check_classfn (tree ctype, tree function, tree template_parms)
     988              : {
     989      9130504 :   if (DECL_USE_TEMPLATE (function)
     990      1185113 :       && !(TREE_CODE (function) == TEMPLATE_DECL
     991         1116 :            && DECL_TEMPLATE_SPECIALIZATION (function))
     992     10314501 :       && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (function)))
     993              :     /* Since this is a specialization of a member template,
     994              :        we're not going to find the declaration in the class.
     995              :        For example, in:
     996              : 
     997              :          struct S { template <typename T> void f(T); };
     998              :          template <> void S::f(int);
     999              : 
    1000              :        we're not going to find `S::f(int)', but there's no
    1001              :        reason we should, either.  We let our callers know we didn't
    1002              :        find the method, but we don't complain.  */
    1003              :     return NULL_TREE;
    1004              : 
    1005              :   /* Basic sanity check: for a template function, the template parameters
    1006              :      either were not passed, or they are the same of DECL_TEMPLATE_PARMS.  */
    1007      8742690 :   if (TREE_CODE (function) == TEMPLATE_DECL)
    1008              :     {
    1009         1134 :       if (template_parms
    1010         2250 :           && !comp_template_parms (template_parms,
    1011         1116 :                                    DECL_TEMPLATE_PARMS (function)))
    1012              :         {
    1013            0 :           error ("template parameter lists provided don%'t match the "
    1014              :                  "template parameters of %qD", function);
    1015            0 :           return error_mark_node;
    1016              :         }
    1017         1134 :       template_parms = DECL_TEMPLATE_PARMS (function);
    1018              :     }
    1019              : 
    1020              :   /* OK, is this a definition of a member template?  */
    1021      8742690 :   bool is_template = (template_parms != NULL_TREE);
    1022              : 
    1023              :   /* [temp.mem]
    1024              : 
    1025              :      A destructor shall not be a member template.  */
    1026     17485380 :   if (DECL_DESTRUCTOR_P (function) && is_template)
    1027              :     {
    1028            6 :       error ("destructor %qD declared as member template", function);
    1029            6 :       return error_mark_node;
    1030              :     }
    1031              : 
    1032              :   /* We must enter the scope here, because conversion operators are
    1033              :      named by target type, and type equivalence relies on typenames
    1034              :      resolving within the scope of CTYPE.  */
    1035      8742684 :   tree pushed_scope = push_scope (ctype);
    1036      8742684 :   tree matched = NULL_TREE;
    1037      8742684 :   tree fns = get_class_binding (ctype, DECL_NAME (function));
    1038      8742684 :   bool saw_template = false;
    1039              : 
    1040     35218880 :   for (ovl_iterator iter (fns); !matched && iter; ++iter)
    1041              :     {
    1042     15701432 :       tree fndecl = *iter;
    1043              : 
    1044     15701432 :       if (TREE_CODE (fndecl) == TEMPLATE_DECL)
    1045      3879208 :         saw_template = true;
    1046              : 
    1047              :       /* A member template definition only matches a member template
    1048              :          declaration.  */
    1049     15701432 :       if (is_template != (TREE_CODE (fndecl) == TEMPLATE_DECL))
    1050      1703613 :         continue;
    1051              : 
    1052     13997819 :       if (!DECL_DECLARES_FUNCTION_P (fndecl))
    1053       292897 :         continue;
    1054              : 
    1055     13704922 :       tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
    1056     13704922 :       tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
    1057              : 
    1058              :       /* We cannot simply call decls_match because this doesn't work
    1059              :          for static member functions that are pretending to be
    1060              :          methods, and because the name may have been changed by
    1061              :          asm("new_name").  */
    1062              : 
    1063              :       /* Get rid of the this parameter on functions that become
    1064              :          static.  */
    1065     13704922 :       if (DECL_STATIC_FUNCTION_P (fndecl)
    1066     13704922 :           && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
    1067       169364 :         p1 = TREE_CHAIN (p1);
    1068              : 
    1069              :       /* ref-qualifier or absence of same must match.  */
    1070     27409844 :       if (type_memfn_rqual (TREE_TYPE (function))
    1071     13704922 :           != type_memfn_rqual (TREE_TYPE (fndecl)))
    1072           86 :         continue;
    1073              : 
    1074              :       // Include constraints in the match.
    1075     13704836 :       tree c1 = get_constraints (function);
    1076     13704836 :       tree c2 = get_constraints (fndecl);
    1077              : 
    1078              :       /* While finding a match, same types and params are not enough
    1079              :          if the function is versioned.  Also check for different target
    1080              :          specific attributes.  */
    1081     13704836 :       if (same_type_p (TREE_TYPE (TREE_TYPE (function)),
    1082              :                        TREE_TYPE (TREE_TYPE (fndecl)))
    1083     12969579 :           && compparms (p1, p2)
    1084      8742612 :           && !disjoint_version_decls (function, fndecl)
    1085      8742612 :           && (!is_template
    1086      2125229 :               || comp_template_parms (template_parms,
    1087      2125229 :                                       DECL_TEMPLATE_PARMS (fndecl)))
    1088      8742606 :           && equivalent_constraints (c1, c2)
    1089      8742555 :           && (DECL_TEMPLATE_SPECIALIZATION (function)
    1090      8742555 :               == DECL_TEMPLATE_SPECIALIZATION (fndecl))
    1091     22447391 :           && (!DECL_TEMPLATE_SPECIALIZATION (function)
    1092       775933 :               || (DECL_TI_TEMPLATE (function) == DECL_TI_TEMPLATE (fndecl))))
    1093              :         matched = fndecl;
    1094              :     }
    1095              : 
    1096          114 :   if (!matched && !is_template && saw_template
    1097      8742699 :       && !processing_template_decl && DECL_UNIQUE_FRIEND_P (function))
    1098              :     {
    1099              :       /* "[if no non-template match is found,] each remaining function template
    1100              :          is replaced with the specialization chosen by deduction from the
    1101              :          friend declaration or discarded if deduction fails."
    1102              : 
    1103              :          So tell check_explicit_specialization to look for a match.  */
    1104            3 :       SET_DECL_IMPLICIT_INSTANTIATION (function);
    1105            3 :       DECL_TEMPLATE_INFO (function) = build_template_info (fns, NULL_TREE);
    1106            3 :       matched = function;
    1107              :     }
    1108              : 
    1109      8742684 :   if (!matched)
    1110              :     {
    1111          126 :       if (!COMPLETE_TYPE_P (ctype))
    1112            6 :         cxx_incomplete_type_error (DECL_SOURCE_LOCATION (function),
    1113              :                                    function, ctype);
    1114              :       else
    1115              :         {
    1116          120 :           if (DECL_CONV_FN_P (function))
    1117            6 :             fns = get_class_binding (ctype, conv_op_identifier);
    1118              : 
    1119          120 :           auto_diagnostic_group d;
    1120          120 :           error_at (DECL_SOURCE_LOCATION (function),
    1121              :                     "no declaration matches %q#D", function);
    1122          120 :           if (fns)
    1123              :             {
    1124           78 :               decl_mismatch_context ctxt (function);
    1125           78 :               print_candidates (DECL_SOURCE_LOCATION (function), fns, &ctxt);
    1126           78 :             }
    1127           42 :           else if (DECL_CONV_FN_P (function))
    1128            3 :             inform (DECL_SOURCE_LOCATION (function),
    1129              :                     "no conversion operators declared");
    1130              :           else
    1131           39 :             inform (DECL_SOURCE_LOCATION (function),
    1132              :                     "no functions named %qD", function);
    1133          120 :           inform (DECL_SOURCE_LOCATION (TYPE_NAME (ctype)),
    1134              :                   "%#qT defined here", ctype);
    1135          120 :         }
    1136          126 :       matched = error_mark_node;
    1137              :     }
    1138              : 
    1139      8742684 :   if (pushed_scope)
    1140      8392372 :     pop_scope (pushed_scope);
    1141              : 
    1142              :   return matched;
    1143              : }
    1144              : 
    1145              : /* DECL is a function with vague linkage.  Remember it so that at the
    1146              :    end of the translation unit we can decide whether or not to emit
    1147              :    it.  */
    1148              : 
    1149              : void
    1150     53898494 : note_vague_linkage_fn (tree decl)
    1151              : {
    1152     53898494 :   if (processing_template_decl)
    1153              :     return;
    1154              : 
    1155     53898485 :   DECL_DEFER_OUTPUT (decl) = 1;
    1156     53898485 :   vec_safe_push (deferred_fns, decl);
    1157              : }
    1158              : 
    1159              : /* As above, but for variables.  */
    1160              : 
    1161              : void
    1162     16849466 : note_vague_linkage_variable (tree decl)
    1163              : {
    1164     16849466 :   vec_safe_push (pending_statics, decl);
    1165     16849466 : }
    1166              : 
    1167              : /* We have just processed the DECL, which is a static data member.
    1168              :    The other parameters are as for cp_finish_decl.  */
    1169              : 
    1170              : void
    1171     16479348 : finish_static_data_member_decl (tree decl,
    1172              :                                 tree init, bool init_const_expr_p,
    1173              :                                 tree asmspec_tree,
    1174              :                                 int flags)
    1175              : {
    1176     16479348 :   if (DECL_TEMPLATE_INSTANTIATED (decl))
    1177              :     /* We already needed to instantiate this, so the processing in this
    1178              :        function is unnecessary/wrong.  */
    1179              :     return;
    1180              : 
    1181     16479345 :   DECL_CONTEXT (decl) = current_class_type;
    1182              : 
    1183              :   /* We cannot call pushdecl here, because that would fill in the
    1184              :      TREE_CHAIN of our decl.  Instead, we modify cp_finish_decl to do
    1185              :      the right thing, namely, to put this decl out straight away.  */
    1186              : 
    1187     16479345 :   if (! processing_template_decl)
    1188     13649948 :     vec_safe_push (pending_statics, decl);
    1189              : 
    1190     16479345 :   if (LOCAL_CLASS_P (current_class_type)
    1191              :       /* We already complained about the template definition.  */
    1192     16479345 :       && !DECL_TEMPLATE_INSTANTIATION (decl))
    1193           15 :     permerror (DECL_SOURCE_LOCATION (decl),
    1194              :                "local class %q#T shall not have static data member %q#D",
    1195              :                current_class_type, decl);
    1196              :   else
    1197     33330833 :     for (tree t = current_class_type; TYPE_P (t);
    1198     16825368 :          t = CP_TYPE_CONTEXT (t))
    1199     33650808 :       if (TYPE_UNNAMED_P (t))
    1200              :         {
    1201           24 :           auto_diagnostic_group d;
    1202           24 :           if (permerror (DECL_SOURCE_LOCATION (decl),
    1203              :                          "static data member %qD in unnamed class", decl))
    1204           24 :             inform (DECL_SOURCE_LOCATION (TYPE_NAME (t)),
    1205              :                     "unnamed class defined here");
    1206           24 :           break;
    1207           24 :         }
    1208              : 
    1209     16479345 :   if (DECL_INLINE_VAR_P (decl) && !DECL_TEMPLATE_INSTANTIATION (decl))
    1210              :     /* An inline variable is immediately defined, so don't set DECL_IN_AGGR_P.
    1211              :        Except that if decl is a template instantiation, it isn't defined until
    1212              :        instantiate_decl.  */;
    1213              :   else
    1214      5647556 :     DECL_IN_AGGR_P (decl) = 1;
    1215              : 
    1216     16479345 :   if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
    1217     16479345 :       && TYPE_DOMAIN (TREE_TYPE (decl)) == NULL_TREE)
    1218       107002 :     SET_VAR_HAD_UNKNOWN_BOUND (decl);
    1219              : 
    1220     16479345 :   if (init)
    1221              :     {
    1222              :       /* Similarly to start_decl_1, we want to complete the type in order
    1223              :          to do the right thing in cp_apply_type_quals_to_decl, possibly
    1224              :          clear TYPE_QUAL_CONST (c++/65579).  */
    1225     11941487 :       tree type = TREE_TYPE (decl) = complete_type (TREE_TYPE (decl));
    1226     11941487 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    1227              :     }
    1228              : 
    1229     16479345 :   cp_finish_decl (decl, init, init_const_expr_p, asmspec_tree, flags);
    1230     16479345 :   check_module_decl_linkage (decl);
    1231              : }
    1232              : 
    1233              : /* DECLARATOR and DECLSPECS correspond to a class member.  The other
    1234              :    parameters are as for cp_finish_decl.  Return the DECL for the
    1235              :    class member declared.  */
    1236              : 
    1237              : tree
    1238     70224634 : grokfield (const cp_declarator *declarator,
    1239              :            cp_decl_specifier_seq *declspecs,
    1240              :            tree init, bool init_const_expr_p,
    1241              :            tree asmspec_tree,
    1242              :            tree attrlist)
    1243              : {
    1244     70224634 :   tree value;
    1245     70224634 :   const char *asmspec = 0;
    1246     70224634 :   int flags;
    1247              : 
    1248     70224634 :   if (init
    1249     12699940 :       && TREE_CODE (init) == TREE_LIST
    1250            0 :       && TREE_VALUE (init) == error_mark_node
    1251     70224634 :       && TREE_CHAIN (init) == NULL_TREE)
    1252              :     init = NULL_TREE;
    1253              : 
    1254     70224634 :   int initialized;
    1255     70224634 :   if (init == ridpointers[(int)RID_DELETE]
    1256     70224634 :       || (init
    1257      9157473 :           && TREE_CODE (init) == STRING_CST
    1258            9 :           && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
    1259              :     initialized = SD_DELETED;
    1260     66682158 :   else if (init == ridpointers[(int)RID_DEFAULT])
    1261              :     initialized = SD_DEFAULTED;
    1262     60090052 :   else if (init)
    1263              :     initialized = SD_INITIALIZED;
    1264              :   else
    1265     57524694 :     initialized = SD_UNINITIALIZED;
    1266              : 
    1267     70224634 :   value = grokdeclarator (declarator, declspecs, FIELD, initialized, &attrlist);
    1268     70224628 :   if (! value || value == error_mark_node)
    1269              :     /* friend or constructor went bad.  */
    1270          340 :     return error_mark_node;
    1271     70224288 :   if (TREE_TYPE (value) == error_mark_node)
    1272              :     return value;
    1273              : 
    1274     70224129 :   if (TREE_CODE (value) == TYPE_DECL && init)
    1275              :     {
    1276            6 :       error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (value)),
    1277              :                 "typedef %qD is initialized (use %qs instead)",
    1278              :                 value, "decltype");
    1279            6 :       init = NULL_TREE;
    1280              :     }
    1281              : 
    1282              :   /* Pass friendly classes back.  */
    1283     70224129 :   if (value == void_type_node)
    1284              :     return value;
    1285              : 
    1286     70224129 :   if (DECL_NAME (value)
    1287     70224129 :       && TREE_CODE (DECL_NAME (value)) == TEMPLATE_ID_EXPR)
    1288              :     {
    1289            3 :       error_at (declarator->id_loc,
    1290              :                 "explicit template argument list not allowed");
    1291            3 :       return error_mark_node;
    1292              :     }
    1293              : 
    1294              :   /* Stash away type declarations.  */
    1295     70224126 :   if (TREE_CODE (value) == TYPE_DECL)
    1296              :     {
    1297     24598603 :       DECL_NONLOCAL (value) = 1;
    1298     24598603 :       DECL_CONTEXT (value) = current_class_type;
    1299              : 
    1300     24598603 :       if (attrlist)
    1301              :         {
    1302        23424 :           int attrflags = 0;
    1303              : 
    1304              :           /* If this is a typedef that names the class for linkage purposes
    1305              :              (7.1.3p8), apply any attributes directly to the type.  */
    1306        46848 :           if (OVERLOAD_TYPE_P (TREE_TYPE (value))
    1307        44835 :               && value == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (value))))
    1308              :             attrflags = ATTR_FLAG_TYPE_IN_PLACE;
    1309              : 
    1310        23424 :           cplus_decl_attributes (&value, attrlist, attrflags);
    1311              :         }
    1312              : 
    1313     24598603 :       if (decl_spec_seq_has_spec_p (declspecs, ds_typedef)
    1314     24598603 :           && TREE_TYPE (value) != error_mark_node
    1315     49197206 :           && TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (value))) != value)
    1316     24597966 :         set_underlying_type (value);
    1317              : 
    1318              :       /* It's important that push_template_decl below follows
    1319              :          set_underlying_type above so that the created template
    1320              :          carries the properly set type of VALUE.  */
    1321     24598603 :       if (processing_template_decl)
    1322     20325889 :         value = push_template_decl (value);
    1323              : 
    1324     24598603 :       record_locally_defined_typedef (value);
    1325     24598603 :       return value;
    1326              :     }
    1327              : 
    1328     45625523 :   int friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
    1329              : 
    1330     45625523 :   if (!friendp && DECL_IN_AGGR_P (value))
    1331              :     {
    1332            0 :       error ("%qD is already defined in %qT", value, DECL_CONTEXT (value));
    1333            0 :       return void_type_node;
    1334              :     }
    1335              : 
    1336     45625523 :   if (asmspec_tree && asmspec_tree != error_mark_node)
    1337          194 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    1338              : 
    1339     45625523 :   if (init)
    1340              :     {
    1341     12699877 :       if (TREE_CODE (value) == FUNCTION_DECL)
    1342              :         {
    1343     10497979 :           if (init == ridpointers[(int)RID_DELETE]
    1344     10497979 :               || (TREE_CODE (init) == STRING_CST
    1345            9 :                   && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
    1346              :             {
    1347      3542470 :               DECL_DELETED_FN (value) = 1;
    1348      3542470 :               DECL_DECLARED_INLINE_P (value) = 1;
    1349      3542470 :               if (TREE_CODE (init) == STRING_CST)
    1350            9 :                 DECL_INITIAL (value) = init;
    1351              :             }
    1352      6955509 :           else if (init == ridpointers[(int)RID_DEFAULT])
    1353              :             {
    1354      6592103 :               if (defaultable_fn_check (value))
    1355              :                 {
    1356      6592024 :                   DECL_DEFAULTED_FN (value) = 1;
    1357      6592024 :                   DECL_INITIALIZED_IN_CLASS_P (value) = 1;
    1358      6592024 :                   DECL_DECLARED_INLINE_P (value) = 1;
    1359              :                   /* grokfndecl set this to error_mark_node, but we want to
    1360              :                      leave it unset until synthesize_method.  */
    1361      6592024 :                   DECL_INITIAL (value) = NULL_TREE;
    1362              :                 }
    1363              :             }
    1364       363406 :           else if (TREE_CODE (init) == DEFERRED_PARSE)
    1365            0 :             error ("invalid initializer for member function %qD", value);
    1366       363406 :           else if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE)
    1367              :             {
    1368       363397 :               if (integer_zerop (init))
    1369       363358 :                 DECL_PURE_VIRTUAL_P (value) = 1;
    1370           39 :               else if (error_operand_p (init))
    1371              :                 ; /* An error has already been reported.  */
    1372              :               else
    1373            0 :                 error ("invalid initializer for member function %qD",
    1374              :                        value);
    1375              :             }
    1376              :           else
    1377              :             {
    1378            9 :               gcc_assert (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE);
    1379            9 :               location_t iloc
    1380            9 :                 = cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (value));
    1381            9 :               if (friendp)
    1382            3 :                 error_at (iloc, "initializer specified for friend "
    1383              :                           "function %qD", value);
    1384              :               else
    1385            6 :                 error_at (iloc, "initializer specified for static "
    1386              :                           "member function %qD", value);
    1387              :             }
    1388              :         }
    1389      2201898 :       else if (TREE_CODE (value) == FIELD_DECL)
    1390              :         /* C++11 NSDMI, keep going.  */;
    1391            0 :       else if (!VAR_P (value))
    1392            0 :         gcc_unreachable ();
    1393              :     }
    1394              : 
    1395              :   /* Pass friend decls back.  */
    1396     45625523 :   if ((TREE_CODE (value) == FUNCTION_DECL
    1397     19506599 :        || TREE_CODE (value) == TEMPLATE_DECL)
    1398     45625580 :       && DECL_CONTEXT (value) != current_class_type)
    1399              :     {
    1400      1980353 :       if (attrlist)
    1401            0 :         cplus_decl_attributes (&value, attrlist, 0);
    1402      1980353 :       return value;
    1403              :     }
    1404              : 
    1405              :   /* Need to set this before push_template_decl.  */
    1406     43645170 :   if (VAR_P (value))
    1407       682246 :     DECL_CONTEXT (value) = current_class_type;
    1408              : 
    1409     43645170 :   if (processing_template_decl && VAR_OR_FUNCTION_DECL_P (value))
    1410              :     {
    1411     15160690 :       value = push_template_decl (value);
    1412     15160690 :       if (error_operand_p (value))
    1413            7 :         return error_mark_node;
    1414              :     }
    1415              : 
    1416     43645163 :   if (attrlist)
    1417       810991 :     cplus_decl_attributes (&value, attrlist, 0);
    1418              : 
    1419     43645163 :   if (init && DIRECT_LIST_INIT_P (init))
    1420              :     flags = LOOKUP_NORMAL;
    1421              :   else
    1422              :     flags = LOOKUP_IMPLICIT;
    1423              : 
    1424     43645163 :   switch (TREE_CODE (value))
    1425              :     {
    1426       682242 :     case VAR_DECL:
    1427       682242 :       finish_static_data_member_decl (value, init, init_const_expr_p,
    1428              :                                       asmspec_tree, flags);
    1429       682242 :       return value;
    1430              : 
    1431     18824296 :     case FIELD_DECL:
    1432     18824296 :       if (asmspec)
    1433            6 :         error ("%<asm%> specifiers are not permitted on non-static data members");
    1434     18824296 :       if (DECL_INITIAL (value) == error_mark_node)
    1435            0 :         init = error_mark_node;
    1436     18824296 :       cp_finish_decl (value, init, /*init_const_expr_p=*/false,
    1437              :                       NULL_TREE, flags);
    1438     18824296 :       DECL_IN_AGGR_P (value) = 1;
    1439     18824296 :       return value;
    1440              : 
    1441     24138625 :     case  FUNCTION_DECL:
    1442     24138625 :       if (asmspec)
    1443           92 :         set_user_assembler_name (value, asmspec);
    1444              : 
    1445     24138625 :       cp_finish_decl (value,
    1446              :                       /*init=*/NULL_TREE,
    1447              :                       /*init_const_expr_p=*/false,
    1448              :                       asmspec_tree, flags);
    1449              : 
    1450              :       /* Pass friends back this way.  */
    1451     24138625 :       if (DECL_UNIQUE_FRIEND_P (value))
    1452            0 :         return void_type_node;
    1453              : 
    1454     24138625 :       DECL_IN_AGGR_P (value) = 1;
    1455     24138625 :       return value;
    1456              : 
    1457            0 :     default:
    1458            0 :       gcc_unreachable ();
    1459              :     }
    1460              :   return NULL_TREE;
    1461              : }
    1462              : 
    1463              : /* Like grokfield, but just for the initial grok of an initialized static
    1464              :    member.  Used to be able to push the new decl before parsing the
    1465              :    initialiser.  */
    1466              : 
    1467              : tree
    1468     11941494 : start_initialized_static_member (const cp_declarator *declarator,
    1469              :                                  cp_decl_specifier_seq *declspecs,
    1470              :                                  tree attrlist)
    1471              : {
    1472     11941494 :   tree value = grokdeclarator (declarator, declspecs, FIELD, SD_INITIALIZED,
    1473     11941494 :                                &attrlist);
    1474     11941494 :   if (!value || error_operand_p (value))
    1475            3 :     return error_mark_node;
    1476     11941491 :   if (TREE_CODE (value) == TYPE_DECL)
    1477              :     {
    1478            0 :       error_at (declarator->init_loc,
    1479              :                 "typedef %qD is initialized (use %qs instead)",
    1480              :                 value, "decltype");
    1481            0 :       return error_mark_node;
    1482              :     }
    1483     11941491 :   else if (TREE_CODE (value) == FUNCTION_DECL)
    1484              :     {
    1485            0 :       if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE)
    1486            0 :         error_at (declarator->init_loc,
    1487              :                   "invalid initializer for member function %qD",
    1488              :                   value);
    1489            0 :       else if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE)
    1490            0 :         error_at (declarator->init_loc,
    1491              :                   "initializer specified for static member function %qD",
    1492              :                   value);
    1493              :       else
    1494            0 :         gcc_unreachable ();
    1495            0 :       return error_mark_node;
    1496              :     }
    1497     11941491 :   else if (TREE_CODE (value) == FIELD_DECL)
    1498              :     {
    1499              :       /* NSDM marked 'static', grokdeclarator has already errored.  */
    1500            3 :       gcc_checking_assert (seen_error ());
    1501            3 :       return error_mark_node;
    1502              :     }
    1503     11941488 :   gcc_checking_assert (VAR_P (value));
    1504              : 
    1505     11941488 :   DECL_CONTEXT (value) = current_class_type;
    1506     11941488 :   DECL_INITIALIZED_IN_CLASS_P (value) = true;
    1507              : 
    1508     11941488 :   if (processing_template_decl)
    1509              :     {
    1510      2671750 :       value = push_template_decl (value);
    1511      2671750 :       if (error_operand_p (value))
    1512            0 :         return error_mark_node;
    1513              :     }
    1514              : 
    1515     11941488 :   if (attrlist)
    1516            7 :     cplus_decl_attributes (&value, attrlist, 0);
    1517              : 
    1518              :   /* When defining a template we need to register the TEMPLATE_DECL.  */
    1519     11941488 :   tree maybe_template = value;
    1520     11941488 :   if (template_parm_scope_p ())
    1521              :     {
    1522       373174 :       if (!DECL_TEMPLATE_SPECIALIZATION (value))
    1523       332112 :         maybe_template = DECL_TI_TEMPLATE (value);
    1524              :       else
    1525              :         maybe_template = NULL_TREE;
    1526              :     }
    1527     11900426 :   if (maybe_template)
    1528     11900426 :     finish_member_declaration (maybe_template);
    1529              : 
    1530     11941488 :   return value;
    1531              : }
    1532              : 
    1533              : /* Whether DECL is a static data member initialized at the point
    1534              :    of declaration within its class.  */
    1535              : 
    1536              : bool
    1537     34181559 : is_static_data_member_initialized_in_class (tree decl)
    1538              : {
    1539     34181559 :   if (!decl || decl == error_mark_node)
    1540              :     return false;
    1541              : 
    1542     34180911 :   tree inner = STRIP_TEMPLATE (decl);
    1543     20466574 :   return (inner
    1544     34180911 :           && VAR_P (inner)
    1545     12425653 :           && DECL_CLASS_SCOPE_P (inner)
    1546     32888546 :           && DECL_INITIALIZED_IN_CLASS_P (inner));
    1547              : }
    1548              : 
    1549              : /* Finish a declaration prepared with start_initialized_static_member.  */
    1550              : 
    1551              : void
    1552     11941491 : finish_initialized_static_member (tree decl, tree init, tree asmspec)
    1553              : {
    1554     11941491 :   if (decl == error_mark_node)
    1555              :     return;
    1556     11941485 :   gcc_checking_assert (is_static_data_member_initialized_in_class (decl));
    1557              : 
    1558     11941485 :   int flags;
    1559     11941485 :   if (init && DIRECT_LIST_INIT_P (init))
    1560              :     flags = LOOKUP_NORMAL;
    1561              :   else
    1562              :     flags = LOOKUP_IMPLICIT;
    1563     11941485 :   finish_static_data_member_decl (decl, init, /*init_const_expr_p=*/true,
    1564              :                                   asmspec, flags);
    1565              : }
    1566              : 
    1567              : /* Like `grokfield', but for bitfields.
    1568              :    WIDTH is the width of the bitfield, a constant expression.
    1569              :    The other parameters are as for grokfield.  */
    1570              : 
    1571              : tree
    1572       594311 : grokbitfield (const cp_declarator *declarator,
    1573              :               cp_decl_specifier_seq *declspecs, tree width, tree init,
    1574              :               tree attrlist)
    1575              : {
    1576       594311 :   tree value = grokdeclarator (declarator, declspecs, BITFIELD,
    1577       594311 :                                init != NULL_TREE, &attrlist);
    1578              : 
    1579       594311 :   if (value == error_mark_node)
    1580              :     return NULL_TREE; /* friends went bad.  */
    1581              : 
    1582       594305 :   tree type = TREE_TYPE (value);
    1583       594305 :   if (type == error_mark_node)
    1584              :     return value;
    1585              : 
    1586              :   /* Pass friendly classes back.  */
    1587       594258 :   if (VOID_TYPE_P (value))
    1588            0 :     return void_type_node;
    1589              : 
    1590       594258 :   if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    1591       594258 :       && (INDIRECT_TYPE_P (type) || !dependent_type_p (type)))
    1592              :     {
    1593           33 :       error_at (DECL_SOURCE_LOCATION (value),
    1594              :                 "bit-field %qD with non-integral type %qT",
    1595              :                 value, type);
    1596           33 :       return error_mark_node;
    1597              :     }
    1598              : 
    1599       594225 :   if (TREE_CODE (value) == TYPE_DECL)
    1600              :     {
    1601            6 :       error_at (DECL_SOURCE_LOCATION (value),
    1602              :                 "cannot declare %qD to be a bit-field type", value);
    1603            6 :       return NULL_TREE;
    1604              :     }
    1605              : 
    1606              :   /* Usually, finish_struct_1 catches bitfields with invalid types.
    1607              :      But, in the case of bitfields with function type, we confuse
    1608              :      ourselves into thinking they are member functions, so we must
    1609              :      check here.  */
    1610       594219 :   if (TREE_CODE (value) == FUNCTION_DECL)
    1611              :     {
    1612            3 :       error_at (DECL_SOURCE_LOCATION (value),
    1613              :                 "cannot declare bit-field %qD with function type", value);
    1614            3 :       return NULL_TREE;
    1615              :     }
    1616              : 
    1617       594216 :   if (TYPE_WARN_IF_NOT_ALIGN (type))
    1618              :     {
    1619            9 :       error_at (DECL_SOURCE_LOCATION (value), "cannot declare bit-field "
    1620              :                 "%qD with %<warn_if_not_aligned%> type", value);
    1621            9 :       return NULL_TREE;
    1622              :     }
    1623              : 
    1624       594207 :   if (DECL_IN_AGGR_P (value))
    1625              :     {
    1626            0 :       error ("%qD is already defined in the class %qT", value,
    1627            0 :              DECL_CONTEXT (value));
    1628            0 :       return void_type_node;
    1629              :     }
    1630              : 
    1631       594207 :   if (TREE_STATIC (value))
    1632              :     {
    1633            6 :       error_at (DECL_SOURCE_LOCATION (value),
    1634              :                 "static member %qD cannot be a bit-field", value);
    1635            6 :       return NULL_TREE;
    1636              :     }
    1637              : 
    1638       594201 :   int flags = LOOKUP_IMPLICIT;
    1639       594201 :   if (init && DIRECT_LIST_INIT_P (init))
    1640              :     flags = LOOKUP_NORMAL;
    1641       594201 :   cp_finish_decl (value, init, false, NULL_TREE, flags);
    1642              : 
    1643       594201 :   if (width != error_mark_node)
    1644              :     {
    1645              :       /* The width must be an integer type.  */
    1646       594184 :       if (!type_dependent_expression_p (width)
    1647       594184 :           && !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (width)))
    1648           12 :         error ("width of bit-field %qD has non-integral type %qT", value,
    1649           12 :                TREE_TYPE (width));
    1650       594172 :       else if (!check_for_bare_parameter_packs (width))
    1651              :         {
    1652              :           /* Temporarily stash the width in DECL_BIT_FIELD_REPRESENTATIVE.
    1653              :              check_bitfield_decl picks it from there later and sets DECL_SIZE
    1654              :              accordingly.  */
    1655       594166 :           DECL_BIT_FIELD_REPRESENTATIVE (value) = width;
    1656       594166 :           SET_DECL_C_BIT_FIELD (value);
    1657              :         }
    1658              :     }
    1659              : 
    1660       594201 :   DECL_IN_AGGR_P (value) = 1;
    1661              : 
    1662       594201 :   if (attrlist)
    1663         1203 :     cplus_decl_attributes (&value, attrlist, /*flags=*/0);
    1664              : 
    1665       594201 :   return value;
    1666              : }
    1667              : 
    1668              : 
    1669              : /* Returns true iff ATTR is an attribute which needs to be applied at
    1670              :    instantiation time rather than template definition time.  */
    1671              : 
    1672              : static bool
    1673     16347282 : is_late_template_attribute (tree attr, tree decl)
    1674              : {
    1675     16347282 :   tree name = get_attribute_name (attr);
    1676     16347282 :   tree args = TREE_VALUE (attr);
    1677     16347282 :   const struct attribute_spec *spec
    1678     16347282 :     = lookup_attribute_spec (TREE_PURPOSE (attr));
    1679     16347282 :   tree arg;
    1680              : 
    1681              :   /* Handle all annotations as late, so that they aren't incorrectly
    1682              :      reordered if some have dependent expressions and others don't.  */
    1683     16347282 :   if (annotation_p (attr))
    1684              :     return true;
    1685              : 
    1686     16347260 :   if (!spec)
    1687              :     /* Unknown attribute.  */
    1688              :     return false;
    1689              : 
    1690              :   /* Attribute weak handling wants to write out assembly right away.  */
    1691     16347226 :   if (is_attribute_p ("weak", name))
    1692              :     return true;
    1693              : 
    1694              :   /* Attributes used and unused or std attribute maybe_unused are applied
    1695              :      directly to typedefs for the benefit of
    1696              :      maybe_warn_unused_local_typedefs.  */
    1697     16347223 :   if (TREE_CODE (decl) == TYPE_DECL
    1698     16347223 :       && (is_attribute_p ("unused", name)
    1699        15118 :           || is_attribute_p ("used", name)
    1700        15112 :           || (is_attribute_p ("maybe_unused", name)
    1701           10 :               && get_attribute_namespace (attr) == NULL_TREE)))
    1702          242 :     return false;
    1703              : 
    1704              :   /* Attribute tls_model wants to modify the symtab.  */
    1705     16346981 :   if (is_attribute_p ("tls_model", name))
    1706              :     return true;
    1707              : 
    1708              :   /* #pragma omp declare simd attribute needs to be always deferred.  */
    1709     16346978 :   if (flag_openmp
    1710     16346978 :       && is_attribute_p ("omp declare simd", name))
    1711              :     return true;
    1712              : 
    1713     16346086 :   if (args == error_mark_node)
    1714              :     return false;
    1715              : 
    1716              :   /* An attribute pack is clearly dependent.  */
    1717     16346086 :   if (args && PACK_EXPANSION_P (args))
    1718              :     return true;
    1719              : 
    1720              :   /* If any of the arguments are dependent expressions, we can't evaluate
    1721              :      the attribute until instantiation time.  */
    1722     17224167 :   for (arg = args; arg; arg = TREE_CHAIN (arg))
    1723              :     {
    1724      1004383 :       tree t = TREE_VALUE (arg);
    1725              : 
    1726              :       /* If the first attribute argument is an identifier, only consider
    1727              :          second and following arguments.  Attributes like mode, format,
    1728              :          cleanup and several target specific attributes aren't late
    1729              :          just because they have an IDENTIFIER_NODE as first argument.  */
    1730      1041262 :       if (arg == args
    1731       964562 :           && get_attribute_namespace (attr) == gnu_identifier
    1732       809193 :           && attribute_takes_identifier_p (name)
    1733      1004383 :           && identifier_p (t))
    1734        36879 :         continue;
    1735              : 
    1736       967504 :       if (value_dependent_expression_p (t))
    1737              :         return true;
    1738              :     }
    1739              : 
    1740     16219784 :   if (TREE_CODE (decl) == TYPE_DECL
    1741     16204774 :       || TYPE_P (decl)
    1742     15849108 :       || spec->type_required)
    1743              :     {
    1744       774092 :       tree type = TYPE_P (decl) ? decl : TREE_TYPE (decl);
    1745              : 
    1746       418426 :       if (!type)
    1747              :         return true;
    1748              : 
    1749              :       /* We can't apply any attributes to a completely unknown type until
    1750              :          instantiation time.  */
    1751       774089 :       enum tree_code code = TREE_CODE (type);
    1752       774089 :       if (code == TEMPLATE_TYPE_PARM
    1753       774089 :           || code == BOUND_TEMPLATE_TEMPLATE_PARM
    1754       773694 :           || code == TYPENAME_TYPE)
    1755              :         return true;
    1756              :       /* Also defer most attributes on dependent types.  This is not
    1757              :          necessary in all cases, but is the better default.  */
    1758       769653 :       else if (dependent_type_p (type)
    1759              :                /* But some attributes specifically apply to templates.  */
    1760       697574 :                && !is_attribute_p ("abi_tag", name)
    1761       697550 :                && !is_attribute_p ("deprecated", name)
    1762       365029 :                && !is_attribute_p ("unavailable", name)
    1763      1134676 :                && !is_attribute_p ("visibility", name))
    1764              :         return true;
    1765              :       else
    1766              :         return false;
    1767              :     }
    1768              :   else
    1769              :     return false;
    1770              : }
    1771              : 
    1772              : /* ATTR_P is a list of attributes.  Remove any attributes which need to be
    1773              :    applied at instantiation time and return them.  If IS_DEPENDENT is true,
    1774              :    the declaration itself is dependent, so all attributes should be applied
    1775              :    at instantiation time.  */
    1776              : 
    1777              : tree
    1778    231525051 : splice_template_attributes (tree *attr_p, tree decl)
    1779              : {
    1780    231525051 :   tree *p = attr_p;
    1781    231525051 :   tree late_attrs = NULL_TREE;
    1782    231525051 :   tree *q = &late_attrs;
    1783              : 
    1784    231525051 :   if (!p || *p == error_mark_node)
    1785              :     return NULL_TREE;
    1786              : 
    1787    247872333 :   for (; *p; )
    1788              :     {
    1789     16347282 :       if (is_late_template_attribute (*p, decl))
    1790              :         {
    1791       496672 :           ATTR_IS_DEPENDENT (*p) = 1;
    1792       496672 :           *q = *p;
    1793       496672 :           *p = TREE_CHAIN (*p);
    1794       496672 :           q = &TREE_CHAIN (*q);
    1795       496672 :           *q = NULL_TREE;
    1796              :         }
    1797              :       else
    1798     15850610 :         p = &TREE_CHAIN (*p);
    1799              :     }
    1800              : 
    1801    231525051 :   return late_attrs;
    1802              : }
    1803              : 
    1804              : /* Attach any LATE_ATTRS to DECL_P, after the non-dependent attributes have
    1805              :    been applied by a previous call to decl_attributes.  */
    1806              : 
    1807              : static void
    1808       494682 : save_template_attributes (tree late_attrs, tree *decl_p, int flags)
    1809              : {
    1810       494682 :   tree *q;
    1811              : 
    1812       494682 :   if (!late_attrs)
    1813              :     return;
    1814              : 
    1815       494682 :   if (DECL_P (*decl_p))
    1816       484305 :     q = &DECL_ATTRIBUTES (*decl_p);
    1817              :   else
    1818        10377 :     q = &TYPE_ATTRIBUTES (*decl_p);
    1819              : 
    1820       494682 :   tree old_attrs = *q;
    1821              : 
    1822              :   /* Place the late attributes at the beginning of the attribute
    1823              :      list.  */
    1824       494682 :   late_attrs = chainon (late_attrs, *q);
    1825       494682 :   if (*q != late_attrs
    1826       494682 :       && !DECL_P (*decl_p)
    1827        10377 :       && !(flags & ATTR_FLAG_TYPE_IN_PLACE))
    1828              :     {
    1829           52 :       if (!dependent_type_p (*decl_p))
    1830           12 :         *decl_p = cp_build_type_attribute_variant (*decl_p, late_attrs);
    1831              :       else
    1832              :         {
    1833           40 :           *decl_p = build_variant_type_copy (*decl_p);
    1834           40 :           TYPE_ATTRIBUTES (*decl_p) = late_attrs;
    1835              :         }
    1836              :     }
    1837              :   else
    1838       494630 :     *q = late_attrs;
    1839              : 
    1840       494682 :   if (!DECL_P (*decl_p) && *decl_p == TYPE_MAIN_VARIANT (*decl_p))
    1841              :     {
    1842              :       /* We've added new attributes directly to the main variant, so
    1843              :          now we need to update all of the other variants to include
    1844              :          these new attributes.  */
    1845        10337 :       tree variant;
    1846        10477 :       for (variant = TYPE_NEXT_VARIANT (*decl_p); variant;
    1847          140 :            variant = TYPE_NEXT_VARIANT (variant))
    1848              :         {
    1849          140 :           gcc_assert (TYPE_ATTRIBUTES (variant) == old_attrs);
    1850          140 :           TYPE_ATTRIBUTES (variant) = TYPE_ATTRIBUTES (*decl_p);
    1851              :         }
    1852              :     }
    1853              : }
    1854              : 
    1855              : /* True if ATTRS contains any dependent attributes that affect type
    1856              :    identity.  */
    1857              : 
    1858              : bool
    1859   2066929766 : any_dependent_type_attributes_p (tree attrs)
    1860              : {
    1861   2098639242 :   for (tree a = attrs; a; a = TREE_CHAIN (a))
    1862     31709884 :     if (ATTR_IS_DEPENDENT (a))
    1863              :       {
    1864      1952099 :         const attribute_spec *as = lookup_attribute_spec (TREE_PURPOSE (a));
    1865      1952099 :         if (as && as->affects_type_identity)
    1866              :           return true;
    1867              :       }
    1868              :   return false;
    1869              : }
    1870              : 
    1871              : /* Return true iff ATTRS are acceptable attributes to be applied in-place
    1872              :    to a typedef which gives a previously unnamed class or enum a name for
    1873              :    linkage purposes.  */
    1874              : 
    1875              : bool
    1876       383942 : attributes_naming_typedef_ok (tree attrs)
    1877              : {
    1878       395410 :   for (; attrs; attrs = TREE_CHAIN (attrs))
    1879              :     {
    1880        11471 :       tree name = get_attribute_name (attrs);
    1881        11471 :       if (is_attribute_p ("vector_size", name))
    1882              :         return false;
    1883              :     }
    1884              :   return true;
    1885              : }
    1886              : 
    1887              : /* Like reconstruct_complex_type, but handle also template trees.  */
    1888              : 
    1889              : tree
    1890        29740 : cp_reconstruct_complex_type (tree type, tree bottom)
    1891              : {
    1892        29740 :   tree inner, outer;
    1893              : 
    1894        29740 :   if (TYPE_PTR_P (type))
    1895              :     {
    1896           36 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1897           36 :       outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
    1898           36 :                                            TYPE_REF_CAN_ALIAS_ALL (type));
    1899              :     }
    1900              :   else if (TYPE_REF_P (type))
    1901              :     {
    1902           12 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1903           12 :       outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
    1904           12 :                                              TYPE_REF_CAN_ALIAS_ALL (type));
    1905              :     }
    1906              :   else if (TREE_CODE (type) == ARRAY_TYPE)
    1907              :     {
    1908           30 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1909           30 :       outer = build_cplus_array_type (inner, TYPE_DOMAIN (type));
    1910              :       /* Don't call cp_build_qualified_type on ARRAY_TYPEs, the
    1911              :          element type qualification will be handled by the recursive
    1912              :          cp_reconstruct_complex_type call and cp_build_qualified_type
    1913              :          for ARRAY_TYPEs changes the element type.  */
    1914           30 :       return outer;
    1915              :     }
    1916              :   else if (TREE_CODE (type) == FUNCTION_TYPE)
    1917              :     {
    1918          116 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1919          116 :       outer = build_function_type (inner, TYPE_ARG_TYPES (type),
    1920          116 :                                    TYPE_NO_NAMED_ARGS_STDARG_P (type));
    1921          116 :       outer = apply_memfn_quals (outer, type_memfn_quals (type));
    1922              :     }
    1923              :   else if (TREE_CODE (type) == METHOD_TYPE)
    1924              :     {
    1925           12 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1926              :       /* The build_method_type_directly() routine prepends 'this' to argument list,
    1927              :          so we must compensate by getting rid of it.  */
    1928           12 :       outer
    1929              :         = build_method_type_directly
    1930           12 :             (class_of_this_parm (type), inner,
    1931           12 :              TREE_CHAIN (TYPE_ARG_TYPES (type)));
    1932              :     }
    1933              :   else if (TREE_CODE (type) == OFFSET_TYPE)
    1934              :     {
    1935            3 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1936            3 :       outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
    1937              :     }
    1938              :   else
    1939              :     return bottom;
    1940              : 
    1941          179 :   if (TYPE_ATTRIBUTES (type))
    1942            0 :     outer = cp_build_type_attribute_variant (outer, TYPE_ATTRIBUTES (type));
    1943          179 :   outer = cp_build_qualified_type (outer, cp_type_quals (type));
    1944          179 :   outer = cxx_copy_lang_qualifiers (outer, type);
    1945              : 
    1946          179 :   return outer;
    1947              : }
    1948              : 
    1949              : /* Replaces any constexpr expression that may be into the attributes
    1950              :    arguments with their reduced value.  */
    1951              : 
    1952              : void
    1953    372504606 : cp_check_const_attributes (tree attributes)
    1954              : {
    1955    372504606 :   if (attributes == error_mark_node)
    1956              :     return;
    1957              : 
    1958              :   tree attr;
    1959    410553481 :   for (attr = attributes; attr; attr = TREE_CHAIN (attr))
    1960              :     {
    1961              :       /* Annotation arguments are handled in handle_annotation_attribute.  */
    1962     38048875 :       if (annotation_p (attr))
    1963          285 :         continue;
    1964              : 
    1965     38048590 :       tree arg;
    1966              :       /* As we implement alignas using gnu::aligned attribute and
    1967              :          alignas argument is a constant expression, force manifestly
    1968              :          constant evaluation of aligned attribute argument.  */
    1969     38048590 :       bool manifestly_const_eval
    1970     38048590 :         = is_attribute_p ("aligned", get_attribute_name (attr));
    1971     49594654 :       for (arg = TREE_VALUE (attr); arg && TREE_CODE (arg) == TREE_LIST;
    1972     11546064 :            arg = TREE_CHAIN (arg))
    1973              :         {
    1974     11546064 :           tree expr = TREE_VALUE (arg);
    1975     11546064 :           if (EXPR_P (expr))
    1976         6064 :             TREE_VALUE (arg)
    1977         3032 :               = fold_non_dependent_expr (expr, tf_warning_or_error,
    1978              :                                          manifestly_const_eval);
    1979              :         }
    1980              :     }
    1981              : }
    1982              : 
    1983              : /* Copies hot or cold attributes to a function FN if present on the
    1984              :    encapsulating class, struct, or union TYPE.  */
    1985              : 
    1986              : void
    1987     28252278 : maybe_propagate_warmth_attributes (tree fn, tree type)
    1988              : {
    1989     28252278 :   if (fn == NULL_TREE || type == NULL_TREE
    1990     28252278 :       || !(TREE_CODE (type) == RECORD_TYPE
    1991              :            || TREE_CODE (type) == UNION_TYPE))
    1992              :     return;
    1993              : 
    1994     28252278 :   tree has_cold_attr = lookup_attribute ("cold", TYPE_ATTRIBUTES (type));
    1995     28252278 :   tree has_hot_attr = lookup_attribute ("hot", TYPE_ATTRIBUTES (type));
    1996              : 
    1997     28252278 :   if (has_cold_attr || has_hot_attr)
    1998              :     {
    1999              :       /* Transparently ignore the new warmth attribute if it
    2000              :          conflicts with a present function attribute.  Otherwise
    2001              :          decl_attribute would still honour the present attribute,
    2002              :          but producing an undesired warning in the process.  */
    2003              : 
    2004           18 :       if (has_cold_attr)
    2005              :         {
    2006            9 :           if (lookup_attribute ("hot", DECL_ATTRIBUTES (fn)) == NULL)
    2007              :             {
    2008            9 :               tree cold_cons
    2009            9 :                 = tree_cons (get_identifier ("cold"), NULL, NULL);
    2010              : 
    2011            9 :               decl_attributes (&fn, cold_cons, 0);
    2012              :             }
    2013              :         }
    2014            9 :       else if (has_hot_attr)
    2015              :         {
    2016            9 :           if (lookup_attribute ("cold", DECL_ATTRIBUTES (fn)) == NULL)
    2017              :             {
    2018            9 :               tree hot_cons
    2019            9 :                 = tree_cons (get_identifier ("hot"), NULL, NULL);
    2020              : 
    2021            9 :               decl_attributes (&fn, hot_cons, 0);
    2022              :             }
    2023              :         }
    2024              :     }
    2025              : }
    2026              : 
    2027              : /* Return the last pushed declaration for the symbol DECL or NULL
    2028              :    when no such declaration exists.  */
    2029              : 
    2030              : static tree
    2031    372439069 : find_last_decl (tree decl)
    2032              : {
    2033    372439069 :   tree last_decl = NULL_TREE;
    2034              : 
    2035    372439069 :   if (tree name = DECL_P (decl) ? DECL_NAME (decl) : NULL_TREE)
    2036              :     {
    2037              :       /* Template specializations are matched elsewhere.  */
    2038    310486901 :       if (DECL_LANG_SPECIFIC (decl)
    2039    310486901 :           && DECL_USE_TEMPLATE (decl))
    2040              :         return NULL_TREE;
    2041              : 
    2042              :       /* Look up the declaration in its scope.  */
    2043    305777713 :       tree pushed_scope = NULL_TREE;
    2044    305777713 :       if (tree ctype = DECL_CONTEXT (decl))
    2045    234599608 :         pushed_scope = push_scope (ctype);
    2046              : 
    2047    305777713 :       last_decl = lookup_name (name);
    2048              : 
    2049    305777713 :       if (pushed_scope)
    2050    132303366 :         pop_scope (pushed_scope);
    2051              : 
    2052              :       /* The declaration may be a member conversion operator
    2053              :          or a bunch of overfloads (handle the latter below).  */
    2054    305777713 :       if (last_decl && BASELINK_P (last_decl))
    2055       173158 :         last_decl = BASELINK_FUNCTIONS (last_decl);
    2056              :     }
    2057              : 
    2058     61900952 :   if (!last_decl)
    2059    273320637 :     return NULL_TREE;
    2060              : 
    2061     94409244 :   if (DECL_P (last_decl) || TREE_CODE (last_decl) == OVERLOAD)
    2062              :     {
    2063              :       /* A set of overloads of the same function.  */
    2064    536717096 :       for (lkp_iterator iter (last_decl); iter; ++iter)
    2065              :         {
    2066    452049880 :           if (TREE_CODE (*iter) == OVERLOAD)
    2067            0 :             continue;
    2068              : 
    2069    452049880 :           tree d = *iter;
    2070              : 
    2071              :           /* We can't compare versions in the middle of processing the
    2072              :              attribute that has the version.  */
    2073    452049880 :           if (TREE_CODE (d) == FUNCTION_DECL
    2074    452049880 :               && DECL_FUNCTION_VERSIONED (d))
    2075      9723623 :             return NULL_TREE;
    2076              : 
    2077    452048752 :           if (decls_match (decl, d, /*record_decls=*/false))
    2078              :             return d;
    2079              :         }
    2080     84667216 :       return NULL_TREE;
    2081              :     }
    2082              : 
    2083              :   return NULL_TREE;
    2084              : }
    2085              : 
    2086              : /* Like decl_attributes, but handle C++ complexity.  */
    2087              : 
    2088              : void
    2089    372502621 : cplus_decl_attributes (tree *decl, tree attributes, int flags)
    2090              : {
    2091    372502621 :   if (*decl == NULL_TREE || *decl == void_type_node
    2092    372502621 :       || *decl == error_mark_node || attributes == error_mark_node)
    2093              :     return;
    2094              : 
    2095              :   /* Add implicit "omp declare target" attribute if requested.  */
    2096    372502538 :   if (vec_safe_length (scope_chain->omp_declare_target_attribute)
    2097        10862 :       && ((VAR_P (*decl)
    2098         2156 :            && (TREE_STATIC (*decl) || DECL_EXTERNAL (*decl)))
    2099         3370 :           || TREE_CODE (*decl) == FUNCTION_DECL))
    2100              :     {
    2101         1691 :       if (VAR_P (*decl)
    2102         1691 :           && DECL_CLASS_SCOPE_P (*decl))
    2103            0 :         error ("%q+D static data member inside of declare target directive",
    2104              :                *decl);
    2105              :       else
    2106              :         {
    2107         1691 :           if (VAR_P (*decl)
    2108         1691 :               && (processing_template_decl
    2109          282 :                   || !omp_mappable_type (TREE_TYPE (*decl))))
    2110           52 :             attributes
    2111           52 :               = tree_cons (get_identifier ("omp declare target implicit"),
    2112              :                            NULL_TREE, attributes);
    2113              :           else
    2114         1639 :             attributes = tree_cons (get_identifier ("omp declare target"),
    2115              :                                     NULL_TREE, attributes);
    2116         1691 :           if (TREE_CODE (*decl) == FUNCTION_DECL)
    2117              :             {
    2118         1409 :               cp_omp_declare_target_attr &last
    2119         1409 :                 = scope_chain->omp_declare_target_attribute->last ();
    2120         1409 :               int device_type = MAX (last.device_type, 0);
    2121         1409 :               if ((device_type & OMP_CLAUSE_DEVICE_TYPE_HOST) != 0
    2122         1409 :                   && !lookup_attribute ("omp declare target host",
    2123              :                                         attributes))
    2124            6 :                 attributes
    2125            6 :                   = tree_cons (get_identifier ("omp declare target host"),
    2126              :                                NULL_TREE, attributes);
    2127         1409 :               if ((device_type & OMP_CLAUSE_DEVICE_TYPE_NOHOST) != 0
    2128         1409 :                   && !lookup_attribute ("omp declare target nohost",
    2129              :                                         attributes))
    2130            6 :                 attributes
    2131            6 :                   = tree_cons (get_identifier ("omp declare target nohost"),
    2132              :                                NULL_TREE, attributes);
    2133         1409 :               if (last.indirect
    2134         1409 :                   && !lookup_attribute ("omp declare target indirect",
    2135              :                                         attributes))
    2136           21 :                 attributes
    2137           21 :                   = tree_cons (get_identifier ("omp declare target indirect"),
    2138              :                                NULL_TREE, attributes);
    2139              :             }
    2140              :         }
    2141              :     }
    2142              : 
    2143    372502538 :   tree late_attrs = NULL_TREE;
    2144    372502538 :   if (processing_template_decl)
    2145              :     {
    2146    231511603 :       if (check_for_bare_parameter_packs (attributes))
    2147              :         return;
    2148    231511594 :       late_attrs = splice_template_attributes (&attributes, *decl);
    2149              :     }
    2150              : 
    2151    372502529 :   cp_check_const_attributes (attributes);
    2152              : 
    2153    372502529 :   if (flag_openmp || flag_openmp_simd)
    2154              :     {
    2155              :       bool diagnosed = false;
    2156      1347331 :       for (tree *pa = &attributes; *pa; )
    2157              :         {
    2158       185939 :           if (get_attribute_namespace (*pa) == omp_identifier)
    2159              :             {
    2160          209 :               tree name = get_attribute_name (*pa);
    2161          209 :               if (is_attribute_p ("directive", name)
    2162            0 :                   || is_attribute_p ("sequence", name)
    2163          209 :                   || is_attribute_p ("decl", name))
    2164              :                 {
    2165          209 :                   const char *p = NULL;
    2166          209 :                   if (TREE_VALUE (*pa) == NULL_TREE)
    2167            9 :                     p = IDENTIFIER_POINTER (name);
    2168          409 :                   for (tree a = TREE_VALUE (*pa); a; a = TREE_CHAIN (a))
    2169              :                     {
    2170          200 :                       tree d = TREE_VALUE (a);
    2171          200 :                       gcc_assert (TREE_CODE (d) == DEFERRED_PARSE);
    2172          340 :                       if (TREE_PUBLIC (d)
    2173          143 :                           && (VAR_P (*decl)
    2174           10 :                               || TREE_CODE (*decl) == FUNCTION_DECL)
    2175          343 :                           && cp_maybe_parse_omp_decl (*decl, d))
    2176          140 :                         continue;
    2177           60 :                       p = TREE_PUBLIC (d) ? "decl" : "directive";
    2178              :                     }
    2179          209 :                   if (p && !diagnosed)
    2180              :                     {
    2181           69 :                       error ("%<omp::%s%> not allowed to be specified in "
    2182              :                              "this context", p);
    2183           69 :                       diagnosed = true;
    2184              :                     }
    2185          209 :                   if (p)
    2186              :                     {
    2187           69 :                       *pa = TREE_CHAIN (*pa);
    2188           69 :                       continue;
    2189              :                     }
    2190              :                 }
    2191              :             }
    2192       185870 :           pa = &TREE_CHAIN (*pa);
    2193              :         }
    2194              :     }
    2195              : 
    2196    372502529 :   if (TREE_CODE (*decl) == TEMPLATE_DECL)
    2197         1116 :     decl = &DECL_TEMPLATE_RESULT (*decl);
    2198              : 
    2199    372502529 :   if (TREE_TYPE (*decl) && TYPE_PTRMEMFUNC_P (TREE_TYPE (*decl)))
    2200              :     {
    2201        63460 :       attributes
    2202        63460 :         = decl_attributes (decl, attributes, flags | ATTR_FLAG_FUNCTION_NEXT);
    2203        63460 :       decl_attributes (&TYPE_PTRMEMFUNC_FN_TYPE_RAW (TREE_TYPE (*decl)),
    2204              :                        attributes, flags);
    2205              :     }
    2206              :   else
    2207              :     {
    2208    372439069 :       tree last_decl = find_last_decl (*decl);
    2209    372439069 :       decl_attributes (decl, attributes, flags, last_decl);
    2210              :     }
    2211              : 
    2212    372502529 :   if (late_attrs)
    2213       494682 :     save_template_attributes (late_attrs, decl, flags);
    2214              : 
    2215              :   /* Propagate deprecation out to the template.  */
    2216    372502529 :   if (TREE_DEPRECATED (*decl))
    2217      1474819 :     if (tree ti = get_template_info (*decl))
    2218              :       {
    2219       466256 :         tree tmpl = TI_TEMPLATE (ti);
    2220       466256 :         tree pattern = (TYPE_P (*decl) ? TREE_TYPE (tmpl)
    2221       466256 :                         : DECL_TEMPLATE_RESULT (tmpl));
    2222       466256 :         if (*decl == pattern)
    2223       418139 :           TREE_DEPRECATED (tmpl) = true;
    2224              :       }
    2225              : 
    2226              :   /* Likewise, propagate unavailability out to the template.  */
    2227    372502529 :   if (TREE_UNAVAILABLE (*decl))
    2228          252 :     if (tree ti = get_template_info (*decl))
    2229              :       {
    2230            9 :         tree tmpl = TI_TEMPLATE (ti);
    2231            9 :         tree pattern = (TYPE_P (*decl) ? TREE_TYPE (tmpl)
    2232            9 :                         : DECL_TEMPLATE_RESULT (tmpl));
    2233            9 :         if (*decl == pattern)
    2234            9 :           TREE_UNAVAILABLE (tmpl) = true;
    2235              :       }
    2236              : 
    2237    372502529 :   if (VAR_P (*decl) && CP_DECL_THREAD_LOCAL_P (*decl))
    2238              :     {
    2239              :       // tls_model attribute can set a stronger TLS access model.
    2240        19365 :       tls_model model = DECL_TLS_MODEL (*decl);
    2241              :       // Don't upgrade TLS model if TLS model isn't set yet.
    2242        19365 :       if (model != TLS_MODEL_NONE)
    2243              :         {
    2244        19241 :           tls_model default_model = decl_default_tls_model (*decl);
    2245        19241 :           if (default_model > model)
    2246        19023 :             set_decl_tls_model (*decl, default_model);
    2247              :         }
    2248              :     }
    2249              : 
    2250              :   /* For target_version semantics, mark any annotated function as versioned
    2251              :      so that it gets mangled even when on its own in a TU.  */
    2252              :   if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    2253              :       && TREE_CODE (*decl) == FUNCTION_DECL
    2254              :       && get_target_version (*decl).is_valid ())
    2255              :     maybe_mark_function_versioned (*decl);
    2256              : }
    2257              : 
    2258              : /* Walks through the namespace- or function-scope anonymous union
    2259              :    OBJECT, with the indicated TYPE, building appropriate VAR_DECLs.
    2260              :    Returns one of the fields for use in the mangled name.  */
    2261              : 
    2262              : static tree
    2263          374 : build_anon_union_vars (tree type, tree object)
    2264              : {
    2265          374 :   tree main_decl = NULL_TREE;
    2266          374 :   tree field;
    2267              : 
    2268              :   /* Rather than write the code to handle the non-union case,
    2269              :      just give an error.  */
    2270          374 :   if (TREE_CODE (type) != UNION_TYPE)
    2271              :     {
    2272            6 :       error_at (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    2273              :                 "anonymous struct not inside named type");
    2274            6 :       return error_mark_node;
    2275              :     }
    2276              : 
    2277          368 :   for (field = TYPE_FIELDS (type);
    2278         1313 :        field != NULL_TREE;
    2279          945 :        field = DECL_CHAIN (field))
    2280              :     {
    2281          945 :       tree decl;
    2282          945 :       tree ref;
    2283              : 
    2284          945 :       if (DECL_ARTIFICIAL (field))
    2285          465 :         continue;
    2286          480 :       if (TREE_CODE (field) != FIELD_DECL)
    2287              :         {
    2288            0 :           permerror (DECL_SOURCE_LOCATION (field),
    2289              :                      "%q#D invalid; an anonymous union can only "
    2290              :                      "have non-static data members", field);
    2291            0 :           continue;
    2292              :         }
    2293              : 
    2294          480 :       if (TREE_PRIVATE (field))
    2295            6 :         permerror (DECL_SOURCE_LOCATION (field),
    2296              :                    "private member %q#D in anonymous union", field);
    2297          474 :       else if (TREE_PROTECTED (field))
    2298            0 :         permerror (DECL_SOURCE_LOCATION (field),
    2299              :                    "protected member %q#D in anonymous union", field);
    2300              : 
    2301          480 :       if (processing_template_decl)
    2302           66 :         ref = build_min_nt_loc (UNKNOWN_LOCATION, COMPONENT_REF, object,
    2303              :                                 field, NULL_TREE);
    2304              :       else
    2305          414 :         ref = build_class_member_access_expr (object, field, NULL_TREE,
    2306              :                                               false, tf_warning_or_error);
    2307              : 
    2308          480 :       if (DECL_NAME (field))
    2309              :         {
    2310          443 :           tree base;
    2311              : 
    2312          443 :           decl = build_decl (input_location,
    2313          443 :                              VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
    2314          443 :           DECL_ANON_UNION_VAR_P (decl) = 1;
    2315          443 :           DECL_ARTIFICIAL (decl) = 1;
    2316              : 
    2317          443 :           base = get_base_address (object);
    2318          443 :           TREE_PUBLIC (decl) = TREE_PUBLIC (base);
    2319          443 :           TREE_STATIC (decl) = TREE_STATIC (base);
    2320          443 :           DECL_EXTERNAL (decl) = DECL_EXTERNAL (base);
    2321              : 
    2322          443 :           SET_DECL_VALUE_EXPR (decl, ref);
    2323          443 :           DECL_HAS_VALUE_EXPR_P (decl) = 1;
    2324              : 
    2325          443 :           decl = pushdecl (decl);
    2326              :         }
    2327           37 :       else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    2328           37 :         decl = build_anon_union_vars (TREE_TYPE (field), ref);
    2329              :       else
    2330              :         decl = 0;
    2331              : 
    2332          480 :       if (main_decl == NULL_TREE)
    2333          945 :         main_decl = decl;
    2334              :     }
    2335              : 
    2336              :   return main_decl;
    2337              : }
    2338              : 
    2339              : /* Finish off the processing of a UNION_TYPE structure.  If the union is an
    2340              :    anonymous union, then all members must be laid out together.  PUBLIC_P
    2341              :    is nonzero if this union is not declared static.  */
    2342              : 
    2343              : void
    2344          346 : finish_anon_union (tree anon_union_decl)
    2345              : {
    2346          346 :   tree type;
    2347          346 :   tree main_decl;
    2348          346 :   bool public_p;
    2349              : 
    2350          346 :   if (anon_union_decl == error_mark_node)
    2351              :     return;
    2352              : 
    2353          337 :   type = TREE_TYPE (anon_union_decl);
    2354          337 :   public_p = TREE_PUBLIC (anon_union_decl);
    2355              : 
    2356              :   /* The VAR_DECL's context is the same as the TYPE's context.  */
    2357          337 :   DECL_CONTEXT (anon_union_decl) = DECL_CONTEXT (TYPE_NAME (type));
    2358              : 
    2359          337 :   if (TYPE_FIELDS (type) == NULL_TREE)
    2360              :     return;
    2361              : 
    2362          337 :   if (public_p)
    2363              :     {
    2364            0 :       error ("namespace-scope anonymous aggregates must be static");
    2365            0 :       return;
    2366              :     }
    2367              : 
    2368          337 :   main_decl = build_anon_union_vars (type, anon_union_decl);
    2369          337 :   if (main_decl == error_mark_node)
    2370              :     return;
    2371          313 :   if (main_decl == NULL_TREE)
    2372              :     {
    2373           12 :       pedwarn (input_location, 0, "anonymous union with no members");
    2374           12 :       return;
    2375              :     }
    2376              : 
    2377          301 :   if (!processing_template_decl)
    2378              :     {
    2379              :       /* Use main_decl to set the mangled name.  */
    2380          262 :       DECL_NAME (anon_union_decl) = DECL_NAME (main_decl);
    2381          262 :       maybe_commonize_var (anon_union_decl);
    2382          262 :       if (TREE_STATIC (anon_union_decl) || DECL_EXTERNAL (anon_union_decl))
    2383              :         {
    2384          149 :           if (DECL_DISCRIMINATOR_P (anon_union_decl))
    2385           45 :             determine_local_discriminator (anon_union_decl);
    2386          149 :           mangle_decl (anon_union_decl);
    2387              :         }
    2388          262 :       DECL_NAME (anon_union_decl) = NULL_TREE;
    2389              :     }
    2390              : 
    2391          301 :   pushdecl (anon_union_decl);
    2392          301 :   cp_finish_decl (anon_union_decl, NULL_TREE, false, NULL_TREE, 0);
    2393              : }
    2394              : 
    2395              : /* Auxiliary functions to make type signatures for
    2396              :    `operator new' and `operator delete' correspond to
    2397              :    what compiler will be expecting.  */
    2398              : 
    2399              : tree
    2400       139431 : coerce_new_type (tree type, location_t loc)
    2401              : {
    2402       139431 :   int e = 0;
    2403       139431 :   tree args = TYPE_ARG_TYPES (type);
    2404              : 
    2405       139431 :   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
    2406              : 
    2407       139431 :   if (!same_type_p (TREE_TYPE (type), ptr_type_node))
    2408              :     {
    2409            6 :       e = 1;
    2410            6 :       error_at (loc, "%<operator new%> must return type %qT",
    2411              :                 ptr_type_node);
    2412              :     }
    2413              : 
    2414       139431 :   if (args && args != void_list_node)
    2415              :     {
    2416       139416 :       if (TREE_PURPOSE (args))
    2417              :         {
    2418              :           /* [basic.stc.dynamic.allocation]
    2419              : 
    2420              :              The first parameter shall not have an associated default
    2421              :              argument.  */
    2422           18 :           error_at (loc, "the first parameter of %<operator new%> cannot "
    2423              :                     "have a default argument");
    2424              :           /* Throw away the default argument.  */
    2425           18 :           TREE_PURPOSE (args) = NULL_TREE;
    2426              :         }
    2427              : 
    2428       139416 :       if (!same_type_p (TREE_VALUE (args), size_type_node))
    2429              :         {
    2430           21 :           e = 2;
    2431           21 :           args = TREE_CHAIN (args);
    2432              :         }
    2433              :     }
    2434              :   else
    2435              :     e = 2;
    2436              : 
    2437           21 :   if (e == 2)
    2438           36 :     permerror (loc, "%<operator new%> takes type %<size_t%> (%qT) "
    2439              :                "as first parameter", size_type_node);
    2440              : 
    2441       139431 :   switch (e)
    2442              :   {
    2443           36 :     case 2:
    2444           36 :       args = tree_cons (NULL_TREE, size_type_node, args);
    2445              :       /* Fall through.  */
    2446           42 :     case 1:
    2447           42 :       type = (cxx_copy_lang_qualifiers
    2448           42 :               (build_function_type (ptr_type_node, args),
    2449              :                type));
    2450              :       /* Fall through.  */
    2451       139431 :     default:;
    2452              :   }
    2453       139431 :   return type;
    2454              : }
    2455              : 
    2456              : void
    2457       186894 : coerce_delete_type (tree decl, location_t loc)
    2458              : {
    2459       186894 :   int e = 0;
    2460       186894 :   tree type = TREE_TYPE (decl);
    2461       186894 :   tree args = TYPE_ARG_TYPES (type);
    2462              : 
    2463       186894 :   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
    2464              : 
    2465       186894 :   if (!same_type_p (TREE_TYPE (type), void_type_node))
    2466              :     {
    2467           15 :       e = 1;
    2468           15 :       error_at (loc, "%<operator delete%> must return type %qT",
    2469              :                 void_type_node);
    2470              :     }
    2471              : 
    2472       186894 :   tree ptrtype = ptr_type_node;
    2473       186894 :   if (destroying_delete_p (decl))
    2474              :     {
    2475           37 :       if (DECL_CLASS_SCOPE_P (decl))
    2476              :         /* If the function is a destroying operator delete declared in class
    2477              :            type C, the type of its first parameter shall be C*.  */
    2478           37 :         ptrtype = build_pointer_type (DECL_CONTEXT (decl));
    2479              :       else
    2480              :         /* A destroying operator delete shall be a class member function named
    2481              :            operator delete.  */
    2482            0 :         error_at (loc,
    2483              :                   "destroying %<operator delete%> must be a member function");
    2484           37 :       const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (DECL_NAME (decl));
    2485           37 :       if (op->flags & OVL_OP_FLAG_VEC)
    2486            0 :         error_at (loc, "%<operator delete[]%> cannot be a destroying delete");
    2487           37 :       if (!usual_deallocation_fn_p (decl))
    2488            0 :         error_at (loc, "destroying %<operator delete%> must be a usual "
    2489              :                   "deallocation function");
    2490              :     }
    2491              : 
    2492       186891 :   if (!args || args == void_list_node
    2493       373782 :       || !same_type_p (TREE_VALUE (args), ptrtype))
    2494              :     {
    2495           15 :       e = 2;
    2496           15 :       if (args && args != void_list_node)
    2497            9 :         args = TREE_CHAIN (args);
    2498           15 :       error_at (loc, "%<operator delete%> takes type %qT as first parameter",
    2499              :                 ptrtype);
    2500              :     }
    2501       186879 :   switch (e)
    2502              :   {
    2503           15 :     case 2:
    2504           15 :       args = tree_cons (NULL_TREE, ptrtype, args);
    2505              :       /* Fall through.  */
    2506           30 :     case 1:
    2507           30 :       type = (cxx_copy_lang_qualifiers
    2508           30 :               (build_function_type (void_type_node, args),
    2509              :                type));
    2510              :       /* Fall through.  */
    2511       186894 :     default:;
    2512              :   }
    2513              : 
    2514       186894 :   TREE_TYPE (decl) = type;
    2515       186894 : }
    2516              : 
    2517              : /* DECL is a VAR_DECL for a vtable: walk through the entries in the vtable
    2518              :    and mark them as needed.  */
    2519              : 
    2520              : static void
    2521       442328 : mark_vtable_entries (tree decl, vec<tree> &consteval_vtables)
    2522              : {
    2523              :   /* It's OK for the vtable to refer to deprecated virtual functions.  */
    2524       442328 :   auto du = make_temp_override (deprecated_state,
    2525       442328 :                                 UNAVAILABLE_DEPRECATED_SUPPRESS);
    2526              : 
    2527       442328 :   bool consteval_seen = false;
    2528              : 
    2529      6401173 :   for (auto &e: CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
    2530              :     {
    2531      5074189 :       tree fnaddr = e.value;
    2532              : 
    2533      5074189 :       STRIP_NOPS (fnaddr);
    2534              : 
    2535      7603863 :       if (TREE_CODE (fnaddr) != ADDR_EXPR
    2536      5074189 :           && TREE_CODE (fnaddr) != FDESC_EXPR)
    2537              :         /* This entry is an offset: a virtual base class offset, a
    2538              :            virtual call offset, an RTTI offset, etc.  */
    2539      2529674 :         continue;
    2540              : 
    2541      2544515 :       tree fn = TREE_OPERAND (fnaddr, 0);
    2542      4568807 :       if (TREE_CODE (fn) == FUNCTION_DECL && DECL_IMMEDIATE_FUNCTION_P (fn))
    2543              :         {
    2544         1067 :           if (!consteval_seen)
    2545              :             {
    2546          370 :               consteval_seen = true;
    2547          370 :               consteval_vtables.safe_push (decl);
    2548              :             }
    2549         1067 :           continue;
    2550              :         }
    2551      2543448 :       TREE_ADDRESSABLE (fn) = 1;
    2552              :       /* When we don't have vcall offsets, we output thunks whenever
    2553              :          we output the vtables that contain them.  With vcall offsets,
    2554              :          we know all the thunks we'll need when we emit a virtual
    2555              :          function, so we emit the thunks there instead.  */
    2556      2543448 :       if (DECL_THUNK_P (fn))
    2557         3899 :         use_thunk (fn, /*emit_p=*/0);
    2558              :       /* Set the location, as marking the function could cause
    2559              :          instantiation.  We do not need to preserve the incoming
    2560              :          location, as we're called from c_parse_final_cleanups, which
    2561              :          takes care of that.  */
    2562      2543448 :       input_location = DECL_SOURCE_LOCATION (fn);
    2563      2543448 :       mark_used (fn);
    2564              :     }
    2565       442328 : }
    2566              : 
    2567              : /* Replace any consteval functions in vtables with null pointers.  */
    2568              : 
    2569              : static void
    2570        95785 : clear_consteval_vfns (vec<tree> &consteval_vtables)
    2571              : {
    2572        96863 :   for (tree vtable : consteval_vtables)
    2573         2938 :     for (constructor_elt &elt : CONSTRUCTOR_ELTS (DECL_INITIAL (vtable)))
    2574              :       {
    2575         1828 :         tree fn = cp_get_fndecl_from_callee (elt.value, /*fold*/false);
    2576         2910 :         if (fn && DECL_IMMEDIATE_FUNCTION_P (fn))
    2577         1067 :           elt.value = build_zero_cst (vtable_entry_type);
    2578              :       }
    2579        95785 : }
    2580              : 
    2581              : /* Adjust the TLS model on variable DECL if need be, typically after
    2582              :    the linkage of DECL has been modified.  */
    2583              : 
    2584              : static void
    2585     70235958 : adjust_var_decl_tls_model (tree decl)
    2586              : {
    2587     70235958 :   if (CP_DECL_THREAD_LOCAL_P (decl)
    2588     70235958 :       && !lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl)))
    2589          296 :     set_decl_tls_model (decl, decl_default_tls_model (decl));
    2590     70235958 : }
    2591              : 
    2592              : /* Set DECL up to have the closest approximation of "initialized common"
    2593              :    linkage available.  */
    2594              : 
    2595              : void
    2596    126824284 : comdat_linkage (tree decl)
    2597              : {
    2598    126824284 :   if (flag_weak)
    2599    126824260 :     make_decl_one_only (decl, cxx_comdat_group (decl));
    2600           24 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    2601           24 :            || (VAR_P (decl) && DECL_ARTIFICIAL (decl)))
    2602              :     /* We can just emit function and compiler-generated variables
    2603              :        statically; having multiple copies is (for the most part) only
    2604              :        a waste of space.
    2605              : 
    2606              :        There are two correctness issues, however: the address of a
    2607              :        template instantiation with external linkage should be the
    2608              :        same, independent of what translation unit asks for the
    2609              :        address, and this will not hold when we emit multiple copies of
    2610              :        the function.  However, there's little else we can do.
    2611              : 
    2612              :        Also, by default, the typeinfo implementation assumes that
    2613              :        there will be only one copy of the string used as the name for
    2614              :        each type.  Therefore, if weak symbols are unavailable, the
    2615              :        run-time library should perform a more conservative check; it
    2616              :        should perform a string comparison, rather than an address
    2617              :        comparison.  */
    2618           24 :     TREE_PUBLIC (decl) = 0;
    2619              :   else
    2620              :     {
    2621              :       /* Static data member template instantiations, however, cannot
    2622              :          have multiple copies.  */
    2623            0 :       if (DECL_INITIAL (decl) == 0
    2624            0 :           || DECL_INITIAL (decl) == error_mark_node)
    2625            0 :         DECL_COMMON (decl) = 1;
    2626            0 :       else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
    2627              :         {
    2628            0 :           DECL_COMMON (decl) = 1;
    2629            0 :           DECL_INITIAL (decl) = error_mark_node;
    2630              :         }
    2631            0 :       else if (!DECL_EXPLICIT_INSTANTIATION (decl))
    2632              :         {
    2633              :           /* We can't do anything useful; leave vars for explicit
    2634              :              instantiation.  */
    2635            0 :           DECL_EXTERNAL (decl) = 1;
    2636            0 :           DECL_NOT_REALLY_EXTERN (decl) = 0;
    2637              :         }
    2638              :     }
    2639              : 
    2640    126824284 :   if (TREE_PUBLIC (decl))
    2641    126824260 :     DECL_COMDAT (decl) = 1;
    2642              : 
    2643    126824284 :   if (VAR_P (decl))
    2644     70235341 :     adjust_var_decl_tls_model (decl);
    2645    126824284 : }
    2646              : 
    2647              : /* For win32 we also want to put explicit instantiations in
    2648              :    linkonce sections, so that they will be merged with implicit
    2649              :    instantiations; otherwise we get duplicate symbol errors.
    2650              :    For Darwin we do not want explicit instantiations to be
    2651              :    linkonce.  */
    2652              : 
    2653              : void
    2654       700573 : maybe_make_one_only (tree decl)
    2655              : {
    2656              :   /* We used to say that this was not necessary on targets that support weak
    2657              :      symbols, because the implicit instantiations will defer to the explicit
    2658              :      one.  However, that's not actually the case in SVR4; a strong definition
    2659              :      after a weak one is an error.  Also, not making explicit
    2660              :      instantiations one_only means that we can end up with two copies of
    2661              :      some template instantiations.  */
    2662       700573 :   if (! flag_weak)
    2663              :     return;
    2664              : 
    2665              :   /* These are not to be output.  */
    2666       700570 :   if (consteval_only_p (decl))
    2667              :     return;
    2668              : 
    2669              :   /* We can't set DECL_COMDAT on functions, or cp_finish_file will think
    2670              :      we can get away with not emitting them if they aren't used.  We need
    2671              :      to for variables so that cp_finish_decl will update their linkage,
    2672              :      because their DECL_INITIAL may not have been set properly yet.  */
    2673              : 
    2674       698087 :   if (!TARGET_WEAK_NOT_IN_ARCHIVE_TOC
    2675              :       || (! DECL_EXPLICIT_INSTANTIATION (decl)
    2676              :           && ! DECL_TEMPLATE_SPECIALIZATION (decl)))
    2677              :     {
    2678       698087 :       make_decl_one_only (decl, cxx_comdat_group (decl));
    2679              : 
    2680       698087 :       if (VAR_P (decl))
    2681              :         {
    2682          617 :           varpool_node *node = varpool_node::get_create (decl);
    2683          617 :           DECL_COMDAT (decl) = 1;
    2684              :           /* Mark it needed so we don't forget to emit it.  */
    2685          617 :           node->forced_by_abi = true;
    2686          617 :           TREE_USED (decl) = 1;
    2687              : 
    2688          617 :           adjust_var_decl_tls_model (decl);
    2689              :         }
    2690              :     }
    2691              : }
    2692              : 
    2693              : /* Returns true iff DECL, a FUNCTION_DECL or VAR_DECL, has vague linkage.
    2694              :    This predicate will give the right answer during parsing of the
    2695              :    function, which other tests may not.  */
    2696              : 
    2697              : bool
    2698     37820345 : vague_linkage_p (tree decl)
    2699              : {
    2700     37820348 :   if (!TREE_PUBLIC (decl))
    2701              :     {
    2702              :       /* maybe_thunk_body clears TREE_PUBLIC and DECL_ABSTRACT_P on the
    2703              :          maybe-in-charge 'tor variants; in that case we need to check one of
    2704              :          the "clones" for the real linkage.  But only in that case; before
    2705              :          maybe_clone_body we haven't yet copied the linkage to the clones.  */
    2706         7786 :       if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl)
    2707           61 :           && !DECL_ABSTRACT_P (decl)
    2708            3 :           && DECL_CHAIN (decl)
    2709         3917 :           && DECL_CLONED_FUNCTION_P (DECL_CHAIN (decl)))
    2710            3 :         return vague_linkage_p (DECL_CHAIN (decl));
    2711              : 
    2712         3911 :       gcc_checking_assert (!DECL_COMDAT (decl));
    2713              :       return false;
    2714              :     }
    2715              :   /* Unfortunately, import_export_decl has not always been called
    2716              :      before the function is processed, so we cannot simply check
    2717              :      DECL_COMDAT.  */
    2718     37816434 :   if (DECL_COMDAT (decl)
    2719       918144 :       || (TREE_CODE (decl) == FUNCTION_DECL
    2720       908281 :           && DECL_NONGNU_INLINE_P (decl))
    2721        63006 :       || (DECL_LANG_SPECIFIC (decl)
    2722        62557 :           && DECL_TEMPLOID_INSTANTIATION (decl))
    2723     37850520 :       || (VAR_P (decl) && DECL_INLINE_VAR_P (decl)))
    2724     37786723 :     return true;
    2725        29711 :   else if (DECL_FUNCTION_SCOPE_P (decl))
    2726              :     /* A local static in an inline effectively has vague linkage.  */
    2727            0 :     return (TREE_STATIC (decl)
    2728            0 :             && vague_linkage_p (DECL_CONTEXT (decl)));
    2729              :   else
    2730              :     return false;
    2731              : }
    2732              : 
    2733              : /* Determine whether or not we want to specifically import or export CTYPE,
    2734              :    using various heuristics.  */
    2735              : 
    2736              : static void
    2737      4093484 : import_export_class (tree ctype)
    2738              : {
    2739              :   /* -1 for imported, 1 for exported.  */
    2740      4093484 :   int import_export = 0;
    2741              : 
    2742              :   /* It only makes sense to call this function at EOF.  The reason is
    2743              :      that this function looks at whether or not the first non-inline
    2744              :      non-abstract virtual member function has been defined in this
    2745              :      translation unit.  But, we can't possibly know that until we've
    2746              :      seen the entire translation unit.  */
    2747      4093484 :   gcc_assert (at_eof);
    2748              : 
    2749      4093484 :   if (CLASSTYPE_INTERFACE_KNOWN (ctype))
    2750              :     return;
    2751              : 
    2752              :   /* If MULTIPLE_SYMBOL_SPACES is set and we saw a #pragma interface,
    2753              :      we will have CLASSTYPE_INTERFACE_ONLY set but not
    2754              :      CLASSTYPE_INTERFACE_KNOWN.  In that case, we don't want to use this
    2755              :      heuristic because someone will supply a #pragma implementation
    2756              :      elsewhere, and deducing it here would produce a conflict.  */
    2757      2345987 :   if (CLASSTYPE_INTERFACE_ONLY (ctype))
    2758              :     return;
    2759              : 
    2760      2345987 :   if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype)))
    2761              :     import_export = -1;
    2762      2345987 :   else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype)))
    2763              :     import_export = 1;
    2764      2345987 :   else if (CLASSTYPE_IMPLICIT_INSTANTIATION (ctype)
    2765      2345987 :            && !flag_implicit_templates)
    2766              :     /* For a template class, without -fimplicit-templates, check the
    2767              :        repository.  If the virtual table is assigned to this
    2768              :        translation unit, then export the class; otherwise, import
    2769              :        it.  */
    2770              :       import_export = -1;
    2771      2345342 :   else if (TYPE_CONTAINS_VPTR_P (ctype))
    2772              :     {
    2773      2178778 :       tree cdecl = TYPE_NAME (ctype);
    2774      2182188 :       if (DECL_LANG_SPECIFIC (cdecl) && DECL_MODULE_ATTACH_P (cdecl))
    2775              :         /* For class types attached to a named module, the ABI specifies
    2776              :            that the tables are uniquely emitted in the object for the
    2777              :            module unit in which it is defined.  */
    2778         1740 :         import_export = (DECL_MODULE_IMPORT_P (cdecl) ? -1 : 1);
    2779              :       else
    2780              :         {
    2781              :           /* The ABI specifies that the virtual table and associated
    2782              :              information are emitted with the key method, if any.  */
    2783      2178583 :           tree method = CLASSTYPE_KEY_METHOD (ctype);
    2784              :           /* If weak symbol support is not available, then we must be
    2785              :              careful not to emit the vtable when the key function is
    2786              :              inline.  An inline function can be defined in multiple
    2787              :              translation units.  If we were to emit the vtable in each
    2788              :              translation unit containing a definition, we would get
    2789              :              multiple definition errors at link-time.  */
    2790      2154981 :           if (method && (flag_weak || ! DECL_NONGNU_INLINE_P (method)))
    2791       564976 :             import_export = (DECL_REALLY_EXTERN (method) ? -1 : 1);
    2792              :         }
    2793              :     }
    2794              : 
    2795              :   /* When MULTIPLE_SYMBOL_SPACES is set, we cannot count on seeing
    2796              :      a definition anywhere else.  */
    2797      2345987 :   if (MULTIPLE_SYMBOL_SPACES && import_export == -1)
    2798              :     import_export = 0;
    2799              : 
    2800              :   /* Allow back ends the chance to overrule the decision.  */
    2801      2345987 :   if (targetm.cxx.import_export_class)
    2802            0 :     import_export = targetm.cxx.import_export_class (ctype, import_export);
    2803              : 
    2804      2345987 :   if (import_export)
    2805              :     {
    2806       565816 :       SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
    2807       565816 :       CLASSTYPE_INTERFACE_ONLY (ctype) = (import_export < 0);
    2808              :     }
    2809              : }
    2810              : 
    2811              : /* Return true if VAR has already been provided to the back end; in that
    2812              :    case VAR should not be modified further by the front end.  */
    2813              : static bool
    2814    114736820 : var_finalized_p (tree var)
    2815              : {
    2816            0 :   return varpool_node::get_create (var)->definition;
    2817              : }
    2818              : 
    2819              : /* DECL is a VAR_DECL or FUNCTION_DECL which, for whatever reason,
    2820              :    must be emitted in this translation unit.  Mark it as such.  */
    2821              : 
    2822              : void
    2823        49594 : mark_needed (tree decl)
    2824              : {
    2825              :   /* These are not to be output.  */
    2826        49594 :   if (consteval_only_p (decl))
    2827              :     return;
    2828              : 
    2829        49589 :   TREE_USED (decl) = 1;
    2830        49589 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    2831              :     {
    2832              :       /* Extern inline functions don't become needed when referenced.
    2833              :          If we know a method will be emitted in other TU and no new
    2834              :          functions can be marked reachable, just use the external
    2835              :          definition.  */
    2836        41558 :       struct cgraph_node *node = cgraph_node::get_create (decl);
    2837        41558 :       node->forced_by_abi = true;
    2838              : 
    2839              :       /* #pragma interface can call mark_needed for
    2840              :           maybe-in-charge 'tors; mark the clones as well.  */
    2841        41558 :       tree clone;
    2842        49940 :       FOR_EACH_CLONE (clone, decl)
    2843         8382 :         mark_needed (clone);
    2844              :     }
    2845         8031 :   else if (VAR_P (decl))
    2846              :     {
    2847         8031 :       varpool_node *node = varpool_node::get_create (decl);
    2848              :       /* C++ frontend use mark_decl_references to force COMDAT variables
    2849              :          to be output that might appear dead otherwise.  */
    2850         8031 :       node->forced_by_abi = true;
    2851              :     }
    2852              : }
    2853              : 
    2854              : /* DECL is either a FUNCTION_DECL or a VAR_DECL.  This function
    2855              :    returns true if a definition of this entity should be provided in
    2856              :    this object file.  Callers use this function to determine whether
    2857              :    or not to let the back end know that a definition of DECL is
    2858              :    available in this translation unit.  */
    2859              : 
    2860              : bool
    2861    362192110 : decl_needed_p (tree decl)
    2862              : {
    2863    362192110 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
    2864              :   /* This function should only be called at the end of the translation
    2865              :      unit.  We cannot be sure of whether or not something will be
    2866              :      COMDAT until that point.  */
    2867    362192110 :   gcc_assert (at_eof);
    2868              : 
    2869              :   /* All entities with external linkage that are not COMDAT/EXTERN should be
    2870              :      emitted; they may be referred to from other object files.  */
    2871    362192110 :   if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_REALLY_EXTERN (decl))
    2872              :     return true;
    2873              : 
    2874              :   /* Functions marked "dllexport" must be emitted so that they are
    2875              :      visible to other DLLs.  */
    2876    362191830 :   if (flag_keep_inline_dllexport
    2877    362191830 :       && lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))
    2878              :     return true;
    2879              : 
    2880              :   /* When not optimizing, do not bother to produce definitions for extern
    2881              :      symbols.  */
    2882    436474889 :   if (DECL_REALLY_EXTERN (decl)
    2883            0 :       && ((TREE_CODE (decl) != FUNCTION_DECL
    2884            0 :            && !optimize)
    2885            0 :           || (TREE_CODE (decl) == FUNCTION_DECL
    2886            0 :               && !opt_for_fn (decl, optimize)))
    2887    362191830 :       && !lookup_attribute ("always_inline", decl))
    2888              :     return false;
    2889              : 
    2890              :   /* If this entity was used, let the back end see it; it will decide
    2891              :      whether or not to emit it into the object file.  */
    2892    362191830 :   if (TREE_USED (decl))
    2893              :     return true;
    2894              : 
    2895              :   /* Virtual functions might be needed for devirtualization.  */
    2896     64856228 :   if (flag_devirtualize
    2897     63054958 :       && TREE_CODE (decl) == FUNCTION_DECL
    2898    126648693 :       && DECL_VIRTUAL_P (decl))
    2899              :     return true;
    2900              : 
    2901              :   /* Otherwise, DECL does not need to be emitted -- yet.  A subsequent
    2902              :      reference to DECL might cause it to be emitted later.  */
    2903              :   return false;
    2904              : }
    2905              : 
    2906              : /* If necessary, write out the vtables for the dynamic class CTYPE.
    2907              :    Returns true if any vtables were emitted.  */
    2908              : 
    2909              : static bool
    2910      3692598 : maybe_emit_vtables (tree ctype, vec<tree> &consteval_vtables)
    2911              : {
    2912      3692598 :   tree vtbl;
    2913      3692598 :   tree primary_vtbl;
    2914      3692598 :   int needed = 0;
    2915      3692598 :   varpool_node *current = NULL, *last = NULL;
    2916              : 
    2917              :   /* If the vtables for this class have already been emitted there is
    2918              :      nothing more to do.  */
    2919      3692598 :   primary_vtbl = CLASSTYPE_VTABLES (ctype);
    2920      3692598 :   if (var_finalized_p (primary_vtbl))
    2921              :     return false;
    2922              :   /* Ignore dummy vtables made by get_vtable_decl.  */
    2923      3692598 :   if (TREE_TYPE (primary_vtbl) == void_type_node)
    2924              :     return false;
    2925              : 
    2926              :   /* On some targets, we cannot determine the key method until the end
    2927              :      of the translation unit -- which is when this function is
    2928              :      called.  */
    2929      3692598 :   if (!targetm.cxx.key_method_may_be_inline ())
    2930            0 :     determine_key_method (ctype);
    2931              : 
    2932              :   /* See if any of the vtables are needed.  */
    2933      8989751 :   for (vtbl = CLASSTYPE_VTABLES (ctype); vtbl; vtbl = DECL_CHAIN (vtbl))
    2934              :     {
    2935      5297153 :       import_export_decl (vtbl);
    2936      5297153 :       if (DECL_NOT_REALLY_EXTERN (vtbl) && decl_needed_p (vtbl))
    2937              :         needed = 1;
    2938              :     }
    2939      3692598 :   if (!needed)
    2940              :     {
    2941              :       /* If the references to this class' vtables are optimized away,
    2942              :          still emit the appropriate debugging information.  See
    2943              :          dfs_debug_mark.  */
    2944      3270133 :       if (DECL_COMDAT (primary_vtbl)
    2945      3270133 :           && CLASSTYPE_DEBUG_REQUESTED (ctype))
    2946        37400 :         note_debug_info_needed (ctype);
    2947      3270133 :       return false;
    2948              :     }
    2949              : 
    2950              :   /* The ABI requires that we emit all of the vtables if we emit any
    2951              :      of them.  */
    2952       864793 :   for (vtbl = CLASSTYPE_VTABLES (ctype); vtbl; vtbl = DECL_CHAIN (vtbl))
    2953              :     {
    2954              :       /* Mark entities references from the virtual table as used.  */
    2955       442328 :       mark_vtable_entries (vtbl, consteval_vtables);
    2956              : 
    2957       442328 :       if (TREE_TYPE (DECL_INITIAL (vtbl)) == 0)
    2958              :         {
    2959            0 :           vec<tree, va_gc> *cleanups = NULL;
    2960            0 :           tree expr = store_init_value (vtbl, DECL_INITIAL (vtbl), &cleanups,
    2961              :                                         LOOKUP_NORMAL);
    2962              : 
    2963              :           /* It had better be all done at compile-time.  */
    2964            0 :           gcc_assert (!expr && !cleanups);
    2965              :         }
    2966              : 
    2967              :       /* Write it out.  */
    2968       442328 :       DECL_EXTERNAL (vtbl) = 0;
    2969       442328 :       rest_of_decl_compilation (vtbl, 1, 1);
    2970              : 
    2971              :       /* Because we're only doing syntax-checking, we'll never end up
    2972              :          actually marking the variable as written.  */
    2973       442328 :       if (flag_syntax_only)
    2974           33 :         TREE_ASM_WRITTEN (vtbl) = 1;
    2975       442295 :       else if (DECL_ONE_ONLY (vtbl))
    2976              :         {
    2977       441613 :           current = varpool_node::get_create (vtbl);
    2978       441613 :           if (last)
    2979        19793 :             current->add_to_same_comdat_group (last);
    2980              :           last = current;
    2981              :         }
    2982              :     }
    2983              : 
    2984              :   /* For abstract classes, the destructor has been removed from the
    2985              :      vtable (in class.cc's build_vtbl_initializer).  For a compiler-
    2986              :      generated destructor, it hence might not have been generated in
    2987              :      this translation unit - and with '#pragma interface' it might
    2988              :      never get generated.  */
    2989       422465 :   if (CLASSTYPE_PURE_VIRTUALS (ctype)
    2990       124018 :       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype)
    2991        68320 :       && !CLASSTYPE_LAZY_DESTRUCTOR (ctype)
    2992       490782 :       && DECL_DEFAULTED_IN_CLASS_P (CLASSTYPE_DESTRUCTOR (ctype)))
    2993           65 :     note_vague_linkage_fn (CLASSTYPE_DESTRUCTOR (ctype));
    2994              : 
    2995              :   /* Since we're writing out the vtable here, also write the debug
    2996              :      info.  */
    2997       422465 :   note_debug_info_needed (ctype);
    2998              : 
    2999       422465 :   return true;
    3000              : }
    3001              : 
    3002              : /* A special return value from type_visibility meaning internal
    3003              :    linkage.  */
    3004              : 
    3005              : enum { VISIBILITY_ANON = VISIBILITY_INTERNAL+1 };
    3006              : 
    3007              : static int expr_visibility (tree);
    3008              : static int type_visibility (tree);
    3009              : 
    3010              : /* walk_tree helper function for type_visibility.  */
    3011              : 
    3012              : static tree
    3013   4170878493 : min_vis_r (tree *tp, int *walk_subtrees, void *data)
    3014              : {
    3015   4170878493 :   int *vis_p = (int *)data;
    3016   4170878493 :   int this_vis = VISIBILITY_DEFAULT;
    3017   4170878493 :   if (! TYPE_P (*tp))
    3018    831931466 :     *walk_subtrees = 0;
    3019   3338947027 :   else if (OVERLOAD_TYPE_P (*tp)
    3020   4382272785 :            && !TREE_PUBLIC (TYPE_MAIN_DECL (*tp)))
    3021              :     {
    3022       912526 :       this_vis = VISIBILITY_ANON;
    3023       912526 :       *walk_subtrees = 0;
    3024              :     }
    3025   3338034501 :   else if (CLASS_TYPE_P (*tp))
    3026              :     {
    3027   1015028631 :       this_vis = CLASSTYPE_VISIBILITY (*tp);
    3028   1015028631 :       *walk_subtrees = 0;
    3029              :     }
    3030   2323005870 :   else if (TREE_CODE (*tp) == ARRAY_TYPE
    3031   2323005870 :            && uses_template_parms (TYPE_DOMAIN (*tp)))
    3032       422469 :     this_vis = expr_visibility (TYPE_MAX_VALUE (TYPE_DOMAIN (*tp)));
    3033              : 
    3034   4170878493 :   if (this_vis > *vis_p)
    3035      1606737 :     *vis_p = this_vis;
    3036              : 
    3037              :   /* Tell cp_walk_subtrees to look through typedefs.  */
    3038   4170878493 :   if (*walk_subtrees == 1)
    3039   2323005870 :     *walk_subtrees = 2;
    3040              : 
    3041   4170878493 :   return NULL;
    3042              : }
    3043              : 
    3044              : /* walk_tree helper function for expr_visibility.  */
    3045              : 
    3046              : static tree
    3047    254296765 : min_vis_expr_r (tree *tp, int *walk_subtrees, void *data)
    3048              : {
    3049    254296765 :   int *vis_p = (int *)data;
    3050    254296765 :   int tpvis = VISIBILITY_DEFAULT;
    3051              : 
    3052    254296765 :   tree t = *tp;
    3053    254296765 :   if (TREE_CODE (t) == PTRMEM_CST)
    3054          765 :     t = PTRMEM_CST_MEMBER (t);
    3055              : 
    3056    254296765 :   if (TREE_CODE (t) == TEMPLATE_DECL)
    3057              :     {
    3058      6752859 :       if (DECL_ALIAS_TEMPLATE_P (t) || concept_definition_p (t))
    3059              :         /* FIXME: We don't maintain TREE_PUBLIC / DECL_VISIBILITY for
    3060              :            alias templates so we can't trust it here (PR107906).  Ditto
    3061              :            for concepts.  */
    3062              :         return NULL_TREE;
    3063              :       t = DECL_TEMPLATE_RESULT (t);
    3064              :       if (!t)
    3065              :         return NULL_TREE;
    3066              :     }
    3067              : 
    3068    253595101 :   switch (TREE_CODE (t))
    3069              :     {
    3070      8256173 :     case CAST_EXPR:
    3071      8256173 :     case IMPLICIT_CONV_EXPR:
    3072      8256173 :     case STATIC_CAST_EXPR:
    3073      8256173 :     case REINTERPRET_CAST_EXPR:
    3074      8256173 :     case CONST_CAST_EXPR:
    3075      8256173 :     case DYNAMIC_CAST_EXPR:
    3076      8256173 :     case NEW_EXPR:
    3077      8256173 :     case CONSTRUCTOR:
    3078      8256173 :     case LAMBDA_EXPR:
    3079      8256173 :     case TYPE_DECL:
    3080      8256173 :       tpvis = type_visibility (TREE_TYPE (t));
    3081      8256173 :       break;
    3082              : 
    3083         3044 :     case ADDR_EXPR:
    3084         3044 :       t = TREE_OPERAND (t, 0);
    3085         3044 :       if (VAR_P (t))
    3086              :         /* If a variable has its address taken, the lvalue-rvalue conversion is
    3087              :            not applied, so skip that case.  */
    3088          668 :         goto addressable;
    3089              :       break;
    3090              : 
    3091      8733641 :     case VAR_DECL:
    3092      8733641 :     case FUNCTION_DECL:
    3093      8733641 :       if (decl_constant_var_p (t))
    3094              :         /* The ODR allows definitions in different TUs to refer to distinct
    3095              :            constant variables with internal or no linkage, so such a reference
    3096              :            shouldn't affect visibility if the lvalue-rvalue conversion is
    3097              :            applied (PR110323).  We still want to restrict visibility according
    3098              :            to the type of the declaration however.  */
    3099              :         {
    3100      4864311 :           tpvis = type_visibility (TREE_TYPE (t));
    3101      4864311 :           break;
    3102              :         }
    3103      3869330 :     addressable:
    3104              :       /* For _DECLs with no linkage refer to the linkage of the containing
    3105              :          entity that does have a name with linkage.  */
    3106      3870171 :       if (decl_linkage (t) == lk_none)
    3107        19989 :         tpvis = expr_visibility (DECL_CONTEXT (t));
    3108              :       /* Decls that have had their visibility constrained will report
    3109              :          as external linkage, but we still want to transitively constrain
    3110              :          if we refer to them, so just check TREE_PUBLIC instead.  */
    3111      3850182 :       else if (!TREE_PUBLIC (t))
    3112              :         tpvis = VISIBILITY_ANON;
    3113              :       else
    3114      3848730 :         tpvis = DECL_VISIBILITY (t);
    3115              :       break;
    3116              : 
    3117          657 :     case FIELD_DECL:
    3118          657 :       tpvis = type_visibility (DECL_CONTEXT (t));
    3119          657 :       break;
    3120              : 
    3121          729 :     case REFLECT_EXPR:
    3122          729 :       tree r;
    3123          729 :       r = REFLECT_EXPR_HANDLE (t);
    3124          729 :       switch (REFLECT_EXPR_KIND (t))
    3125              :         {
    3126           17 :         case REFLECT_BASE:
    3127              :           /* For direct base class relationship, determine visibility
    3128              :              from both D and B types.  */
    3129           17 :           tpvis = type_visibility (BINFO_TYPE (r));
    3130           17 :           if (tpvis > *vis_p)
    3131            1 :             *vis_p = tpvis;
    3132           17 :           tpvis = type_visibility (direct_base_derived (r));
    3133           17 :           *walk_subtrees = 0;
    3134           17 :           break;
    3135           13 :         case REFLECT_DATA_MEMBER_SPEC:
    3136              :           /* For data member description determine visibility
    3137              :              from the type.  */
    3138           13 :           tpvis = type_visibility (TREE_VEC_ELT (r, 0));
    3139           13 :           *walk_subtrees = 0;
    3140           13 :           break;
    3141           25 :         case REFLECT_PARM:
    3142              :           /* For function parameter reflection determine visibility
    3143              :              based on parent_of.  */
    3144           25 :           tpvis = expr_visibility (DECL_CONTEXT (r));
    3145           25 :           *walk_subtrees = 0;
    3146           25 :           break;
    3147            3 :         case REFLECT_ANNOTATION:
    3148              :           /* Annotations are always local to the TU.  */
    3149            3 :           tpvis = VISIBILITY_ANON;
    3150            3 :           *walk_subtrees = 0;
    3151            3 :           break;
    3152            8 :         case REFLECT_OBJECT:
    3153            8 :           r = get_base_address (r);
    3154          671 :           gcc_fallthrough ();
    3155          671 :         default:
    3156          671 :           if (TYPE_P (r))
    3157              :             {
    3158          128 :               tpvis = type_visibility (r);
    3159          128 :               *walk_subtrees = 0;
    3160          128 :               break;
    3161              :             }
    3162          543 :           if (VAR_P (r) || TREE_CODE (r) == PARM_DECL)
    3163              :             {
    3164          173 :               t = r;
    3165          173 :               goto addressable;
    3166              :             }
    3167              :           break;
    3168              :         }
    3169              :       break;
    3170              : 
    3171              :     default:
    3172              :       break;
    3173              :     }
    3174              : 
    3175    253595101 :   if (tpvis > *vis_p)
    3176         3219 :     *vis_p = tpvis;
    3177              : 
    3178              :   return NULL_TREE;
    3179              : }
    3180              : 
    3181              : /* Returns the visibility of TYPE, which is the minimum visibility of its
    3182              :    component types.  */
    3183              : 
    3184              : static int
    3185   1225649700 : type_visibility (tree type)
    3186              : {
    3187   1225649700 :   int vis = VISIBILITY_DEFAULT;
    3188   1225649700 :   cp_walk_tree_without_duplicates (&type, min_vis_r, &vis);
    3189   1225649700 :   return vis;
    3190              : }
    3191              : 
    3192              : /* Returns the visibility of an expression EXPR that appears in the signature
    3193              :    of a function template, which is the minimum visibility of names that appear
    3194              :    in its mangling.  */
    3195              : 
    3196              : static int
    3197     88831209 : expr_visibility (tree expr)
    3198              : {
    3199     88831209 :   int vis = VISIBILITY_DEFAULT;
    3200     88831209 :   cp_walk_tree_without_duplicates (&expr, min_vis_expr_r, &vis);
    3201     88831209 :   return vis;
    3202              : }
    3203              : 
    3204              : /* Limit the visibility of DECL to VISIBILITY, if not explicitly
    3205              :    specified (or if VISIBILITY is static).  If TMPL is true, this
    3206              :    constraint is for a template argument, and takes precedence
    3207              :    over explicitly-specified visibility on the template.  */
    3208              : 
    3209              : static void
    3210     90479735 : constrain_visibility (tree decl, int visibility, bool tmpl)
    3211              : {
    3212     90479735 :   if (visibility == VISIBILITY_ANON)
    3213              :     {
    3214              :       /* extern "C" declarations aren't affected by the anonymous
    3215              :          namespace.  */
    3216      1324639 :       if (!DECL_EXTERN_C_P (decl))
    3217              :         {
    3218      1324466 :           TREE_PUBLIC (decl) = 0;
    3219      1324466 :           DECL_WEAK (decl) = 0;
    3220      1324466 :           DECL_COMMON (decl) = 0;
    3221      1324466 :           DECL_COMDAT (decl) = false;
    3222      1324466 :           if (VAR_OR_FUNCTION_DECL_P (decl))
    3223              :             {
    3224       384833 :               struct symtab_node *snode = symtab_node::get (decl);
    3225              : 
    3226       384833 :               if (snode)
    3227        32092 :                 snode->set_comdat_group (NULL);
    3228              :             }
    3229      1324466 :           DECL_INTERFACE_KNOWN (decl) = 1;
    3230      1324466 :           if (DECL_LANG_SPECIFIC (decl))
    3231       388448 :             DECL_NOT_REALLY_EXTERN (decl) = 1;
    3232              :         }
    3233              :     }
    3234     89155096 :   else if (visibility > DECL_VISIBILITY (decl)
    3235     89155096 :            && (tmpl || !DECL_VISIBILITY_SPECIFIED (decl)))
    3236              :     {
    3237          309 :       DECL_VISIBILITY (decl) = (enum symbol_visibility) visibility;
    3238              :       /* This visibility was not specified.  */
    3239          309 :       DECL_VISIBILITY_SPECIFIED (decl) = false;
    3240              :     }
    3241     90479735 : }
    3242              : 
    3243              : /* Constrain the visibility of DECL based on the visibility of its template
    3244              :    arguments.  */
    3245              : 
    3246              : static void
    3247    378796192 : constrain_visibility_for_template (tree decl, tree targs)
    3248              : {
    3249              :   /* If this is a template instantiation, check the innermost
    3250              :      template args for visibility constraints.  The outer template
    3251              :      args are covered by the class check.  */
    3252    378796192 :   tree args = INNERMOST_TEMPLATE_ARGS (targs);
    3253    378796192 :   int i;
    3254   1090060980 :   for (i = TREE_VEC_LENGTH (args); i > 0; --i)
    3255              :     {
    3256    711264788 :       int vis = 0;
    3257              : 
    3258    711264788 :       tree arg = TREE_VEC_ELT (args, i-1);
    3259    711264788 :       if (TYPE_P (arg))
    3260    624643904 :         vis = type_visibility (arg);
    3261              :       else
    3262     86620884 :         vis = expr_visibility (arg);
    3263    711264788 :       if (vis)
    3264       336514 :         constrain_visibility (decl, vis, true);
    3265              :     }
    3266    378796192 : }
    3267              : 
    3268              : /* Like c_determine_visibility, but with additional C++-specific
    3269              :    behavior.
    3270              : 
    3271              :    Function-scope entities can rely on the function's visibility because
    3272              :    it is set in start_preparsed_function.
    3273              : 
    3274              :    Class-scope entities cannot rely on the class's visibility until the end
    3275              :    of the enclosing class definition.
    3276              : 
    3277              :    Note that because namespaces have multiple independent definitions,
    3278              :    namespace visibility is handled elsewhere using the #pragma visibility
    3279              :    machinery rather than by decorating the namespace declaration.
    3280              : 
    3281              :    The goal is for constraints from the type to give a diagnostic, and
    3282              :    other constraints to be applied silently.  */
    3283              : 
    3284              : void
    3285    734531845 : determine_visibility (tree decl)
    3286              : {
    3287              :   /* Remember that all decls get VISIBILITY_DEFAULT when built.  */
    3288              : 
    3289              :   /* Only relevant for names with external linkage.  */
    3290    734531845 :   if (!TREE_PUBLIC (decl))
    3291              :     return;
    3292              : 
    3293              :   /* Cloned constructors and destructors get the same visibility as
    3294              :      the underlying function.  That should be set up in
    3295              :      maybe_clone_body.  */
    3296    671189019 :   gcc_assert (!DECL_CLONED_FUNCTION_P (decl));
    3297              : 
    3298    671189019 :   bool orig_visibility_specified = DECL_VISIBILITY_SPECIFIED (decl);
    3299    671189019 :   enum symbol_visibility orig_visibility = DECL_VISIBILITY (decl);
    3300              : 
    3301              :   /* The decl may be a template instantiation, which could influence
    3302              :      visibilty.  */
    3303    671189019 :   tree template_decl = NULL_TREE;
    3304    671189019 :   if (TREE_CODE (decl) == TYPE_DECL)
    3305              :     {
    3306    184662858 :       if (CLASS_TYPE_P (TREE_TYPE (decl)))
    3307              :         {
    3308    181557209 :           if (CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)))
    3309    384125398 :             template_decl = decl;
    3310              :         }
    3311      3105649 :       else if (TYPE_TEMPLATE_INFO (TREE_TYPE (decl)))
    3312    384125398 :         template_decl = decl;
    3313              :     }
    3314    486526161 :   else if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    3315              :     template_decl = decl;
    3316              : 
    3317    671189019 :   if (TREE_CODE (decl) == TYPE_DECL
    3318    365146029 :       && LAMBDA_TYPE_P (TREE_TYPE (decl))
    3319    674731780 :       && CLASSTYPE_LAMBDA_EXPR (TREE_TYPE (decl)) != error_mark_node)
    3320      3537698 :     if (tree extra = LAMBDA_TYPE_EXTRA_SCOPE (TREE_TYPE (decl)))
    3321              :       {
    3322              :         /* The lambda's visibility is limited by that of its extra
    3323              :            scope.  */
    3324      1767842 :         int vis = 0;
    3325      1767842 :         if (TYPE_P (extra))
    3326            0 :           vis = type_visibility (extra);
    3327              :         else
    3328      1767842 :           vis = expr_visibility (extra);
    3329      1767842 :         constrain_visibility (decl, vis, false);
    3330              :       }
    3331              : 
    3332              :   /* If DECL is a member of a class, visibility specifiers on the
    3333              :      class can influence the visibility of the DECL.  */
    3334    671189019 :   tree class_type = NULL_TREE;
    3335    671189019 :   if (DECL_CLASS_SCOPE_P (decl))
    3336    335580681 :     class_type = DECL_CONTEXT (decl);
    3337              :   else
    3338              :     {
    3339              :       /* Not a class member.  */
    3340              : 
    3341              :       /* Virtual tables have DECL_CONTEXT set to their associated class,
    3342              :          so they are automatically handled above.  */
    3343    335608338 :       gcc_assert (!VAR_P (decl)
    3344              :                   || !DECL_VTABLE_OR_VTT_P (decl));
    3345              : 
    3346    335608338 :       if (DECL_FUNCTION_SCOPE_P (decl) && ! DECL_VISIBILITY_SPECIFIED (decl))
    3347              :         {
    3348              :           /* Local statics and classes get the visibility of their
    3349              :              containing function by default, except that
    3350              :              -fvisibility-inlines-hidden doesn't affect them.  */
    3351      2704556 :           tree fn = DECL_CONTEXT (decl);
    3352      2704556 :           if (DECL_VISIBILITY_SPECIFIED (fn))
    3353              :             {
    3354      2640514 :               DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
    3355      2640514 :               DECL_VISIBILITY_SPECIFIED (decl) =
    3356      2640514 :                 DECL_VISIBILITY_SPECIFIED (fn);
    3357              :             }
    3358              :           else
    3359              :             {
    3360        64042 :               if (DECL_CLASS_SCOPE_P (fn))
    3361        32825 :                 determine_visibility_from_class (decl, DECL_CONTEXT (fn));
    3362        31217 :               else if (determine_hidden_inline (fn))
    3363              :                 {
    3364            6 :                   DECL_VISIBILITY (decl) = default_visibility;
    3365            6 :                   DECL_VISIBILITY_SPECIFIED (decl) =
    3366            6 :                     visibility_options.inpragma;
    3367              :                 }
    3368              :               else
    3369              :                 {
    3370        31211 :                   DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
    3371        31211 :                   DECL_VISIBILITY_SPECIFIED (decl) =
    3372        31211 :                     DECL_VISIBILITY_SPECIFIED (fn);
    3373              :                 }
    3374              :             }
    3375              : 
    3376              :           /* Local classes in templates have CLASSTYPE_USE_TEMPLATE set,
    3377              :              but have no TEMPLATE_INFO, so don't try to check it.  */
    3378              :           template_decl = NULL_TREE;
    3379              :         }
    3380     59702049 :       else if (VAR_P (decl) && DECL_TINFO_P (decl)
    3381    338249270 :                && flag_visibility_ms_compat)
    3382              :         {
    3383              :           /* Under -fvisibility-ms-compat, types are visible by default,
    3384              :              even though their contents aren't.  */
    3385           84 :           tree underlying_type = TREE_TYPE (DECL_NAME (decl));
    3386           84 :           int underlying_vis = type_visibility (underlying_type);
    3387           84 :           if (underlying_vis == VISIBILITY_ANON
    3388           84 :               || (CLASS_TYPE_P (underlying_type)
    3389           69 :                   && CLASSTYPE_VISIBILITY_SPECIFIED (underlying_type)))
    3390           54 :             constrain_visibility (decl, underlying_vis, false);
    3391              :           else
    3392           30 :             DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    3393              :         }
    3394    332903698 :       else if (VAR_P (decl) && DECL_TINFO_P (decl))
    3395              :         {
    3396              :           /* tinfo visibility is based on the type it's for.  */
    3397      5345404 :           constrain_visibility
    3398      5345404 :             (decl, type_visibility (TREE_TYPE (DECL_NAME (decl))), false);
    3399              : 
    3400              :           /* Give the target a chance to override the visibility associated
    3401              :              with DECL.  */
    3402      5345404 :           if (TREE_PUBLIC (decl)
    3403      5343512 :               && !DECL_REALLY_EXTERN (decl)
    3404      5343512 :               && CLASS_TYPE_P (TREE_TYPE (DECL_NAME (decl)))
    3405     10659049 :               && !CLASSTYPE_VISIBILITY_SPECIFIED (TREE_TYPE (DECL_NAME (decl))))
    3406       107531 :             targetm.cxx.determine_class_data_visibility (decl);
    3407              :         }
    3408    327558294 :       else if (template_decl)
    3409              :         /* Template instantiations and specializations get visibility based
    3410              :            on their template unless they override it with an attribute.  */;
    3411    104826470 :       else if (! DECL_VISIBILITY_SPECIFIED (decl))
    3412              :         {
    3413     96610012 :           if (determine_hidden_inline (decl))
    3414           12 :             DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
    3415              :           else
    3416              :             {
    3417              :               /* Set default visibility to whatever the user supplied with
    3418              :                  #pragma GCC visibility or a namespace visibility attribute.  */
    3419     96610000 :               DECL_VISIBILITY (decl) = default_visibility;
    3420     96610000 :               DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
    3421              :             }
    3422              :         }
    3423              :     }
    3424              : 
    3425    445752639 :   if (template_decl)
    3426              :     {
    3427              :       /* If the specialization doesn't specify visibility, use the
    3428              :          visibility from the template.  */
    3429    383452463 :       tree tinfo = get_template_info (template_decl);
    3430    383452463 :       tree args = TI_ARGS (tinfo);
    3431    383452463 :       tree attribs = (TREE_CODE (decl) == TYPE_DECL
    3432    383452463 :                       ? TYPE_ATTRIBUTES (TREE_TYPE (decl))
    3433    383452463 :                       : DECL_ATTRIBUTES (decl));
    3434    383452463 :       tree attr = lookup_attribute ("visibility", attribs);
    3435              : 
    3436    383452463 :       if (args != error_mark_node)
    3437              :         {
    3438    383452463 :           tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
    3439              : 
    3440    383452463 :           if (!DECL_VISIBILITY_SPECIFIED (decl))
    3441              :             {
    3442    175768665 :               if (!attr
    3443    175768665 :                   && determine_hidden_inline (decl))
    3444           33 :                 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
    3445              :               else
    3446              :                 {
    3447    175768632 :                   DECL_VISIBILITY (decl) = DECL_VISIBILITY (pattern);
    3448    351537264 :                   DECL_VISIBILITY_SPECIFIED (decl)
    3449    175768632 :                     = DECL_VISIBILITY_SPECIFIED (pattern);
    3450              :                 }
    3451              :             }
    3452              : 
    3453    383452463 :           if (args
    3454              :               /* Template argument visibility outweighs #pragma or namespace
    3455              :                  visibility, but not an explicit attribute.  */
    3456    383452463 :               && !attr)
    3457              :             {
    3458    383452442 :               int depth = TMPL_ARGS_DEPTH (args);
    3459    383452442 :               if (DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (TI_TEMPLATE (tinfo)))
    3460              :                 /* Class template args don't affect template friends.  */;
    3461    380650027 :               else if (DECL_VISIBILITY_SPECIFIED (decl))
    3462              :                 {
    3463              :                   /* A class template member with explicit visibility
    3464              :                      overrides the class visibility, so we need to apply
    3465              :                      all the levels of template args directly.  */
    3466              :                   int i;
    3467    665094777 :                   for (i = 1; i <= depth; ++i)
    3468              :                     {
    3469    338667710 :                       tree lev = TMPL_ARGS_LEVEL (args, i);
    3470    338667710 :                       constrain_visibility_for_template (decl, lev);
    3471              :                     }
    3472              :                 }
    3473     54222960 :               else if (PRIMARY_TEMPLATE_P (TI_TEMPLATE (tinfo)))
    3474              :                 /* Limit visibility based on its template arguments.  */
    3475     40128482 :                 constrain_visibility_for_template (decl, args);
    3476              :             }
    3477              :         }
    3478              :     }
    3479              : 
    3480    671189019 :   if (class_type)
    3481    335580681 :     determine_visibility_from_class (decl, class_type);
    3482              : 
    3483    671189019 :   if (decl_internal_context_p (decl))
    3484              :     /* Names in an anonymous namespace get internal linkage.  */
    3485       275409 :     constrain_visibility (decl, VISIBILITY_ANON, false);
    3486    670913610 :   else if (TREE_CODE (decl) != TYPE_DECL)
    3487              :     {
    3488              :       /* Propagate anonymity from type to decl.  */
    3489    486381362 :       int tvis = type_visibility (TREE_TYPE (decl));
    3490    486381362 :       if (tvis == VISIBILITY_ANON
    3491    486381362 :           || ! DECL_VISIBILITY_SPECIFIED (decl))
    3492     82026597 :         constrain_visibility (decl, tvis, false);
    3493              :     }
    3494    184532248 :   else if (no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/true))
    3495              :     /* DR 757: A type without linkage shall not be used as the type of a
    3496              :        variable or function with linkage, unless
    3497              :        o the variable or function has extern "C" linkage (7.5 [dcl.link]), or
    3498              :        o the variable or function is not used (3.2 [basic.def.odr]) or is
    3499              :        defined in the same translation unit.
    3500              : 
    3501              :        Since non-extern "C" decls need to be defined in the same
    3502              :        translation unit, we can make the type internal.  */
    3503       727915 :     constrain_visibility (decl, VISIBILITY_ANON, false);
    3504              : 
    3505              :   /* If visibility changed and DECL already has DECL_RTL, ensure
    3506              :      symbol flags are updated.  */
    3507    671189019 :   if ((DECL_VISIBILITY (decl) != orig_visibility
    3508    670200964 :        || DECL_VISIBILITY_SPECIFIED (decl) != orig_visibility_specified)
    3509    343163081 :       && ((VAR_P (decl) && TREE_STATIC (decl))
    3510    318726562 :           || TREE_CODE (decl) == FUNCTION_DECL)
    3511    992296384 :       && DECL_RTL_SET_P (decl))
    3512            0 :     make_decl_rtl (decl);
    3513              : }
    3514              : 
    3515              : /* By default, static data members and function members receive
    3516              :    the visibility of their containing class.  */
    3517              : 
    3518              : static void
    3519    335613506 : determine_visibility_from_class (tree decl, tree class_type)
    3520              : {
    3521    335613506 :   if (DECL_VISIBILITY_SPECIFIED (decl))
    3522              :     return;
    3523              : 
    3524    164885035 :   if (determine_hidden_inline (decl))
    3525          145 :     DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
    3526              :   else
    3527              :     {
    3528              :       /* Default to the class visibility.  */
    3529    164884890 :       DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
    3530    329769780 :       DECL_VISIBILITY_SPECIFIED (decl)
    3531    164884890 :         = CLASSTYPE_VISIBILITY_SPECIFIED (class_type);
    3532              :     }
    3533              : 
    3534              :   /* Give the target a chance to override the visibility associated
    3535              :      with DECL.  */
    3536    164885035 :   if (VAR_P (decl)
    3537     16413129 :       && TREE_PUBLIC (decl)
    3538     16413117 :       && (DECL_TINFO_P (decl) || DECL_VTABLE_OR_VTT_P (decl))
    3539      2310468 :       && !DECL_REALLY_EXTERN (decl)
    3540    167195503 :       && !CLASSTYPE_VISIBILITY_SPECIFIED (class_type))
    3541        75117 :     targetm.cxx.determine_class_data_visibility (decl);
    3542              : }
    3543              : 
    3544              : /* Returns true iff DECL is an inline that should get hidden visibility
    3545              :    because of -fvisibility-inlines-hidden.  */
    3546              : 
    3547              : static bool
    3548    437294929 : determine_hidden_inline (tree decl)
    3549              : {
    3550    437294929 :   return (visibility_options.inlines_hidden
    3551              :           /* Don't do this for inline templates; specializations might not be
    3552              :              inline, and we don't want them to inherit the hidden
    3553              :              visibility.  We'll set it here for all inline instantiations.  */
    3554          410 :           && !processing_template_decl
    3555          386 :           && TREE_CODE (decl) == FUNCTION_DECL
    3556          297 :           && DECL_DECLARED_INLINE_P (decl)
    3557    437295140 :           && (! DECL_LANG_SPECIFIC (decl)
    3558          211 :               || ! DECL_EXPLICIT_INSTANTIATION (decl)));
    3559              : }
    3560              : 
    3561              : /* Constrain the visibility of a class TYPE based on the visibility of its
    3562              :    field types.  Warn if any fields require lesser visibility.  */
    3563              : 
    3564              : void
    3565     55778517 : constrain_class_visibility (tree type)
    3566              : {
    3567     55778517 :   tree binfo;
    3568     55778517 :   tree t;
    3569     55778517 :   int i;
    3570              : 
    3571     55778517 :   int vis = type_visibility (type);
    3572              : 
    3573     55778517 :   if (vis == VISIBILITY_ANON
    3574     55778517 :       || DECL_IN_SYSTEM_HEADER (TYPE_MAIN_DECL (type)))
    3575      1278342 :     return;
    3576              : 
    3577              :   /* Don't warn about visibility if the class has explicit visibility.  */
    3578     54500175 :   if (CLASSTYPE_VISIBILITY_SPECIFIED (type))
    3579     53763100 :     vis = VISIBILITY_INTERNAL;
    3580              : 
    3581    430959039 :   for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
    3582     40705341 :     if (TREE_CODE (t) == FIELD_DECL && TREE_TYPE (t) != error_mark_node
    3583    417164047 :         && !DECL_ARTIFICIAL (t))
    3584              :       {
    3585     14463269 :         tree ftype = strip_pointer_or_array_types (TREE_TYPE (t));
    3586     14463269 :         int subvis = type_visibility (ftype);
    3587              : 
    3588     14463269 :         if (subvis == VISIBILITY_ANON)
    3589              :           {
    3590          110 :             if (!in_main_input_context())
    3591              :               {
    3592           27 :                 tree nlt = no_linkage_check (ftype, /*relaxed_p=*/false);
    3593           27 :                 if (nlt)
    3594              :                   {
    3595            6 :                     if (same_type_p (TREE_TYPE (t), nlt))
    3596            6 :                       warning (OPT_Wsubobject_linkage, "\
    3597              : %qT has a field %q#D whose type has no linkage",
    3598              :                                type, t);
    3599              :                     else
    3600            0 :                       warning (OPT_Wsubobject_linkage, "\
    3601              : %qT has a field %qD whose type depends on the type %qT which has no linkage",
    3602              :                                type, t, nlt);
    3603              :                   }
    3604           21 :                 else if (cxx_dialect > cxx98
    3605           21 :                          && !decl_anon_ns_mem_p (ftype))
    3606            2 :                   warning (OPT_Wsubobject_linkage, "\
    3607              : %qT has a field %q#D whose type has internal linkage",
    3608              :                            type, t);
    3609              :                 else // In C++98 this can only happen with unnamed namespaces.
    3610           19 :                   warning (OPT_Wsubobject_linkage, "\
    3611              : %qT has a field %q#D whose type uses the anonymous namespace",
    3612              :                            type, t);
    3613              :               }
    3614              :           }
    3615     14463159 :         else if (MAYBE_CLASS_TYPE_P (ftype)
    3616      5853549 :                  && vis < VISIBILITY_HIDDEN
    3617      5853549 :                  && subvis >= VISIBILITY_HIDDEN)
    3618            6 :           warning (OPT_Wattributes, "\
    3619              : %qT declared with greater visibility than the type of its field %qD",
    3620              :                    type, t);
    3621              :       }
    3622              : 
    3623     54500175 :   binfo = TYPE_BINFO (type);
    3624     80416019 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, t); ++i)
    3625              :     {
    3626     25915844 :       tree btype = BINFO_TYPE (t);
    3627     25915844 :       int subvis = type_visibility (btype);
    3628              : 
    3629     25915844 :       if (subvis == VISIBILITY_ANON)
    3630              :         {
    3631           32 :           if (!in_main_input_context())
    3632              :             {
    3633           18 :               tree nlt = no_linkage_check (btype, /*relaxed_p=*/false);
    3634           18 :               if (nlt)
    3635              :                 {
    3636            6 :                   if (same_type_p (btype, nlt))
    3637            6 :                     warning (OPT_Wsubobject_linkage, "\
    3638              : %qT has a base %qT which has no linkage",
    3639              :                              type, btype);
    3640              :                   else
    3641            0 :                     warning (OPT_Wsubobject_linkage, "\
    3642              : %qT has a base %qT which depends on the type %qT which has no linkage",
    3643              :                              type, btype, nlt);
    3644              :                 }
    3645           12 :               else if (cxx_dialect > cxx98
    3646           12 :                        && !decl_anon_ns_mem_p (btype))
    3647            3 :                 warning (OPT_Wsubobject_linkage, "\
    3648              : %qT has a base %qT which has internal linkage",
    3649              :                          type, btype);
    3650              :               else // In C++98 this can only happen with unnamed namespaces.
    3651            9 :                 warning (OPT_Wsubobject_linkage, "\
    3652              : %qT has a base %qT which uses the anonymous namespace",
    3653              :                          type, btype);
    3654              :             }
    3655              :         }
    3656     25915812 :       else if (vis < VISIBILITY_HIDDEN
    3657     25915812 :                && subvis >= VISIBILITY_HIDDEN)
    3658            6 :         warning (OPT_Wattributes, "\
    3659              : %qT declared with greater visibility than its base %qT",
    3660            6 :                  type, TREE_TYPE (t));
    3661              :     }
    3662              : }
    3663              : 
    3664              : /* Functions for adjusting the visibility of a tagged type and its nested
    3665              :    types and declarations when it gets a name for linkage purposes from a
    3666              :    typedef.  */
    3667              : // FIXME: It is now a DR for such a class type to contain anything
    3668              : // other than C.  So at minium most of this can probably be deleted.
    3669              : 
    3670              : /* First reset the visibility of all the types.  */
    3671              : 
    3672              : static void
    3673      1061700 : reset_type_linkage_1 (tree type)
    3674              : {
    3675      1061700 :   set_linkage_according_to_type (type, TYPE_MAIN_DECL (type));
    3676      1061700 :   if (CLASS_TYPE_P (type))
    3677      3576074 :     for (tree member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
    3678      2843442 :       if (DECL_IMPLICIT_TYPEDEF_P (member))
    3679       229780 :         reset_type_linkage_1 (TREE_TYPE (member));
    3680      1061700 : }
    3681              : 
    3682              : /* Then reset the visibility of any static data members or member
    3683              :    functions that use those types.  */
    3684              : 
    3685              : static void
    3686          103 : reset_decl_linkage (tree decl)
    3687              : {
    3688          103 :   if (TREE_PUBLIC (decl))
    3689              :     return;
    3690          103 :   if (DECL_CLONED_FUNCTION_P (decl))
    3691              :     return;
    3692           99 :   TREE_PUBLIC (decl) = true;
    3693           99 :   DECL_INTERFACE_KNOWN (decl) = false;
    3694           99 :   determine_visibility (decl);
    3695           99 :   tentative_decl_linkage (decl);
    3696              : }
    3697              : 
    3698              : void
    3699       831920 : reset_type_linkage (tree type)
    3700              : {
    3701       831920 :   reset_type_linkage_1 (type);
    3702       831920 :   if (CLASS_TYPE_P (type))
    3703              :     {
    3704       502864 :       if (tree vt = CLASSTYPE_VTABLES (type))
    3705              :         {
    3706           15 :           tree name = mangle_vtbl_for_type (type);
    3707           15 :           DECL_NAME (vt) = name;
    3708           15 :           SET_DECL_ASSEMBLER_NAME (vt, name);
    3709           15 :           reset_decl_linkage (vt);
    3710              :         }
    3711       502864 :       if (!ANON_AGGR_TYPE_P (type))
    3712       502715 :         if (tree ti = CLASSTYPE_TYPEINFO_VAR (type))
    3713              :           {
    3714           12 :             tree name = mangle_typeinfo_for_type (type);
    3715           12 :             DECL_NAME (ti) = name;
    3716           12 :             SET_DECL_ASSEMBLER_NAME (ti, name);
    3717           12 :             TREE_TYPE (name) = type;
    3718           12 :             reset_decl_linkage (ti);
    3719              :           }
    3720      2366247 :       for (tree m = TYPE_FIELDS (type); m; m = DECL_CHAIN (m))
    3721              :         {
    3722      1863383 :           tree mem = STRIP_TEMPLATE (m);
    3723      1863383 :           if (TREE_CODE (mem) == VAR_DECL || TREE_CODE (mem) == FUNCTION_DECL)
    3724           76 :             reset_decl_linkage (mem);
    3725      1863307 :           else if (DECL_IMPLICIT_TYPEDEF_P (mem))
    3726       120684 :             reset_type_linkage (TREE_TYPE (mem));
    3727              :         }
    3728              :     }
    3729       831920 : }
    3730              : 
    3731              : /* Set up our initial idea of what the linkage of DECL should be.  */
    3732              : 
    3733              : void
    3734     29997688 : tentative_decl_linkage (tree decl)
    3735              : {
    3736     29997688 :   if (DECL_INTERFACE_KNOWN (decl))
    3737              :     /* We've already made a decision as to how this function will
    3738              :        be handled.  */;
    3739     29996666 :   else if (vague_linkage_p (decl))
    3740              :     {
    3741     29996098 :       if (TREE_CODE (decl) == FUNCTION_DECL
    3742     29996098 :           && decl_defined_p (decl))
    3743              :         {
    3744     29975028 :           DECL_EXTERNAL (decl) = 1;
    3745     29975028 :           DECL_NOT_REALLY_EXTERN (decl) = 1;
    3746     29975028 :           note_vague_linkage_fn (decl);
    3747              :           /* A non-template inline function with external linkage will
    3748              :              always be COMDAT.  As we must eventually determine the
    3749              :              linkage of all functions, and as that causes writes to
    3750              :              the data mapped in from the PCH file, it's advantageous
    3751              :              to mark the functions at this point.  */
    3752     29975028 :           if (DECL_DECLARED_INLINE_P (decl))
    3753              :             {
    3754     29972560 :               if (!DECL_IMPLICIT_INSTANTIATION (decl)
    3755     29972560 :                   || DECL_DEFAULTED_FN (decl))
    3756              :                 {
    3757              :                   /* This function must have external linkage, as
    3758              :                      otherwise DECL_INTERFACE_KNOWN would have been
    3759              :                      set.  */
    3760     24452417 :                   gcc_assert (TREE_PUBLIC (decl));
    3761     24452417 :                   comdat_linkage (decl);
    3762     24452417 :                   DECL_INTERFACE_KNOWN (decl) = 1;
    3763              :                 }
    3764      5520143 :               else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl))
    3765              :                 /* For implicit instantiations of cdtors try to make
    3766              :                    it comdat, so that maybe_clone_body can use aliases.
    3767              :                    See PR113208.  */
    3768       669661 :                 maybe_make_one_only (decl);
    3769              :             }
    3770              :         }
    3771        21070 :       else if (VAR_P (decl))
    3772        21068 :         maybe_commonize_var (decl);
    3773              :     }
    3774     29997688 : }
    3775              : 
    3776              : /* For a polymorphic class type CTYPE, whether its vtables are emitted in a
    3777              :    unique object as per the ABI.  */
    3778              : 
    3779              : static bool
    3780         2845 : vtables_uniquely_emitted (tree ctype)
    3781              : {
    3782              :   /* If the class is templated, the tables are emitted in every object that
    3783              :      references any of them.  */
    3784         2845 :   if (CLASSTYPE_USE_TEMPLATE (ctype))
    3785              :     return false;
    3786              : 
    3787              :   /* Otherwise, if the class is attached to a module, the tables are uniquely
    3788              :      emitted in the object for the module unit in which it is defined.  */
    3789         2219 :   tree cdecl = TYPE_NAME (ctype);
    3790         2219 :   if (DECL_LANG_SPECIFIC (cdecl) && DECL_MODULE_ATTACH_P (cdecl))
    3791              :     return true;
    3792              : 
    3793              :   /* Otherwise, if the class has a key function, the tables are emitted in the
    3794              :      object for the TU containing the definition of the key function.  This is
    3795              :      unique if the key function is not inline.  */
    3796         2087 :   tree key_method = CLASSTYPE_KEY_METHOD (ctype);
    3797         4154 :   if (key_method && !DECL_NONGNU_INLINE_P (key_method))
    3798         2047 :     return true;
    3799              : 
    3800              :   /* Otherwise, the tables are emitted in every object that references
    3801              :      any of them.  */
    3802              :   return false;
    3803              : }
    3804              : 
    3805              : /* DECL is a FUNCTION_DECL or VAR_DECL.  If the object file linkage
    3806              :    for DECL has not already been determined, do so now by setting
    3807              :    DECL_EXTERNAL, DECL_COMDAT and other related flags.  Until this
    3808              :    function is called entities with vague linkage whose definitions
    3809              :    are available must have TREE_PUBLIC set.
    3810              : 
    3811              :    If this function decides to place DECL in COMDAT, it will set
    3812              :    appropriate flags -- but will not clear DECL_EXTERNAL.  It is up to
    3813              :    the caller to decide whether or not to clear DECL_EXTERNAL.  Some
    3814              :    callers defer that decision until it is clear that DECL is actually
    3815              :    required.  */
    3816              : 
    3817              : void
    3818    255569077 : import_export_decl (tree decl)
    3819              : {
    3820    255569077 :   bool comdat_p;
    3821    255569077 :   bool import_p;
    3822    255569077 :   tree class_type = NULL_TREE;
    3823              : 
    3824    255569077 :   if (DECL_INTERFACE_KNOWN (decl))
    3825              :     return;
    3826              : 
    3827              :   /* We cannot determine what linkage to give to an entity with vague
    3828              :      linkage until the end of the file.  For example, a virtual table
    3829              :      for a class will be defined if and only if the key method is
    3830              :      defined in this translation unit.  */
    3831     51147266 :   gcc_assert (at_eof);
    3832              :   /* Object file linkage for explicit instantiations is handled in
    3833              :      mark_decl_instantiated.  For static variables in functions with
    3834              :      vague linkage, maybe_commonize_var is used.
    3835              : 
    3836              :      Therefore, the only declarations that should be provided to this
    3837              :      function are those with external linkage that are:
    3838              : 
    3839              :      * implicit instantiations of function templates
    3840              : 
    3841              :      * inline functions
    3842              : 
    3843              :      * inline variables
    3844              : 
    3845              :      * implicit instantiations of static data members of class
    3846              :        templates
    3847              : 
    3848              :      * virtual tables
    3849              : 
    3850              :      * typeinfo objects
    3851              : 
    3852              :      Furthermore, all entities that reach this point must have a
    3853              :      definition available in this translation unit.
    3854              : 
    3855              :      The following assertions check these conditions.  */
    3856     51147266 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
    3857              :   /* Any code that creates entities with TREE_PUBLIC cleared should
    3858              :      also set DECL_INTERFACE_KNOWN.  */
    3859     51147266 :   gcc_assert (TREE_PUBLIC (decl));
    3860     51147266 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    3861     28126067 :     gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl)
    3862              :                 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
    3863              :                 || DECL_DECLARED_INLINE_P (decl));
    3864              :   else
    3865     23021199 :     gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl)
    3866              :                 || DECL_INLINE_VAR_P (decl)
    3867              :                 || DECL_VTABLE_OR_VTT_P (decl)
    3868              :                 || DECL_TINFO_P (decl));
    3869              :   /* Check that a definition of DECL is available in this translation
    3870              :      unit.  */
    3871     51147266 :   gcc_assert (!DECL_REALLY_EXTERN (decl));
    3872              : 
    3873              :   /* Assume that DECL will not have COMDAT linkage.  */
    3874     51147266 :   comdat_p = false;
    3875              :   /* Assume that DECL will not be imported into this translation
    3876              :      unit.  */
    3877     51147266 :   import_p = false;
    3878              : 
    3879     51147266 :   if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
    3880              :     {
    3881      1692673 :       class_type = DECL_CONTEXT (decl);
    3882      1692673 :       import_export_class (class_type);
    3883      1692673 :       if (CLASSTYPE_INTERFACE_KNOWN (class_type)
    3884      1692673 :           && CLASSTYPE_INTERFACE_ONLY (class_type))
    3885              :         import_p = true;
    3886       611842 :       else if ((!flag_weak || TARGET_WEAK_NOT_IN_ARCHIVE_TOC)
    3887       611842 :                && !vtables_uniquely_emitted (class_type))
    3888              :         /* The ABI historically required that all virtual tables be
    3889              :            emitted with COMDAT linkage.  However, on systems where
    3890              :            COMDAT symbols don't show up in the table of contents for
    3891              :            a static archive, or on systems without weak symbols (where
    3892              :            we approximate COMDAT linkage by using internal linkage),
    3893              :            the linker will report errors about undefined symbols because
    3894              :            it will not see the virtual table definition.  Therefore,
    3895              :            in the case that we know that the virtual table will be
    3896              :            emitted in only one translation unit, we make the virtual
    3897              :            table an ordinary definition with external linkage.  */
    3898            3 :         DECL_EXTERNAL (decl) = 0;
    3899       611839 :       else if (CLASSTYPE_INTERFACE_KNOWN (class_type))
    3900              :         {
    3901              :           /* CLASS_TYPE is being exported from this translation unit,
    3902              :              so DECL should be defined here.  */
    3903         2842 :           if (!flag_weak && CLASSTYPE_EXPLICIT_INSTANTIATION (class_type))
    3904              :             /* If a class is declared in a header with the "extern
    3905              :                template" extension, then it will not be instantiated,
    3906              :                even in translation units that would normally require
    3907              :                it.  Often such classes are explicitly instantiated in
    3908              :                one translation unit.  Therefore, the explicit
    3909              :                instantiation must be made visible to other translation
    3910              :                units.  */
    3911            0 :             DECL_EXTERNAL (decl) = 0;
    3912              :           else
    3913              :             {
    3914              :               /* The generic C++ ABI used to say that class data is always
    3915              :                  COMDAT, even if emitted in a unique object.  This is no
    3916              :                  longer true, but for now we continue to do so for
    3917              :                  compatibility with programs that are not strictly valid.
    3918              :                  However, some variants (e.g., the ARM EABI) explicitly say
    3919              :                  that class data only has COMDAT linkage if the class data
    3920              :                  might be emitted in more than one translation unit.
    3921              :                  When the key method can be inline and is inline, we still
    3922              :                  have to arrange for comdat even though
    3923              :                  class_data_always_comdat is false.  */
    3924         2842 :               if (!vtables_uniquely_emitted (class_type)
    3925         2842 :                   || targetm.cxx.class_data_always_comdat ())
    3926              :                 {
    3927              :                   /* The ABI requires COMDAT linkage.  Normally, we
    3928              :                      only emit COMDAT things when they are needed;
    3929              :                      make sure that we realize that this entity is
    3930              :                      indeed needed.  */
    3931         2842 :                   comdat_p = true;
    3932         2842 :                   mark_needed (decl);
    3933              :                 }
    3934              :             }
    3935              :         }
    3936       608997 :       else if (!flag_implicit_templates
    3937       608997 :                && CLASSTYPE_IMPLICIT_INSTANTIATION (class_type))
    3938              :         import_p = true;
    3939              :       else
    3940              :         comdat_p = true;
    3941              :     }
    3942     49454593 :   else if (VAR_P (decl) && DECL_TINFO_P (decl))
    3943              :     {
    3944      2403480 :       tree type = TREE_TYPE (DECL_NAME (decl));
    3945      2403480 :       if (CLASS_TYPE_P (type))
    3946              :         {
    3947      2400811 :           class_type = type;
    3948      2400811 :           import_export_class (type);
    3949      2400811 :           if (CLASSTYPE_INTERFACE_KNOWN (type)
    3950      1229640 :               && TYPE_CONTAINS_VPTR_P (type)
    3951      1229562 :               && CLASSTYPE_INTERFACE_ONLY (type)
    3952              :               /* If -fno-rtti was specified, then we cannot be sure
    3953              :                  that RTTI information will be emitted with the
    3954              :                  virtual table of the class, so we must emit it
    3955              :                  wherever it is used.  */
    3956      3626471 :               && flag_rtti)
    3957              :             import_p = true;
    3958              :           else
    3959              :             {
    3960      1175197 :               if (CLASSTYPE_INTERFACE_KNOWN (type)
    3961      1175197 :                   && !CLASSTYPE_INTERFACE_ONLY (type))
    3962              :                 {
    3963         3932 :                   comdat_p = (targetm.cxx.class_data_always_comdat ()
    3964         3932 :                               || !vtables_uniquely_emitted (class_type));
    3965         3932 :                   mark_needed (decl);
    3966         3932 :                   if (!flag_weak)
    3967              :                     {
    3968            0 :                       comdat_p = false;
    3969            0 :                       DECL_EXTERNAL (decl) = 0;
    3970              :                     }
    3971              :                 }
    3972              :               else
    3973              :                 comdat_p = true;
    3974              :             }
    3975              :         }
    3976              :       else
    3977              :         comdat_p = true;
    3978              :     }
    3979     47051113 :   else if (DECL_TEMPLOID_INSTANTIATION (decl))
    3980              :     {
    3981              :       /* DECL is an implicit instantiation of a function or static
    3982              :          data member.  */
    3983     46757700 :       if (flag_implicit_templates
    3984     46757700 :           || (flag_implicit_inline_templates
    3985        21244 :               && TREE_CODE (decl) == FUNCTION_DECL
    3986        17015 :               && DECL_DECLARED_INLINE_P (decl)))
    3987              :         comdat_p = true;
    3988              :       else
    3989              :         /* If we are not implicitly generating templates, then mark
    3990              :            this entity as undefined in this translation unit.  */
    3991              :         import_p = true;
    3992              :     }
    3993       293413 :   else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_FUNCTION_MEMBER_P (decl))
    3994              :     {
    3995       285294 :       if (!DECL_NONGNU_INLINE_P (decl))
    3996              :         {
    3997            0 :           tree ctype = DECL_CONTEXT (decl);
    3998            0 :           import_export_class (ctype);
    3999            0 :           if (CLASSTYPE_INTERFACE_KNOWN (ctype))
    4000              :             {
    4001            0 :               DECL_NOT_REALLY_EXTERN (decl)
    4002            0 :                 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
    4003            0 :                      || (DECL_DECLARED_INLINE_P (decl)
    4004            0 :                          && ! flag_implement_inlines
    4005            0 :                          && !DECL_VINDEX (decl)));
    4006              : 
    4007            0 :               if (!DECL_NOT_REALLY_EXTERN (decl))
    4008            0 :                 DECL_EXTERNAL (decl) = 1;
    4009              : 
    4010              :               /* Always make artificials weak.  */
    4011            0 :               if (DECL_ARTIFICIAL (decl) && flag_weak)
    4012              :                 comdat_p = true;
    4013              :               else
    4014            0 :                 maybe_make_one_only (decl);
    4015              :             }
    4016              :         }
    4017              :       else
    4018              :         comdat_p = true;
    4019              :     }
    4020              :   else
    4021              :     comdat_p = true;
    4022              : 
    4023         2845 :   if (import_p)
    4024              :     {
    4025              :       /* If we are importing DECL into this translation unit, mark is
    4026              :          an undefined here.  */
    4027      2314053 :       DECL_EXTERNAL (decl) = 1;
    4028      2314053 :       DECL_NOT_REALLY_EXTERN (decl) = 0;
    4029              :     }
    4030     48833213 :   else if (comdat_p)
    4031              :     {
    4032              :       /* If we decided to put DECL in COMDAT, mark it accordingly at
    4033              :          this point.  */
    4034     48833210 :       comdat_linkage (decl);
    4035              :     }
    4036              : 
    4037     51147266 :   DECL_INTERFACE_KNOWN (decl) = 1;
    4038              : }
    4039              : 
    4040              : /* Return an expression that performs the destruction of DECL, which
    4041              :    must be a VAR_DECL whose type has a non-trivial destructor, or is
    4042              :    an array whose (innermost) elements have a non-trivial destructor.  */
    4043              : 
    4044              : tree
    4045         1300 : build_cleanup (tree decl)
    4046              : {
    4047         1300 :   tree clean = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
    4048         1300 :   gcc_assert (clean != NULL_TREE);
    4049         1300 :   return clean;
    4050              : }
    4051              : 
    4052              : /* GUARD is a helper variable for DECL; make them have the same linkage and
    4053              :    visibility.  */
    4054              : 
    4055              : void
    4056       136885 : copy_linkage (tree guard, tree decl)
    4057              : {
    4058       136885 :   TREE_PUBLIC (guard) = TREE_PUBLIC (decl);
    4059       136885 :   TREE_STATIC (guard) = TREE_STATIC (decl);
    4060       136885 :   DECL_COMMON (guard) = DECL_COMMON (decl);
    4061       136885 :   DECL_COMDAT (guard) = DECL_COMDAT (decl);
    4062       136885 :   if (TREE_STATIC (guard))
    4063              :     {
    4064         6295 :       CP_DECL_THREAD_LOCAL_P (guard) = CP_DECL_THREAD_LOCAL_P (decl);
    4065         6295 :       set_decl_tls_model (guard, DECL_TLS_MODEL (decl));
    4066         6295 :       if (DECL_ONE_ONLY (decl))
    4067         4371 :         make_decl_one_only (guard, cxx_comdat_group (guard));
    4068         6295 :       if (TREE_PUBLIC (decl))
    4069         5103 :         DECL_WEAK (guard) = DECL_WEAK (decl);
    4070              :       /* Also check vague_linkage_p, as DECL_WEAK and DECL_ONE_ONLY might not
    4071              :          be set until import_export_decl at EOF.  */
    4072         6295 :       if (vague_linkage_p (decl))
    4073         4389 :         comdat_linkage (guard);
    4074         6295 :       DECL_VISIBILITY (guard) = DECL_VISIBILITY (decl);
    4075         6295 :       DECL_VISIBILITY_SPECIFIED (guard) = DECL_VISIBILITY_SPECIFIED (decl);
    4076         6295 :       if (!TREE_PUBLIC (decl))
    4077              :         {
    4078         1192 :           gcc_checking_assert (DECL_INTERFACE_KNOWN (decl));
    4079         1192 :           DECL_INTERFACE_KNOWN (guard) = 1;
    4080         1192 :           if (DECL_LANG_SPECIFIC (decl) && DECL_LANG_SPECIFIC (guard))
    4081          244 :             DECL_NOT_REALLY_EXTERN (guard) = DECL_NOT_REALLY_EXTERN (decl);
    4082              :         }
    4083              :     }
    4084       136885 : }
    4085              : 
    4086              : /* Returns the initialization guard variable for the variable DECL,
    4087              :    which has static storage duration.  */
    4088              : 
    4089              : tree
    4090         4735 : get_guard (tree decl)
    4091              : {
    4092         4735 :   tree sname = mangle_guard_variable (decl);
    4093         4735 :   tree guard = get_global_binding (sname);
    4094         4735 :   if (! guard)
    4095              :     {
    4096         4735 :       tree guard_type;
    4097              : 
    4098              :       /* We use a type that is big enough to contain a mutex as well
    4099              :          as an integer counter.  */
    4100         4735 :       guard_type = targetm.cxx.guard_type ();
    4101         4735 :       guard = build_decl (DECL_SOURCE_LOCATION (decl),
    4102              :                           VAR_DECL, sname, guard_type);
    4103              : 
    4104              :       /* The guard should have the same linkage as what it guards.  */
    4105         4735 :       copy_linkage (guard, decl);
    4106              : 
    4107         4735 :       DECL_ARTIFICIAL (guard) = 1;
    4108         4735 :       DECL_IGNORED_P (guard) = 1;
    4109         4735 :       TREE_USED (guard) = 1;
    4110         4735 :       pushdecl_top_level_and_finish (guard, NULL_TREE);
    4111              :     }
    4112         4735 :   return guard;
    4113              : }
    4114              : 
    4115              : /* Returns true if accessing the GUARD atomic is expensive,
    4116              :    i.e. involves a call to __sync_synchronize or similar.
    4117              :    In this case let __cxa_guard_acquire handle the atomics.  */
    4118              : 
    4119              : static bool
    4120         3714 : is_atomic_expensive_p (machine_mode mode)
    4121              : {
    4122         3714 :   if (!flag_inline_atomics)
    4123              :     return true;
    4124              : 
    4125         3714 :   if (!can_compare_and_swap_p (mode, false) || !can_atomic_load_p (mode))
    4126            0 :     return true;
    4127              : 
    4128              :   return false;
    4129              : }
    4130              : 
    4131              : /* Return an atomic load of src with the appropriate memory model.  */
    4132              : 
    4133              : static tree
    4134         3714 : build_atomic_load_type (tree src, HOST_WIDE_INT model, tree type)
    4135              : {
    4136         3714 :   tree ptr_type = build_pointer_type (type);
    4137         3714 :   tree mem_model = build_int_cst (integer_type_node, model);
    4138         3714 :   tree t, addr, val;
    4139         3714 :   unsigned int size;
    4140         3714 :   int fncode;
    4141              : 
    4142         3714 :   size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    4143              : 
    4144         3714 :   fncode = BUILT_IN_ATOMIC_LOAD_N + exact_log2 (size) + 1;
    4145         3714 :   t = builtin_decl_implicit ((enum built_in_function) fncode);
    4146              : 
    4147         3714 :   addr = build1 (ADDR_EXPR, ptr_type, src);
    4148         3714 :   val = build_call_expr (t, 2, addr, mem_model);
    4149         3714 :   return val;
    4150              : }
    4151              : 
    4152              : /* Return those bits of the GUARD variable that should be set when the
    4153              :    guarded entity is actually initialized.  */
    4154              : 
    4155              : static tree
    4156         2042 : get_guard_bits (tree guard)
    4157              : {
    4158         2042 :   if (!targetm.cxx.guard_mask_bit ())
    4159              :     {
    4160              :       /* We only set the first byte of the guard, in order to leave room
    4161              :          for a mutex in the high-order bits.  */
    4162         2042 :       guard = build1 (ADDR_EXPR,
    4163         2042 :                       build_pointer_type (TREE_TYPE (guard)),
    4164              :                       guard);
    4165         2042 :       guard = build1 (NOP_EXPR,
    4166              :                       build_pointer_type (char_type_node),
    4167              :                       guard);
    4168         2042 :       guard = build1 (INDIRECT_REF, char_type_node, guard);
    4169              :     }
    4170              : 
    4171         2042 :   return guard;
    4172              : }
    4173              : 
    4174              : /* Return an expression which determines whether or not the GUARD
    4175              :    variable has already been initialized.  */
    4176              : 
    4177              : tree
    4178         4735 : get_guard_cond (tree guard, bool thread_safe)
    4179              : {
    4180         4735 :   tree guard_value;
    4181              : 
    4182         4735 :   if (!thread_safe)
    4183         1021 :     guard = get_guard_bits (guard);
    4184              :   else
    4185              :     {
    4186         3714 :       tree type = targetm.cxx.guard_mask_bit ()
    4187         3714 :                   ? TREE_TYPE (guard) : char_type_node;
    4188              : 
    4189         3714 :       if (is_atomic_expensive_p (TYPE_MODE (type)))
    4190            0 :         guard = integer_zero_node;
    4191              :       else
    4192         3714 :         guard = build_atomic_load_type (guard, MEMMODEL_ACQUIRE, type);
    4193              :     }
    4194              : 
    4195              :   /* Mask off all but the low bit.  */
    4196         4735 :   if (targetm.cxx.guard_mask_bit ())
    4197              :     {
    4198            0 :       guard_value = integer_one_node;
    4199            0 :       if (!same_type_p (TREE_TYPE (guard_value), TREE_TYPE (guard)))
    4200            0 :         guard_value = fold_convert (TREE_TYPE (guard), guard_value);
    4201            0 :       guard = cp_build_binary_op (input_location,
    4202              :                                   BIT_AND_EXPR, guard, guard_value,
    4203              :                                   tf_warning_or_error);
    4204              :     }
    4205              : 
    4206         4735 :   guard_value = integer_zero_node;
    4207         4735 :   if (!same_type_p (TREE_TYPE (guard_value), TREE_TYPE (guard)))
    4208         4735 :     guard_value = fold_convert (TREE_TYPE (guard), guard_value);
    4209         4735 :   return cp_build_binary_op (input_location,
    4210              :                              EQ_EXPR, guard, guard_value,
    4211         4735 :                              tf_warning_or_error);
    4212              : }
    4213              : 
    4214              : /* Return an expression which sets the GUARD variable, indicating that
    4215              :    the variable being guarded has been initialized.  */
    4216              : 
    4217              : tree
    4218         1021 : set_guard (tree guard)
    4219              : {
    4220         1021 :   tree guard_init;
    4221              : 
    4222              :   /* Set the GUARD to one.  */
    4223         1021 :   guard = get_guard_bits (guard);
    4224         1021 :   guard_init = integer_one_node;
    4225         1021 :   if (!same_type_p (TREE_TYPE (guard_init), TREE_TYPE (guard)))
    4226         1021 :     guard_init = fold_convert (TREE_TYPE (guard), guard_init);
    4227         1021 :   return cp_build_modify_expr (input_location, guard, NOP_EXPR, guard_init,
    4228         1021 :                                tf_warning_or_error);
    4229              : }
    4230              : 
    4231              : /* Returns true iff we can tell that VAR does not have a dynamic
    4232              :    initializer.  */
    4233              : 
    4234              : static bool
    4235         2602 : var_defined_without_dynamic_init (tree var)
    4236              : {
    4237              :   /* constinit vars are guaranteed to not have dynamic initializer,
    4238              :      but still registering the destructor counts as dynamic initialization.  */
    4239         2602 :   if (DECL_DECLARED_CONSTINIT_P (var)
    4240           24 :       && COMPLETE_TYPE_P (TREE_TYPE (var))
    4241         2620 :       && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (var)))
    4242              :     return true;
    4243              :   /* If it's defined in another TU, we can't tell.  */
    4244         2590 :   if (DECL_EXTERNAL (var))
    4245              :     return false;
    4246              :   /* If it has a non-trivial destructor, registering the destructor
    4247              :      counts as dynamic initialization.  */
    4248         2343 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (var)))
    4249              :     return false;
    4250              :   /* If it's in this TU, its initializer has been processed, unless
    4251              :      it's a case of self-initialization, then DECL_INITIALIZED_P is
    4252              :      false while the initializer is handled by finish_id_expression.  */
    4253         2162 :   if (!DECL_INITIALIZED_P (var))
    4254              :     return false;
    4255              :   /* If it has no initializer or a constant one, it's not dynamic.  */
    4256         2156 :   return (!DECL_NONTRIVIALLY_INITIALIZED_P (var)
    4257         2156 :           || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var));
    4258              : }
    4259              : 
    4260              : /* Returns true iff VAR is a variable that needs uses to be
    4261              :    wrapped for possible dynamic initialization.  */
    4262              : 
    4263              : bool
    4264        74923 : var_needs_tls_wrapper (tree var)
    4265              : {
    4266        74923 :   return (!error_operand_p (var)
    4267        74920 :           && CP_DECL_THREAD_LOCAL_P (var)
    4268        74920 :           && !DECL_GNU_TLS_P (var)
    4269         2740 :           && !DECL_FUNCTION_SCOPE_P (var)
    4270        77525 :           && !var_defined_without_dynamic_init (var));
    4271              : }
    4272              : 
    4273              : /* Get the FUNCTION_DECL for the shared TLS init function for this
    4274              :    translation unit.  */
    4275              : 
    4276              : static tree
    4277          195 : get_local_tls_init_fn (location_t loc)
    4278              : {
    4279          195 :   tree sname = get_identifier ("__tls_init");
    4280          195 :   tree fn = get_global_binding (sname);
    4281          195 :   if (!fn)
    4282              :     {
    4283          123 :       fn = build_lang_decl_loc (loc, FUNCTION_DECL, sname,
    4284              :                                 build_function_type (void_type_node,
    4285              :                                                      void_list_node));
    4286          123 :       SET_DECL_LANGUAGE (fn, lang_c);
    4287          123 :       TREE_PUBLIC (fn) = false;
    4288          123 :       DECL_ARTIFICIAL (fn) = true;
    4289          123 :       mark_used (fn);
    4290          123 :       set_global_binding (fn);
    4291              :     }
    4292          195 :   return fn;
    4293              : }
    4294              : 
    4295              : /* Get a FUNCTION_DECL for the init function for the thread_local
    4296              :    variable VAR.  The init function will be an alias to the function
    4297              :    that initializes all the non-local TLS variables in the translation
    4298              :    unit.  The init function is only used by the wrapper function.  */
    4299              : 
    4300              : static tree
    4301         1294 : get_tls_init_fn (tree var)
    4302              : {
    4303              :   /* Only C++11 TLS vars need this init fn.  */
    4304         1294 :   if (!var_needs_tls_wrapper (var))
    4305              :     return NULL_TREE;
    4306              : 
    4307              :   /* If -fno-extern-tls-init, assume that we don't need to call
    4308              :      a tls init function for a variable defined in another TU.  */
    4309         1275 :   if (!flag_extern_tls_init && DECL_EXTERNAL (var))
    4310              :     return NULL_TREE;
    4311              : 
    4312              :   /* If the variable is internal, or if we can't generate aliases,
    4313              :      call the local init function directly.  */
    4314         1274 :   if (!TREE_PUBLIC (var) || !TARGET_SUPPORTS_ALIASES)
    4315           72 :     return get_local_tls_init_fn (DECL_SOURCE_LOCATION (var));
    4316              : 
    4317         1202 :   tree sname = mangle_tls_init_fn (var);
    4318         1202 :   tree fn = get_global_binding (sname);
    4319         1202 :   if (!fn)
    4320              :     {
    4321          777 :       fn = build_lang_decl (FUNCTION_DECL, sname,
    4322              :                             build_function_type (void_type_node,
    4323              :                                                  void_list_node));
    4324          777 :       SET_DECL_LANGUAGE (fn, lang_c);
    4325          777 :       TREE_PUBLIC (fn) = TREE_PUBLIC (var);
    4326          777 :       DECL_ARTIFICIAL (fn) = true;
    4327          777 :       DECL_CONTEXT (fn) = FROB_CONTEXT (global_namespace);
    4328          777 :       DECL_COMDAT (fn) = DECL_COMDAT (var);
    4329          777 :       DECL_EXTERNAL (fn) = DECL_EXTERNAL (var);
    4330          777 :       if (DECL_ONE_ONLY (var))
    4331            3 :         make_decl_one_only (fn, cxx_comdat_group (fn));
    4332          777 :       if (TREE_PUBLIC (var))
    4333              :         {
    4334          777 :           tree obtype = strip_array_types (non_reference (TREE_TYPE (var)));
    4335              :           /* If the variable is defined somewhere else and might have static
    4336              :              initialization, make the init function a weak reference.  */
    4337          777 :           if ((!TYPE_NEEDS_CONSTRUCTING (obtype)
    4338          615 :                || TYPE_HAS_CONSTEXPR_CTOR (obtype)
    4339          597 :                || TYPE_HAS_TRIVIAL_DFLT (obtype))
    4340          180 :               && TYPE_HAS_TRIVIAL_DESTRUCTOR (obtype)
    4341          939 :               && DECL_EXTERNAL (var))
    4342           51 :             declare_weak (fn);
    4343              :           else
    4344          726 :             DECL_WEAK (fn) = DECL_WEAK (var);
    4345              :         }
    4346          777 :       DECL_VISIBILITY (fn) = DECL_VISIBILITY (var);
    4347          777 :       DECL_VISIBILITY_SPECIFIED (fn) = DECL_VISIBILITY_SPECIFIED (var);
    4348          777 :       DECL_DLLIMPORT_P (fn) = DECL_DLLIMPORT_P (var);
    4349          777 :       DECL_IGNORED_P (fn) = 1;
    4350          777 :       mark_used (fn);
    4351              : 
    4352          777 :       DECL_BEFRIENDING_CLASSES (fn) = var;
    4353              : 
    4354          777 :       set_global_binding (fn);
    4355              :     }
    4356              :   return fn;
    4357              : }
    4358              : 
    4359              : /* Get a FUNCTION_DECL for the init wrapper function for the thread_local
    4360              :    variable VAR.  The wrapper function calls the init function (if any) for
    4361              :    VAR and then returns a reference to VAR.  The wrapper function is used
    4362              :    in place of VAR everywhere VAR is mentioned.  */
    4363              : 
    4364              : static tree
    4365        73614 : get_tls_wrapper_fn (tree var)
    4366              : {
    4367              :   /* Only C++11 TLS vars need this wrapper fn.  */
    4368        73614 :   if (!var_needs_tls_wrapper (var))
    4369              :     return NULL_TREE;
    4370              : 
    4371          749 :   tree sname = mangle_tls_wrapper_fn (var);
    4372          749 :   tree fn = get_global_binding (sname);
    4373          749 :   if (!fn)
    4374              :     {
    4375              :       /* A named rvalue reference is an lvalue, so the wrapper should
    4376              :          always return an lvalue reference.  */
    4377          586 :       tree type = non_reference (TREE_TYPE (var));
    4378          586 :       type = build_reference_type (type);
    4379          586 :       tree fntype = build_function_type (type, void_list_node);
    4380              : 
    4381          586 :       fn = build_lang_decl_loc (DECL_SOURCE_LOCATION (var),
    4382              :                                 FUNCTION_DECL, sname, fntype);
    4383          586 :       SET_DECL_LANGUAGE (fn, lang_c);
    4384          586 :       TREE_PUBLIC (fn) = TREE_PUBLIC (var);
    4385          586 :       DECL_ARTIFICIAL (fn) = true;
    4386          586 :       DECL_IGNORED_P (fn) = 1;
    4387          586 :       DECL_CONTEXT (fn) = FROB_CONTEXT (global_namespace);
    4388              :       /* The wrapper is inline and emitted everywhere var is used.  */
    4389          586 :       DECL_DECLARED_INLINE_P (fn) = true;
    4390          586 :       if (TREE_PUBLIC (var))
    4391              :         {
    4392          514 :           comdat_linkage (fn);
    4393              : #ifdef HAVE_GAS_HIDDEN
    4394              :           /* Make the wrapper bind locally; there's no reason to share
    4395              :              the wrapper between multiple shared objects.  */
    4396          514 :           DECL_VISIBILITY (fn) = VISIBILITY_INTERNAL;
    4397          514 :           DECL_VISIBILITY_SPECIFIED (fn) = true;
    4398              : #endif
    4399              :         }
    4400          586 :       if (!TREE_PUBLIC (fn))
    4401           72 :         DECL_INTERFACE_KNOWN (fn) = true;
    4402          586 :       mark_used (fn);
    4403          586 :       note_vague_linkage_fn (fn);
    4404              : 
    4405              : #if 0
    4406              :       /* We want CSE to commonize calls to the wrapper, but marking it as
    4407              :          pure is unsafe since it has side-effects.  I guess we need a new
    4408              :          ECF flag even weaker than ECF_PURE.  FIXME!  */
    4409              :       DECL_PURE_P (fn) = true;
    4410              : #endif
    4411              : 
    4412          586 :       DECL_BEFRIENDING_CLASSES (fn) = var;
    4413              : 
    4414          586 :       set_global_binding (fn);
    4415              :     }
    4416              :   return fn;
    4417              : }
    4418              : 
    4419              : /* If EXPR is a thread_local variable that should be wrapped by init
    4420              :    wrapper function, return a call to that function, otherwise return
    4421              :    NULL.  */
    4422              : 
    4423              : tree
    4424   1029316375 : maybe_get_tls_wrapper_call (tree expr)
    4425              : {
    4426   1029316375 :   if (VAR_P (expr)
    4427    375378625 :       && !processing_template_decl
    4428    186229646 :       && !cp_unevaluated_operand
    4429   1212664461 :       && CP_DECL_THREAD_LOCAL_P (expr))
    4430        73614 :     if (tree wrap = get_tls_wrapper_fn (expr))
    4431          749 :       return build_cxx_call (wrap, 0, NULL, tf_warning_or_error);
    4432              :   return NULL;
    4433              : }
    4434              : 
    4435              : /* At EOF, generate the definition for the TLS wrapper function FN:
    4436              : 
    4437              :    T& var_wrapper() {
    4438              :      if (init_fn) init_fn();
    4439              :      return var;
    4440              :    }  */
    4441              : 
    4442              : static void
    4443          586 : generate_tls_wrapper (tree fn)
    4444              : {
    4445          586 :   tree var = DECL_BEFRIENDING_CLASSES (fn);
    4446              : 
    4447          586 :   start_preparsed_function (fn, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
    4448          586 :   tree body = begin_function_body ();
    4449              :   /* Only call the init fn if there might be one.  */
    4450          586 :   if (tree init_fn = get_tls_init_fn (var))
    4451              :     {
    4452          566 :       tree if_stmt = NULL_TREE;
    4453              :       /* If init_fn is a weakref, make sure it exists before calling.  */
    4454          566 :       if (lookup_attribute ("weak", DECL_ATTRIBUTES (init_fn)))
    4455              :         {
    4456           51 :           if_stmt = begin_if_stmt ();
    4457           51 :           tree addr = cp_build_addr_expr (init_fn, tf_warning_or_error);
    4458           51 :           tree cond = cp_build_binary_op (DECL_SOURCE_LOCATION (var),
    4459              :                                           NE_EXPR, addr, nullptr_node,
    4460              :                                           tf_warning_or_error);
    4461           51 :           finish_if_stmt_cond (cond, if_stmt);
    4462              :         }
    4463          566 :       finish_expr_stmt (build_cxx_call
    4464              :                         (init_fn, 0, NULL, tf_warning_or_error));
    4465          566 :       if (if_stmt)
    4466              :         {
    4467           51 :           finish_then_clause (if_stmt);
    4468           51 :           finish_if_stmt (if_stmt);
    4469              :         }
    4470              :     }
    4471              :   else
    4472              :     /* If there's no initialization, the wrapper is a constant function.  */
    4473           20 :     TREE_READONLY (fn) = true;
    4474          586 :   finish_return_stmt (convert_from_reference (var));
    4475          586 :   finish_function_body (body);
    4476          586 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
    4477          586 : }
    4478              : 
    4479              : /* Start a global constructor or destructor function.  */
    4480              : 
    4481              : static tree
    4482         7271 : start_objects (bool initp, unsigned priority, bool has_body,
    4483              :                bool omp_target = false)
    4484              : {
    4485         7271 :   bool default_init = initp && priority == DEFAULT_INIT_PRIORITY;
    4486              :   /* FIXME: We may eventually want to treat OpenMP offload initializers
    4487              :      in modules specially as well.  */
    4488         7271 :   bool is_module_init = (default_init
    4489         7271 :                          && !omp_target
    4490         7271 :                          && module_global_init_needed ());
    4491         7271 :   tree name = NULL_TREE;
    4492              : 
    4493         7271 :   if (is_module_init)
    4494         1869 :     name = mangle_module_global_init (0);
    4495              :   else
    4496              :     {
    4497         5402 :       char type[14];
    4498              : 
    4499              :       /* We use `I' to indicate initialization and `D' to indicate
    4500              :          destruction.  */
    4501         5402 :       unsigned len;
    4502         5402 :       if (omp_target)
    4503              :         /* Use "off_" signifying "offload" here.  The name must be distinct
    4504              :            from the non-offload case.  The format of the name is scanned in
    4505              :            tree.cc/get_file_function_name, so stick to the same length for
    4506              :            both name variants.  */
    4507           15 :         len = sprintf (type, "off_%c", initp ? 'I' : 'D');
    4508              :       else
    4509         5396 :         len = sprintf (type, "sub_%c", initp ? 'I' : 'D');
    4510         5402 :       if (priority != DEFAULT_INIT_PRIORITY)
    4511              :         {
    4512           40 :           char joiner = '_';
    4513              : #ifdef JOINER
    4514           40 :           joiner = JOINER;
    4515              : #endif
    4516           40 :           type[len++] = joiner;
    4517           40 :           sprintf (type + len, "%.5u", priority);
    4518              :         }
    4519         5402 :       name = get_file_function_name (type);
    4520              :     }
    4521              : 
    4522         7271 :   tree fntype = build_function_type (void_type_node, void_list_node);
    4523         7271 :   tree fndecl = build_lang_decl (FUNCTION_DECL, name, fntype);
    4524              : 
    4525         7271 :   if (omp_target)
    4526              :     {
    4527           15 :       DECL_ATTRIBUTES (fndecl)
    4528           15 :         = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
    4529           15 :                      DECL_ATTRIBUTES (fndecl));
    4530           15 :       DECL_ATTRIBUTES (fndecl)
    4531           30 :         = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
    4532           15 :                      DECL_ATTRIBUTES (fndecl));
    4533              :     }
    4534              : 
    4535         7271 :   DECL_CONTEXT (fndecl) = FROB_CONTEXT (global_namespace);
    4536         7271 :   if (is_module_init)
    4537              :     {
    4538         1869 :       SET_DECL_ASSEMBLER_NAME (fndecl, name);
    4539         1869 :       TREE_PUBLIC (fndecl) = true;
    4540         1869 :       determine_visibility (fndecl);
    4541              :     }
    4542              :   else
    4543         5402 :     TREE_PUBLIC (fndecl) = 0;
    4544         7271 :   start_preparsed_function (fndecl, /*attrs=*/NULL_TREE, SF_PRE_PARSED);
    4545              : 
    4546              :   /* Mark as artificial because it's not explicitly in the user's
    4547              :      source code.  */
    4548         7271 :   DECL_ARTIFICIAL (current_function_decl) = 1;
    4549              : 
    4550              :   /* Mark this declaration as used to avoid spurious warnings.  */
    4551         7271 :   TREE_USED (current_function_decl) = 1;
    4552              : 
    4553              :   /* Mark this function as a global constructor or destructor.  */
    4554         7271 :   if (initp)
    4555         7262 :     DECL_GLOBAL_CTOR_P (current_function_decl) = 1;
    4556              :   else
    4557            9 :     DECL_GLOBAL_DTOR_P (current_function_decl) = 1;
    4558              : 
    4559         7271 :   tree body = begin_compound_stmt (BCS_FN_BODY);
    4560              : 
    4561         7271 :   if (is_module_init && has_body)
    4562              :     {
    4563              :       // If the function is going to be empty, don't emit idempotency.
    4564              :       // 'static bool __in_chrg = false;
    4565              :       // if (__inchrg) return;
    4566              :       // __inchrg = true
    4567           61 :       tree var = build_lang_decl (VAR_DECL, in_charge_identifier,
    4568              :                                   boolean_type_node);
    4569           61 :       DECL_CONTEXT (var) = fndecl;
    4570           61 :       DECL_ARTIFICIAL (var) = true;
    4571           61 :       TREE_STATIC (var) = true;
    4572           61 :       pushdecl (var);
    4573           61 :       cp_finish_decl (var, NULL_TREE, false, NULL_TREE, 0);
    4574              : 
    4575           61 :       tree if_stmt = begin_if_stmt ();
    4576           61 :       finish_if_stmt_cond (var, if_stmt);
    4577           61 :       finish_return_stmt (NULL_TREE);
    4578           61 :       finish_then_clause (if_stmt);
    4579           61 :       finish_if_stmt (if_stmt);
    4580              : 
    4581           61 :       tree assign = build2 (MODIFY_EXPR, boolean_type_node,
    4582              :                             var, boolean_true_node);
    4583           61 :       TREE_SIDE_EFFECTS (assign) = true;
    4584           61 :       finish_expr_stmt (assign);
    4585              :     }
    4586              : 
    4587         7271 :   return body;
    4588              : }
    4589              : 
    4590              : /* Finish a global constructor or destructor.  Add it to the global
    4591              :    ctors or dtors, if STARTP is true.  */
    4592              : 
    4593              : static tree
    4594         7268 : finish_objects (bool initp, unsigned priority, tree body, bool startp)
    4595              : {
    4596              :   /* Finish up.  */
    4597         7268 :   finish_compound_stmt (body);
    4598         7268 :   tree fn = finish_function (/*inline_p=*/false);
    4599              : 
    4600         7268 :   if (!startp)
    4601              :     ; // Neither ctor nor dtor I be.
    4602         5460 :   else if (initp)
    4603              :     {
    4604         5451 :       DECL_STATIC_CONSTRUCTOR (fn) = 1;
    4605         5451 :       decl_init_priority_insert (fn, priority);
    4606              :     }
    4607              :   else
    4608              :     {
    4609            9 :       DECL_STATIC_DESTRUCTOR (fn) = 1;
    4610            9 :       decl_fini_priority_insert (fn, priority);
    4611              :     }
    4612              : 
    4613         7268 :   return fn;
    4614              : }
    4615              : 
    4616              : /* The name of the function we create to handle initializations and
    4617              :    destructions for objects with static storage duration.  */
    4618              : #define SSDF_IDENTIFIER "__static_initialization_and_destruction"
    4619              : #define OMP_SSDF_IDENTIFIER "__omp_target_static_init_and_destruction"
    4620              : 
    4621              : /* Begins the generation of the function that will handle all
    4622              :    initialization or destruction of objects with static storage
    4623              :    duration at PRIORITY.
    4624              : 
    4625              :    It is assumed that this function will be called once for the host, and once
    4626              :    for an OpenMP offload target.  */
    4627              : 
    4628              : static tree
    4629         5469 : start_partial_init_fini_fn (bool initp, unsigned priority, unsigned count,
    4630              :                             bool omp_target)
    4631              : {
    4632         5469 :   char id[MAX (sizeof (SSDF_IDENTIFIER), sizeof (OMP_SSDF_IDENTIFIER))
    4633              :           + 1 /* \0 */ + 32];
    4634         5469 :   tree name;
    4635              : 
    4636              :   /* Create the identifier for this function.  It will be of the form
    4637              :      SSDF_IDENTIFIER_<number> if not omp_target and otherwise
    4638              :      OMP_SSDF_IDENTIFIER_<number>.  */
    4639         5469 :   sprintf (id, "%s_%u", omp_target ? OMP_SSDF_IDENTIFIER : SSDF_IDENTIFIER,
    4640              :            count);
    4641         5469 :   name = get_identifier (id);
    4642         5469 :   tree type = build_function_type (void_type_node, void_list_node);
    4643              : 
    4644              :   /* Create the FUNCTION_DECL itself.  */
    4645         5469 :   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
    4646         5469 :   TREE_PUBLIC (fn) = 0;
    4647         5469 :   DECL_ARTIFICIAL (fn) = 1;
    4648              : 
    4649         5469 :   if (omp_target)
    4650              :     {
    4651           15 :       DECL_ATTRIBUTES (fn)
    4652           15 :         = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
    4653           15 :                      DECL_ATTRIBUTES (fn));
    4654           15 :       DECL_ATTRIBUTES (fn)
    4655           30 :         = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
    4656           15 :                      DECL_ATTRIBUTES (fn));
    4657              :     }
    4658              : 
    4659         5469 :   int idx = initp + 2 * omp_target;
    4660              : 
    4661              :   /* Put this function in the list of functions to be called from the
    4662              :      static constructors and destructors.  */
    4663         5469 :   if (!static_init_fini_fns[idx])
    4664         5439 :     static_init_fini_fns[idx] = priority_map_t::create_ggc ();
    4665         5469 :   auto &slot = static_init_fini_fns[idx]->get_or_insert (priority);
    4666         5469 :   slot = tree_cons (fn, NULL_TREE, slot);
    4667              : 
    4668              :   /* Put the function in the global scope.  */
    4669         5469 :   pushdecl (fn);
    4670              : 
    4671              :   /* Start the function itself.  This is equivalent to declaring the
    4672              :      function as:
    4673              : 
    4674              :        static void __ssdf (int __initialize_p, init __priority_p);
    4675              : 
    4676              :      It is static because we only need to call this function from the
    4677              :      various constructor and destructor functions for this module.  */
    4678         5469 :   start_preparsed_function (fn, /*attrs=*/NULL_TREE, SF_PRE_PARSED);
    4679              : 
    4680              :   /* Set up the scope of the outermost block in the function.  */
    4681         5469 :   return begin_compound_stmt (BCS_FN_BODY);
    4682              : }
    4683              : 
    4684              : /* Finish the generation of the function which performs initialization
    4685              :    or destruction of objects with static storage duration.  */
    4686              : 
    4687              : static void
    4688         5469 : finish_partial_init_fini_fn (tree body)
    4689              : {
    4690              :   /* Close out the function.  */
    4691         5469 :   finish_compound_stmt (body);
    4692         5469 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
    4693         5469 : }
    4694              : 
    4695              : /* The effective initialization priority of a DECL.  */
    4696              : 
    4697              : #define DECL_EFFECTIVE_INIT_PRIORITY(decl)                                    \
    4698              :         ((!DECL_HAS_INIT_PRIORITY_P (decl) || DECL_INIT_PRIORITY (decl) == 0) \
    4699              :          ? DEFAULT_INIT_PRIORITY : DECL_INIT_PRIORITY (decl))
    4700              : 
    4701              : /* Whether a DECL needs a guard to protect it against multiple
    4702              :    initialization.  */
    4703              : 
    4704              : #define NEEDS_GUARD_P(decl) (TREE_PUBLIC (decl) && (DECL_COMMON (decl)      \
    4705              :                                                     || DECL_ONE_ONLY (decl) \
    4706              :                                                     || DECL_WEAK (decl)))
    4707              : 
    4708              : /* Walks the initializer list of a global variable and looks for
    4709              :    temporary variables (DECL_NAME() == NULL and DECL_ARTIFICIAL != 0)
    4710              :    and that have their DECL_CONTEXT() == NULL.  For each such
    4711              :    temporary variable, set their DECL_CONTEXT() to CTX -- the
    4712              :    initializing function. This is necessary because otherwise some
    4713              :    optimizers (enabled by -O2 -fprofile-arcs) might crash when trying
    4714              :    to refer to a temporary variable that does not have its
    4715              :    DECL_CONTEXT() properly set.  */
    4716              : 
    4717              : static tree
    4718       265747 : fix_temporary_vars_context_r (tree *node,
    4719              :                               int  * /*unused*/,
    4720              :                               void *ctx)
    4721              : {
    4722       265747 :   if (TREE_CODE (*node) == BIND_EXPR)
    4723          792 :     for (tree var = BIND_EXPR_VARS (*node); var; var = DECL_CHAIN (var))
    4724          396 :       if (VAR_P (var) && !DECL_NAME (var)
    4725          792 :           && DECL_ARTIFICIAL (var) && !DECL_CONTEXT (var))
    4726          396 :         DECL_CONTEXT (var) = tree (ctx);
    4727              : 
    4728       265747 :   return NULL_TREE;
    4729              : }
    4730              : 
    4731              : /* Set up to handle the initialization or destruction of DECL.  If
    4732              :    INITP is nonzero, we are initializing the variable.  Otherwise, we
    4733              :    are destroying it.  */
    4734              : 
    4735              : static void
    4736        11057 : one_static_initialization_or_destruction (bool initp, tree decl, tree init,
    4737              :                                           bool omp_target)
    4738              : {
    4739              :   /* If we are supposed to destruct and there's a trivial destructor,
    4740              :      nothing has to be done.  */
    4741        11057 :   gcc_checking_assert (init || !TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)));
    4742              : 
    4743              :   /* Trick the compiler into thinking we are at the file and line
    4744              :      where DECL was declared so that error-messages make sense, and so
    4745              :      that the debugger will show somewhat sensible file and line
    4746              :      information.  */
    4747        11057 :   input_location = DECL_SOURCE_LOCATION (decl);
    4748              : 
    4749              :   /* Make sure temporary variables in the initialiser all have
    4750              :      their DECL_CONTEXT() set to a value different from NULL_TREE.
    4751              :      This can happen when global variables initializers are built.
    4752              :      In that case, the DECL_CONTEXT() of the global variables _AND_ of all
    4753              :      the temporary variables that might have been generated in the
    4754              :      accompanying initializers is NULL_TREE, meaning the variables have been
    4755              :      declared in the global namespace.
    4756              :      What we want to do here is to fix that and make sure the DECL_CONTEXT()
    4757              :      of the temporaries are set to the current function decl.  */
    4758        11057 :   cp_walk_tree_without_duplicates (&init,
    4759              :                                    fix_temporary_vars_context_r,
    4760              :                                    current_function_decl);
    4761              : 
    4762              :   /* Because of:
    4763              : 
    4764              :        [class.access.spec]
    4765              : 
    4766              :        Access control for implicit calls to the constructors,
    4767              :        the conversion functions, or the destructor called to
    4768              :        create and destroy a static data member is performed as
    4769              :        if these calls appeared in the scope of the member's
    4770              :        class.
    4771              : 
    4772              :      we pretend we are in a static member function of the class of
    4773              :      which the DECL is a member.  */
    4774        11057 :   if (member_p (decl))
    4775              :     {
    4776         1620 :       DECL_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
    4777         1620 :       DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
    4778              :     }
    4779              : 
    4780              :   /* Assume we don't need a guard.  */
    4781        11057 :   tree guard_if_stmt = NULL_TREE;
    4782              : 
    4783              :   /* We need a guard if this is an object with external linkage that
    4784              :      might be initialized in more than one place.  (For example, a
    4785              :      static data member of a template, when the data member requires
    4786              :      construction.)  */
    4787        11057 :   if (NEEDS_GUARD_P (decl))
    4788              :     {
    4789          876 :       tree guard = get_guard (decl);
    4790          876 :       tree guard_cond;
    4791              : 
    4792          876 :       if (flag_use_cxa_atexit)
    4793              :         {
    4794              :           /* When using __cxa_atexit, we just check the GUARD as we
    4795              :              would for a local static.  We never try to destroy
    4796              :              anything from a static destructor.  */
    4797          876 :           gcc_assert (initp);
    4798          876 :           guard_cond = get_guard_cond (guard, false);
    4799              :         }
    4800              :       else
    4801              :         {
    4802              :           /* If we don't have __cxa_atexit, then we will be running
    4803              :              destructors from .fini sections, or their equivalents.
    4804              :              So, we need to know how many times we've tried to
    4805              :              initialize this object.  We do initializations only if
    4806              :              the GUARD was or becomes zero (initp vs !initp
    4807              :              respectively).  */
    4808            0 :           guard_cond = cp_build_unary_op (initp ? POSTINCREMENT_EXPR
    4809              :                                           : PREDECREMENT_EXPR,
    4810              :                                           guard,
    4811              :                                           /*noconvert=*/true,
    4812              :                                           tf_warning_or_error);
    4813            0 :           guard_cond = cp_build_binary_op (input_location, EQ_EXPR, guard_cond,
    4814              :                                            integer_zero_node,
    4815              :                                            tf_warning_or_error);
    4816              :         }
    4817              : 
    4818          876 :       guard_if_stmt = begin_if_stmt ();
    4819          876 :       finish_if_stmt_cond (guard_cond, guard_if_stmt);
    4820              : 
    4821          876 :       if (flag_use_cxa_atexit)
    4822              :         /* Set the GUARD now.  */
    4823          876 :         finish_expr_stmt (set_guard (guard));
    4824              :     }
    4825              : 
    4826              :   /* Perform the initialization or destruction.  */
    4827        11057 :   if (initp)
    4828              :     {
    4829        11042 :       if (init)
    4830              :         {
    4831        10513 :           finish_expr_stmt (init);
    4832        10513 :           if (sanitize_flags_p (SANITIZE_ADDRESS, decl))
    4833           28 :             if (varpool_node *vnode = varpool_node::get (decl))
    4834           28 :               vnode->dynamically_initialized = 1;
    4835              :         }
    4836              : 
    4837              :       /* If we're using __cxa_atexit, register a function that calls the
    4838              :          destructor for the object.  */
    4839        11042 :       if (flag_use_cxa_atexit)
    4840        11033 :         finish_expr_stmt (register_dtor_fn (decl, omp_target));
    4841              :     }
    4842              :   else
    4843           15 :     finish_expr_stmt (build_cleanup (decl));
    4844              : 
    4845              :   /* Finish the guard if-stmt, if necessary.  */
    4846        11057 :   if (guard_if_stmt)
    4847              :     {
    4848          876 :       finish_then_clause (guard_if_stmt);
    4849          876 :       finish_if_stmt (guard_if_stmt);
    4850              :     }
    4851              : 
    4852              :   /* Now that we're done with DECL we don't need to pretend to be a
    4853              :      member of its class any longer.  */
    4854        11057 :   DECL_CONTEXT (current_function_decl) = NULL_TREE;
    4855        11057 :   DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
    4856        11057 : }
    4857              : 
    4858              : /* Helper function for emit_partial_init_fini_fn and handle_tls_init.
    4859              :    For structured bindings, disable stmts_are_full_exprs_p ()
    4860              :    on STATIC_INIT_DECOMP_BASE_P nodes, reenable it on the
    4861              :    first STATIC_INIT_DECOMP_NONBASE_P node and emit all the
    4862              :    STATIC_INIT_DECOMP_BASE_P and STATIC_INIT_DECOMP_NONBASE_P
    4863              :    consecutive nodes in a single STATEMENT_LIST wrapped with
    4864              :    CLEANUP_POINT_EXPR.  */
    4865              : 
    4866              : static inline tree
    4867        11057 : decomp_handle_one_var (tree node, tree sl, bool *saw_nonbase,
    4868              :                        int save_stmts_are_full_exprs_p)
    4869              : {
    4870        11126 :   if (sl && !*saw_nonbase && STATIC_INIT_DECOMP_NONBASE_P (node))
    4871              :     {
    4872           63 :       *saw_nonbase = true;
    4873           63 :       current_stmt_tree ()->stmts_are_full_exprs_p
    4874           63 :         = save_stmts_are_full_exprs_p;
    4875              :     }
    4876        11204 :   else if (sl && *saw_nonbase && !STATIC_INIT_DECOMP_NONBASE_P (node))
    4877              :     {
    4878           45 :       sl = pop_stmt_list (sl);
    4879           45 :       sl = maybe_cleanup_point_expr_void (sl);
    4880           45 :       add_stmt (sl);
    4881           45 :       sl = NULL_TREE;
    4882              :     }
    4883        21880 :   if (sl == NULL_TREE && STATIC_INIT_DECOMP_BASE_P (node))
    4884              :     {
    4885           63 :       sl = push_stmt_list ();
    4886           63 :       *saw_nonbase = false;
    4887           63 :       current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    4888              :     }
    4889        11057 :   return sl;
    4890              : }
    4891              : 
    4892              : /* Similarly helper called when the whole var list is processed.  */
    4893              : 
    4894              : static inline void
    4895         5549 : decomp_finalize_var_list (tree sl, int save_stmts_are_full_exprs_p)
    4896              : {
    4897         5549 :   if (sl)
    4898              :     {
    4899           18 :       current_stmt_tree ()->stmts_are_full_exprs_p
    4900           18 :         = save_stmts_are_full_exprs_p;
    4901           18 :       sl = pop_stmt_list (sl);
    4902           18 :       sl = maybe_cleanup_point_expr_void (sl);
    4903           18 :       add_stmt (sl);
    4904              :     }
    4905         5549 : }
    4906              : 
    4907              : /* Helper for emit_partial_init_fini_fn OpenMP target handling, called via
    4908              :    walk_tree.  Set DECL_CONTEXT on any automatic temporaries which still
    4909              :    have it NULL to id->src_fn, so that later copy_tree_body_r can remap those.
    4910              :    Otherwise DECL_CONTEXT would be set only during gimplification of the host
    4911              :    fn and when copy_tree_body_r doesn't remap those, we'd ICE during the
    4912              :    target fn gimplification because the same automatic VAR_DECL can't be
    4913              :    used in multiple functions (with the exception of nested functions).  */
    4914              : 
    4915              : static tree
    4916          303 : set_context_for_auto_vars_r (tree *tp, int *, void *data)
    4917              : {
    4918          303 :   copy_body_data *id = (copy_body_data *) data;
    4919          303 :   if (auto_var_in_fn_p (*tp, NULL_TREE) && DECL_ARTIFICIAL (*tp))
    4920           11 :     DECL_CONTEXT (*tp) = id->src_fn;
    4921          303 :   return NULL_TREE;
    4922              : }
    4923              : 
    4924              : /* Generate code to do the initialization or destruction of the decls in VARS,
    4925              :    a TREE_LIST of VAR_DECL with static storage duration.
    4926              :    Whether initialization or destruction is performed is specified by INITP.  */
    4927              : 
    4928              : static tree
    4929         5426 : emit_partial_init_fini_fn (bool initp, unsigned priority, tree vars,
    4930              :                            unsigned counter, location_t locus, tree host_fn)
    4931              : {
    4932         5426 :   input_location = locus;
    4933         5426 :   bool omp_target = (host_fn != NULL_TREE);
    4934         5426 :   tree body = start_partial_init_fini_fn (initp, priority, counter, omp_target);
    4935         5426 :   tree fndecl = current_function_decl;
    4936              : 
    4937         5426 :   tree nonhost_if_stmt = NULL_TREE;
    4938         5426 :   if (omp_target)
    4939              :     {
    4940           15 :       nonhost_if_stmt = begin_if_stmt ();
    4941              :       /* We add an "omp declare target nohost" attribute, but (for
    4942              :          now) we still get a copy of the constructor/destructor on
    4943              :          the host.  Make sure it does nothing unless we're on the
    4944              :          target device.  */
    4945           15 :       tree fn = builtin_decl_explicit (BUILT_IN_OMP_IS_INITIAL_DEVICE);
    4946           15 :       tree initial_dev = build_call_expr (fn, 0);
    4947           15 :       tree target_dev_p
    4948           15 :         = cp_build_binary_op (input_location, NE_EXPR, initial_dev,
    4949              :                               integer_one_node, tf_warning_or_error);
    4950           15 :       finish_if_stmt_cond (target_dev_p, nonhost_if_stmt);
    4951              :     }
    4952              : 
    4953         5426 :   tree sl = NULL_TREE;
    4954         5426 :   int save_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    4955         5426 :   bool saw_nonbase = false;
    4956        15676 :   for (tree node = vars; node; node = TREE_CHAIN (node))
    4957              :     {
    4958        10250 :       tree decl = TREE_VALUE (node);
    4959        10250 :       tree init = TREE_PURPOSE (node);
    4960        10250 :       sl = decomp_handle_one_var (node, sl, &saw_nonbase,
    4961              :                                   save_stmts_are_full_exprs_p);
    4962              :       /* We will emit 'init' twice, and it is modified in-place during
    4963              :          gimplification.  Make a copy here.  */
    4964        10250 :       if (omp_target)
    4965              :         {
    4966              :           /* We've already emitted INIT in the host version of the ctor/dtor
    4967              :              function.  We need to deep-copy it (including new versions of
    4968              :              local variables introduced, etc.) for use in the target
    4969              :              ctor/dtor function.  */
    4970           19 :           copy_body_data id;
    4971           19 :           hash_map<tree, tree> decl_map;
    4972           19 :           memset (&id, 0, sizeof (id));
    4973           19 :           id.src_fn = host_fn;
    4974           19 :           id.dst_fn = current_function_decl;
    4975           19 :           id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
    4976           19 :           id.decl_map = &decl_map;
    4977           19 :           id.copy_decl = copy_decl_no_change;
    4978           19 :           id.transform_call_graph_edges = CB_CGE_DUPLICATE;
    4979           19 :           id.transform_new_cfg = true;
    4980           19 :           id.transform_return_to_modify = false;
    4981           19 :           id.eh_lp_nr = 0;
    4982           19 :           walk_tree (&init, set_context_for_auto_vars_r, &id, NULL);
    4983           19 :           walk_tree (&init, copy_tree_body_r, &id, NULL);
    4984           19 :         }
    4985              :       /* Do one initialization or destruction.  */
    4986        10250 :       one_static_initialization_or_destruction (initp, decl, init, omp_target);
    4987              :     }
    4988         5426 :   decomp_finalize_var_list (sl, save_stmts_are_full_exprs_p);
    4989              : 
    4990         5426 :   if (omp_target)
    4991              :     {
    4992              :       /* Finish up nonhost if-stmt body.  */
    4993           15 :       finish_then_clause (nonhost_if_stmt);
    4994           15 :       finish_if_stmt (nonhost_if_stmt);
    4995              :     }
    4996              : 
    4997              :   /* Finish up the static storage duration function for this
    4998              :      round.  */
    4999         5426 :   input_location = locus;
    5000         5426 :   finish_partial_init_fini_fn (body);
    5001              : 
    5002         5426 :   return fndecl;
    5003              : }
    5004              : 
    5005              : /* VARS is a list of variables with static storage duration which may
    5006              :    need initialization and/or finalization.  Remove those variables
    5007              :    that don't really need to be initialized or finalized, and return
    5008              :    the resulting list.  The order in which the variables appear in
    5009              :    VARS is in reverse order of the order in which they should actually
    5010              :    be initialized.  That order is preserved.  */
    5011              : 
    5012              : static tree
    5013       281312 : prune_vars_needing_no_initialization (tree *vars)
    5014              : {
    5015       281312 :   tree *var = vars;
    5016       281312 :   tree result = NULL_TREE;
    5017              : 
    5018       292341 :   while (*var)
    5019              :     {
    5020        11029 :       tree t = *var;
    5021        11029 :       tree decl = TREE_VALUE (t);
    5022        11029 :       tree init = TREE_PURPOSE (t);
    5023              : 
    5024              :       /* Deal gracefully with error.  */
    5025        11029 :       if (error_operand_p (decl))
    5026              :         {
    5027            0 :           var = &TREE_CHAIN (t);
    5028            0 :           continue;
    5029              :         }
    5030              : 
    5031              :       /* The only things that can be initialized are variables.  */
    5032        11029 :       gcc_assert (VAR_P (decl));
    5033              : 
    5034              :       /* If this object is not defined, we don't need to do anything
    5035              :          here.  */
    5036        11029 :       if (DECL_EXTERNAL (decl))
    5037              :         {
    5038            0 :           gcc_checking_assert (!STATIC_INIT_DECOMP_BASE_P (t)
    5039              :                                && !STATIC_INIT_DECOMP_NONBASE_P (t));
    5040            0 :           var = &TREE_CHAIN (t);
    5041            0 :           continue;
    5042              :         }
    5043              : 
    5044              :       /* Also, if the initializer already contains errors, we can bail
    5045              :          out now.  */
    5046        10497 :       if (init && TREE_CODE (init) == TREE_LIST
    5047        11029 :           && value_member (error_mark_node, init))
    5048              :         {
    5049            0 :           var = &TREE_CHAIN (t);
    5050            0 :           continue;
    5051              :         }
    5052              : 
    5053              :       /* Reflections are consteval-only types and we don't want them
    5054              :          to survive until gimplification.  */
    5055        11029 :       if (consteval_only_p (decl))
    5056              :         {
    5057            0 :           var = &TREE_CHAIN (t);
    5058            0 :           continue;
    5059              :         }
    5060              : 
    5061              :       /* This variable is going to need initialization and/or
    5062              :          finalization, so we add it to the list.  */
    5063        11029 :       *var = TREE_CHAIN (t);
    5064        11029 :       TREE_CHAIN (t) = result;
    5065        11029 :       result = t;
    5066              :     }
    5067              : 
    5068       281312 :   return result;
    5069              : }
    5070              : 
    5071              : /* Split VAR_LIST by init priority and add into PARTS hash table.
    5072              :    This reverses the variable ordering.  */
    5073              : 
    5074              : void
    5075         5394 : partition_vars_for_init_fini (tree var_list, priority_map_t *(&parts)[4])
    5076              : {
    5077         5394 :   unsigned priority = 0;
    5078         5394 :   enum { none, base, nonbase } decomp_state = none;
    5079        15616 :   for (auto node = var_list; node; node = TREE_CHAIN (node))
    5080              :     {
    5081        10222 :       tree decl = TREE_VALUE (node);
    5082        10222 :       tree init = TREE_PURPOSE (node);
    5083        10222 :       bool has_cleanup = !TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl));
    5084        10222 :       if (decomp_state == base && STATIC_INIT_DECOMP_NONBASE_P (node))
    5085              :         decomp_state = nonbase;
    5086        10186 :       else if (decomp_state == nonbase && !STATIC_INIT_DECOMP_NONBASE_P (node))
    5087              :         decomp_state = none;
    5088        10201 :       if (decomp_state == none)
    5089        20173 :         priority = DECL_EFFECTIVE_INIT_PRIORITY (decl);
    5090              : 
    5091        10222 :       if (init || (flag_use_cxa_atexit && has_cleanup))
    5092              :         {
    5093              :           // Add to initialization list.
    5094        10216 :           if (!parts[true])
    5095         5388 :             parts[true] = priority_map_t::create_ggc ();
    5096        10216 :           auto &slot = parts[true]->get_or_insert (priority);
    5097        10216 :           slot = tree_cons (init, decl, slot);
    5098        10216 :           if (init
    5099         9717 :               && STATIC_INIT_DECOMP_BASE_P (node)
    5100        10252 :               && decomp_state == none)
    5101              :             {
    5102              :               /* If one or more STATIC_INIT_DECOMP_BASE_P with at least
    5103              :                  one init is followed by at least one
    5104              :                  STATIC_INIT_DECOMP_NONBASE_P with init, mark it in the
    5105              :                  resulting chain as well.  */
    5106           39 :               for (tree n = TREE_CHAIN (node); n; n = TREE_CHAIN (n))
    5107           39 :                 if (STATIC_INIT_DECOMP_BASE_P (n))
    5108            0 :                   continue;
    5109           39 :                 else if (STATIC_INIT_DECOMP_NONBASE_P (n))
    5110              :                   {
    5111           39 :                     if (TREE_PURPOSE (n))
    5112              :                       {
    5113              :                         decomp_state = base;
    5114              :                         break;
    5115              :                       }
    5116              :                     else
    5117            3 :                       continue;
    5118              :                   }
    5119              :                 else
    5120              :                   break;
    5121              :             }
    5122        10216 :           if (init && decomp_state == base)
    5123           36 :             STATIC_INIT_DECOMP_BASE_P (slot) = 1;
    5124        10180 :           else if (decomp_state == nonbase)
    5125          120 :             STATIC_INIT_DECOMP_NONBASE_P (slot) = 1;
    5126              :         }
    5127              : 
    5128        10222 :       if (!flag_use_cxa_atexit && has_cleanup)
    5129              :         {
    5130              :           // Add to finalization list.
    5131           15 :           if (!parts[false])
    5132            9 :             parts[false] = priority_map_t::create_ggc ();
    5133           15 :           auto &slot = parts[false]->get_or_insert (priority);
    5134           15 :           slot = tree_cons (NULL_TREE, decl, slot);
    5135              :         }
    5136              : 
    5137        10222 :       if (flag_openmp
    5138        10222 :           && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
    5139              :         {
    5140           19 :           priority_map_t **omp_parts = parts + 2;
    5141              : 
    5142           19 :           if (init || (flag_use_cxa_atexit && has_cleanup))
    5143              :             {
    5144              :               // Add to initialization list.
    5145           19 :               if (!omp_parts[true])
    5146           14 :                 omp_parts[true] = priority_map_t::create_ggc ();
    5147           19 :               auto &slot = omp_parts[true]->get_or_insert (priority);
    5148           19 :               slot = tree_cons (init, decl, slot);
    5149           19 :               if (init && decomp_state == base)
    5150            0 :                 STATIC_INIT_DECOMP_BASE_P (slot) = 1;
    5151           19 :               else if (decomp_state == nonbase)
    5152            0 :                 STATIC_INIT_DECOMP_NONBASE_P (slot) = 1;
    5153              :             }
    5154              : 
    5155           19 :           if (!flag_use_cxa_atexit && has_cleanup)
    5156              :             {
    5157              :               // Add to finalization list.
    5158            0 :               if (!omp_parts[false])
    5159            0 :                 omp_parts[false] = priority_map_t::create_ggc ();
    5160            0 :               auto &slot = omp_parts[false]->get_or_insert (priority);
    5161            0 :               slot = tree_cons (NULL_TREE, decl, slot);
    5162              :             }
    5163              :         }
    5164              :     }
    5165         5394 : }
    5166              : 
    5167              : /* Make sure we have told the back end about all the variables in
    5168              :    VARS.  */
    5169              : 
    5170              : static void
    5171         5517 : write_out_vars (tree vars)
    5172              : {
    5173         5517 :   tree v;
    5174              : 
    5175        16546 :   for (v = vars; v; v = TREE_CHAIN (v))
    5176              :     {
    5177        11029 :       tree var = TREE_VALUE (v);
    5178        11029 :       if (!var_finalized_p (var))
    5179              :         {
    5180          807 :           import_export_decl (var);
    5181          807 :           rest_of_decl_compilation (var, 1, 1);
    5182              :         }
    5183              :     }
    5184         5517 : }
    5185              : 
    5186              : /* Generate a static constructor or destructor that calls the given
    5187              :    init/fini fns at the indicated priority.  */
    5188              : 
    5189              : static void
    5190         7262 : generate_ctor_or_dtor_function (bool initp, unsigned priority,
    5191              :                                 tree fns, location_t locus, bool omp_target)
    5192              : {
    5193         7262 :   input_location = locus;
    5194         7262 :   tree body = start_objects (initp, priority, bool (fns), omp_target);
    5195              : 
    5196         7262 :   if (fns)
    5197              :     {
    5198              :       /* To make sure dynamic construction doesn't access globals from
    5199              :          other compilation units where they might not be yet
    5200              :          constructed, for -fsanitize=address insert
    5201              :          __asan_before_dynamic_init call that prevents access to
    5202              :          either all global variables that need construction in other
    5203              :          compilation units, or at least those that haven't been
    5204              :          initialized yet.  Variables that need dynamic construction in
    5205              :          the current compilation unit are kept accessible.  */
    5206         5454 :       if (initp && (flag_sanitize & SANITIZE_ADDRESS))
    5207           21 :         finish_expr_stmt (asan_dynamic_init_call (/*after_p=*/false));
    5208              : 
    5209              :       /* Call the static init/fini functions.  */
    5210        10923 :       for (tree node = fns; node; node = TREE_CHAIN (node))
    5211              :         {
    5212         5469 :           tree fn = TREE_PURPOSE (node);
    5213              : 
    5214              :           // We should never find a pure or constant cdtor.
    5215         5469 :           gcc_checking_assert (!(flags_from_decl_or_type (fn)
    5216              :                                  & (ECF_CONST | ECF_PURE)));
    5217              : 
    5218         5469 :           tree call = cp_build_function_call_nary (fn, tf_warning_or_error,
    5219              :                                                    NULL_TREE);
    5220         5469 :           finish_expr_stmt (call);
    5221              :         }
    5222              : 
    5223              :       /* Revert what __asan_before_dynamic_init did by calling
    5224              :          __asan_after_dynamic_init.  */
    5225         5454 :       if (initp && (flag_sanitize & SANITIZE_ADDRESS))
    5226           21 :         finish_expr_stmt (asan_dynamic_init_call (/*after_p=*/true));
    5227              :     }
    5228              : 
    5229              :   /* Close out the function, and arrange for it to be called at init
    5230              :      or fini time, if non-empty.  (Even non-nop module initializer
    5231              :      functions need this, as we cannot guarantee the module is
    5232              :      imported somewhere in the program.)  */
    5233         7262 :   expand_or_defer_fn (finish_objects (initp, priority, body, fns != NULL_TREE));
    5234         7262 : }
    5235              : 
    5236              : /* Return C++ property of T, based on given operation OP.  */
    5237              : 
    5238              : static int
    5239         1941 : cpp_check (tree t, cpp_operation op)
    5240              : {
    5241         1941 :   switch (op)
    5242              :     {
    5243            9 :       case HAS_DEPENDENT_TEMPLATE_ARGS:
    5244            9 :         {
    5245            9 :           tree ti = CLASSTYPE_TEMPLATE_INFO (t);
    5246            9 :           if (!ti)
    5247              :             return 0;
    5248            9 :           ++processing_template_decl;
    5249            9 :           const bool dep = any_dependent_template_arguments_p (TI_ARGS (ti));
    5250            9 :           --processing_template_decl;
    5251            9 :           return dep;
    5252              :         }
    5253          294 :       case IS_ABSTRACT:
    5254          294 :         return DECL_PURE_VIRTUAL_P (t);
    5255          165 :       case IS_ASSIGNMENT_OPERATOR:
    5256          165 :         return DECL_ASSIGNMENT_OPERATOR_P (t);
    5257          165 :       case IS_CONSTRUCTOR:
    5258          330 :         return DECL_CONSTRUCTOR_P (t);
    5259          165 :       case IS_DESTRUCTOR:
    5260          330 :         return DECL_DESTRUCTOR_P (t);
    5261          165 :       case IS_COPY_CONSTRUCTOR:
    5262          477 :         return DECL_COPY_CONSTRUCTOR_P (t);
    5263          165 :       case IS_MOVE_CONSTRUCTOR:
    5264          483 :         return DECL_MOVE_CONSTRUCTOR_P (t);
    5265          447 :       case IS_TEMPLATE:
    5266          447 :         return TREE_CODE (t) == TEMPLATE_DECL;
    5267          366 :       case IS_TRIVIAL:
    5268          366 :         return trivial_type_p (t);
    5269              :       default:
    5270              :         return 0;
    5271              :     }
    5272              : }
    5273              : 
    5274              : /* Collect source file references recursively, starting from NAMESPC.  */
    5275              : 
    5276              : static void
    5277           78 : collect_source_refs (tree namespc)
    5278              : {
    5279              :   /* Iterate over names in this name space.  */
    5280       183143 :   for (tree t = NAMESPACE_LEVEL (namespc)->names; t; t = TREE_CHAIN (t))
    5281       183065 :     if (DECL_IS_UNDECLARED_BUILTIN (t))
    5282              :       ;
    5283          240 :     else if (TREE_CODE (t) == NAMESPACE_DECL && !DECL_NAMESPACE_ALIAS (t))
    5284            3 :       collect_source_refs (t);
    5285              :     else
    5286          237 :       collect_source_ref (DECL_SOURCE_FILE (t));
    5287           78 : }
    5288              : 
    5289              : /* Collect decls relevant to SOURCE_FILE from all namespaces recursively,
    5290              :    starting from NAMESPC.  */
    5291              : 
    5292              : static void
    5293          228 : collect_ada_namespace (tree namespc, const char *source_file)
    5294              : {
    5295          228 :   tree decl = NAMESPACE_LEVEL (namespc)->names;
    5296              : 
    5297              :   /* Collect decls from this namespace.  This will skip
    5298              :      NAMESPACE_DECLs (both aliases and regular, it cannot tell).  */
    5299          228 :   collect_ada_nodes (decl, source_file);
    5300              : 
    5301              :   /* Now scan for namespace children, and dump them.  */
    5302       219321 :   for (; decl; decl = TREE_CHAIN (decl))
    5303       218865 :     if (TREE_CODE (decl) == NAMESPACE_DECL && !DECL_NAMESPACE_ALIAS (decl))
    5304          153 :       collect_ada_namespace (decl, source_file);
    5305          228 : }
    5306              : 
    5307              : /* Returns true iff there is a definition available for variable or
    5308              :    function DECL.  */
    5309              : 
    5310              : bool
    5311     88587954 : decl_defined_p (tree decl)
    5312              : {
    5313     88587954 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    5314     78272548 :     return (DECL_INITIAL (decl) != NULL_TREE
    5315              :             /* A pending instantiation of a friend temploid is defined.  */
    5316     78272548 :             || (DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
    5317      7385892 :                 && DECL_INITIAL (DECL_TEMPLATE_RESULT
    5318              :                                  (DECL_TI_TEMPLATE (decl)))));
    5319              :   else
    5320              :     {
    5321     10315406 :       gcc_assert (VAR_P (decl));
    5322     10315406 :       return !DECL_EXTERNAL (decl);
    5323              :     }
    5324              : }
    5325              : 
    5326              : /* Nonzero for a VAR_DECL whose value can be used in a constant expression.
    5327              : 
    5328              :       [expr.const]
    5329              : 
    5330              :       An integral constant-expression can only involve ... const
    5331              :       variables of integral or enumeration types initialized with
    5332              :       constant expressions ...
    5333              : 
    5334              :       C++0x also allows constexpr variables and temporaries initialized
    5335              :       with constant expressions.  We handle the former here, but the latter
    5336              :       are just folded away in cxx_eval_constant_expression.
    5337              : 
    5338              :    The standard does not require that the expression be non-volatile.
    5339              :    G++ implements the proposed correction in DR 457.  */
    5340              : 
    5341              : bool
    5342   1359241277 : decl_constant_var_p (tree decl)
    5343              : {
    5344   1359241277 :   if (!decl_maybe_constant_var_p (decl))
    5345              :     return false;
    5346              : 
    5347              :   /* We don't know if a template static data member is initialized with
    5348              :      a constant expression until we instantiate its initializer.  Even
    5349              :      in the case of a constexpr variable, we can't treat it as a
    5350              :      constant until its initializer is complete in case it's used in
    5351              :      its own initializer.  */
    5352    168236186 :   maybe_instantiate_decl (decl);
    5353    168233489 :   return DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl);
    5354              : }
    5355              : 
    5356              : /* Returns true if DECL could be a symbolic constant variable, depending on
    5357              :    its initializer.  */
    5358              : 
    5359              : bool
    5360   1777529590 : decl_maybe_constant_var_p (tree decl)
    5361              : {
    5362   1777529590 :   tree type = TREE_TYPE (decl);
    5363   1777529590 :   if (!VAR_P (decl))
    5364              :     return false;
    5365    850727077 :   if (DECL_DECLARED_CONSTEXPR_P (decl)
    5366    850727077 :       && (!TREE_THIS_VOLATILE (decl) || NULLPTR_TYPE_P (type)))
    5367              :     return true;
    5368    490592611 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    5369              :     /* A proxy isn't constant.  */
    5370              :     return false;
    5371    481866821 :   if (TYPE_REF_P (type))
    5372              :     /* References can be constant.  */;
    5373    473588470 :   else if (CP_TYPE_CONST_NON_VOLATILE_P (type)
    5374    473588470 :            && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    5375              :     /* And const integers.  */;
    5376              :   else
    5377              :     return false;
    5378              : 
    5379     92573333 :   if (DECL_INITIAL (decl)
    5380    142091679 :       && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
    5381              :     /* We know the initializer, and it isn't constant.  */
    5382              :     return false;
    5383              :   else
    5384              :     return true;
    5385              : }
    5386              : 
    5387              : /* Complain that DECL uses a type with no linkage.  In C++98 mode this is
    5388              :    called from grokfndecl and grokvardecl; in all modes it is called from
    5389              :    cp_write_global_declarations.  */
    5390              : 
    5391              : void
    5392      1781475 : no_linkage_error (tree decl)
    5393              : {
    5394      1781475 :   if (cxx_dialect >= cxx11
    5395      1781475 :       && (decl_defined_p (decl)
    5396              :           /* Treat templates which limit_bad_template_recursion decided
    5397              :              not to instantiate as if they were defined.  */
    5398          128 :           || (errorcount + sorrycount > 0
    5399           53 :               && DECL_LANG_SPECIFIC (decl)
    5400           53 :               && DECL_TEMPLATE_INFO (decl)
    5401           33 :               && warning_suppressed_p (decl /* What warning? */))))
    5402              :     /* In C++11 it's ok if the decl is defined.  */
    5403       659024 :     return;
    5404              : 
    5405      1122451 :   if (DECL_LANG_SPECIFIC (decl) && DECL_MODULE_IMPORT_P (decl))
    5406              :     /* An imported decl is ok.  */
    5407              :     return;
    5408              : 
    5409              :   /* Metafunctions are magic and should be considered defined even though
    5410              :      they have no bodies.  ??? This can't be checked in decl_defined_p;
    5411              :      we'd get redefinition errors for some of our metafunctions.  */
    5412      1122406 :   if (TREE_CODE (decl) == FUNCTION_DECL && metafunction_p (decl))
    5413              :     return;
    5414              : 
    5415      1122403 :   tree t = no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false);
    5416      1122403 :   if (t == NULL_TREE)
    5417              :     /* The type that got us on no_linkage_decls must have gotten a name for
    5418              :        linkage purposes.  */;
    5419           74 :   else if (CLASS_TYPE_P (t) && TYPE_BEING_DEFINED (t))
    5420              :     // FIXME: This is now invalid, as a DR to c++98
    5421              :     /* The type might end up having a typedef name for linkage purposes.  */
    5422            0 :     vec_safe_push (no_linkage_decls, decl);
    5423          201 :   else if (TYPE_UNNAMED_P (t))
    5424              :     {
    5425           26 :       bool d = false;
    5426           26 :       auto_diagnostic_group grp;
    5427           26 :       if (cxx_dialect >= cxx11)
    5428              :         {
    5429              :           /* If t is declared in a module CMI, then decl could actually
    5430              :              be defined in a different TU, so don't warn since C++20.  */
    5431            9 :           tree relaxed = no_linkage_check (t, /*relaxed_p=*/true);
    5432            9 :           if (relaxed != NULL_TREE)
    5433            9 :             d = permerror (DECL_SOURCE_LOCATION (decl),
    5434              :                            "%q#D, declared using an unnamed type, "
    5435              :                            "is used but never defined", decl);
    5436            0 :           else if (cxx_dialect < cxx20)
    5437            0 :             d = pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__20_extensions,
    5438              :                          "%q#D, declared using an unnamed type, "
    5439              :                          "is used but not defined", decl);
    5440              :         }
    5441           17 :       else if (DECL_EXTERN_C_P (decl))
    5442              :         /* Allow this; it's pretty common in C.  */;
    5443           17 :       else if (VAR_P (decl))
    5444              :         /* DRs 132, 319 and 389 seem to indicate types with
    5445              :            no linkage can only be used to declare extern "C"
    5446              :            entities.  Since it's not always an error in the
    5447              :            ISO C++ 90 Standard, we only issue a warning.  */
    5448           16 :         d = warning_at (DECL_SOURCE_LOCATION (decl), 0, "unnamed type "
    5449              :                         "with no linkage used to declare variable %q#D with "
    5450              :                         "linkage", decl);
    5451              :       else
    5452            1 :         d = permerror (DECL_SOURCE_LOCATION (decl), "unnamed type with no "
    5453              :                        "linkage used to declare function %q#D with linkage",
    5454              :                        decl);
    5455           26 :       if (d && is_typedef_decl (TYPE_NAME (t)))
    5456            0 :         inform (DECL_SOURCE_LOCATION (TYPE_NAME (t)), "%q#D does not refer "
    5457              :                 "to the unqualified type, so it is not used for linkage",
    5458            0 :                 TYPE_NAME (t));
    5459              :       /* Suppress warning from check_global_declaration if needed.  */
    5460           26 :       if (d)
    5461           23 :         suppress_warning (decl, OPT_Wunused);
    5462           26 :     }
    5463           48 :   else if (cxx_dialect >= cxx11)
    5464              :     {
    5465           48 :       if (VAR_P (decl) || !DECL_PURE_VIRTUAL_P (decl))
    5466              :         {
    5467              :           /* Similarly for local types in a function with vague linkage or
    5468              :              defined in a module CMI, then decl could actually be defined
    5469              :              in a different TU, so don't warn since C++20.  */
    5470           45 :           bool d = false;
    5471           45 :           tree relaxed = no_linkage_check (t, /*relaxed_p=*/true);
    5472           45 :           if (relaxed != NULL_TREE)
    5473           30 :             d = permerror (DECL_SOURCE_LOCATION (decl),
    5474              :                            "%q#D, declared using local type "
    5475              :                            "%qT, is used but never defined", decl, t);
    5476           15 :           else if (cxx_dialect < cxx20)
    5477            3 :             d = pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__20_extensions,
    5478              :                          "%q#D, declared using local type "
    5479              :                          "%qT, is used but not defined here", decl, t);
    5480              :           /* Suppress warning from check_global_declaration if needed.  */
    5481           33 :           if (d)
    5482           33 :             suppress_warning (decl, OPT_Wunused);
    5483              :         }
    5484              :     }
    5485            0 :   else if (VAR_P (decl))
    5486            0 :     warning_at (DECL_SOURCE_LOCATION (decl), 0, "type %qT with no linkage "
    5487              :                 "used to declare variable %q#D with linkage", t, decl);
    5488              :   else
    5489            0 :     permerror (DECL_SOURCE_LOCATION (decl), "type %qT with no linkage used "
    5490              :                "to declare function %q#D with linkage", t, decl);
    5491              : }
    5492              : 
    5493              : /* Collect declarations from all namespaces relevant to SOURCE_FILE.  */
    5494              : 
    5495              : static void
    5496           75 : collect_all_refs (const char *source_file)
    5497              : {
    5498           75 :   collect_ada_namespace (global_namespace, source_file);
    5499           75 : }
    5500              : 
    5501              : /* Clear DECL_EXTERNAL for NODE.  */
    5502              : 
    5503              : static bool
    5504    173440066 : clear_decl_external (struct cgraph_node *node, void * /*data*/)
    5505              : {
    5506    173440066 :   DECL_EXTERNAL (node->decl) = 0;
    5507    173440066 :   return false;
    5508              : }
    5509              : 
    5510              : /* Build up the function to run dynamic initializers for thread_local
    5511              :    variables in this translation unit and alias the init functions for the
    5512              :    individual variables to it.  */
    5513              : 
    5514              : static void
    5515       140656 : handle_tls_init (void)
    5516              : {
    5517       140656 :   tree vars = prune_vars_needing_no_initialization (&tls_aggregates);
    5518       140656 :   if (vars == NULL_TREE)
    5519       140533 :     return;
    5520              : 
    5521          123 :   location_t loc = DECL_SOURCE_LOCATION (TREE_VALUE (vars));
    5522              : 
    5523          123 :   write_out_vars (vars);
    5524              : 
    5525          123 :   tree guard = build_decl (loc, VAR_DECL, get_identifier ("__tls_guard"),
    5526              :                            boolean_type_node);
    5527          123 :   TREE_PUBLIC (guard) = false;
    5528          123 :   TREE_STATIC (guard) = true;
    5529          123 :   DECL_ARTIFICIAL (guard) = true;
    5530          123 :   DECL_IGNORED_P (guard) = true;
    5531          123 :   TREE_USED (guard) = true;
    5532          123 :   CP_DECL_THREAD_LOCAL_P (guard) = true;
    5533          123 :   set_decl_tls_model (guard, decl_default_tls_model (guard));
    5534          123 :   pushdecl_top_level_and_finish (guard, NULL_TREE);
    5535              : 
    5536          123 :   tree fn = get_local_tls_init_fn (loc);
    5537          123 :   start_preparsed_function (fn, NULL_TREE, SF_PRE_PARSED);
    5538          123 :   tree body = begin_function_body ();
    5539          123 :   tree if_stmt = begin_if_stmt ();
    5540          123 :   tree cond = cp_build_unary_op (TRUTH_NOT_EXPR, guard, false,
    5541              :                                  tf_warning_or_error);
    5542          123 :   finish_if_stmt_cond (cond, if_stmt);
    5543          123 :   finish_expr_stmt (cp_build_modify_expr (loc, guard, NOP_EXPR,
    5544              :                                           boolean_true_node,
    5545              :                                           tf_warning_or_error));
    5546          123 :   tree sl = NULL_TREE;
    5547          123 :   int save_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    5548          123 :   bool saw_nonbase = false;
    5549          930 :   for (; vars; vars = TREE_CHAIN (vars))
    5550              :     {
    5551          807 :       tree var = TREE_VALUE (vars);
    5552          807 :       tree init = TREE_PURPOSE (vars);
    5553          807 :       sl = decomp_handle_one_var (vars, sl, &saw_nonbase,
    5554              :                                   save_stmts_are_full_exprs_p);
    5555          807 :       one_static_initialization_or_destruction (/*initp=*/true, var, init,
    5556              :                                                 false);
    5557              : 
    5558              :       /* Output init aliases even with -fno-extern-tls-init.  */
    5559          807 :       if (TARGET_SUPPORTS_ALIASES && TREE_PUBLIC (var))
    5560              :         {
    5561          708 :           tree single_init_fn = get_tls_init_fn (var);
    5562          708 :           if (single_init_fn == NULL_TREE)
    5563            0 :             continue;
    5564          708 :           cgraph_node *alias
    5565          708 :             = cgraph_node::get_create (fn)->create_same_body_alias
    5566          708 :                 (single_init_fn, fn);
    5567          708 :           gcc_assert (alias != NULL);
    5568              :         }
    5569              :     }
    5570          123 :   decomp_finalize_var_list (sl, save_stmts_are_full_exprs_p);
    5571              : 
    5572          123 :   finish_then_clause (if_stmt);
    5573          123 :   finish_if_stmt (if_stmt);
    5574          123 :   finish_function_body (body);
    5575          123 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
    5576              : }
    5577              : 
    5578              : /* We're at the end of compilation, so generate any mangling aliases that
    5579              :    we've been saving up, if DECL is going to be output and ID2 isn't
    5580              :    already taken by another declaration.  */
    5581              : 
    5582              : static void
    5583        25567 : generate_mangling_alias (tree decl, tree id2)
    5584              : {
    5585        25567 :   struct cgraph_node *n = NULL;
    5586              : 
    5587        25567 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    5588              :     {
    5589        25513 :       n = cgraph_node::get (decl);
    5590        25513 :       if (!n)
    5591              :         /* Don't create an alias to an unreferenced function.  */
    5592              :         return;
    5593              :     }
    5594              : 
    5595        25567 :   tree *slot
    5596        25567 :     = mangled_decls->find_slot_with_hash (id2, IDENTIFIER_HASH_VALUE (id2),
    5597              :                                           INSERT);
    5598              : 
    5599              :   /* If there's a declaration already using this mangled name,
    5600              :      don't create a compatibility alias that conflicts.  */
    5601        25567 :   if (*slot)
    5602              :     return;
    5603              : 
    5604        25537 :   tree alias = make_alias_for (decl, id2);
    5605        25537 :   *slot = alias;
    5606              : 
    5607        25537 :   DECL_IGNORED_P (alias) = 1;
    5608        25537 :   TREE_PUBLIC (alias) = TREE_PUBLIC (decl);
    5609        25537 :   DECL_VISIBILITY (alias) = DECL_VISIBILITY (decl);
    5610        25537 :   if (vague_linkage_p (decl))
    5611        25419 :     DECL_WEAK (alias) = 1;
    5612              : 
    5613        25537 :   if (n)
    5614        25483 :     n->create_same_body_alias (alias, decl);
    5615              :   else
    5616           54 :     varpool_node::create_extra_name_alias (alias, decl);
    5617              : }
    5618              : 
    5619              : /* Note that we might want to emit an alias with the symbol ID2 for DECL at
    5620              :    the end of translation, for compatibility across bugs in the mangling
    5621              :    implementation.  */
    5622              : 
    5623              : void
    5624        25597 : note_mangling_alias (tree decl, tree id2)
    5625              : {
    5626        25597 :   if (TARGET_SUPPORTS_ALIASES)
    5627              :     {
    5628        25597 :       if (!defer_mangling_aliases)
    5629        16744 :         generate_mangling_alias (decl, id2);
    5630              :       else
    5631              :         {
    5632         8853 :           vec_safe_push (mangling_aliases, decl);
    5633         8853 :           vec_safe_push (mangling_aliases, id2);
    5634              :         }
    5635              :     }
    5636        25597 : }
    5637              : 
    5638              : /* Emit all mangling aliases that were deferred up to this point.  */
    5639              : 
    5640              : void
    5641        95785 : generate_mangling_aliases ()
    5642              : {
    5643       104608 :   while (!vec_safe_is_empty (mangling_aliases))
    5644              :     {
    5645         8823 :       tree id2 = mangling_aliases->pop();
    5646         8823 :       tree decl = mangling_aliases->pop();
    5647         8823 :       generate_mangling_alias (decl, id2);
    5648              :     }
    5649        95785 :   defer_mangling_aliases = false;
    5650        95785 : }
    5651              : 
    5652              : /* Record a mangling of DECL, whose DECL_ASSEMBLER_NAME has just been
    5653              :    set.  NEED_WARNING is true if we must warn about collisions.  We do
    5654              :    this to spot changes in mangling that may require compatibility
    5655              :    aliases.  */
    5656              : 
    5657              : void
    5658     94060661 : record_mangling (tree decl, bool need_warning)
    5659              : {
    5660     94060661 :   if (!mangled_decls)
    5661        74195 :     mangled_decls = hash_table<mangled_decl_hash>::create_ggc (499);
    5662              : 
    5663     94060661 :   gcc_checking_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
    5664     94060661 :   tree id = DECL_ASSEMBLER_NAME_RAW (decl);
    5665     94060661 :   tree *slot
    5666     94060661 :     = mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE (id),
    5667              :                                           INSERT);
    5668              : 
    5669              :   /* If this is already an alias, cancel the alias, because the real
    5670              :      decl takes precedence.  */
    5671     94060661 :   if (*slot && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot))
    5672              :     {
    5673           27 :       if (symtab_node *n = symtab_node::get (*slot))
    5674              :         {
    5675           27 :           if (n->cpp_implicit_alias)
    5676              :             /* Actually removing the node isn't safe if other code is already
    5677              :                holding a pointer to it, so just neutralize it.  */
    5678           27 :             n->reset ();
    5679              :         }
    5680              :       else
    5681              :         /* analyze_functions might have already removed the alias from the
    5682              :            symbol table if it's internal.  */
    5683            0 :         gcc_checking_assert (!TREE_PUBLIC (*slot));
    5684              : 
    5685           27 :       *slot = NULL_TREE;
    5686              :     }
    5687              : 
    5688     94060661 :   if (!*slot)
    5689     94060458 :     *slot = decl;
    5690          203 :   else if (need_warning)
    5691              :     {
    5692            3 :       auto_diagnostic_group d;
    5693            3 :       error_at (DECL_SOURCE_LOCATION (decl),
    5694              :                 "mangling of %q#D as %qE conflicts with a previous mangle",
    5695              :                 decl, id);
    5696            3 :       inform (DECL_SOURCE_LOCATION (*slot),
    5697              :               "previous mangling %q#D", *slot);
    5698            3 :       inform (DECL_SOURCE_LOCATION (decl),
    5699              :               "a later %<-fabi-version=%> (or =0)"
    5700              :               " avoids this error with a change in mangling");
    5701            3 :       *slot = decl;
    5702            3 :     }
    5703     94060661 : }
    5704              : 
    5705              : /* The mangled name of DECL is being forcibly changed to NAME.  Remove
    5706              :    any existing knowledge of DECL's mangled name meaning DECL.  */
    5707              : 
    5708              : void
    5709    281563621 : overwrite_mangling (tree decl, tree name)
    5710              : {
    5711    281563621 :   if (tree id = DECL_ASSEMBLER_NAME_RAW (decl))
    5712       223677 :     if ((TREE_CODE (decl) == VAR_DECL
    5713       223587 :          || TREE_CODE (decl) == FUNCTION_DECL)
    5714       223677 :         && mangled_decls)
    5715       434214 :       if (tree *slot
    5716       217107 :           = mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE (id),
    5717              :                                                 NO_INSERT))
    5718       132387 :         if (*slot == decl)
    5719              :           {
    5720           75 :             mangled_decls->clear_slot (slot);
    5721              : 
    5722              :             /* If this is an alias, remove it from the symbol table.  */
    5723           75 :             if (DECL_ARTIFICIAL (decl) && DECL_IGNORED_P (decl))
    5724            0 :               if (symtab_node *n = symtab_node::get (decl))
    5725            0 :                 if (n->cpp_implicit_alias)
    5726            0 :                   n->remove ();
    5727              :           }
    5728              : 
    5729    281563621 :   DECL_ASSEMBLER_NAME_RAW (decl) = name;
    5730    281563621 : }
    5731              : 
    5732              : /* The entire file is now complete.  If requested, dump everything
    5733              :    to a file.  */
    5734              : 
    5735              : static void
    5736        95882 : dump_tu (void)
    5737              : {
    5738        95882 :   dump_flags_t flags;
    5739        95882 :   if (FILE *stream = dump_begin (raw_dump_id, &flags))
    5740              :     {
    5741            6 :       dump_node (global_namespace, flags & ~TDF_SLIM, stream);
    5742            6 :       dump_end (raw_dump_id, stream);
    5743              :     }
    5744        95882 : }
    5745              : 
    5746              : static location_t locus_at_end_of_parsing;
    5747              : 
    5748              : /* Check the deallocation functions for CODE to see if we want to warn that
    5749              :    only one was defined.  */
    5750              : 
    5751              : static void
    5752         1926 : maybe_warn_sized_delete (enum tree_code code)
    5753              : {
    5754         1926 :   tree sized = NULL_TREE;
    5755         1926 :   tree unsized = NULL_TREE;
    5756              : 
    5757        10552 :   for (ovl_iterator iter (get_global_binding (ovl_op_identifier (false, code)));
    5758        10552 :        iter; ++iter)
    5759              :     {
    5760         8626 :       tree fn = *iter;
    5761              :       /* We're only interested in usual deallocation functions.  */
    5762         8626 :       if (!usual_deallocation_fn_p (fn))
    5763          938 :         continue;
    5764         7688 :       if (FUNCTION_ARG_CHAIN (fn) == void_list_node)
    5765              :         unsized = fn;
    5766              :       else
    5767         5762 :         sized = fn;
    5768              :     }
    5769         1926 :   if (DECL_INITIAL (unsized) && !DECL_INITIAL (sized))
    5770            6 :     warning_at (DECL_SOURCE_LOCATION (unsized), OPT_Wsized_deallocation,
    5771              :                 "the program should also define %qD", sized);
    5772         1920 :   else if (!DECL_INITIAL (unsized) && DECL_INITIAL (sized))
    5773            4 :     warning_at (DECL_SOURCE_LOCATION (sized), OPT_Wsized_deallocation,
    5774              :                 "the program should also define %qD", unsized);
    5775         1926 : }
    5776              : 
    5777              : /* Check the global deallocation functions to see if we want to warn about
    5778              :    defining unsized without sized (or vice versa).  */
    5779              : 
    5780              : static void
    5781        95785 : maybe_warn_sized_delete ()
    5782              : {
    5783        95785 :   if (!flag_sized_deallocation || !warn_sized_deallocation)
    5784              :     return;
    5785          963 :   maybe_warn_sized_delete (DELETE_EXPR);
    5786          963 :   maybe_warn_sized_delete (VEC_DELETE_EXPR);
    5787              : }
    5788              : 
    5789              : /* Earlier we left PTRMEM_CST in variable initializers alone so that we could
    5790              :    look them up when evaluating non-type template parameters.  Now we need to
    5791              :    lower them to something the back end can understand.  */
    5792              : 
    5793              : static void
    5794        95785 : lower_var_init ()
    5795              : {
    5796        95785 :   varpool_node *node;
    5797     36995045 :   FOR_EACH_VARIABLE (node)
    5798              :     {
    5799     36899260 :       tree d = node->decl;
    5800     36899260 :       if (tree init = DECL_INITIAL (d))
    5801     34587962 :         DECL_INITIAL (d) = cplus_expand_constant (init);
    5802              :     }
    5803        95785 : }
    5804              : 
    5805              : /* This routine is called at the end of compilation.
    5806              :    Its job is to create all the code needed to initialize and
    5807              :    destroy the global aggregates.  We do the destruction
    5808              :    first, since that way we only need to reverse the decls once.  */
    5809              : 
    5810              : void
    5811        95897 : c_parse_final_cleanups (void)
    5812              : {
    5813        95897 :   size_t i;
    5814        95897 :   tree decl;
    5815              : 
    5816        95897 :   locus_at_end_of_parsing = input_location;
    5817              :   /* We're done parsing.  */
    5818        95897 :   at_eof = 1;
    5819              : 
    5820              :   /* Bad parse errors.  Just forget about it.  */
    5821       191794 :   if (! global_bindings_p () || current_class_type
    5822       191794 :       || !vec_safe_is_empty (decl_namespace_list))
    5823          100 :     return;
    5824              : 
    5825              :   /* This is the point to write out a PCH if we're doing that.
    5826              :      In that case we do not want to do anything else.  */
    5827        95894 :   if (pch_file)
    5828              :     {
    5829              :       /* Mangle all symbols at PCH creation time.  */
    5830           97 :       symtab_node *node;
    5831        49614 :       FOR_EACH_SYMBOL (node)
    5832        49517 :         if (! is_a <varpool_node *> (node)
    5833        16460 :             || ! DECL_HARD_REGISTER (node->decl))
    5834        49517 :           DECL_ASSEMBLER_NAME (node->decl);
    5835           97 :       c_common_write_pch ();
    5836           97 :       dump_tu ();
    5837              :       /* Ensure even the callers don't try to finalize the CU.  */
    5838           97 :       flag_syntax_only = 1;
    5839           97 :       return;
    5840              :     }
    5841              : 
    5842        95797 :   timevar_stop (TV_PHASE_PARSING);
    5843        95797 :   timevar_start (TV_PHASE_DEFERRED);
    5844              : 
    5845        95797 :   symtab->process_same_body_aliases ();
    5846              : 
    5847              :   /* Handle -fdump-ada-spec[-slim] */
    5848        95797 :   if (flag_dump_ada_spec || flag_dump_ada_spec_slim)
    5849              :     {
    5850           75 :       collect_source_ref (main_input_filename);
    5851           75 :       if (!flag_dump_ada_spec_slim)
    5852           75 :         collect_source_refs (global_namespace);
    5853              : 
    5854           75 :       dump_ada_specs (collect_all_refs, cpp_check);
    5855              :     }
    5856              : 
    5857              :   /* FIXME - huh?  was  input_line -= 1;*/
    5858              : 
    5859              :   /* We now have to write out all the stuff we put off writing out.
    5860              :      These include:
    5861              : 
    5862              :        o Template specializations that we have not yet instantiated,
    5863              :          but which are needed.
    5864              :        o Initialization and destruction for non-local objects with
    5865              :          static storage duration.  (Local objects with static storage
    5866              :          duration are initialized when their scope is first entered,
    5867              :          and are cleaned up via atexit.)
    5868              :        o Virtual function tables.
    5869              : 
    5870              :      All of these may cause others to be needed.  For example,
    5871              :      instantiating one function may cause another to be needed, and
    5872              :      generating the initializer for an object may cause templates to be
    5873              :      instantiated, etc., etc.  */
    5874              : 
    5875        95797 :   emit_support_tinfos ();
    5876              : 
    5877              :   /* Track vtables we want to emit that refer to consteval functions.  */
    5878        95797 :   auto_vec<tree> consteval_vtables;
    5879              : 
    5880        95797 :   int retries = 0;
    5881        95797 :   unsigned ssdf_count = 0, omp_ssdf_count = 0;
    5882       237346 :   for (bool reconsider = true; reconsider; retries++)
    5883              :     {
    5884       141561 :       reconsider = false;
    5885              : 
    5886              :       /* If there are templates that we've put off instantiating, do
    5887              :          them now.  */
    5888       141561 :       instantiate_pending_templates (retries);
    5889       141549 :       ggc_collect ();
    5890              : 
    5891       141549 :       if (header_module_p ())
    5892              :         /* A header modules initializations are handled in its
    5893              :            importer.  */
    5894          893 :         continue;
    5895              : 
    5896              :       /* Emit wrappers where needed, and if that causes more to be added then
    5897              :          make sure we account for possible additional instantiations.  */
    5898       140656 :       if (flag_contracts)
    5899          182 :         if (emit_contract_wrapper_func (/*done*/false))
    5900       140656 :           reconsider = true;
    5901              : 
    5902              :       /* Write out virtual tables as required.  Writing out the
    5903              :          virtual table for a template class may cause the
    5904              :          instantiation of members of that class.  If we write out
    5905              :          vtables then we remove the class from our list so we don't
    5906              :          have to look at it again.  */
    5907       140656 :       tree t;
    5908       140656 :       for (i = keyed_classes->length ();
    5909      3833254 :            keyed_classes->iterate (--i, &t);)
    5910      3692598 :         if (maybe_emit_vtables (t, consteval_vtables))
    5911              :           {
    5912       422465 :             reconsider = true;
    5913       422465 :             keyed_classes->unordered_remove (i);
    5914              :           }
    5915              :       /* The input_location may have been changed during marking of
    5916              :          vtable entries.  */
    5917       140656 :       input_location = locus_at_end_of_parsing;
    5918              : 
    5919              :       /* Write out needed type info variables.  We have to be careful
    5920              :          looping through unemitted decls, because emit_tinfo_decl may
    5921              :          cause other variables to be needed. New elements will be
    5922              :          appended, and we remove from the vector those that actually
    5923              :          get emitted.  */
    5924       140656 :       for (i = unemitted_tinfo_decls->length ();
    5925      6034801 :            unemitted_tinfo_decls->iterate (--i, &t);)
    5926      5894145 :         if (DECL_INITIAL (t) || emit_tinfo_decl (t))
    5927              :           {
    5928       506639 :             reconsider = true;
    5929       506639 :             unemitted_tinfo_decls->unordered_remove (i);
    5930              :           }
    5931              : 
    5932              :       /* The list of objects with static storage duration is built up
    5933              :          in reverse order.  We clear STATIC_AGGREGATES so that any new
    5934              :          aggregates added during the initialization of these will be
    5935              :          initialized in the correct order when we next come around the
    5936              :          loop.  */
    5937       140656 :       if (tree vars = prune_vars_needing_no_initialization (&static_aggregates))
    5938              :         {
    5939         5394 :           if (flag_openmp)
    5940              :             /* Add initializer information from VARS into
    5941              :                DYNAMIC_INITIALIZERS.  */
    5942          394 :             for (t = vars; t; t = TREE_CHAIN (t))
    5943          566 :               hash_map_safe_put<hm_ggc> (dynamic_initializers,
    5944          283 :                                          TREE_VALUE (t), TREE_PURPOSE (t));
    5945              : 
    5946              :           /* Make sure the back end knows about all the variables.  */
    5947         5394 :           write_out_vars (vars);
    5948              : 
    5949         5394 :           function_depth++; // Disable GC
    5950         5394 :           priority_map_t *parts[4] = {nullptr, nullptr, nullptr, nullptr};
    5951         5394 :           partition_vars_for_init_fini (vars, parts);
    5952         5394 :           tree host_init_fini[2] = { NULL_TREE, NULL_TREE };
    5953              : 
    5954        16182 :           for (unsigned initp = 2; initp--;)
    5955        10788 :             if (parts[initp])
    5956        16205 :               for (auto iter : *parts[initp])
    5957              :                 {
    5958         5411 :                   auto list = iter.second;
    5959         5411 :                   if (initp)
    5960              :                     // Partitioning kept the vars in reverse order.
    5961              :                     // We only want that for dtors.
    5962         5402 :                     list = nreverse (list);
    5963         5411 :                   host_init_fini[initp]
    5964         5411 :                     = emit_partial_init_fini_fn (initp, iter.first, list,
    5965              :                                                  ssdf_count++,
    5966              :                                                  locus_at_end_of_parsing,
    5967              :                                                  NULL_TREE);
    5968              :                 }
    5969              : 
    5970         5394 :           if (flag_openmp)
    5971              :             {
    5972              :               priority_map_t **omp_parts = parts + 2;
    5973          333 :               for (unsigned initp = 2; initp--;)
    5974          222 :                 if (omp_parts[initp])
    5975           58 :                   for (auto iter : *omp_parts[initp])
    5976              :                     {
    5977           15 :                       auto list = iter.second;
    5978           15 :                       if (initp)
    5979              :                         // Partitioning kept the vars in reverse order.
    5980              :                         // We only want that for dtors.
    5981           15 :                         list = nreverse (list);
    5982           15 :                       emit_partial_init_fini_fn (initp, iter.first, list,
    5983              :                                                  omp_ssdf_count++,
    5984              :                                                  locus_at_end_of_parsing,
    5985              :                                                  host_init_fini[initp]);
    5986              :                   }
    5987              :             }
    5988              : 
    5989         5394 :           function_depth--; // Re-enable GC
    5990              : 
    5991              :           /* All those initializations and finalizations might cause
    5992              :              us to need more inline functions, more template
    5993              :              instantiations, etc.  */
    5994         5394 :           reconsider = true;
    5995              :         }
    5996              : 
    5997              :       /* Now do the same for thread_local variables.  */
    5998       140656 :       handle_tls_init ();
    5999              : 
    6000              :       /* Go through the set of inline functions whose bodies have not
    6001              :          been emitted yet.  If out-of-line copies of these functions
    6002              :          are required, emit them.  */
    6003    202762480 :       FOR_EACH_VEC_SAFE_ELT (deferred_fns, i, decl)
    6004              :         {
    6005              :           /* Does it need synthesizing?  */
    6006    209270038 :           if (DECL_DEFAULTED_FN (decl) && ! DECL_INITIAL (decl)
    6007    202621830 :               && (! DECL_REALLY_EXTERN (decl) || possibly_inlined_p (decl)))
    6008              :             {
    6009              :               /* Even though we're already at the top-level, we push
    6010              :                  there again.  That way, when we pop back a few lines
    6011              :                  hence, all of our state is restored.  Otherwise,
    6012              :                  finish_function doesn't clean things up, and we end
    6013              :                  up with CURRENT_FUNCTION_DECL set.  */
    6014            6 :               push_to_top_level ();
    6015              :               /* The decl's location will mark where it was first
    6016              :                  needed.  Save that so synthesize method can indicate
    6017              :                  where it was needed from, in case of error  */
    6018            6 :               input_location = DECL_SOURCE_LOCATION (decl);
    6019            6 :               synthesize_method (decl);
    6020            6 :               pop_from_top_level ();
    6021            6 :               reconsider = true;
    6022              :             }
    6023              : 
    6024    202621824 :           if (!DECL_INITIAL (decl) && decl_tls_wrapper_p (decl))
    6025          586 :             generate_tls_wrapper (decl);
    6026              : 
    6027    202621824 :           if (!DECL_SAVED_TREE (decl))
    6028       343785 :             continue;
    6029              : 
    6030    202278039 :           cgraph_node *node = cgraph_node::get_create (decl);
    6031              : 
    6032              :           /* We lie to the back end, pretending that some functions
    6033              :              are not defined when they really are.  This keeps these
    6034              :              functions from being put out unnecessarily.  But, we must
    6035              :              stop lying when the functions are referenced, or if they
    6036              :              are not comdat since they need to be put out now.  If
    6037              :              DECL_INTERFACE_KNOWN, then we have already set
    6038              :              DECL_EXTERNAL appropriately, so there's no need to check
    6039              :              again, and we do not want to clear DECL_EXTERNAL if a
    6040              :              previous call to import_export_decl set it.
    6041              : 
    6042              :              This is done in a separate for cycle, because if some
    6043              :              deferred function is contained in another deferred
    6044              :              function later in deferred_fns varray,
    6045              :              rest_of_compilation would skip this function and we
    6046              :              really cannot expand the same function twice.  */
    6047    202278039 :           import_export_decl (decl);
    6048    202278039 :           if (DECL_NOT_REALLY_EXTERN (decl)
    6049    198654312 :               && DECL_INITIAL (decl)
    6050    400932351 :               && decl_needed_p (decl))
    6051              :             {
    6052    138197177 :               if (node->cpp_implicit_alias)
    6053     12529331 :                 node = node->get_alias_target ();
    6054              : 
    6055    138197177 :               node->call_for_symbol_thunks_and_aliases (clear_decl_external,
    6056              :                                                         NULL, true);
    6057              :               /* If we mark !DECL_EXTERNAL one of the symbols in some comdat
    6058              :                  group, we need to mark all symbols in the same comdat group
    6059              :                  that way.  */
    6060    138197177 :               if (node->same_comdat_group)
    6061     35221493 :                 for (cgraph_node *next
    6062     17397835 :                        = dyn_cast<cgraph_node *> (node->same_comdat_group);
    6063     35221493 :                      next != node;
    6064     53045151 :                      next = dyn_cast<cgraph_node *> (next->same_comdat_group))
    6065     17823658 :                   next->call_for_symbol_thunks_and_aliases (clear_decl_external,
    6066              :                                                             NULL, true);
    6067              :             }
    6068              : 
    6069              :           /* If we're going to need to write this function out, and
    6070              :              there's already a body for it, create RTL for it now.
    6071              :              (There might be no body if this is a method we haven't
    6072              :              gotten around to synthesizing yet.)  */
    6073    202278039 :           if (!DECL_EXTERNAL (decl)
    6074    142372998 :               && decl_needed_p (decl)
    6075    139938188 :               && !TREE_ASM_WRITTEN (decl)
    6076    259655824 :               && !DECL_IMMEDIATE_FUNCTION_P (decl)
    6077    324168385 :               && !node->definition)
    6078              :             {
    6079              :               /* We will output the function; no longer consider it in this
    6080              :                  loop.  */
    6081            0 :               DECL_DEFER_OUTPUT (decl) = 0;
    6082              :               /* Generate RTL for this function now that we know we
    6083              :                  need it.  */
    6084            0 :               expand_or_defer_fn (decl);
    6085            0 :               reconsider = true;
    6086              :             }
    6087              :         }
    6088              : 
    6089       140656 :       if (wrapup_namespace_globals ())
    6090          525 :         reconsider = true;
    6091              : 
    6092              :       /* Static data members are just like namespace-scope globals.  */
    6093    111173975 :       FOR_EACH_VEC_SAFE_ELT (pending_statics, i, decl)
    6094              :         {
    6095    203099924 :           if (consteval_only_p (decl)
    6096    111033193 :               || var_finalized_p (decl)
    6097     29508453 :               || DECL_REALLY_EXTERN (decl)
    6098              :               /* Don't write it out if we haven't seen a definition.  */
    6099    130006074 :               || DECL_IN_AGGR_P (decl))
    6100     92066605 :             continue;
    6101     18966714 :           import_export_decl (decl);
    6102              :           /* If this static data member is needed, provide it to the
    6103              :              back end.  */
    6104     18966714 :           if (DECL_NOT_REALLY_EXTERN (decl) && decl_needed_p (decl))
    6105     18937758 :             DECL_EXTERNAL (decl) = 0;
    6106              :         }
    6107              : 
    6108       282205 :       if (vec_safe_length (pending_statics) != 0
    6109       113176 :           && wrapup_global_declarations (pending_statics->address (),
    6110        56588 :                                          pending_statics->length ()))
    6111              :         reconsider = true;
    6112              :     }
    6113              : 
    6114        95785 :   if (flag_contracts)
    6115              :     {
    6116          130 :       emit_contract_wrapper_func (/*done*/true);
    6117          130 :       maybe_emit_violation_handler_wrappers ();
    6118              :     }
    6119              : 
    6120              :   /* All templates have been instantiated.  */
    6121        95785 :   at_eof = 2;
    6122              : 
    6123        95785 :   void *module_cookie = finish_module_processing (parse_in);
    6124              : 
    6125        95785 :   lower_var_init ();
    6126              : 
    6127        95785 :   generate_mangling_aliases ();
    6128              : 
    6129              :   /* All used inline functions must have a definition at this point.  */
    6130     53961802 :   FOR_EACH_VEC_SAFE_ELT (deferred_fns, i, decl)
    6131              :     {
    6132     53866017 :       if (/* Check online inline functions that were actually used.  */
    6133     90243936 :           DECL_ODR_USED (decl) && DECL_DECLARED_INLINE_P (decl)
    6134              :           /* If the definition actually was available here, then the
    6135              :              fact that the function was not defined merely represents
    6136              :              that for some reason (use of a template repository,
    6137              :              #pragma interface, etc.) we decided not to emit the
    6138              :              definition here.  */
    6139     36376525 :           && !DECL_INITIAL (decl)
    6140              :           /* A defaulted fn or TLS wrapper in a header module can be
    6141              :              synthesized on demand later.  (In non-header modules we
    6142              :              should have synthesized it above.)  */
    6143         3878 :           && !(header_module_p ()
    6144            6 :                && (DECL_DEFAULTED_FN (decl) || decl_tls_wrapper_p (decl)))
    6145              :           /* Metafunctions are never defined.  */
    6146         3872 :           && !metafunction_p (decl)
    6147              :           /* Don't complain if the template was defined.  */
    6148          719 :           && !(DECL_TEMPLOID_INSTANTIATION (decl)
    6149          652 :                && DECL_INITIAL (DECL_TEMPLATE_RESULT
    6150              :                                 (template_for_substitution (decl))))
    6151     90243936 :           && warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6152              :                          "inline function %qD used but never defined", decl))
    6153              :         /* Avoid a duplicate warning from check_global_declaration.  */
    6154           73 :         suppress_warning (decl, OPT_Wunused);
    6155              :     }
    6156              : 
    6157              :   /* So must decls that use a type with no linkage.  */
    6158       754914 :   FOR_EACH_VEC_SAFE_ELT (no_linkage_decls, i, decl)
    6159       659129 :     no_linkage_error (decl);
    6160              : 
    6161        95785 :   maybe_warn_sized_delete ();
    6162              : 
    6163              :   // Place the init fns in the right order.  We need to do this now,
    6164              :   // so that any module init will go at the start.
    6165        95785 :   if (static_init_fini_fns[true])
    6166        16169 :     for (auto iter : *static_init_fini_fns[true])
    6167         5399 :       iter.second = nreverse (iter.second);
    6168              : 
    6169        95785 :   if (flag_openmp && static_init_fini_fns[2 + true])
    6170           43 :     for (auto iter : *static_init_fini_fns[2 + true])
    6171           15 :       iter.second = nreverse (iter.second);
    6172              : 
    6173              :   /* Now we've instantiated all templates.  Now we can escalate the functions
    6174              :      we squirreled away earlier.  */
    6175        95785 :   process_and_check_pending_immediate_escalating_fns ();
    6176              : 
    6177              :   /* Then, do the Objective-C stuff.  This is where all the
    6178              :      Objective-C module stuff gets generated (symtab,
    6179              :      class/protocol/selector lists etc).  This must be done after C++
    6180              :      templates, destructors etc. so that selectors used in C++
    6181              :      templates are properly allocated.  */
    6182        95785 :   if (c_dialect_objc ())
    6183            0 :     objc_write_global_declarations ();
    6184              : 
    6185        95785 :   bool has_module_inits = module_determine_import_inits ();
    6186        95785 :   bool has_objc_init = c_dialect_objc () && objc_static_init_needed_p ();
    6187        95785 :   if (has_module_inits || has_objc_init)
    6188              :     {
    6189           43 :       input_location = locus_at_end_of_parsing;
    6190           43 :       tree body = start_partial_init_fini_fn (true, DEFAULT_INIT_PRIORITY,
    6191              :                                               ssdf_count++, false);
    6192              :       /* For Objective-C++, we may need to initialize metadata found
    6193              :          in this module.  This must be done _before_ any other static
    6194              :          initializations.  */
    6195           43 :       if (has_objc_init)
    6196            0 :         objc_generate_static_init_call (NULL_TREE);
    6197           43 :       if (has_module_inits)
    6198           43 :         module_add_import_initializers ();
    6199           43 :       input_location = locus_at_end_of_parsing;
    6200           43 :       finish_partial_init_fini_fn (body);
    6201              :     }
    6202              : 
    6203        95785 :   if (module_global_init_needed ())
    6204              :     {
    6205              :       // Make sure there's a default priority entry.
    6206         1869 :       if (!static_init_fini_fns[true])
    6207         1808 :         static_init_fini_fns[true] = priority_map_t::create_ggc ();
    6208         1869 :       if (static_init_fini_fns[true]->get_or_insert (DEFAULT_INIT_PRIORITY))
    6209        95785 :         has_module_inits = true;
    6210              : 
    6211              :       /* FIXME: We need to work out what static constructors on OpenMP offload
    6212              :          target in modules will look like.  */
    6213              :     }
    6214              : 
    6215              :   /* Generate initialization and destruction functions for all
    6216              :      priorities for which they are required.  They have C-language
    6217              :      linkage.  */
    6218        95785 :   push_lang_context (lang_name_c);
    6219       478925 :   for (unsigned initp = 4; initp--;)
    6220       383140 :     if (static_init_fini_fns[initp])
    6221              :       {
    6222        14509 :         for (auto iter : *static_init_fini_fns[initp])
    6223         7262 :           generate_ctor_or_dtor_function (initp & 1, iter.first, iter.second,
    6224              :                                           locus_at_end_of_parsing,
    6225         7262 :                                           (initp & 2) != 0);
    6226         7247 :         static_init_fini_fns[initp] = nullptr;
    6227              :       }
    6228        95785 :   pop_lang_context ();
    6229              : 
    6230        95785 :   fini_modules (parse_in, module_cookie, has_module_inits);
    6231              : 
    6232              :   /* Generate any missing aliases.  */
    6233        95785 :   maybe_apply_pending_pragma_weaks ();
    6234              : 
    6235        95785 :   if (flag_vtable_verify)
    6236              :     {
    6237            9 :       vtv_recover_class_info ();
    6238            9 :       vtv_compute_class_hierarchy_transitive_closure ();
    6239            9 :       vtv_build_vtable_verify_fndecl ();
    6240              :     }
    6241              : 
    6242        95785 :   perform_deferred_noexcept_checks ();
    6243              : 
    6244        95785 :   fini_constexpr ();
    6245        95785 :   cp_tree_c_finish_parsing ();
    6246        95785 :   clear_consteval_vfns (consteval_vtables);
    6247              : 
    6248              :   /* The entire file is now complete.  If requested, dump everything
    6249              :      to a file.  */
    6250        95785 :   dump_tu ();
    6251              : 
    6252        95785 :   if (flag_detailed_statistics)
    6253              :     {
    6254            0 :       dump_tree_statistics ();
    6255            0 :       dump_time_statistics ();
    6256              :     }
    6257              : 
    6258        95785 :   timevar_stop (TV_PHASE_DEFERRED);
    6259        95785 :   timevar_start (TV_PHASE_PARSING);
    6260              : 
    6261              :   /* Indicate that we're done with front end processing.  */
    6262        95785 :   at_eof = 3;
    6263        95785 : }
    6264              : 
    6265              : /* Perform any post compilation-proper cleanups for the C++ front-end.
    6266              :    This should really go away.  No front-end should need to do
    6267              :    anything past the compilation process.  */
    6268              : 
    6269              : void
    6270        95543 : cxx_post_compilation_parsing_cleanups (void)
    6271              : {
    6272        95543 :   timevar_start (TV_PHASE_LATE_PARSING_CLEANUPS);
    6273              : 
    6274        95543 :   if (flag_vtable_verify)
    6275              :     {
    6276              :       /* Generate the special constructor initialization function that
    6277              :          calls __VLTRegisterPairs, and give it a very high
    6278              :          initialization priority.  This must be done after
    6279              :          finalize_compilation_unit so that we have accurate
    6280              :          information about which vtable will actually be emitted.  */
    6281            9 :       vtv_generate_init_routine ();
    6282              :     }
    6283              : 
    6284        95543 :   input_location = locus_at_end_of_parsing;
    6285              : 
    6286        95543 :   if (flag_checking)
    6287        95534 :     validate_conversion_obstack ();
    6288              : 
    6289        95543 :   timevar_stop (TV_PHASE_LATE_PARSING_CLEANUPS);
    6290        95543 : }
    6291              : 
    6292              : /* FN is an OFFSET_REF, DOTSTAR_EXPR or MEMBER_REF indicating the
    6293              :    function to call in parse-tree form; it has not yet been
    6294              :    semantically analyzed.  ARGS are the arguments to the function.
    6295              :    They have already been semantically analyzed.  This may change
    6296              :    ARGS.  */
    6297              : 
    6298              : tree
    6299       352009 : build_offset_ref_call_from_tree (tree fn, vec<tree, va_gc> **args,
    6300              :                                  tsubst_flags_t complain)
    6301              : {
    6302       352009 :   tree orig_fn;
    6303       352009 :   vec<tree, va_gc> *orig_args = NULL;
    6304       352009 :   tree expr;
    6305       352009 :   tree object;
    6306              : 
    6307       352009 :   orig_fn = fn;
    6308       352009 :   object = TREE_OPERAND (fn, 0);
    6309              : 
    6310       352009 :   if (processing_template_decl)
    6311              :     {
    6312       268881 :       gcc_assert (TREE_CODE (fn) == DOTSTAR_EXPR
    6313              :                   || TREE_CODE (fn) == MEMBER_REF);
    6314       268881 :       if (type_dependent_expression_p (fn)
    6315       268881 :           || any_type_dependent_arguments_p (*args))
    6316       268842 :         return build_min_nt_call_vec (fn, *args);
    6317              : 
    6318           39 :       orig_args = make_tree_vector_copy (*args);
    6319              : 
    6320              :       /* Transform the arguments and add the implicit "this"
    6321              :          parameter.  */
    6322           39 :       if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
    6323              :         {
    6324           33 :           if (TREE_CODE (fn) == DOTSTAR_EXPR)
    6325           27 :             object = cp_build_addr_expr (object, complain);
    6326           33 :           vec_safe_insert (*args, 0, object);
    6327              :         }
    6328              :     }
    6329              : 
    6330              :   /* A qualified name corresponding to a bound pointer-to-member is
    6331              :      represented as an OFFSET_REF:
    6332              : 
    6333              :         struct B { void g(); };
    6334              :         void (B::*p)();
    6335              :         void B::g() { (this->*p)(); }  */
    6336        83167 :   if (TREE_CODE (fn) == OFFSET_REF)
    6337              :     {
    6338        83128 :       tree object_addr = cp_build_addr_expr (object, complain);
    6339        83128 :       fn = TREE_OPERAND (fn, 1);
    6340        83128 :       fn = get_member_function_from_ptrfunc (&object_addr, fn,
    6341              :                                              complain);
    6342        83128 :       vec_safe_insert (*args, 0, object_addr);
    6343              :     }
    6344              : 
    6345        83167 :   if (CLASS_TYPE_P (TREE_TYPE (fn)))
    6346            3 :     expr = build_op_call (fn, args, complain);
    6347              :   else
    6348        83164 :     expr = cp_build_function_call_vec (fn, args, complain);
    6349        83167 :   if (processing_template_decl && expr != error_mark_node)
    6350           39 :     expr = build_min_non_dep_call_vec (expr, orig_fn, orig_args);
    6351              : 
    6352        83167 :   if (orig_args != NULL)
    6353           39 :     release_tree_vector (orig_args);
    6354              : 
    6355              :   return expr;
    6356              : }
    6357              : 
    6358              : 
    6359              : void
    6360    356233362 : check_default_args (tree x)
    6361              : {
    6362    356233362 :   tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
    6363    356233362 :   bool saw_def = false;
    6364    356233362 :   bool noted_first_def = false;
    6365    356233362 :   int idx_of_first_default_arg = 0;
    6366    356233362 :   location_t loc_of_first_default_arg = UNKNOWN_LOCATION;
    6367    356233362 :   int i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
    6368    356233362 :   tree fndecl = STRIP_TEMPLATE (x);
    6369    356233362 :   auto_diagnostic_group d;
    6370    971971657 :   for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
    6371              :     {
    6372    615738295 :       if (TREE_PURPOSE (arg))
    6373              :         {
    6374     11359236 :           if (!saw_def)
    6375              :             {
    6376      8504582 :               saw_def = true;
    6377      8504582 :               idx_of_first_default_arg = i;
    6378      8504582 :               location_t loc = get_fndecl_argument_location (fndecl, i);
    6379      8504582 :               if (loc != DECL_SOURCE_LOCATION (x))
    6380      8504554 :                 loc_of_first_default_arg = loc;
    6381              :             }
    6382              :         }
    6383    604379059 :       else if (saw_def && !PACK_EXPANSION_P (TREE_VALUE (arg)))
    6384              :         {
    6385          147 :           error_at (get_fndecl_argument_location (fndecl, i),
    6386              :                     "default argument missing for parameter %P of %q#D", i, x);
    6387          147 :           if (loc_of_first_default_arg != UNKNOWN_LOCATION
    6388          147 :               && !noted_first_def)
    6389              :             {
    6390          144 :               inform (loc_of_first_default_arg,
    6391              :                       "...following parameter %P which has a default argument",
    6392              :                       idx_of_first_default_arg);
    6393          144 :               noted_first_def = true;
    6394              :             }
    6395          147 :           TREE_PURPOSE (arg) = error_mark_node;
    6396              :         }
    6397              :     }
    6398    356233362 : }
    6399              : 
    6400              : /* Return true if function DECL can be inlined.  This is used to force
    6401              :    instantiation of methods that might be interesting for inlining.  */
    6402              : bool
    6403            3 : possibly_inlined_p (tree decl)
    6404              : {
    6405            3 :   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
    6406            3 :   if (DECL_UNINLINABLE (decl))
    6407              :     return false;
    6408            3 :   if (!optimize)
    6409            3 :     return DECL_DECLARED_INLINE_P (decl);
    6410              :   /* When optimizing, we might inline everything when flatten
    6411              :      attribute or heuristics inlining for size or autoinlining
    6412              :      is used.  */
    6413              :   return true;
    6414              : }
    6415              : 
    6416              : /* If DECL is a function or variable template specialization, instantiate
    6417              :    its definition now.  */
    6418              : 
    6419              : void
    6420    196064014 : maybe_instantiate_decl (tree decl)
    6421              : {
    6422      1640787 :   if (VAR_OR_FUNCTION_DECL_P (decl)
    6423    196064014 :       && DECL_LANG_SPECIFIC (decl)
    6424    153557517 :       && DECL_TEMPLATE_INFO (decl)
    6425    321660013 :       && !uses_template_parms (DECL_TI_ARGS (decl)))
    6426              :     {
    6427              :       /* Instantiating a function will result in garbage collection.  We
    6428              :          must treat this situation as if we were within the body of a
    6429              :          function so as to avoid collecting live data only referenced from
    6430              :          the stack (such as overload resolution candidates).  */
    6431    121231175 :       ++function_depth;
    6432    121231175 :       instantiate_decl (decl, /*defer_ok=*/false,
    6433              :                         /*expl_inst_class_mem_p=*/false);
    6434    121228478 :       --function_depth;
    6435              :     }
    6436    196061317 : }
    6437              : 
    6438              : /* Error if the DECL is unavailable (unless this is currently suppressed).
    6439              :    Maybe warn if DECL is deprecated, subject to COMPLAIN.  Returns true if
    6440              :    an error or warning was emitted.  */
    6441              : 
    6442              : bool
    6443   4275751072 : cp_handle_deprecated_or_unavailable (tree decl, tsubst_flags_t complain)
    6444              : {
    6445   4275751072 :   if (!decl)
    6446              :     return false;
    6447              : 
    6448   4237953035 :   if ((complain & tf_error)
    6449   3751159102 :       && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
    6450              :     {
    6451   3040404008 :       if (TREE_UNAVAILABLE (decl))
    6452              :         {
    6453          252 :           error_unavailable_use (decl, NULL_TREE);
    6454          252 :           return true;
    6455              :         }
    6456              :       else
    6457              :         {
    6458              :           /* Perhaps this is an unavailable typedef.  */
    6459   3040403756 :           if (TYPE_P (decl)
    6460    769479527 :               && TYPE_NAME (decl)
    6461   3803884033 :               && TREE_UNAVAILABLE (TYPE_NAME (decl)))
    6462              :             {
    6463            6 :               decl = TYPE_NAME (decl);
    6464              :               /* Don't error within members of a unavailable type.  */
    6465            6 :               if (TYPE_P (decl)
    6466            6 :                   && currently_open_class (decl))
    6467              :                 return false;
    6468              : 
    6469            6 :               error_unavailable_use (decl, NULL_TREE);
    6470            6 :               return true;
    6471              :             }
    6472              :         }
    6473              :       /* Carry on to consider deprecatedness.  */
    6474              :     }
    6475              : 
    6476   4237952777 :   if (!(complain & tf_warning)
    6477   3703754999 :       || deprecated_state == DEPRECATED_SUPPRESS
    6478   3701683734 :       || deprecated_state == UNAVAILABLE_DEPRECATED_SUPPRESS)
    6479              :     return false;
    6480              : 
    6481   2996895800 :   if (!TREE_DEPRECATED (decl))
    6482              :     {
    6483              :       /* Perhaps this is a deprecated typedef.  */
    6484   2996380096 :       if (TYPE_P (decl) && TYPE_NAME (decl))
    6485    762249258 :         decl = TYPE_NAME (decl);
    6486              : 
    6487   2996380096 :       if (!TREE_DEPRECATED (decl))
    6488              :         return false;
    6489              :     }
    6490              : 
    6491              :   /* Don't warn within members of a deprecated type.  */
    6492       515712 :   if (TYPE_P (decl)
    6493       515712 :       && currently_open_class (decl))
    6494              :     return false;
    6495              : 
    6496        42253 :   bool warned = false;
    6497        42253 :   if (cxx_dialect >= cxx11
    6498        42162 :       && DECL_P (decl)
    6499        42071 :       && DECL_ARTIFICIAL (decl)
    6500        19484 :       && DECL_IOBJ_MEMBER_FUNCTION_P (decl)
    6501        61737 :       && copy_fn_p (decl))
    6502              :     {
    6503              :       /* Don't warn if the flag was disabled around the class definition
    6504              :          (c++/94492).  */
    6505        19472 :       if (warning_enabled_at (DECL_SOURCE_LOCATION (decl),
    6506        19472 :                               OPT_Wdeprecated_copy))
    6507              :         {
    6508           16 :           auto_diagnostic_group d;
    6509           16 :           tree ctx = DECL_CONTEXT (decl);
    6510           16 :           tree other = classtype_has_depr_implicit_copy (ctx);
    6511           16 :           int opt = (DECL_DESTRUCTOR_P (other)
    6512           16 :                      ? OPT_Wdeprecated_copy_dtor
    6513            0 :                      : OPT_Wdeprecated_copy);
    6514           16 :           warned = warning (opt, "implicitly-declared %qD is deprecated",
    6515              :                             decl);
    6516           16 :           if (warned)
    6517            4 :             inform (DECL_SOURCE_LOCATION (other),
    6518              :                     "because %qT has user-provided %qD",
    6519              :                     ctx, other);
    6520           16 :         }
    6521              :     }
    6522              :   else
    6523              :     {
    6524        22781 :       if (!warning_suppressed_at (input_location,
    6525              :                                   OPT_Wdeprecated_declarations))
    6526        20036 :         warned = warn_deprecated_use (decl, NULL_TREE);
    6527        22781 :       suppress_warning_at (input_location, OPT_Wdeprecated_declarations);
    6528              :     }
    6529              : 
    6530              :   return warned;
    6531              : }
    6532              : 
    6533              : /* Like above, but takes into account outer scopes.  */
    6534              : 
    6535              : void
    6536   1477954698 : cp_warn_deprecated_use_scopes (tree scope)
    6537              : {
    6538   1477954698 :   while (scope
    6539   2591770795 :          && scope != error_mark_node
    6540   5183541555 :          && scope != global_namespace)
    6541              :     {
    6542    247793200 :       if ((TREE_CODE (scope) == NAMESPACE_DECL || OVERLOAD_TYPE_P (scope))
    6543   1345327495 :           && cp_handle_deprecated_or_unavailable (scope))
    6544              :         return;
    6545   1113816097 :       if (TYPE_P (scope))
    6546    233203370 :         scope = CP_TYPE_CONTEXT (scope);
    6547              :       else
    6548    880612727 :         scope = CP_DECL_CONTEXT (scope);
    6549              :     }
    6550              : }
    6551              : 
    6552              : /* True if DECL or its enclosing scope have unbound template parameters.  */
    6553              : 
    6554              : bool
    6555    604967736 : decl_dependent_p (tree decl)
    6556              : {
    6557    604967736 :   tree orig_decl = decl;
    6558   1209252844 :   if (DECL_FUNCTION_SCOPE_P (decl)
    6559    302570397 :       || TREE_CODE (decl) == CONST_DECL
    6560    302570397 :       || TREE_CODE (decl) == USING_DECL
    6561    907538133 :       || TREE_CODE (decl) == FIELD_DECL)
    6562    302397339 :     decl = CP_DECL_CONTEXT (decl);
    6563    604967736 :   if (tree tinfo = get_template_info (decl))
    6564    535743303 :     if (any_dependent_template_arguments_p (TI_ARGS (tinfo)))
    6565              :       return true;
    6566    442205020 :   if (LAMBDA_FUNCTION_P (decl)
    6567    439989880 :       && dependent_type_p (DECL_CONTEXT (decl)))
    6568              :     return true;
    6569              :   /* for-range-declaration of expansion statement as well as variable
    6570              :      declarations in the expansion statement body when the expansion statement
    6571              :      is not inside a template still need to be treated as dependent during
    6572              :      parsing.  When the body is instantiated, in_expansion_stmt will be already
    6573              :      false.  */
    6574    434656522 :   if (VAR_P (orig_decl) && in_expansion_stmt && decl == current_function_decl)
    6575              :     return true;
    6576              :   return false;
    6577              : }
    6578              : 
    6579              : /* [basic.def.odr] A function is named [and therefore odr-used] by an
    6580              :    expression or conversion if it is the selected member of an overload set in
    6581              :    an overload resolution performed as part of forming that expression or
    6582              :    conversion, unless it is a pure virtual function and either the expression
    6583              :    is not an id-expression naming the function with an explicitly qualified
    6584              :    name or the expression forms a pointer to member.
    6585              : 
    6586              :    Mostly, we call mark_used in places that actually do something with a
    6587              :    function, like build_over_call.  But in a few places we end up with a
    6588              :    non-overloaded FUNCTION_DECL that we aren't going to do any more with, like
    6589              :    convert_to_void.  resolve_nondeduced_context is called in those places,
    6590              :    but it's also called in too many other places.  */
    6591              : 
    6592              : bool
    6593    621175202 : mark_single_function (tree expr, tsubst_flags_t complain)
    6594              : {
    6595    621175202 :   expr = maybe_undo_parenthesized_ref (expr);
    6596    621175202 :   expr = tree_strip_any_location_wrapper (expr);
    6597              : 
    6598    621175202 :   if (expr == error_mark_node)
    6599              :     return false;
    6600              : 
    6601    621174566 :   if (is_overloaded_fn (expr) == 1
    6602    162384675 :       && !mark_used (expr, complain)
    6603    621174602 :       && !(complain & tf_error))
    6604              :     return false;
    6605              :   return true;
    6606              : }
    6607              : 
    6608              : /* True iff we have started, but not finished, defining FUNCTION_DECL DECL.  */
    6609              : 
    6610              : bool
    6611    136631727 : fn_being_defined (tree decl)
    6612              : {
    6613              :   /* DECL_INITIAL is set to error_mark_node in grokfndecl for a definition, and
    6614              :      changed to BLOCK by poplevel at the end of the function.  */
    6615    136631727 :   return (TREE_CODE (decl) == FUNCTION_DECL
    6616    136631727 :           && DECL_INITIAL (decl) == error_mark_node);
    6617              : }
    6618              : 
    6619              : /* True if DECL is an instantiation of a function template currently being
    6620              :    defined.  */
    6621              : 
    6622              : bool
    6623    434656148 : fn_template_being_defined (tree decl)
    6624              : {
    6625    434656148 :   if (TREE_CODE (decl) != FUNCTION_DECL
    6626    226777504 :       || !DECL_LANG_SPECIFIC (decl)
    6627    226777504 :       || !DECL_TEMPLOID_INSTANTIATION (decl)
    6628    635009012 :       || DECL_TEMPLATE_INSTANTIATED (decl))
    6629              :     return false;
    6630    136631727 :   tree tinfo = DECL_TEMPLATE_INFO (decl);
    6631    136631727 :   tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
    6632    136631727 :   return fn_being_defined (pattern);
    6633              : }
    6634              : 
    6635              : /* Mark DECL (either a _DECL or a BASELINK) as "used" in the program.
    6636              :    If DECL is a specialization or implicitly declared class member,
    6637              :    generate the actual definition.  Return false if something goes
    6638              :    wrong, true otherwise.  */
    6639              : 
    6640              : bool
    6641   1614425219 : mark_used (tree decl, tsubst_flags_t complain /* = tf_warning_or_error */)
    6642              : {
    6643   1614425219 :   if (decl == error_mark_node)
    6644              :     return false;
    6645              : 
    6646              :   /* If we're just testing conversions or resolving overloads, we
    6647              :      don't want any permanent effects like forcing functions to be
    6648              :      output or instantiating templates.  */
    6649   1614425143 :   if ((complain & tf_conv))
    6650              :     return true;
    6651              : 
    6652              :   /* If DECL is a BASELINK for a single function, then treat it just
    6653              :      like the DECL for the function.  Otherwise, if the BASELINK is
    6654              :      for an overloaded function, we don't know which function was
    6655              :      actually used until after overload resolution.  */
    6656   1614404539 :   if (BASELINK_P (decl))
    6657              :     {
    6658        12774 :       tree fns = BASELINK_FUNCTIONS (decl);
    6659        12774 :       if (really_overloaded_fn (fns))
    6660              :         return true;
    6661        12732 :       fns = OVL_FIRST (fns);
    6662        12732 :       if (!mark_used (fns, complain))
    6663              :         return false;
    6664              :       /* We might have deduced its return type.  */
    6665        12720 :       TREE_TYPE (decl) = TREE_TYPE (fns);
    6666        12720 :       return true;
    6667              :     }
    6668              : 
    6669   1614391765 :   if (!DECL_P (decl))
    6670              :     return true;
    6671              : 
    6672              :   /* Set TREE_USED for the benefit of -Wunused.  */
    6673   1613418838 :   TREE_USED (decl) = true;
    6674              : 
    6675              :   /* And for structured bindings also the underlying decl.  */
    6676   1613418838 :   if (DECL_DECOMPOSITION_P (decl) && !DECL_DECOMP_IS_BASE (decl))
    6677      1101395 :     TREE_USED (DECL_DECOMP_BASE (decl)) = true;
    6678              : 
    6679   1613418838 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    6680              :     return true;
    6681              : 
    6682   1613408158 :   if (DECL_CLONED_FUNCTION_P (decl))
    6683     24922077 :     TREE_USED (DECL_CLONED_FUNCTION (decl)) = 1;
    6684              : 
    6685              :   /* Mark enumeration types as used.  */
    6686   1613408158 :   if (TREE_CODE (decl) == CONST_DECL)
    6687     41060219 :     used_types_insert (DECL_CONTEXT (decl));
    6688              : 
    6689   1613408158 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    6690              :     {
    6691    423443416 :       if (DECL_MAYBE_DELETED (decl))
    6692              :         {
    6693        32340 :           ++function_depth;
    6694        32340 :           maybe_synthesize_method (decl);
    6695        32340 :           --function_depth;
    6696              :         }
    6697              : 
    6698    423443416 :       if (DECL_DELETED_FN (decl))
    6699              :         {
    6700         2403 :           if (DECL_ARTIFICIAL (decl)
    6701         1631 :               && DECL_CONV_FN_P (decl)
    6702         2415 :               && LAMBDA_TYPE_P (DECL_CONTEXT (decl)))
    6703              :             /* We mark a lambda conversion op as deleted if we can't
    6704              :                generate it properly; see maybe_add_lambda_conv_op.  */
    6705            6 :             sorry ("converting lambda that uses %<...%> to function pointer");
    6706         2397 :           else if (complain & tf_error)
    6707              :             {
    6708         2379 :               auto_diagnostic_group d;
    6709         2379 :               if (DECL_INITIAL (decl)
    6710         2379 :                   && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
    6711              :                 {
    6712           23 :                   escaped_string msg;
    6713           23 :                   msg.escape (TREE_STRING_POINTER (DECL_INITIAL (decl)));
    6714           23 :                   error ("use of deleted function %qD: %s",
    6715              :                          decl, (const char *) msg);
    6716           23 :                 }
    6717              :               else
    6718         2356 :                 error ("use of deleted function %qD", decl);
    6719         2379 :               if (!maybe_explain_implicit_delete (decl))
    6720          661 :                 inform (DECL_SOURCE_LOCATION (decl), "declared here");
    6721         2379 :             }
    6722         2403 :           return false;
    6723              :         }
    6724              : 
    6725    423441013 :       if (!maybe_instantiate_noexcept (decl, complain))
    6726              :         return false;
    6727              :     }
    6728              : 
    6729   1613405659 :   if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_LOCAL_DECL_P (decl))
    6730              :     {
    6731        69659 :       if (!DECL_LANG_SPECIFIC (decl))
    6732              :         /* An unresolved dependent local extern.  */
    6733              :         return true;
    6734              : 
    6735        69659 :       DECL_ODR_USED (decl) = 1;
    6736        69659 :       auto alias = DECL_LOCAL_DECL_ALIAS (decl);
    6737        69659 :       if (!alias || alias == error_mark_node)
    6738              :         return true;
    6739              : 
    6740              :       /* Process the underlying decl.  */
    6741        69367 :       decl = alias;
    6742        69367 :       TREE_USED (decl) = true;
    6743              :     }
    6744              : 
    6745   1613405367 :   cp_handle_deprecated_or_unavailable (decl, complain);
    6746              : 
    6747              :   /* We can only check DECL_ODR_USED on variables or functions with
    6748              :      DECL_LANG_SPECIFIC set, and these are also the only decls that we
    6749              :      might need special handling for.  */
    6750    949559618 :   if (!VAR_OR_FUNCTION_DECL_P (decl)
    6751   2036846262 :       || DECL_THUNK_P (decl))
    6752              :     return true;
    6753              : 
    6754              :   /* We only want to do this processing once.  We don't need to keep trying
    6755              :      to instantiate inline templates, because unit-at-a-time will make sure
    6756              :      we get them compiled before functions that want to inline them.  */
    6757   1087278236 :   if (DECL_LANG_SPECIFIC (decl) && DECL_ODR_USED (decl))
    6758              :     return true;
    6759              : 
    6760    599147406 :   if (flag_concepts && TREE_CODE (decl) == FUNCTION_DECL
    6761    831178517 :       && !constraints_satisfied_p (decl))
    6762              :     {
    6763           15 :       if (complain & tf_error)
    6764              :         {
    6765            6 :           auto_diagnostic_group d;
    6766            6 :           error ("use of function %qD with unsatisfied constraints",
    6767              :                  decl);
    6768            6 :           location_t loc = DECL_SOURCE_LOCATION (decl);
    6769            6 :           inform (loc, "declared here");
    6770            6 :           diagnose_constraints (loc, decl, NULL_TREE);
    6771            6 :         }
    6772           15 :       return false;
    6773              :     }
    6774              : 
    6775              :   /* If DECL has a deduced return type, we need to instantiate it now to
    6776              :      find out its type.  For OpenMP user defined reductions, we need them
    6777              :      instantiated for reduction clauses which inline them by hand directly.
    6778              :      OpenMP declared mappers are used implicitly so must be instantiated
    6779              :      before they can be detected.  */
    6780    604967736 :   if (undeduced_auto_decl (decl)
    6781    577159436 :       || (VAR_P (decl)
    6782    351239879 :           && VAR_HAD_UNKNOWN_BOUND (decl))
    6783    577140260 :       || (TREE_CODE (decl) == FUNCTION_DECL
    6784    225919557 :           && DECL_OMP_DECLARE_REDUCTION_P (decl))
    6785   1182107734 :       || (TREE_CODE (decl) == VAR_DECL
    6786    351220703 :           && DECL_LANG_SPECIFIC (decl)
    6787     84470304 :           && DECL_OMP_DECLARE_MAPPER_P (decl)))
    6788     27827810 :     maybe_instantiate_decl (decl);
    6789              : 
    6790    604967736 :   if (!decl_dependent_p (decl)
    6791              :       /* Don't require this yet for an instantiation of a function template
    6792              :          we're currently defining (c++/120555).  */
    6793    434656148 :       && !fn_template_being_defined (decl)
    6794   1039504177 :       && !require_deduced_type (decl, complain))
    6795              :     return false;
    6796              : 
    6797    604967084 :   if (DECL_LANG_SPECIFIC (decl) == NULL)
    6798              :     return true;
    6799              : 
    6800    312708216 :   if (processing_template_decl || in_template_context)
    6801              :     return true;
    6802              : 
    6803              :   /* Check this too in case we're within instantiate_non_dependent_expr.  */
    6804    258832613 :   if (DECL_TEMPLATE_INFO (decl)
    6805    258832613 :       && uses_template_parms (DECL_TI_ARGS (decl)))
    6806              :     return true;
    6807              : 
    6808    258832613 :   if (builtin_pack_fn_p (decl))
    6809              :     {
    6810           12 :       error ("use of built-in parameter pack %qD outside of a template",
    6811            6 :              DECL_NAME (decl));
    6812            6 :       return false;
    6813              :     }
    6814              : 
    6815              :   /* If we don't need a value, then we don't need to synthesize DECL.  */
    6816    258832607 :   if (cp_unevaluated_operand || in_discarded_stmt)
    6817              :     return true;
    6818              : 
    6819     58875274 :   DECL_ODR_USED (decl) = 1;
    6820     58875274 :   if (DECL_CLONED_FUNCTION_P (decl))
    6821      8125646 :     DECL_ODR_USED (DECL_CLONED_FUNCTION (decl)) = 1;
    6822              : 
    6823              :   /* DR 757: A type without linkage shall not be used as the type of a
    6824              :      variable or function with linkage, unless
    6825              :    o the variable or function has extern "C" linkage (7.5 [dcl.link]), or
    6826              :    o the variable or function is not used (3.2 [basic.def.odr]) or is
    6827              :    defined in the same translation unit.  */
    6828     58875274 :   if (cxx_dialect > cxx98
    6829     58659553 :       && decl_linkage (decl) != lk_none
    6830     53430280 :       && !DECL_EXTERN_C_P (decl)
    6831     48945512 :       && !DECL_ARTIFICIAL (decl)
    6832     46973075 :       && !decl_defined_p (decl)
    6833     95153396 :       && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
    6834       659214 :     vec_safe_push (no_linkage_decls, decl);
    6835              : 
    6836     58875274 :   if (TREE_CODE (decl) == FUNCTION_DECL
    6837     44310430 :       && DECL_DECLARED_INLINE_P (decl)
    6838     35429164 :       && !DECL_INITIAL (decl)
    6839     24561652 :       && !DECL_ARTIFICIAL (decl)
    6840     82816429 :       && !DECL_PURE_VIRTUAL_P (decl))
    6841              :     /* Remember it, so we can check it was defined.  */
    6842     23922809 :     note_vague_linkage_fn (decl);
    6843              : 
    6844              :   /* Is it a synthesized method that needs to be synthesized?  */
    6845     58875274 :   if (TREE_CODE (decl) == FUNCTION_DECL
    6846     44310430 :       && DECL_DEFAULTED_FN (decl)
    6847              :       /* A function defaulted outside the class is synthesized either by
    6848              :          cp_finish_decl or instantiate_decl.  */
    6849      1763244 :       && !DECL_DEFAULTED_OUTSIDE_CLASS_P (decl)
    6850     60638295 :       && ! DECL_INITIAL (decl))
    6851              :     {
    6852              :       /* Remember the current location for a function we will end up
    6853              :          synthesizing.  Then we can inform the user where it was
    6854              :          required in the case of error.  */
    6855      1552355 :       if (decl_remember_implicit_trigger_p (decl))
    6856       551408 :         DECL_SOURCE_LOCATION (decl) = input_location;
    6857              : 
    6858              :       /* Synthesizing an implicitly defined member function will result in
    6859              :          garbage collection.  We must treat this situation as if we were
    6860              :          within the body of a function so as to avoid collecting live data
    6861              :          on the stack (such as overload resolution candidates).
    6862              : 
    6863              :          We could just let c_parse_final_cleanups handle synthesizing
    6864              :          this function by adding it to deferred_fns, but doing
    6865              :          it at the use site produces better error messages.  */
    6866      1552355 :       ++function_depth;
    6867      1552355 :       synthesize_method (decl);
    6868      1552355 :       --function_depth;
    6869              :       /* If this is a synthesized method we don't need to
    6870              :          do the instantiation test below.  */
    6871              :     }
    6872     42758075 :   else if (VAR_OR_FUNCTION_DECL_P (decl)
    6873     57322919 :            && DECL_TEMPLATE_INFO (decl)
    6874     93890588 :            && (!DECL_EXPLICIT_INSTANTIATION (decl)
    6875       524368 :                || always_instantiate_p (decl)))
    6876              :     /* If this is a function or variable that is an instance of some
    6877              :        template, we now know that we will need to actually do the
    6878              :        instantiation. We check that DECL is not an explicit
    6879              :        instantiation because that is not checked in instantiate_decl.
    6880              : 
    6881              :        We put off instantiating functions in order to improve compile
    6882              :        times.  Maintaining a stack of active functions is expensive,
    6883              :        and the inliner knows to instantiate any functions it might
    6884              :        need.  Therefore, we always try to defer instantiation.  */
    6885              :     {
    6886     36507150 :       ++function_depth;
    6887     36507150 :       instantiate_decl (decl, /*defer_ok=*/true,
    6888              :                         /*expl_inst_class_mem_p=*/false);
    6889     36499050 :       --function_depth;
    6890              :     }
    6891              : 
    6892              :   return true;
    6893              : }
    6894              : 
    6895              : tree
    6896            9 : vtv_start_verification_constructor_init_function (void)
    6897              : {
    6898            9 :   return start_objects (/*initp=*/true, MAX_RESERVED_INIT_PRIORITY - 1, true);
    6899              : }
    6900              : 
    6901              : tree
    6902            6 : vtv_finish_verification_constructor_init_function (tree body)
    6903              : {
    6904            6 :   return finish_objects (/*initp=*/true, MAX_RESERVED_INIT_PRIORITY - 1, body);
    6905              : }
    6906              : 
    6907              : #include "gt-cp-decl2.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.