LCOV - code coverage report
Current view: top level - gcc/cp - decl2.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 95.3 % 2918 2782
Test Date: 2026-12-05 16:10:02 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    627641096 :   static hashval_t hash (const value_type decl)
     106              :   {
     107    627641096 :     return IDENTIFIER_HASH_VALUE (DECL_ASSEMBLER_NAME_RAW (decl));
     108              :   }
     109    607820794 :   static bool equal (const value_type existing, compare_type candidate)
     110              :   {
     111    607820794 :     tree name = DECL_ASSEMBLER_NAME_RAW (existing);
     112    607820794 :     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    800782365 :   static bool is_deleted (value_type e)
     120              :   {
     121    800782365 :     return e == reinterpret_cast <value_type> (1);
     122              :   }
     123           81 :   static void mark_deleted (value_type &e)
     124              :   {
     125           81 :     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       532947 :   template <typename T> static bool is_empty (const T &entry)
     153              :   {
     154       532947 :     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 deletable
     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    106393394 : build_memfn_type (tree fntype, tree ctype, cp_cv_quals quals,
     197              :                   cp_ref_qualifier rqual)
     198              : {
     199    106393394 :   if (fntype == error_mark_node || ctype == error_mark_node)
     200              :     return error_mark_node;
     201              : 
     202    106393391 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
     203              : 
     204    106393391 :   cp_cv_quals type_quals = quals & ~TYPE_QUAL_RESTRICT;
     205    106393391 :   ctype = cp_build_qualified_type (ctype, type_quals);
     206              : 
     207    106393391 :   tree newtype
     208    106393391 :     = build_method_type_directly (ctype, TREE_TYPE (fntype),
     209    106393391 :                                   (TREE_CODE (fntype) == METHOD_TYPE
     210        60547 :                                    ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
     211    106332844 :                                    : TYPE_ARG_TYPES (fntype)));
     212    106393391 :   if (tree attrs = TYPE_ATTRIBUTES (fntype))
     213           71 :     newtype = cp_build_type_attribute_variant (newtype, attrs);
     214    319180173 :   newtype = build_cp_fntype_variant (newtype, rqual,
     215    106393391 :                                      TYPE_RAISES_EXCEPTIONS (fntype),
     216    106393391 :                                      TYPE_HAS_LATE_RETURN_TYPE (fntype));
     217              : 
     218    106393391 :   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      1213384 : change_return_type (tree new_ret, tree fntype)
     226              : {
     227      1213384 :   if (new_ret == error_mark_node)
     228              :     return fntype;
     229              : 
     230      1213384 :   if (same_type_p (new_ret, TREE_TYPE (fntype)))
     231              :     return fntype;
     232              : 
     233      1213381 :   tree newtype;
     234      1213381 :   tree args = TYPE_ARG_TYPES (fntype);
     235              : 
     236      1213381 :   if (TREE_CODE (fntype) == FUNCTION_TYPE)
     237              :     {
     238      1362159 :       newtype = build_function_type (new_ret, args,
     239       454053 :                                      TYPE_NO_NAMED_ARGS_STDARG_P (fntype));
     240       454053 :       newtype = apply_memfn_quals (newtype,
     241              :                                    type_memfn_quals (fntype));
     242              :     }
     243              :   else
     244       759328 :     newtype = build_method_type_directly
     245       759328 :       (class_of_this_parm (fntype), new_ret, TREE_CHAIN (args));
     246              : 
     247      1213381 :   if (tree attrs = TYPE_ATTRIBUTES (fntype))
     248          110 :     newtype = cp_build_type_attribute_variant (newtype, attrs);
     249      1213381 :   newtype = cxx_copy_lang_qualifiers (newtype, fntype);
     250              : 
     251      1213381 :   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    568610497 : cp_build_parm_decl (tree fn, tree name, tree type)
     259              : {
     260    568610497 :   tree parm = build_decl (input_location,
     261              :                           PARM_DECL, name, type);
     262    568610497 :   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    568610497 :   if (!processing_template_decl)
     267    196638971 :     DECL_ARG_TYPE (parm) = type_passed_as (type);
     268              : 
     269    568610497 :   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    246406892 : build_artificial_parm (tree fn, tree name, tree type)
     277              : {
     278    246406892 :   tree parm = cp_build_parm_decl (fn, name, type);
     279    246406892 :   DECL_ARTIFICIAL (parm) = 1;
     280              :   /* All our artificial parms are implicitly `const'; they cannot be
     281              :      assigned to.  */
     282    246406892 :   TREE_READONLY (parm) = 1;
     283    246406892 :   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     83803186 : maybe_retrofit_in_chrg (tree fn)
     298              : {
     299     83803186 :   tree basetype, arg_types, parms, parm, fntype;
     300              : 
     301              :   /* If we've already add the in-charge parameter don't do it again.  */
     302     83803186 :   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     83803186 :   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     53433246 :   if (!CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
     313              :     return;
     314              : 
     315      1156537 :   arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn));
     316      1156537 :   basetype = TREE_TYPE (TREE_VALUE (arg_types));
     317      1156537 :   arg_types = TREE_CHAIN (arg_types);
     318              : 
     319      1156537 :   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      1156537 :   if (CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
     324              :     {
     325      1156537 :       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      1156537 :       DECL_CHAIN (parm) = parms;
     329      1156537 :       parms = parm;
     330              : 
     331              :       /* ...and then to TYPE_ARG_TYPES.  */
     332      1156537 :       arg_types = hash_tree_chain (vtt_parm_type, arg_types);
     333              : 
     334      1156537 :       DECL_HAS_VTT_PARM_P (fn) = 1;
     335              :     }
     336              : 
     337              :   /* Then add the in-charge parm (before the VTT parm).  */
     338      1156537 :   parm = build_artificial_parm (fn, in_charge_identifier, integer_type_node);
     339      1156537 :   DECL_CHAIN (parm) = parms;
     340      1156537 :   parms = parm;
     341      1156537 :   arg_types = hash_tree_chain (integer_type_node, arg_types);
     342              : 
     343              :   /* Insert our new parameter(s) into the list.  */
     344      1156537 :   DECL_CHAIN (DECL_ARGUMENTS (fn)) = parms;
     345              : 
     346              :   /* And rebuild the function type.  */
     347      1156537 :   fntype = build_method_type_directly (basetype, TREE_TYPE (TREE_TYPE (fn)),
     348              :                                        arg_types);
     349      1156537 :   if (TYPE_ATTRIBUTES (TREE_TYPE (fn)))
     350            3 :     fntype = (cp_build_type_attribute_variant
     351            3 :               (fntype, TYPE_ATTRIBUTES (TREE_TYPE (fn))));
     352      1156537 :   fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (fn));
     353      1156537 :   TREE_TYPE (fn) = fntype;
     354              : 
     355              :   /* Now we've got the in-charge parameter.  */
     356      1156537 :   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    148499278 : grokclassfn (tree ctype, tree function, enum overload_flags flags)
     381              : {
     382    148499278 :   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    148499278 :   SET_DECL_LANGUAGE (function, lang_cplusplus);
     387              : 
     388    148499278 :   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    148499278 :   DECL_CONTEXT (function) = ctype;
     396              : 
     397    148499278 :   if (flags == DTOR_FLAG)
     398     11620695 :     DECL_CXX_DESTRUCTOR_P (function) = 1;
     399              : 
     400    285377861 :   if (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))
     401     56204925 :     maybe_retrofit_in_chrg (function);
     402    148499278 : }
     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     11951322 : 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     11951322 :   tree type;
     414     11951322 :   tree expr;
     415     11951322 :   tree orig_array_expr = array_expr;
     416     11951322 :   tree orig_index_exp = index_exp;
     417     11941655 :   vec<tree, va_gc> *orig_index_exp_list
     418     11951322 :     = index_exp_list ? *index_exp_list : NULL;
     419     11951322 :   tree overload = NULL_TREE;
     420              : 
     421     11951322 :   if (error_operand_p (array_expr) || error_operand_p (index_exp))
     422          117 :     return error_mark_node;
     423              : 
     424     11951205 :   if (processing_template_decl)
     425              :     {
     426     10276773 :       if (type_dependent_expression_p (array_expr)
     427     10276806 :           || (index_exp ? type_dependent_expression_p (index_exp)
     428           33 :                         : any_type_dependent_arguments_p (*index_exp_list)))
     429              :         {
     430      8496193 :           if (index_exp == NULL)
     431        11073 :             index_exp = build_min_nt_call_vec (ovl_op_identifier (ARRAY_REF),
     432              :                                                *index_exp_list);
     433      8496193 :           return build_min_nt_loc (loc, ARRAY_REF, array_expr, index_exp,
     434      8496193 :                                    NULL_TREE, NULL_TREE);
     435              :         }
     436      1780580 :       if (!index_exp)
     437           32 :         orig_index_exp_list = make_tree_vector_copy (*index_exp_list);
     438              :     }
     439              : 
     440      3455012 :   type = TREE_TYPE (array_expr);
     441      3455012 :   gcc_assert (type);
     442      3455012 :   type = non_reference (type);
     443              : 
     444              :   /* If they have an `operator[]', use that.  */
     445      3455012 :   if (MAYBE_CLASS_TYPE_P (type)
     446      3236200 :       || (index_exp && MAYBE_CLASS_TYPE_P (TREE_TYPE (index_exp)))
     447              :       || (index_exp == NULL_TREE
     448           60 :           && !(*index_exp_list)->is_empty ()
     449           53 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE ((*index_exp_list)->last ()))))
     450              :     {
     451       218854 :       if (index_exp)
     452       218151 :         expr = build_new_op (loc, ARRAY_REF, LOOKUP_NORMAL, array_expr,
     453              :                              index_exp, NULL_TREE, NULL_TREE,
     454              :                              &overload, complain);
     455          703 :       else if ((*index_exp_list)->is_empty ())
     456          141 :         expr = build_op_subscript (loc, array_expr, index_exp_list, &overload,
     457              :                                    complain);
     458              :       else
     459              :         {
     460          562 :           expr = build_op_subscript (loc, array_expr, index_exp_list,
     461              :                                      &overload, complain & tf_decltype);
     462          562 :           if (expr == error_mark_node
     463              :               /* Don't do the backward compatibility fallback in a SFINAE
     464              :                  context.   */
     465           17 :               && (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      3236158 :       tree p1, p2, i1, i2;
     503      3236158 :       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      3236158 :       if (TREE_CODE (type) == ARRAY_TYPE || VECTOR_TYPE_P (type))
     510              :         p1 = array_expr;
     511              :       else
     512      2094934 :         p1 = build_expr_type_conversion (WANT_POINTER, array_expr, false);
     513              : 
     514      3236158 :       if (index_exp == NULL_TREE)
     515              :         {
     516           60 :           if (!(complain & tf_error))
     517              :             /* Don't do the backward compatibility fallback in a SFINAE
     518              :                context.  */
     519           12 :             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      3236145 :       if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
     554              :         p2 = index_exp;
     555              :       else
     556      3236109 :         p2 = build_expr_type_conversion (WANT_POINTER, index_exp, false);
     557              : 
     558      3236145 :       i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr,
     559              :                                        false);
     560      3236145 :       i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp,
     561              :                                        false);
     562              : 
     563      3236145 :       if ((p1 && i2) && (i1 && p2))
     564            0 :         error ("ambiguous conversion for array subscript");
     565              : 
     566      3236145 :       if (p1 && i2)
     567              :         array_expr = p1, index_exp = i2;
     568           82 :       else if (i1 && p2)
     569              :         swapped = true, array_expr = p2, index_exp = i1;
     570              :       else
     571              :         {
     572           31 :           if (complain & tf_error)
     573           25 :             error_at (loc, "invalid types %<%T[%T]%> for array subscript",
     574           25 :                       type, TREE_TYPE (index_exp));
     575           31 :           return error_mark_node;
     576              :         }
     577              : 
     578      3236114 :       if (array_expr == error_mark_node || index_exp == error_mark_node)
     579            0 :         error ("ambiguous conversion for array subscript");
     580              : 
     581      3236114 :       if (TYPE_PTR_P (TREE_TYPE (array_expr)))
     582      2094880 :         array_expr = mark_rvalue_use (array_expr);
     583              :       else
     584      1141234 :         array_expr = mark_lvalue_use_nonread (array_expr);
     585      3236114 :       index_exp = mark_rvalue_use (index_exp);
     586      3236114 :       if (swapped
     587           51 :           && flag_strong_eval_order == 2
     588      3236158 :           && (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      3236096 :         expr = build_array_ref (input_location, array_expr, index_exp);
     592              :     }
     593      3454968 :   if (processing_template_decl && expr != error_mark_node)
     594              :     {
     595      1780580 :       if (overload != NULL_TREE)
     596              :         {
     597       180349 :           if (orig_index_exp == NULL_TREE)
     598              :             {
     599           29 :               expr = build_min_non_dep_op_overload (expr, overload,
     600              :                                                     orig_array_expr,
     601              :                                                     orig_index_exp_list);
     602           29 :               release_tree_vector (orig_index_exp_list);
     603           29 :               return expr;
     604              :             }
     605       180320 :           return build_min_non_dep_op_overload (ARRAY_REF, expr, overload,
     606              :                                                 orig_array_expr,
     607       180320 :                                                 orig_index_exp);
     608              :         }
     609              : 
     610      1600231 :       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      1600231 :       return build_min_non_dep (ARRAY_REF, expr, orig_array_expr,
     619      1600231 :                                 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         4979 : grok_omp_array_section (location_t loc, tree array_expr, tree index,
     629              :                         tree length)
     630              : {
     631         4979 :   tree orig_array_expr = array_expr;
     632         4979 :   tree orig_index = index;
     633         4979 :   tree orig_length = length;
     634              : 
     635         4979 :   if (error_operand_p (array_expr)
     636         4970 :       || error_operand_p (index)
     637         9949 :       || error_operand_p (length))
     638            9 :     return error_mark_node;
     639              : 
     640         4970 :   if (processing_template_decl
     641         4970 :       && (type_dependent_expression_p (array_expr)
     642          757 :           || type_dependent_expression_p (index)
     643          741 :           || type_dependent_expression_p (length)))
     644          933 :     return build_min_nt_loc (loc, OMP_ARRAY_SECTION, array_expr, index, length);
     645              : 
     646         4037 :   index = fold_non_dependent_expr (index);
     647         4037 :   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         4037 :   tree expr = build_omp_array_section (loc, array_expr, index, length);
     654              : 
     655         4037 :   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       579636 : delete_sanity (location_t loc, tree exp, tree size, bool doing_vec,
     670              :                int use_global_delete, tsubst_flags_t complain)
     671              : {
     672       579636 :   tree t, type;
     673              : 
     674       579636 :   if (exp == error_mark_node)
     675              :     return exp;
     676              : 
     677       579519 :   if (processing_template_decl)
     678              :     {
     679       448745 :       t = build_min (DELETE_EXPR, void_type_node, exp, size);
     680       448745 :       DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
     681       448745 :       DELETE_EXPR_USE_VEC (t) = doing_vec;
     682       448745 :       TREE_SIDE_EFFECTS (t) = 1;
     683       448745 :       SET_EXPR_LOCATION (t, loc);
     684       448745 :       return t;
     685              :     }
     686              : 
     687       130774 :   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       130774 :   if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
     691       130774 :       && (complain & tf_warning))
     692           21 :     warning_at (exp_loc, 0, "deleting array %q#E", exp);
     693              : 
     694       130774 :   t = build_expr_type_conversion (WANT_POINTER, exp, true);
     695              : 
     696       130774 :   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       130753 :   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       130753 :   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       130747 :   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       130747 :   if (integer_zerop (t))
     730            3 :     return build1_loc (loc, NOP_EXPR, void_type_node, t);
     731              : 
     732       130744 :   if (doing_vec)
     733        21649 :     return build_vec_delete (loc, t, /*maxindex=*/NULL_TREE,
     734              :                              sfk_deleting_destructor,
     735        21649 :                              use_global_delete, complain);
     736              :   else
     737       109095 :     return build_delete (loc, type, t, sfk_deleting_destructor,
     738              :                          LOOKUP_NORMAL, use_global_delete,
     739       109095 :                          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     23263319 : check_member_template (tree tmpl)
     747              : {
     748     23263319 :   tree decl;
     749              : 
     750     23263319 :   gcc_assert (TREE_CODE (tmpl) == TEMPLATE_DECL);
     751     23263319 :   decl = DECL_TEMPLATE_RESULT (tmpl);
     752              : 
     753     23263319 :   if (TREE_CODE (decl) == FUNCTION_DECL
     754      2456527 :       || DECL_ALIAS_TEMPLATE_P (tmpl)
     755     24417397 :       || (TREE_CODE (decl) == TYPE_DECL
     756       803929 :           && 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     23421602 :       gcc_assert (!current_function_decl || LAMBDA_FUNCTION_P (decl));
     761              :       /* The parser rejects any use of virtual in a function template.  */
     762     22913170 :       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     22913170 :       DECL_IGNORED_P (tmpl) = 1;
     768              :     }
     769       350149 :   else if (variable_template_p (tmpl))
     770              :     /* OK */;
     771              :   else
     772            0 :     error ("template declaration of %q#D", decl);
     773     23263319 : }
     774              : 
     775              : /* A struct for conveniently working with the parameter types of a
     776              :    fndecl.  */
     777              : 
     778          300 : struct fndecl_signature
     779              : {
     780          200 :   fndecl_signature (tree fndecl)
     781          200 :   : m_fndecl (fndecl),
     782          200 :     m_num_artificial_parms (num_artificial_parms_for (fndecl)),
     783          200 :     m_variadic (true)
     784              :   {
     785          200 :     function_args_iterator iter;
     786          200 :     tree argtype;
     787          660 :     FOREACH_FUNCTION_ARGS (TREE_TYPE (fndecl), argtype, iter)
     788              :       {
     789              :         /* A trailing "void" type means that FNDECL is non-variadic.  */
     790          648 :         if (VOID_TYPE_P (argtype))
     791              :           {
     792          188 :             gcc_assert (!TREE_CHAIN (iter.next));
     793          188 :             m_variadic = false;
     794          188 :             break;
     795              :           }
     796          460 :         m_parm_types.safe_push (argtype);
     797              :       }
     798          400 :     gcc_assert (m_parm_types.length () >= (size_t)m_num_artificial_parms);
     799          200 :     m_num_user_parms = m_parm_types.length () - m_num_artificial_parms;
     800          200 :   }
     801              : 
     802              :   /* Convert from index within DECL_ARGUMENTS to 0-based user-written
     803              :      parameter, or -1 for "this".  */
     804              :   int
     805           98 :   get_argno_from_idx (size_t idx) const
     806              :   {
     807           98 :     return static_cast<int> (idx) - m_num_artificial_parms;
     808              :   }
     809              : 
     810              :   location_t
     811           98 :   get_argno_location (int argno) const
     812              :   {
     813           98 :     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          147 : class parm_rich_location : public gcc_rich_location
     827              : {
     828              : public:
     829           98 :   parm_rich_location (const fndecl_signature &fndecl_sig,
     830              :                       int argno,
     831              :                       const char *highlight_color)
     832              :   : gcc_rich_location (fndecl_sig.get_argno_location (argno),
     833              :                        nullptr,
     834           98 :                        highlight_color)
     835              :   {
     836           98 :   }
     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          100 : class fndecl_comparison
     843              : {
     844              : public:
     845          100 :   fndecl_comparison (tree decl_a,
     846              :                      tree decl_b)
     847          100 :   : m_decl_a (decl_a),
     848          100 :     m_decl_b (decl_b)
     849              :   {
     850          100 :     gcc_assert (TREE_CODE (decl_a) == FUNCTION_DECL);
     851          100 :     gcc_assert (TREE_CODE (decl_b) == FUNCTION_DECL);
     852          100 :   }
     853              : 
     854              :   /* Attempt to emit diagnostic notes describing the differences between
     855              :      the fndecls, when they are a sufficiently close match.  */
     856              :   void
     857          100 :   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          100 :     if (m_decl_a.m_variadic != m_decl_b.m_variadic)
     862           12 :       return;
     863              : 
     864           88 :     auto_vec<parm_difference> differences = get_differences ();
     865          137 :     if (differences.length () == 1)
     866              :       {
     867           49 :         auto_diagnostic_nesting_level sentinel;
     868           49 :         print_parm_type_difference (differences[0]);
     869           49 :       }
     870           88 :   }
     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           88 :   get_differences () const
     883              :   {
     884           88 :     auto_vec<parm_difference> differences;
     885              : 
     886              :     /* For now, just handle the case where the "user parm" count is
     887              :        equal.  */
     888           88 :     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           70 :     if (m_decl_a.m_num_artificial_parms == m_decl_b.m_num_artificial_parms)
     899           67 :       for (int parm_idx = 0;
     900          134 :            parm_idx < m_decl_a.m_num_artificial_parms;
     901              :            ++parm_idx)
     902           67 :         compare (parm_idx, parm_idx, differences);
     903              : 
     904              :     /* Find differences in user-provided params.  */
     905          149 :     for (size_t user_parm_idx = 0;
     906          149 :          user_parm_idx < m_decl_a.m_num_user_parms;
     907              :          ++user_parm_idx)
     908              :       {
     909           79 :         const size_t idx_a = m_decl_a.m_num_artificial_parms + user_parm_idx;
     910           79 :         const size_t idx_b = m_decl_b.m_num_artificial_parms + user_parm_idx;
     911           79 :         compare (idx_a, idx_b, differences);
     912              :       }
     913              : 
     914              :     return differences;
     915              :   }
     916              : 
     917              :   void
     918          146 :   compare (size_t idx_a, size_t idx_b,
     919              :            auto_vec<parm_difference> &differences) const
     920              :   {
     921          146 :     if (!same_type_p (m_decl_a.m_parm_types[idx_a],
     922              :                       m_decl_b.m_parm_types[idx_b]))
     923           49 :       differences.safe_push (parm_difference {idx_a, idx_b});
     924          146 :   }
     925              : 
     926              :   void
     927           49 :   print_parm_type_difference (const parm_difference &diff) const
     928              :   {
     929           49 :     const char * const highlight_a = "highlight-a";
     930           49 :     pp_markup::element_quoted_type type_of_parm_a
     931           49 :       (m_decl_a.m_parm_types[diff.m_parm_idx_a],
     932           49 :        highlight_a);
     933           49 :     const int argno_a = m_decl_a.get_argno_from_idx (diff.m_parm_idx_a);
     934           49 :     parm_rich_location rich_loc_a (m_decl_a, argno_a, highlight_a);
     935           49 :     inform (&rich_loc_a,
     936              :             "parameter %P of candidate has type %e...",
     937              :             argno_a, &type_of_parm_a);
     938              : 
     939           49 :     const char * const highlight_b = "highlight-b";
     940           49 :     pp_markup::element_quoted_type type_of_parm_b
     941           49 :       (m_decl_b.m_parm_types[diff.m_parm_idx_b],
     942           49 :        highlight_b);
     943           49 :     const int argno_b = m_decl_b.get_argno_from_idx (diff.m_parm_idx_b);
     944           49 :     parm_rich_location rich_loc_b (m_decl_b, argno_b, highlight_b);
     945           49 :     inform (&rich_loc_b,
     946              :             "...which does not match type %e",
     947              :             &type_of_parm_b);
     948           49 :   }
     949              : 
     950              :   fndecl_signature m_decl_a;
     951              :   fndecl_signature m_decl_b;
     952              : };
     953              : 
     954           81 : class decl_mismatch_context : public candidate_context
     955              : {
     956              : public:
     957           81 :   decl_mismatch_context (tree function)
     958           81 :   : m_function (function)
     959              :   {
     960           81 :     gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
     961           81 :   }
     962              : 
     963              :   void
     964          109 :   emit_any_notes_for_candidate (tree cand) final override
     965              :   {
     966          109 :     if (TREE_CODE (cand) == FUNCTION_DECL)
     967              :       {
     968          100 :         fndecl_comparison diff (cand, m_function);
     969          100 :         diff.maybe_emit_notes_for_close_match ();
     970          100 :       }
     971          109 :   }
     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      9573973 : check_classfn (tree ctype, tree function, tree template_parms)
     988              : {
     989      9573973 :   if (DECL_USE_TEMPLATE (function)
     990      1214049 :       && !(TREE_CODE (function) == TEMPLATE_DECL
     991          969 :            && DECL_TEMPLATE_SPECIALIZATION (function))
     992     10787053 :       && 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      9177786 :   if (TREE_CODE (function) == TEMPLATE_DECL)
    1008              :     {
    1009          987 :       if (template_parms
    1010         1956 :           && !comp_template_parms (template_parms,
    1011          969 :                                    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          987 :       template_parms = DECL_TEMPLATE_PARMS (function);
    1018              :     }
    1019              : 
    1020              :   /* OK, is this a definition of a member template?  */
    1021      9177786 :   bool is_template = (template_parms != NULL_TREE);
    1022              : 
    1023              :   /* [temp.mem]
    1024              : 
    1025              :      A destructor shall not be a member template.  */
    1026     18355572 :   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      9177780 :   tree pushed_scope = push_scope (ctype);
    1036      9177780 :   tree matched = NULL_TREE;
    1037      9177780 :   tree fns = get_class_binding (ctype, DECL_NAME (function));
    1038      9177780 :   bool saw_template = false;
    1039              : 
    1040     36950710 :   for (ovl_iterator iter (fns); !matched && iter; ++iter)
    1041              :     {
    1042     16440706 :       tree fndecl = *iter;
    1043              : 
    1044     16440706 :       if (TREE_CODE (fndecl) == TEMPLATE_DECL)
    1045      4148482 :         saw_template = true;
    1046              : 
    1047              :       /* A member template definition only matches a member template
    1048              :          declaration.  */
    1049     16440706 :       if (is_template != (TREE_CODE (fndecl) == TEMPLATE_DECL))
    1050      1773759 :         continue;
    1051              : 
    1052     14666947 :       if (!DECL_DECLARES_FUNCTION_P (fndecl))
    1053       304282 :         continue;
    1054              : 
    1055     14362665 :       tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
    1056     14362665 :       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     14362665 :       if (DECL_STATIC_FUNCTION_P (fndecl)
    1066     14362665 :           && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
    1067       179211 :         p1 = TREE_CHAIN (p1);
    1068              : 
    1069              :       /* ref-qualifier or absence of same must match.  */
    1070     28725330 :       if (type_memfn_rqual (TREE_TYPE (function))
    1071     14362665 :           != type_memfn_rqual (TREE_TYPE (fndecl)))
    1072           86 :         continue;
    1073              : 
    1074              :       // Include constraints in the match.
    1075     14362579 :       tree c1 = get_constraints (function);
    1076     14362579 :       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     14362579 :       if (same_type_p (TREE_TYPE (TREE_TYPE (function)),
    1082              :                        TREE_TYPE (TREE_TYPE (fndecl)))
    1083     13599415 :           && compparms (p1, p2)
    1084      9177705 :           && !disjoint_version_decls (function, fndecl)
    1085      9177705 :           && (!is_template
    1086      2309279 :               || comp_template_parms (template_parms,
    1087      2309279 :                                       DECL_TEMPLATE_PARMS (fndecl)))
    1088      9177699 :           && equivalent_constraints (c1, c2)
    1089      9177648 :           && (DECL_TEMPLATE_SPECIALIZATION (function)
    1090      9177648 :               == DECL_TEMPLATE_SPECIALIZATION (fndecl))
    1091     23540227 :           && (!DECL_TEMPLATE_SPECIALIZATION (function)
    1092       795911 :               || (DECL_TI_TEMPLATE (function) == DECL_TI_TEMPLATE (fndecl))))
    1093              :         matched = fndecl;
    1094              :     }
    1095              : 
    1096          117 :   if (!matched && !is_template && saw_template
    1097      9177795 :       && !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      9177780 :   if (!matched)
    1110              :     {
    1111          129 :       if (!COMPLETE_TYPE_P (ctype))
    1112            6 :         cxx_incomplete_type_error (DECL_SOURCE_LOCATION (function),
    1113              :                                    function, ctype);
    1114              :       else
    1115              :         {
    1116          123 :           if (DECL_CONV_FN_P (function))
    1117            6 :             fns = get_class_binding (ctype, conv_op_identifier);
    1118              : 
    1119          123 :           auto_diagnostic_group d;
    1120          123 :           error_at (DECL_SOURCE_LOCATION (function),
    1121              :                     "no declaration matches %q#D", function);
    1122          123 :           if (fns)
    1123              :             {
    1124           81 :               decl_mismatch_context ctxt (function);
    1125           81 :               print_candidates (DECL_SOURCE_LOCATION (function), fns, &ctxt);
    1126           81 :             }
    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          123 :           inform (DECL_SOURCE_LOCATION (TYPE_NAME (ctype)),
    1134              :                   "%#qT defined here", ctype);
    1135          123 :         }
    1136          129 :       matched = error_mark_node;
    1137              :     }
    1138              : 
    1139      9177780 :   if (pushed_scope)
    1140      8818916 :     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     51097858 : note_vague_linkage_fn (tree decl)
    1151              : {
    1152     51097858 :   if (processing_template_decl)
    1153              :     return;
    1154              : 
    1155     51097849 :   DECL_DEFER_OUTPUT (decl) = 1;
    1156     51097849 :   vec_safe_push (deferred_fns, decl);
    1157              : }
    1158              : 
    1159              : /* As above, but for variables.  */
    1160              : 
    1161              : void
    1162     13299109 : note_vague_linkage_variable (tree decl)
    1163              : {
    1164     13299109 :   vec_safe_push (pending_statics, decl);
    1165     13299109 : }
    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     17319388 : finish_static_data_member_decl (tree decl,
    1172              :                                 tree init, bool init_const_expr_p,
    1173              :                                 tree asmspec_tree,
    1174              :                                 int flags)
    1175              : {
    1176     17319388 :   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     17319385 :   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     17319385 :   if (! processing_template_decl)
    1188     14313630 :     vec_safe_push (pending_statics, decl);
    1189              : 
    1190     17319385 :   if (LOCAL_CLASS_P (current_class_type)
    1191              :       /* We already complained about the template definition.  */
    1192     17319385 :       && !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     35039496 :     for (tree t = current_class_type; TYPE_P (t);
    1198     17692394 :          t = CP_TYPE_CONTEXT (t))
    1199     35384860 :       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     17319385 :   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      5737633 :     DECL_IN_AGGR_P (decl) = 1;
    1215              : 
    1216     17319385 :   if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
    1217     17319385 :       && TYPE_DOMAIN (TREE_TYPE (decl)) == NULL_TREE)
    1218       110084 :     SET_VAR_HAD_UNKNOWN_BOUND (decl);
    1219              : 
    1220     17319385 :   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     12739429 :       tree type = TREE_TYPE (decl) = complete_type (TREE_TYPE (decl));
    1226     12739429 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    1227              :     }
    1228              : 
    1229     17319385 :   cp_finish_decl (decl, init, init_const_expr_p, asmspec_tree, flags);
    1230     17319383 :   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     74162728 : 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     74162728 :   tree value;
    1245     74162728 :   const char *asmspec = 0;
    1246     74162728 :   int flags;
    1247              : 
    1248     74162728 :   if (init
    1249     13481450 :       && TREE_CODE (init) == TREE_LIST
    1250            0 :       && TREE_VALUE (init) == error_mark_node
    1251     74162728 :       && TREE_CHAIN (init) == NULL_TREE)
    1252              :     init = NULL_TREE;
    1253              : 
    1254     74162728 :   int initialized;
    1255     74162728 :   if (init == ridpointers[(int)RID_DELETE]
    1256     74162728 :       || (init
    1257      9740640 :           && TREE_CODE (init) == STRING_CST
    1258          373 :           && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
    1259              :     initialized = SD_DELETED;
    1260     70421545 :   else if (init == ridpointers[(int)RID_DEFAULT])
    1261              :     initialized = SD_DEFAULTED;
    1262     63424625 :   else if (init)
    1263              :     initialized = SD_INITIALIZED;
    1264              :   else
    1265     60681278 :     initialized = SD_UNINITIALIZED;
    1266              : 
    1267     74162728 :   value = grokdeclarator (declarator, declspecs, FIELD, initialized, &attrlist);
    1268     74162722 :   if (! value || value == error_mark_node)
    1269              :     /* friend or constructor went bad.  */
    1270          340 :     return error_mark_node;
    1271     74162382 :   if (TREE_TYPE (value) == error_mark_node)
    1272              :     return value;
    1273              : 
    1274     74162223 :   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     74162223 :   if (value == void_type_node)
    1284              :     return value;
    1285              : 
    1286     74162223 :   if (DECL_NAME (value)
    1287     74162223 :       && 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     74162220 :   if (TREE_CODE (value) == TYPE_DECL)
    1296              :     {
    1297     26133837 :       DECL_NONLOCAL (value) = 1;
    1298     26133837 :       DECL_CONTEXT (value) = current_class_type;
    1299              : 
    1300     26133837 :       if (attrlist)
    1301              :         {
    1302        23029 :           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        23029 :           if (TYPE_DECL_FOR_LINKAGE_PURPOSES_P (value))
    1307           12 :             attrflags = ATTR_FLAG_TYPE_IN_PLACE;
    1308              : 
    1309        23029 :           cplus_decl_attributes (&value, attrlist, attrflags);
    1310              :         }
    1311              : 
    1312     26133837 :       if (decl_spec_seq_has_spec_p (declspecs, ds_typedef)
    1313     26133837 :           && TREE_TYPE (value) != error_mark_node
    1314     52267674 :           && TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (value))) != value)
    1315     26133189 :         set_underlying_type (value);
    1316              : 
    1317              :       /* It's important that push_template_decl below follows
    1318              :          set_underlying_type above so that the created template
    1319              :          carries the properly set type of VALUE.  */
    1320     26133837 :       if (processing_template_decl)
    1321     21604191 :         value = push_template_decl (value);
    1322              : 
    1323     26133837 :       record_locally_defined_typedef (value);
    1324     26133837 :       return value;
    1325              :     }
    1326              : 
    1327     48028383 :   int friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
    1328              : 
    1329     48028383 :   if (!friendp && DECL_IN_AGGR_P (value))
    1330              :     {
    1331            0 :       error ("%qD is already defined in %qT", value, DECL_CONTEXT (value));
    1332            0 :       return void_type_node;
    1333              :     }
    1334              : 
    1335     48028383 :   if (asmspec_tree && asmspec_tree != error_mark_node)
    1336          194 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    1337              : 
    1338     48028383 :   if (init)
    1339              :     {
    1340     13481387 :       if (TREE_CODE (value) == FUNCTION_DECL)
    1341              :         {
    1342     11113213 :           if (init == ridpointers[(int)RID_DELETE]
    1343     11113213 :               || (TREE_CODE (init) == STRING_CST
    1344          373 :                   && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
    1345              :             {
    1346      3741177 :               DECL_DELETED_FN (value) = 1;
    1347      3741177 :               DECL_DECLARED_INLINE_P (value) = 1;
    1348      3741177 :               if (TREE_CODE (init) == STRING_CST)
    1349          373 :                 DECL_INITIAL (value) = init;
    1350              :             }
    1351      7372036 :           else if (init == ridpointers[(int)RID_DEFAULT])
    1352              :             {
    1353      6996917 :               if (defaultable_fn_check (value))
    1354              :                 {
    1355      6996832 :                   DECL_DEFAULTED_FN (value) = 1;
    1356      6996832 :                   DECL_INITIALIZED_IN_CLASS_P (value) = 1;
    1357      6996832 :                   DECL_DECLARED_INLINE_P (value) = 1;
    1358              :                   /* grokfndecl set this to error_mark_node, but we want to
    1359              :                      leave it unset until synthesize_method.  */
    1360      6996832 :                   DECL_INITIAL (value) = NULL_TREE;
    1361              :                 }
    1362              :             }
    1363       375119 :           else if (TREE_CODE (init) == DEFERRED_PARSE)
    1364            0 :             error ("invalid initializer for member function %qD", value);
    1365       375119 :           else if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE)
    1366              :             {
    1367       375110 :               if (integer_zerop (init))
    1368       375071 :                 DECL_PURE_VIRTUAL_P (value) = 1;
    1369           39 :               else if (error_operand_p (init))
    1370              :                 ; /* An error has already been reported.  */
    1371              :               else
    1372            0 :                 error ("invalid initializer for member function %qD",
    1373              :                        value);
    1374              :             }
    1375              :           else
    1376              :             {
    1377            9 :               gcc_assert (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE);
    1378            9 :               location_t iloc
    1379            9 :                 = cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (value));
    1380            9 :               if (friendp)
    1381            3 :                 error_at (iloc, "initializer specified for friend "
    1382              :                           "function %qD", value);
    1383              :               else
    1384            6 :                 error_at (iloc, "initializer specified for static "
    1385              :                           "member function %qD", value);
    1386              :             }
    1387              :         }
    1388      2368174 :       else if (TREE_CODE (value) == FIELD_DECL)
    1389              :         /* C++11 NSDMI, keep going.  */;
    1390            0 :       else if (!VAR_P (value))
    1391            0 :         gcc_unreachable ();
    1392              :     }
    1393              : 
    1394              :   /* Pass friend decls back.  */
    1395     48028383 :   if ((TREE_CODE (value) == FUNCTION_DECL
    1396     20587895 :        || TREE_CODE (value) == TEMPLATE_DECL)
    1397     48028440 :       && DECL_CONTEXT (value) != current_class_type)
    1398              :     {
    1399      2113115 :       if (attrlist)
    1400            0 :         cplus_decl_attributes (&value, attrlist, 0);
    1401      2113115 :       return value;
    1402              :     }
    1403              : 
    1404              :   /* Need to set this before push_template_decl.  */
    1405     45915268 :   if (VAR_P (value))
    1406       706038 :     DECL_CONTEXT (value) = current_class_type;
    1407              : 
    1408     45915268 :   if (processing_template_decl && VAR_OR_FUNCTION_DECL_P (value))
    1409              :     {
    1410     16027510 :       value = push_template_decl (value);
    1411     16027510 :       if (error_operand_p (value))
    1412            7 :         return error_mark_node;
    1413              :     }
    1414              : 
    1415     45915261 :   if (attrlist)
    1416       903717 :     cplus_decl_attributes (&value, attrlist, 0);
    1417              : 
    1418     45915261 :   if (init && DIRECT_LIST_INIT_P (init))
    1419              :     flags = LOOKUP_NORMAL;
    1420              :   else
    1421              :     flags = LOOKUP_IMPLICIT;
    1422              : 
    1423     45915261 :   switch (TREE_CODE (value))
    1424              :     {
    1425       706034 :     case VAR_DECL:
    1426       706034 :       finish_static_data_member_decl (value, init, init_const_expr_p,
    1427              :                                       asmspec_tree, flags);
    1428       706034 :       return value;
    1429              : 
    1430     19881800 :     case FIELD_DECL:
    1431     19881800 :       if (asmspec)
    1432            6 :         error ("%<asm%> specifiers are not permitted on non-static data members");
    1433     19881800 :       if (DECL_INITIAL (value) == error_mark_node)
    1434            0 :         init = error_mark_node;
    1435     19881800 :       cp_finish_decl (value, init, /*init_const_expr_p=*/false,
    1436              :                       NULL_TREE, flags);
    1437     19881800 :       DECL_IN_AGGR_P (value) = 1;
    1438     19881800 :       return value;
    1439              : 
    1440     25327427 :     case  FUNCTION_DECL:
    1441     25327427 :       if (asmspec)
    1442           92 :         set_user_assembler_name (value, asmspec);
    1443              : 
    1444     25327427 :       cp_finish_decl (value,
    1445              :                       /*init=*/NULL_TREE,
    1446              :                       /*init_const_expr_p=*/false,
    1447              :                       asmspec_tree, flags);
    1448              : 
    1449              :       /* Pass friends back this way.  */
    1450     25327427 :       if (DECL_UNIQUE_FRIEND_P (value))
    1451            0 :         return void_type_node;
    1452              : 
    1453     25327427 :       DECL_IN_AGGR_P (value) = 1;
    1454     25327427 :       return value;
    1455              : 
    1456            0 :     default:
    1457            0 :       gcc_unreachable ();
    1458              :     }
    1459              :   return NULL_TREE;
    1460              : }
    1461              : 
    1462              : /* Like grokfield, but just for the initial grok of an initialized static
    1463              :    member.  Used to be able to push the new decl before parsing the
    1464              :    initialiser.  */
    1465              : 
    1466              : tree
    1467     12739438 : start_initialized_static_member (const cp_declarator *declarator,
    1468              :                                  cp_decl_specifier_seq *declspecs,
    1469              :                                  tree attrlist)
    1470              : {
    1471     12739438 :   tree value = grokdeclarator (declarator, declspecs, FIELD, SD_INITIALIZED,
    1472     12739438 :                                &attrlist);
    1473     12739438 :   if (!value || error_operand_p (value))
    1474            3 :     return error_mark_node;
    1475     12739435 :   if (TREE_CODE (value) == TYPE_DECL)
    1476              :     {
    1477            0 :       error_at (declarator->init_loc,
    1478              :                 "typedef %qD is initialized (use %qs instead)",
    1479              :                 value, "decltype");
    1480            0 :       return error_mark_node;
    1481              :     }
    1482     12739435 :   else if (TREE_CODE (value) == FUNCTION_DECL)
    1483              :     {
    1484            0 :       if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE)
    1485            0 :         error_at (declarator->init_loc,
    1486              :                   "invalid initializer for member function %qD",
    1487              :                   value);
    1488            0 :       else if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE)
    1489            0 :         error_at (declarator->init_loc,
    1490              :                   "initializer specified for static member function %qD",
    1491              :                   value);
    1492              :       else
    1493            0 :         gcc_unreachable ();
    1494            0 :       return error_mark_node;
    1495              :     }
    1496     12739435 :   else if (TREE_CODE (value) == FIELD_DECL)
    1497              :     {
    1498              :       /* NSDM marked 'static', grokdeclarator has already errored.  */
    1499            3 :       gcc_checking_assert (seen_error ());
    1500            3 :       return error_mark_node;
    1501              :     }
    1502     12739432 :   gcc_checking_assert (VAR_P (value));
    1503              : 
    1504     12739432 :   DECL_CONTEXT (value) = current_class_type;
    1505     12739432 :   DECL_INITIALIZED_IN_CLASS_P (value) = true;
    1506              : 
    1507     12739432 :   if (processing_template_decl)
    1508              :     {
    1509      2843746 :       value = push_template_decl (value);
    1510      2843746 :       if (error_operand_p (value))
    1511            2 :         return error_mark_node;
    1512              :     }
    1513              : 
    1514     12739430 :   if (attrlist)
    1515       144912 :     cplus_decl_attributes (&value, attrlist, 0);
    1516              : 
    1517              :   /* When defining a template we need to register the TEMPLATE_DECL.  */
    1518     12739430 :   tree maybe_template = value;
    1519     12739430 :   if (template_parm_scope_p ())
    1520              :     {
    1521       394295 :       if (!DECL_TEMPLATE_SPECIALIZATION (value))
    1522       350038 :         maybe_template = DECL_TI_TEMPLATE (value);
    1523              :       else
    1524              :         maybe_template = NULL_TREE;
    1525              :     }
    1526     12695173 :   if (maybe_template)
    1527     12695173 :     finish_member_declaration (maybe_template);
    1528              : 
    1529     12739430 :   return value;
    1530              : }
    1531              : 
    1532              : /* Whether DECL is a static data member initialized at the point
    1533              :    of declaration within its class.  */
    1534              : 
    1535              : bool
    1536     36317388 : is_static_data_member_initialized_in_class (tree decl)
    1537              : {
    1538     36317388 :   if (!decl || decl == error_mark_node)
    1539              :     return false;
    1540              : 
    1541     36316178 :   tree inner = STRIP_TEMPLATE (decl);
    1542     21911747 :   return (inner
    1543     36316178 :           && VAR_P (inner)
    1544     13252902 :           && DECL_CLASS_SCOPE_P (inner)
    1545     35158441 :           && DECL_INITIALIZED_IN_CLASS_P (inner));
    1546              : }
    1547              : 
    1548              : /* Finish a declaration prepared with start_initialized_static_member.  */
    1549              : 
    1550              : void
    1551     12739435 : finish_initialized_static_member (tree decl, tree init, tree asmspec)
    1552              : {
    1553     12739435 :   if (decl == error_mark_node)
    1554              :     return;
    1555     12739427 :   gcc_checking_assert (is_static_data_member_initialized_in_class (decl));
    1556              : 
    1557     12739427 :   int flags;
    1558     12739427 :   if (init && DIRECT_LIST_INIT_P (init))
    1559              :     flags = LOOKUP_NORMAL;
    1560              :   else
    1561              :     flags = LOOKUP_IMPLICIT;
    1562     12739427 :   finish_static_data_member_decl (decl, init, /*init_const_expr_p=*/true,
    1563              :                                   asmspec, flags);
    1564              : }
    1565              : 
    1566              : /* Like `grokfield', but for bitfields.
    1567              :    WIDTH is the width of the bitfield, a constant expression.
    1568              :    The other parameters are as for grokfield.  */
    1569              : 
    1570              : tree
    1571       613787 : grokbitfield (const cp_declarator *declarator,
    1572              :               cp_decl_specifier_seq *declspecs, tree width, tree init,
    1573              :               tree attrlist)
    1574              : {
    1575       613787 :   tree value = grokdeclarator (declarator, declspecs, BITFIELD,
    1576       613787 :                                init != NULL_TREE, &attrlist);
    1577              : 
    1578       613787 :   if (value == error_mark_node)
    1579              :     return NULL_TREE; /* friends went bad.  */
    1580              : 
    1581       613781 :   tree type = TREE_TYPE (value);
    1582       613781 :   if (type == error_mark_node)
    1583              :     return value;
    1584              : 
    1585              :   /* Pass friendly classes back.  */
    1586       613734 :   if (VOID_TYPE_P (value))
    1587            0 :     return void_type_node;
    1588              : 
    1589       613734 :   if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    1590       613734 :       && (INDIRECT_TYPE_P (type) || !dependent_type_p (type)))
    1591              :     {
    1592           33 :       error_at (DECL_SOURCE_LOCATION (value),
    1593              :                 "bit-field %qD with non-integral type %qT",
    1594              :                 value, type);
    1595           33 :       return error_mark_node;
    1596              :     }
    1597              : 
    1598       613701 :   if (TREE_CODE (value) == TYPE_DECL)
    1599              :     {
    1600            6 :       error_at (DECL_SOURCE_LOCATION (value),
    1601              :                 "cannot declare %qD to be a bit-field type", value);
    1602            6 :       return NULL_TREE;
    1603              :     }
    1604              : 
    1605              :   /* Usually, finish_struct_1 catches bitfields with invalid types.
    1606              :      But, in the case of bitfields with function type, we confuse
    1607              :      ourselves into thinking they are member functions, so we must
    1608              :      check here.  */
    1609       613695 :   if (TREE_CODE (value) == FUNCTION_DECL)
    1610              :     {
    1611            3 :       error_at (DECL_SOURCE_LOCATION (value),
    1612              :                 "cannot declare bit-field %qD with function type", value);
    1613            3 :       return NULL_TREE;
    1614              :     }
    1615              : 
    1616       613692 :   if (TYPE_WARN_IF_NOT_ALIGN (type))
    1617              :     {
    1618            9 :       error_at (DECL_SOURCE_LOCATION (value), "cannot declare bit-field "
    1619              :                 "%qD with %<warn_if_not_aligned%> type", value);
    1620            9 :       return NULL_TREE;
    1621              :     }
    1622              : 
    1623       613683 :   if (DECL_IN_AGGR_P (value))
    1624              :     {
    1625            0 :       error ("%qD is already defined in the class %qT", value,
    1626            0 :              DECL_CONTEXT (value));
    1627            0 :       return void_type_node;
    1628              :     }
    1629              : 
    1630       613683 :   if (TREE_STATIC (value))
    1631              :     {
    1632            6 :       error_at (DECL_SOURCE_LOCATION (value),
    1633              :                 "static member %qD cannot be a bit-field", value);
    1634            6 :       return NULL_TREE;
    1635              :     }
    1636              : 
    1637              :   /* [class.bit]/2 "An unnamed bit-field shall not be declared with
    1638              :      a cv-qualified type."  */
    1639       613677 :   if (!DECL_NAME (value) && TYPE_QUALS (type) != TYPE_UNQUALIFIED)
    1640           18 :     pedwarn (DECL_SOURCE_LOCATION (value), 0,
    1641              :              "unnamed bit-field cannot be cv-qualified");
    1642              : 
    1643       613677 :   int flags = LOOKUP_IMPLICIT;
    1644       613677 :   if (init && DIRECT_LIST_INIT_P (init))
    1645              :     flags = LOOKUP_NORMAL;
    1646       613677 :   cp_finish_decl (value, init, false, NULL_TREE, flags);
    1647              : 
    1648       613677 :   if (width != error_mark_node)
    1649              :     {
    1650              :       /* The width must be an integer type.  */
    1651       613660 :       if (!type_dependent_expression_p (width)
    1652       613660 :           && !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (width)))
    1653           21 :         error ("width of bit-field %qD has non-integral type %qT", value,
    1654           21 :                TREE_TYPE (width));
    1655       613639 :       else if (!check_for_bare_parameter_packs (width))
    1656              :         {
    1657              :           /* Temporarily stash the width in DECL_BIT_FIELD_REPRESENTATIVE.
    1658              :              check_bitfield_decl picks it from there later and sets DECL_SIZE
    1659              :              accordingly.  */
    1660       613633 :           DECL_BIT_FIELD_REPRESENTATIVE (value) = width;
    1661       613633 :           SET_DECL_C_BIT_FIELD (value);
    1662              :         }
    1663              :     }
    1664              : 
    1665       613677 :   DECL_IN_AGGR_P (value) = 1;
    1666              : 
    1667       613677 :   if (attrlist)
    1668         1212 :     cplus_decl_attributes (&value, attrlist, /*flags=*/0);
    1669              : 
    1670       613677 :   return value;
    1671              : }
    1672              : 
    1673              : 
    1674              : /* Returns true iff ATTR is an attribute which needs to be applied at
    1675              :    instantiation time rather than template definition time.  */
    1676              : 
    1677              : static bool
    1678     18382431 : is_late_template_attribute (tree attr, tree decl)
    1679              : {
    1680     18382431 :   tree name = get_attribute_name (attr);
    1681     18382431 :   tree args = TREE_VALUE (attr);
    1682     18382431 :   const struct attribute_spec *spec
    1683     18382431 :     = lookup_attribute_spec (TREE_PURPOSE (attr));
    1684     18382431 :   tree arg;
    1685              : 
    1686              :   /* Handle all annotations as late, so that they aren't incorrectly
    1687              :      reordered if some have dependent expressions and others don't.  */
    1688     18382431 :   if (annotation_p (attr))
    1689              :     return true;
    1690              : 
    1691     18382351 :   if (!spec)
    1692              :     /* Unknown attribute.  */
    1693              :     return false;
    1694              : 
    1695              :   /* Attribute weak handling wants to write out assembly right away.  */
    1696     18382317 :   if (is_attribute_p ("weak", name))
    1697              :     return true;
    1698              : 
    1699              :   /* Attributes used and unused or std attribute maybe_unused are applied
    1700              :      directly to typedefs for the benefit of
    1701              :      maybe_warn_unused_local_typedefs.  */
    1702     18382314 :   if (TREE_CODE (decl) == TYPE_DECL
    1703     18382314 :       && (is_attribute_p ("unused", name)
    1704        19806 :           || is_attribute_p ("used", name)
    1705        19800 :           || (is_attribute_p ("maybe_unused", name)
    1706           10 :               && get_attribute_namespace (attr) == NULL_TREE)))
    1707              :     return false;
    1708              : 
    1709              :   /* Attribute tls_model wants to modify the symtab.  */
    1710     18382064 :   if (is_attribute_p ("tls_model", name))
    1711              :     return true;
    1712              : 
    1713              :   /* #pragma omp declare simd attribute needs to be always deferred.  */
    1714     18382061 :   if (flag_openmp
    1715     18382061 :       && is_attribute_p ("omp declare simd", name))
    1716              :     return true;
    1717              : 
    1718     18381130 :   if (args == error_mark_node)
    1719              :     return false;
    1720              : 
    1721              :   /* An attribute pack is clearly dependent.  */
    1722     18381130 :   if (args && PACK_EXPANSION_P (args))
    1723              :     return true;
    1724              : 
    1725              :   /* If any of the arguments are dependent expressions, we can't evaluate
    1726              :      the attribute until instantiation time.  */
    1727     19322205 :   for (arg = args; arg; arg = TREE_CHAIN (arg))
    1728              :     {
    1729      1075296 :       tree t = TREE_VALUE (arg);
    1730              : 
    1731              :       /* If the first attribute argument is an identifier, only consider
    1732              :          second and following arguments.  Attributes like mode, format,
    1733              :          cleanup and several target specific attributes aren't late
    1734              :          just because they have an IDENTIFIER_NODE as first argument.  */
    1735      1113454 :       if (arg == args
    1736      1034139 :           && get_attribute_namespace (attr) == gnu_identifier
    1737       871781 :           && attribute_takes_identifier_p (name)
    1738      1075296 :           && identifier_p (t))
    1739        38158 :         continue;
    1740              : 
    1741      1037138 :       if (value_dependent_expression_p (t))
    1742              :         return true;
    1743              :     }
    1744              : 
    1745     18246909 :   if (TREE_CODE (decl) == TYPE_DECL
    1746     18229745 :       || TYPE_P (decl)
    1747     17763670 :       || spec->type_required)
    1748              :     {
    1749       893567 :       tree type = TYPE_P (decl) ? decl : TREE_TYPE (decl);
    1750              : 
    1751       427492 :       if (!type)
    1752              :         return true;
    1753              : 
    1754              :       /* Some attributes specifically apply to templates.  */
    1755       893564 :       if (is_attribute_p ("abi_tag", name)
    1756       893540 :           || is_attribute_p ("deprecated", name)
    1757       511326 :           || is_attribute_p ("unavailable", name)
    1758       511320 :           || is_attribute_p ("visibility", name)
    1759      1404872 :           || is_attribute_p ("no_specializations", name))
    1760              :         return false;
    1761              :       /* Defer most attributes on dependent types.  This is not
    1762              :          necessary in all cases, but is the better default.  */
    1763       438373 :       else if (dependent_type_p (type))
    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    246281843 : splice_template_attributes (tree *attr_p, tree decl)
    1779              : {
    1780    246281843 :   tree *p = attr_p;
    1781    246281843 :   tree late_attrs = NULL_TREE;
    1782    246281843 :   tree *q = &late_attrs;
    1783              : 
    1784    246281843 :   if (!p || *p == error_mark_node)
    1785              :     return NULL_TREE;
    1786              : 
    1787    264664274 :   for (; *p; )
    1788              :     {
    1789     18382431 :       if (is_late_template_attribute (*p, decl))
    1790              :         {
    1791       520163 :           ATTR_IS_DEPENDENT (*p) = 1;
    1792       520163 :           *q = *p;
    1793       520163 :           *p = TREE_CHAIN (*p);
    1794       520163 :           q = &TREE_CHAIN (*q);
    1795       520163 :           *q = NULL_TREE;
    1796              :         }
    1797              :       else
    1798     17862268 :         p = &TREE_CHAIN (*p);
    1799              :     }
    1800              : 
    1801    246281843 :   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       518236 : save_template_attributes (tree late_attrs, tree *decl_p, int flags)
    1809              : {
    1810       518236 :   tree *q;
    1811              : 
    1812       518236 :   if (!late_attrs)
    1813              :     return;
    1814              : 
    1815       518236 :   if (DECL_P (*decl_p))
    1816       493062 :     q = &DECL_ATTRIBUTES (*decl_p);
    1817              :   else
    1818        25174 :     q = &TYPE_ATTRIBUTES (*decl_p);
    1819              : 
    1820       518236 :   tree old_attrs = *q;
    1821              : 
    1822              :   /* Place the late attributes at the beginning of the attribute
    1823              :      list.  */
    1824       518236 :   late_attrs = chainon (late_attrs, *q);
    1825       518236 :   if (*q != late_attrs
    1826       518236 :       && !DECL_P (*decl_p)
    1827        25174 :       && !(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       518184 :     *q = late_attrs;
    1839              : 
    1840       518236 :   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        25134 :       tree variant;
    1846        25276 :       for (variant = TYPE_NEXT_VARIANT (*decl_p); variant;
    1847          142 :            variant = TYPE_NEXT_VARIANT (variant))
    1848              :         {
    1849          142 :           gcc_assert (TYPE_ATTRIBUTES (variant) == old_attrs);
    1850          142 :           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   2002103262 : any_dependent_type_attributes_p (tree attrs)
    1860              : {
    1861   2036955538 :   for (tree a = attrs; a; a = TREE_CHAIN (a))
    1862     34853503 :     if (ATTR_IS_DEPENDENT (a))
    1863              :       {
    1864      2037202 :         const attribute_spec *as = lookup_attribute_spec (TREE_PURPOSE (a));
    1865      2037202 :         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       403325 : attributes_naming_typedef_ok (tree attrs)
    1877              : {
    1878       415041 :   for (; attrs; attrs = TREE_CHAIN (attrs))
    1879              :     {
    1880        11719 :       tree name = get_attribute_name (attrs);
    1881        11719 :       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        31540 : cp_reconstruct_complex_type (tree type, tree bottom)
    1891              : {
    1892        31540 :   tree inner, outer;
    1893              : 
    1894        31540 :   if (TYPE_PTR_P (type))
    1895              :     {
    1896           42 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1897           42 :       outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
    1898           42 :                                            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          131 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1919          131 :       outer = build_function_type (inner, TYPE_ARG_TYPES (type),
    1920          131 :                                    TYPE_NO_NAMED_ARGS_STDARG_P (type));
    1921          131 :       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          200 :   if (TYPE_ATTRIBUTES (type))
    1942            0 :     outer = cp_build_type_attribute_variant (outer, TYPE_ATTRIBUTES (type));
    1943          200 :   outer = cp_build_qualified_type (outer, cp_type_quals (type));
    1944          200 :   outer = cxx_copy_lang_qualifiers (outer, type);
    1945              : 
    1946          200 :   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    394550148 : cp_check_const_attributes (tree attributes)
    1954              : {
    1955    394550148 :   if (attributes == error_mark_node)
    1956              :     return;
    1957              : 
    1958              :   tree attr;
    1959    435991314 :   for (attr = attributes; attr; attr = TREE_CHAIN (attr))
    1960              :     {
    1961              :       /* Annotation arguments are handled in handle_annotation_attribute.  */
    1962     41441166 :       if (annotation_p (attr))
    1963          758 :         continue;
    1964              : 
    1965     41440408 :       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     41440408 :       bool manifestly_const_eval
    1970     41440408 :         = is_attribute_p ("aligned", get_attribute_name (attr));
    1971     53583989 :       for (arg = TREE_VALUE (attr); arg && TREE_CODE (arg) == TREE_LIST;
    1972     12143581 :            arg = TREE_CHAIN (arg))
    1973              :         {
    1974     12143581 :           tree expr = TREE_VALUE (arg);
    1975     12143581 :           if (EXPR_P (expr))
    1976         8898 :             TREE_VALUE (arg)
    1977         4449 :               = 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     25433564 : maybe_propagate_warmth_attributes (tree fn, tree type)
    1988              : {
    1989     25433564 :   if (fn == NULL_TREE || type == NULL_TREE
    1990     25433564 :       || !(TREE_CODE (type) == RECORD_TYPE
    1991              :            || TREE_CODE (type) == UNION_TYPE))
    1992              :     return;
    1993              : 
    1994     25433564 :   tree has_cold_attr = lookup_attribute ("cold", TYPE_ATTRIBUTES (type));
    1995     25433564 :   tree has_hot_attr = lookup_attribute ("hot", TYPE_ATTRIBUTES (type));
    1996              : 
    1997     25433564 :   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    394482917 : find_last_decl (tree decl)
    2032              : {
    2033    394482917 :   tree last_decl = NULL_TREE;
    2034              : 
    2035    394482917 :   if (tree name = DECL_P (decl) ? DECL_NAME (decl) : NULL_TREE)
    2036              :     {
    2037              :       /* Template specializations are matched elsewhere.  */
    2038    328895205 :       if (DECL_LANG_SPECIFIC (decl)
    2039    328895205 :           && DECL_USE_TEMPLATE (decl))
    2040              :         return NULL_TREE;
    2041              : 
    2042              :       /* Look up the declaration in its scope.  */
    2043    323637739 :       tree pushed_scope = NULL_TREE;
    2044    323637739 :       if (tree ctype = DECL_CONTEXT (decl))
    2045    248193950 :         pushed_scope = push_scope (ctype);
    2046              : 
    2047    323637739 :       last_decl = lookup_name (name);
    2048              : 
    2049    323637739 :       if (pushed_scope)
    2050    140005551 :         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    323637739 :       if (last_decl && BASELINK_P (last_decl))
    2055       183553 :         last_decl = BASELINK_FUNCTIONS (last_decl);
    2056              :     }
    2057              : 
    2058     65525215 :   if (!last_decl)
    2059              :     return NULL_TREE;
    2060              : 
    2061    100460550 :   if (DECL_P (last_decl) || TREE_CODE (last_decl) == OVERLOAD)
    2062              :     {
    2063              :       /* A set of overloads of the same function.  */
    2064    571545900 :       for (lkp_iterator iter (last_decl); iter; ++iter)
    2065              :         {
    2066    481611916 :           if (TREE_CODE (*iter) == OVERLOAD)
    2067            0 :             continue;
    2068              : 
    2069    481611916 :           tree d = *iter;
    2070              : 
    2071              :           /* We can't compare versions in the middle of processing the
    2072              :              attribute that has the version.  */
    2073    481611916 :           if (TREE_CODE (d) == FUNCTION_DECL
    2074    481611916 :               && DECL_FUNCTION_VERSIONED (d))
    2075     10507461 :             return NULL_TREE;
    2076              : 
    2077    481610779 :           if (decls_match (decl, d, /*record_decls=*/false))
    2078              :             return d;
    2079              :         }
    2080     89933984 :       return NULL_TREE;
    2081              :     }
    2082              : 
    2083              :   return NULL_TREE;
    2084              : }
    2085              : 
    2086              : /* Like decl_attributes, but handle C++ complexity.  */
    2087              : 
    2088              : void
    2089    394548159 : cplus_decl_attributes (tree *decl, tree attributes, int flags)
    2090              : {
    2091    394548159 :   if (*decl == NULL_TREE || *decl == void_type_node
    2092    394548159 :       || *decl == error_mark_node || attributes == error_mark_node)
    2093              :     return;
    2094              : 
    2095              :   /* Add implicit "omp declare target" attribute if requested.  */
    2096    394548080 :   if (vec_safe_length (scope_chain->omp_declare_target_attribute)
    2097        11731 :       && ((VAR_P (*decl)
    2098         2218 :            && (TREE_STATIC (*decl) || DECL_EXTERNAL (*decl)))
    2099         3389 :           || TREE_CODE (*decl) == FUNCTION_DECL))
    2100              :     {
    2101         1758 :       if (VAR_P (*decl)
    2102         1758 :           && DECL_CLASS_SCOPE_P (*decl))
    2103            0 :         error ("%q+D static data member inside of declare target directive",
    2104              :                *decl);
    2105              :       else
    2106              :         {
    2107         1758 :           if (VAR_P (*decl)
    2108         1758 :               && (processing_template_decl
    2109          337 :                   || !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         1706 :             attributes = tree_cons (get_identifier ("omp declare target"),
    2115              :                                     NULL_TREE, attributes);
    2116         1758 :           if (TREE_CODE (*decl) == FUNCTION_DECL)
    2117              :             {
    2118         1421 :               cp_omp_declare_target_attr &last
    2119         1421 :                 = scope_chain->omp_declare_target_attribute->last ();
    2120         1421 :               int device_type = MAX (last.device_type, 0);
    2121         1421 :               if ((device_type & OMP_CLAUSE_DEVICE_TYPE_HOST) != 0
    2122         1421 :                   && !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         1421 :               if ((device_type & OMP_CLAUSE_DEVICE_TYPE_NOHOST) != 0
    2128         1421 :                   && !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         1421 :               if (last.indirect
    2134         1421 :                   && !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    394548080 :   tree late_attrs = NULL_TREE;
    2144    394548080 :   if (processing_template_decl)
    2145              :     {
    2146    246268527 :       if (check_for_bare_parameter_packs (attributes))
    2147              :         return;
    2148              : 
    2149              :       /* Ask the target now rather than leaving it to decl_attributes below:
    2150              :          a target that adds an attribute of its own in reaction to one of
    2151              :          these would never see the ones we are about to splice out.  */
    2152    246268518 :       targetm.insert_attributes (STRIP_TEMPLATE (*decl), &attributes);
    2153              : 
    2154    246268518 :       late_attrs = splice_template_attributes (&attributes, *decl);
    2155              :     }
    2156              : 
    2157    394548071 :   cp_check_const_attributes (attributes);
    2158              : 
    2159    394548071 :   if (flag_openmp || flag_openmp_simd)
    2160              :     {
    2161              :       bool diagnosed = false;
    2162      1423446 :       for (tree *pa = &attributes; *pa; )
    2163              :         {
    2164       194979 :           if (get_attribute_namespace (*pa) == omp_identifier)
    2165              :             {
    2166          209 :               tree name = get_attribute_name (*pa);
    2167          209 :               if (is_attribute_p ("directive", name)
    2168            0 :                   || is_attribute_p ("sequence", name)
    2169          209 :                   || is_attribute_p ("decl", name))
    2170              :                 {
    2171          209 :                   const char *p = NULL;
    2172          209 :                   if (TREE_VALUE (*pa) == NULL_TREE)
    2173            9 :                     p = IDENTIFIER_POINTER (name);
    2174          409 :                   for (tree a = TREE_VALUE (*pa); a; a = TREE_CHAIN (a))
    2175              :                     {
    2176          200 :                       tree d = TREE_VALUE (a);
    2177          200 :                       gcc_assert (TREE_CODE (d) == DEFERRED_PARSE);
    2178          340 :                       if (TREE_PUBLIC (d)
    2179          143 :                           && (VAR_P (*decl)
    2180           10 :                               || TREE_CODE (*decl) == FUNCTION_DECL)
    2181          343 :                           && cp_maybe_parse_omp_decl (*decl, d))
    2182          140 :                         continue;
    2183           60 :                       p = TREE_PUBLIC (d) ? "decl" : "directive";
    2184              :                     }
    2185          209 :                   if (p && !diagnosed)
    2186              :                     {
    2187           69 :                       error ("%<omp::%s%> not allowed to be specified in "
    2188              :                              "this context", p);
    2189           69 :                       diagnosed = true;
    2190              :                     }
    2191          209 :                   if (p)
    2192              :                     {
    2193           69 :                       *pa = TREE_CHAIN (*pa);
    2194           69 :                       continue;
    2195              :                     }
    2196              :                 }
    2197              :             }
    2198       194910 :           pa = &TREE_CHAIN (*pa);
    2199              :         }
    2200              :     }
    2201              : 
    2202    394548071 :   if (TREE_CODE (*decl) == TEMPLATE_DECL)
    2203          969 :     decl = &DECL_TEMPLATE_RESULT (*decl);
    2204              : 
    2205    394548071 :   if (TREE_TYPE (*decl) && TYPE_PTRMEMFUNC_P (TREE_TYPE (*decl)))
    2206              :     {
    2207        65154 :       attributes
    2208        65154 :         = decl_attributes (decl, attributes, flags | ATTR_FLAG_FUNCTION_NEXT);
    2209        65154 :       decl_attributes (&TYPE_PTRMEMFUNC_FN_TYPE_RAW (TREE_TYPE (*decl)),
    2210              :                        attributes, flags);
    2211              :     }
    2212              :   else
    2213              :     {
    2214    394482917 :       tree last_decl = find_last_decl (*decl);
    2215    394482917 :       decl_attributes (decl, attributes, flags, last_decl);
    2216              :     }
    2217              : 
    2218    394548071 :   if (late_attrs)
    2219       518236 :     save_template_attributes (late_attrs, decl, flags);
    2220              : 
    2221              :   /* Propagate deprecation out to the template.  */
    2222    394548071 :   if (TREE_DEPRECATED (*decl))
    2223      1719551 :     if (tree ti = get_template_info (*decl))
    2224              :       {
    2225       491791 :         tree tmpl = TI_TEMPLATE (ti);
    2226       491791 :         tree pattern = (TYPE_P (*decl) ? TREE_TYPE (tmpl)
    2227       491791 :                         : DECL_TEMPLATE_RESULT (tmpl));
    2228       491791 :         if (*decl == pattern)
    2229       448459 :           TREE_DEPRECATED (tmpl) = true;
    2230              :       }
    2231              : 
    2232              :   /* Likewise, propagate unavailability out to the template.  */
    2233    394548071 :   if (TREE_UNAVAILABLE (*decl))
    2234          252 :     if (tree ti = get_template_info (*decl))
    2235              :       {
    2236            9 :         tree tmpl = TI_TEMPLATE (ti);
    2237            9 :         tree pattern = (TYPE_P (*decl) ? TREE_TYPE (tmpl)
    2238            9 :                         : DECL_TEMPLATE_RESULT (tmpl));
    2239            9 :         if (*decl == pattern)
    2240            9 :           TREE_UNAVAILABLE (tmpl) = true;
    2241              :       }
    2242              : 
    2243    394548071 :   if (VAR_P (*decl) && CP_DECL_THREAD_LOCAL_P (*decl))
    2244              :     {
    2245              :       // tls_model attribute can set a stronger TLS access model.
    2246        20162 :       tls_model model = DECL_TLS_MODEL (*decl);
    2247              :       // Don't upgrade TLS model if TLS model isn't set yet.
    2248        20162 :       if (model != TLS_MODEL_NONE)
    2249              :         {
    2250        20037 :           tls_model default_model = decl_default_tls_model (*decl);
    2251        20037 :           if (default_model > model)
    2252        19803 :             set_decl_tls_model (*decl, default_model);
    2253              :         }
    2254              :     }
    2255              : 
    2256              :   /* For target_version semantics, mark any annotated function as versioned
    2257              :      so that it gets mangled even when on its own in a TU.  */
    2258              :   if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    2259              :       && TREE_CODE (*decl) == FUNCTION_DECL
    2260              :       && get_target_version (*decl).is_valid ())
    2261              :     maybe_mark_function_versioned (*decl);
    2262              : }
    2263              : 
    2264              : /* Walks through the namespace- or function-scope anonymous union
    2265              :    OBJECT, with the indicated TYPE, building appropriate VAR_DECLs.
    2266              :    Returns one of the fields for use in the mangled name.  */
    2267              : 
    2268              : static tree
    2269          457 : build_anon_union_vars (tree type, tree object)
    2270              : {
    2271          457 :   tree main_decl = NULL_TREE;
    2272          457 :   tree field;
    2273              : 
    2274              :   /* Rather than write the code to handle the non-union case,
    2275              :      just give an error.  */
    2276          457 :   if (TREE_CODE (type) != UNION_TYPE)
    2277              :     {
    2278            6 :       error_at (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    2279              :                 "anonymous struct not inside named type");
    2280            6 :       return error_mark_node;
    2281              :     }
    2282              : 
    2283          451 :   for (field = TYPE_FIELDS (type);
    2284         1578 :        field != NULL_TREE;
    2285         1127 :        field = DECL_CHAIN (field))
    2286              :     {
    2287         1127 :       tree decl;
    2288         1127 :       tree ref;
    2289              : 
    2290         1127 :       if (DECL_ARTIFICIAL (field))
    2291          555 :         continue;
    2292          572 :       if (TREE_CODE (field) != FIELD_DECL)
    2293              :         {
    2294            0 :           permerror (DECL_SOURCE_LOCATION (field),
    2295              :                      "%q#D invalid; an anonymous union can only "
    2296              :                      "have non-static data members", field);
    2297            0 :           continue;
    2298              :         }
    2299              : 
    2300          572 :       if (TREE_PRIVATE (field))
    2301            6 :         permerror (DECL_SOURCE_LOCATION (field),
    2302              :                    "private member %q#D in anonymous union", field);
    2303          566 :       else if (TREE_PROTECTED (field))
    2304            0 :         permerror (DECL_SOURCE_LOCATION (field),
    2305              :                    "protected member %q#D in anonymous union", field);
    2306              : 
    2307          572 :       if (processing_template_decl)
    2308           66 :         ref = build_min_nt_loc (UNKNOWN_LOCATION, COMPONENT_REF, object,
    2309              :                                 field, NULL_TREE);
    2310              :       else
    2311          506 :         ref = build_class_member_access_expr (object, field, NULL_TREE,
    2312              :                                               false, tf_warning_or_error);
    2313              : 
    2314          572 :       if (DECL_NAME (field))
    2315              :         {
    2316          531 :           tree base;
    2317              : 
    2318          531 :           decl = build_decl (input_location,
    2319          531 :                              VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
    2320          531 :           DECL_ANON_UNION_VAR_P (decl) = 1;
    2321          531 :           DECL_ARTIFICIAL (decl) = 1;
    2322              : 
    2323          531 :           base = get_base_address (object);
    2324          531 :           TREE_PUBLIC (decl) = TREE_PUBLIC (base);
    2325          531 :           TREE_STATIC (decl) = TREE_STATIC (base);
    2326          531 :           DECL_EXTERNAL (decl) = DECL_EXTERNAL (base);
    2327              : 
    2328          531 :           SET_DECL_VALUE_EXPR (decl, ref);
    2329          531 :           DECL_HAS_VALUE_EXPR_P (decl) = 1;
    2330              : 
    2331          531 :           decl = pushdecl (decl);
    2332              :         }
    2333           41 :       else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    2334           41 :         decl = build_anon_union_vars (TREE_TYPE (field), ref);
    2335              :       else
    2336              :         decl = 0;
    2337              : 
    2338          572 :       if (main_decl == NULL_TREE)
    2339         1127 :         main_decl = decl;
    2340              :     }
    2341              : 
    2342              :   return main_decl;
    2343              : }
    2344              : 
    2345              : /* Finish off the processing of a UNION_TYPE structure.  If the union is an
    2346              :    anonymous union, then all members must be laid out together.  PUBLIC_P
    2347              :    is nonzero if this union is not declared static.  */
    2348              : 
    2349              : void
    2350          425 : finish_anon_union (tree anon_union_decl)
    2351              : {
    2352          425 :   tree type;
    2353          425 :   tree main_decl;
    2354          425 :   bool public_p;
    2355              : 
    2356          425 :   if (anon_union_decl == error_mark_node)
    2357              :     return;
    2358              : 
    2359          416 :   type = TREE_TYPE (anon_union_decl);
    2360          416 :   public_p = TREE_PUBLIC (anon_union_decl);
    2361              : 
    2362              :   /* The VAR_DECL's context is the same as the TYPE's context.  */
    2363          416 :   DECL_CONTEXT (anon_union_decl) = DECL_CONTEXT (TYPE_NAME (type));
    2364              : 
    2365          416 :   if (TYPE_FIELDS (type) == NULL_TREE)
    2366              :     return;
    2367              : 
    2368          416 :   if (public_p)
    2369              :     {
    2370            0 :       error ("namespace-scope anonymous aggregates must be static");
    2371            0 :       return;
    2372              :     }
    2373              : 
    2374          416 :   main_decl = build_anon_union_vars (type, anon_union_decl);
    2375          416 :   if (main_decl == error_mark_node)
    2376              :     return;
    2377          392 :   if (main_decl == NULL_TREE)
    2378              :     {
    2379           12 :       pedwarn (input_location, 0, "anonymous union with no members");
    2380           12 :       return;
    2381              :     }
    2382              : 
    2383          380 :   if (!processing_template_decl)
    2384              :     {
    2385              :       /* Use main_decl to set the mangled name.  */
    2386          341 :       DECL_NAME (anon_union_decl) = DECL_NAME (main_decl);
    2387          341 :       maybe_commonize_var (anon_union_decl);
    2388          341 :       if (TREE_STATIC (anon_union_decl) || DECL_EXTERNAL (anon_union_decl))
    2389              :         {
    2390          215 :           if (DECL_DISCRIMINATOR_P (anon_union_decl))
    2391           47 :             determine_local_discriminator (anon_union_decl);
    2392          215 :           mangle_decl (anon_union_decl);
    2393              :         }
    2394          341 :       DECL_NAME (anon_union_decl) = NULL_TREE;
    2395              :     }
    2396              : 
    2397          380 :   pushdecl (anon_union_decl);
    2398          380 :   cp_finish_decl (anon_union_decl, NULL_TREE, false, NULL_TREE, 0);
    2399              : }
    2400              : 
    2401              : /* Auxiliary functions to make type signatures for
    2402              :    `operator new' and `operator delete' correspond to
    2403              :    what compiler will be expecting.  */
    2404              : 
    2405              : tree
    2406       150678 : coerce_new_type (tree type, location_t loc)
    2407              : {
    2408       150678 :   int e = 0;
    2409       150678 :   tree args = TYPE_ARG_TYPES (type);
    2410              : 
    2411       150678 :   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
    2412              : 
    2413       150678 :   if (!same_type_p (TREE_TYPE (type), ptr_type_node))
    2414              :     {
    2415            6 :       e = 1;
    2416            6 :       error_at (loc, "%<operator new%> must return type %qT",
    2417              :                 ptr_type_node);
    2418              :     }
    2419              : 
    2420       150678 :   if (args && args != void_list_node)
    2421              :     {
    2422       150663 :       if (TREE_PURPOSE (args))
    2423              :         {
    2424              :           /* [basic.stc.dynamic.allocation]
    2425              : 
    2426              :              The first parameter shall not have an associated default
    2427              :              argument.  */
    2428           18 :           error_at (loc, "the first parameter of %<operator new%> cannot "
    2429              :                     "have a default argument");
    2430              :           /* Throw away the default argument.  */
    2431           18 :           TREE_PURPOSE (args) = NULL_TREE;
    2432              :         }
    2433              : 
    2434       150663 :       if (!same_type_p (TREE_VALUE (args), size_type_node))
    2435              :         {
    2436           21 :           e = 2;
    2437           21 :           args = TREE_CHAIN (args);
    2438              :         }
    2439              :     }
    2440              :   else
    2441              :     e = 2;
    2442              : 
    2443           21 :   if (e == 2)
    2444           36 :     permerror (loc, "%<operator new%> takes type %<size_t%> (%qT) "
    2445              :                "as first parameter", size_type_node);
    2446              : 
    2447       150678 :   switch (e)
    2448              :   {
    2449           36 :     case 2:
    2450           36 :       args = tree_cons (NULL_TREE, size_type_node, args);
    2451              :       /* Fall through.  */
    2452           42 :     case 1:
    2453           42 :       type = (cxx_copy_lang_qualifiers
    2454           42 :               (build_function_type (ptr_type_node, args),
    2455              :                type));
    2456              :       /* Fall through.  */
    2457       150678 :     default:;
    2458              :   }
    2459       150678 :   return type;
    2460              : }
    2461              : 
    2462              : void
    2463       200708 : coerce_delete_type (tree decl, location_t loc)
    2464              : {
    2465       200708 :   int e = 0;
    2466       200708 :   tree type = TREE_TYPE (decl);
    2467       200708 :   tree args = TYPE_ARG_TYPES (type);
    2468              : 
    2469       200708 :   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
    2470              : 
    2471       200708 :   if (!same_type_p (TREE_TYPE (type), void_type_node))
    2472              :     {
    2473           15 :       e = 1;
    2474           15 :       error_at (loc, "%<operator delete%> must return type %qT",
    2475              :                 void_type_node);
    2476              :     }
    2477              : 
    2478       200708 :   tree ptrtype = ptr_type_node;
    2479       200708 :   if (destroying_delete_p (decl))
    2480              :     {
    2481           42 :       if (DECL_CLASS_SCOPE_P (decl))
    2482              :         /* If the function is a destroying operator delete declared in class
    2483              :            type C, the type of its first parameter shall be C*.  */
    2484           42 :         ptrtype = build_pointer_type (DECL_CONTEXT (decl));
    2485              :       else
    2486              :         /* A destroying operator delete shall be a class member function named
    2487              :            operator delete.  */
    2488            0 :         error_at (loc,
    2489              :                   "destroying %<operator delete%> must be a member function");
    2490           42 :       const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (DECL_NAME (decl));
    2491           42 :       if (op->flags & OVL_OP_FLAG_VEC)
    2492            0 :         error_at (loc, "%<operator delete[]%> cannot be a destroying delete");
    2493           42 :       if (!usual_deallocation_fn_p (decl))
    2494            0 :         error_at (loc, "destroying %<operator delete%> must be a usual "
    2495              :                   "deallocation function");
    2496              :     }
    2497              : 
    2498       200705 :   if (!args || args == void_list_node
    2499       401410 :       || !same_type_p (TREE_VALUE (args), ptrtype))
    2500              :     {
    2501           15 :       e = 2;
    2502           15 :       if (args && args != void_list_node)
    2503            9 :         args = TREE_CHAIN (args);
    2504           15 :       error_at (loc, "%<operator delete%> takes type %qT as first parameter",
    2505              :                 ptrtype);
    2506              :     }
    2507       200693 :   switch (e)
    2508              :   {
    2509           15 :     case 2:
    2510           15 :       args = tree_cons (NULL_TREE, ptrtype, args);
    2511              :       /* Fall through.  */
    2512           30 :     case 1:
    2513           30 :       type = (cxx_copy_lang_qualifiers
    2514           30 :               (build_function_type (void_type_node, args),
    2515              :                type));
    2516              :       /* Fall through.  */
    2517       200708 :     default:;
    2518              :   }
    2519              : 
    2520       200708 :   TREE_TYPE (decl) = type;
    2521       200708 : }
    2522              : 
    2523              : /* DECL is a VAR_DECL for a vtable: walk through the entries in the vtable
    2524              :    and mark them as needed.  */
    2525              : 
    2526              : static void
    2527       375461 : mark_vtable_entries (tree decl, vec<tree> &consteval_vtables)
    2528              : {
    2529              :   /* It's OK for the vtable to refer to deprecated virtual functions.  */
    2530       375461 :   auto du = make_temp_override (deprecated_state,
    2531       375461 :                                 UNAVAILABLE_DEPRECATED_SUPPRESS);
    2532              : 
    2533       375461 :   bool consteval_seen = false;
    2534              : 
    2535      5875381 :   for (auto &e: CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
    2536              :     {
    2537      4748998 :       tree fnaddr = e.value;
    2538              : 
    2539      4748998 :       STRIP_NOPS (fnaddr);
    2540              : 
    2541      7220055 :       if (TREE_CODE (fnaddr) != ADDR_EXPR
    2542      4748998 :           && TREE_CODE (fnaddr) != FDESC_EXPR)
    2543              :         /* This entry is an offset: a virtual base class offset, a
    2544              :            virtual call offset, an RTTI offset, etc.  */
    2545      2471057 :         continue;
    2546              : 
    2547      2277941 :       tree fn = TREE_OPERAND (fnaddr, 0);
    2548      4102018 :       if (TREE_CODE (fn) == FUNCTION_DECL && DECL_IMMEDIATE_FUNCTION_P (fn))
    2549              :         {
    2550           95 :           if (!consteval_seen)
    2551              :             {
    2552           50 :               consteval_seen = true;
    2553           50 :               consteval_vtables.safe_push (decl);
    2554              :             }
    2555           95 :           continue;
    2556              :         }
    2557      2277846 :       TREE_ADDRESSABLE (fn) = 1;
    2558              :       /* When we don't have vcall offsets, we output thunks whenever
    2559              :          we output the vtables that contain them.  With vcall offsets,
    2560              :          we know all the thunks we'll need when we emit a virtual
    2561              :          function, so we emit the thunks there instead.  */
    2562      2277846 :       if (DECL_THUNK_P (fn))
    2563         4115 :         use_thunk (fn, /*emit_p=*/0);
    2564              :       /* Set the location, as marking the function could cause
    2565              :          instantiation.  We do not need to preserve the incoming
    2566              :          location, as we're called from c_parse_final_cleanups, which
    2567              :          takes care of that.  */
    2568      2277846 :       input_location = DECL_SOURCE_LOCATION (fn);
    2569      2277846 :       mark_used (fn);
    2570              :     }
    2571       375461 : }
    2572              : 
    2573              : /* Replace any consteval functions in vtables with null pointers.  */
    2574              : 
    2575              : static void
    2576       100997 : clear_consteval_vfns (vec<tree> &consteval_vtables)
    2577              : {
    2578       101109 :   for (tree vtable : consteval_vtables)
    2579          366 :     for (constructor_elt &elt : CONSTRUCTOR_ELTS (DECL_INITIAL (vtable)))
    2580              :       {
    2581          216 :         tree fn = cp_get_fndecl_from_callee (elt.value, /*fold*/false);
    2582          326 :         if (fn && DECL_IMMEDIATE_FUNCTION_P (fn))
    2583           95 :           elt.value = build_zero_cst (vtable_entry_type);
    2584              :       }
    2585       100997 : }
    2586              : 
    2587              : /* Adjust the TLS model on variable DECL if need be, typically after
    2588              :    the linkage of DECL has been modified.  */
    2589              : 
    2590              : static void
    2591     60258632 : adjust_var_decl_tls_model (tree decl)
    2592              : {
    2593     60258632 :   if (CP_DECL_THREAD_LOCAL_P (decl)
    2594     60258632 :       && !lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl)))
    2595          297 :     set_decl_tls_model (decl, decl_default_tls_model (decl));
    2596     60258632 : }
    2597              : 
    2598              : /* Set DECL up to have the closest approximation of "initialized common"
    2599              :    linkage available.  */
    2600              : 
    2601              : void
    2602    111777315 : comdat_linkage (tree decl)
    2603              : {
    2604    111777315 :   if (flag_weak)
    2605    111777291 :     make_decl_one_only (decl, cxx_comdat_group (decl));
    2606           24 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    2607           24 :            || (VAR_P (decl) && DECL_ARTIFICIAL (decl)))
    2608              :     /* We can just emit function and compiler-generated variables
    2609              :        statically; having multiple copies is (for the most part) only
    2610              :        a waste of space.
    2611              : 
    2612              :        There are two correctness issues, however: the address of a
    2613              :        template instantiation with external linkage should be the
    2614              :        same, independent of what translation unit asks for the
    2615              :        address, and this will not hold when we emit multiple copies of
    2616              :        the function.  However, there's little else we can do.
    2617              : 
    2618              :        Also, by default, the typeinfo implementation assumes that
    2619              :        there will be only one copy of the string used as the name for
    2620              :        each type.  Therefore, if weak symbols are unavailable, the
    2621              :        run-time library should perform a more conservative check; it
    2622              :        should perform a string comparison, rather than an address
    2623              :        comparison.  */
    2624           24 :     TREE_PUBLIC (decl) = 0;
    2625              :   else
    2626              :     {
    2627              :       /* Static data member template instantiations, however, cannot
    2628              :          have multiple copies.  */
    2629            0 :       if (DECL_INITIAL (decl) == 0
    2630            0 :           || DECL_INITIAL (decl) == error_mark_node)
    2631            0 :         DECL_COMMON (decl) = 1;
    2632            0 :       else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
    2633              :         {
    2634            0 :           DECL_COMMON (decl) = 1;
    2635            0 :           DECL_INITIAL (decl) = error_mark_node;
    2636              :         }
    2637            0 :       else if (!DECL_EXPLICIT_INSTANTIATION (decl))
    2638              :         {
    2639              :           /* We can't do anything useful; leave vars for explicit
    2640              :              instantiation.  */
    2641            0 :           DECL_EXTERNAL (decl) = 1;
    2642            0 :           DECL_NOT_REALLY_EXTERN (decl) = 0;
    2643              :         }
    2644              :     }
    2645              : 
    2646    111777315 :   if (TREE_PUBLIC (decl))
    2647    111777291 :     DECL_COMDAT (decl) = 1;
    2648              : 
    2649    111777315 :   if (VAR_P (decl))
    2650     60257853 :     adjust_var_decl_tls_model (decl);
    2651    111777315 : }
    2652              : 
    2653              : /* For win32 we also want to put explicit instantiations in
    2654              :    linkonce sections, so that they will be merged with implicit
    2655              :    instantiations; otherwise we get duplicate symbol errors.
    2656              :    For Darwin we do not want explicit instantiations to be
    2657              :    linkonce.  */
    2658              : 
    2659              : void
    2660       740712 : maybe_make_one_only (tree decl)
    2661              : {
    2662              :   /* We used to say that this was not necessary on targets that support weak
    2663              :      symbols, because the implicit instantiations will defer to the explicit
    2664              :      one.  However, that's not actually the case in SVR4; a strong definition
    2665              :      after a weak one is an error.  Also, not making explicit
    2666              :      instantiations one_only means that we can end up with two copies of
    2667              :      some template instantiations.  */
    2668       740712 :   if (! flag_weak)
    2669              :     return;
    2670              : 
    2671              :   /* Don't output reflection variables.  */
    2672       740709 :   if (consteval_only_p (decl))
    2673              :     return;
    2674              : 
    2675              :   /* We can't set DECL_COMDAT on functions, or cp_finish_file will think
    2676              :      we can get away with not emitting them if they aren't used.  We need
    2677              :      to for variables so that cp_finish_decl will update their linkage,
    2678              :      because their DECL_INITIAL may not have been set properly yet.  */
    2679              : 
    2680       740705 :   if (!TARGET_WEAK_NOT_IN_ARCHIVE_TOC
    2681              :       || (! DECL_EXPLICIT_INSTANTIATION (decl)
    2682              :           && ! DECL_TEMPLATE_SPECIALIZATION (decl)))
    2683              :     {
    2684       740705 :       make_decl_one_only (decl, cxx_comdat_group (decl));
    2685              : 
    2686       740705 :       if (VAR_P (decl))
    2687              :         {
    2688          779 :           varpool_node *node = varpool_node::get_create (decl);
    2689          779 :           DECL_COMDAT (decl) = 1;
    2690              :           /* Mark it needed so we don't forget to emit it.  */
    2691          779 :           node->forced_by_abi = true;
    2692          779 :           TREE_USED (decl) = 1;
    2693              : 
    2694          779 :           adjust_var_decl_tls_model (decl);
    2695              :         }
    2696              :     }
    2697              : }
    2698              : 
    2699              : /* Returns true iff DECL, a FUNCTION_DECL or VAR_DECL, has vague linkage.
    2700              :    This predicate will give the right answer during parsing of the
    2701              :    function, which other tests may not.  */
    2702              : 
    2703              : bool
    2704     37822519 : vague_linkage_p (tree decl)
    2705              : {
    2706     37822522 :   if (!TREE_PUBLIC (decl))
    2707              :     {
    2708              :       /* maybe_thunk_body clears TREE_PUBLIC and DECL_ABSTRACT_P on the
    2709              :          maybe-in-charge 'tor variants; in that case we need to check one of
    2710              :          the "clones" for the real linkage.  But only in that case; before
    2711              :          maybe_clone_body we haven't yet copied the linkage to the clones.  */
    2712         9280 :       if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl)
    2713          327 :           && !DECL_ABSTRACT_P (decl)
    2714            3 :           && DECL_CHAIN (decl)
    2715         4797 :           && DECL_CLONED_FUNCTION_P (DECL_CHAIN (decl)))
    2716            3 :         return vague_linkage_p (DECL_CHAIN (decl));
    2717              : 
    2718         4791 :       gcc_checking_assert (!DECL_COMDAT (decl));
    2719              :       return false;
    2720              :     }
    2721              :   /* Unfortunately, import_export_decl has not always been called
    2722              :      before the function is processed, so we cannot simply check
    2723              :      DECL_COMDAT.  */
    2724     37817728 :   if (DECL_COMDAT (decl)
    2725       968170 :       || (TREE_CODE (decl) == FUNCTION_DECL
    2726       953972 :           && DECL_NONGNU_INLINE_P (decl))
    2727        70473 :       || (DECL_LANG_SPECIFIC (decl)
    2728        69837 :           && DECL_TEMPLOID_INSTANTIATION (decl))
    2729     37859281 :       || (VAR_P (decl) && DECL_INLINE_VAR_P (decl)))
    2730              :     return true;
    2731        35728 :   else if (DECL_FUNCTION_SCOPE_P (decl))
    2732              :     /* A local static in an inline effectively has vague linkage.  */
    2733            0 :     return (TREE_STATIC (decl)
    2734            0 :             && vague_linkage_p (DECL_CONTEXT (decl)));
    2735              :   else
    2736              :     return false;
    2737              : }
    2738              : 
    2739              : /* Determine whether or not we want to specifically import or export CTYPE,
    2740              :    using various heuristics.  */
    2741              : 
    2742              : static void
    2743      3957734 : import_export_class (tree ctype)
    2744              : {
    2745              :   /* -1 for imported, 1 for exported.  */
    2746      3957734 :   int import_export = 0;
    2747              : 
    2748              :   /* It only makes sense to call this function at EOF.  The reason is
    2749              :      that this function looks at whether or not the first non-inline
    2750              :      non-abstract virtual member function has been defined in this
    2751              :      translation unit.  But, we can't possibly know that until we've
    2752              :      seen the entire translation unit.  */
    2753      3957734 :   gcc_assert (at_eof);
    2754              : 
    2755      3957734 :   if (CLASSTYPE_INTERFACE_KNOWN (ctype))
    2756              :     return;
    2757              : 
    2758              :   /* If MULTIPLE_SYMBOL_SPACES is set and we saw a #pragma interface,
    2759              :      we will have CLASSTYPE_INTERFACE_ONLY set but not
    2760              :      CLASSTYPE_INTERFACE_KNOWN.  In that case, we don't want to use this
    2761              :      heuristic because someone will supply a #pragma implementation
    2762              :      elsewhere, and deducing it here would produce a conflict.  */
    2763      2152696 :   if (CLASSTYPE_INTERFACE_ONLY (ctype))
    2764              :     return;
    2765              : 
    2766      2152696 :   if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype)))
    2767              :     import_export = -1;
    2768      2152696 :   else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype)))
    2769              :     import_export = 1;
    2770      2152696 :   else if (CLASSTYPE_IMPLICIT_INSTANTIATION (ctype)
    2771      2152696 :            && !flag_implicit_templates)
    2772              :     /* For a template class, without -fimplicit-templates, check the
    2773              :        repository.  If the virtual table is assigned to this
    2774              :        translation unit, then export the class; otherwise, import
    2775              :        it.  */
    2776              :       import_export = -1;
    2777      2152053 :   else if (TYPE_CONTAINS_VPTR_P (ctype))
    2778              :     {
    2779      1979173 :       tree cdecl = TYPE_NAME (ctype);
    2780      1983017 :       if (DECL_LANG_SPECIFIC (cdecl) && DECL_MODULE_ATTACH_P (cdecl))
    2781              :         /* For class types attached to a named module, the ABI specifies
    2782              :            that the tables are uniquely emitted in the object for the
    2783              :            module unit in which it is defined.  */
    2784         1746 :         import_export = (DECL_MODULE_IMPORT_P (cdecl) ? -1 : 1);
    2785              :       else
    2786              :         {
    2787              :           /* The ABI specifies that the virtual table and associated
    2788              :              information are emitted with the key method, if any.  */
    2789      1978978 :           tree method = CLASSTYPE_KEY_METHOD (ctype);
    2790              :           /* If weak symbol support is not available, then we must be
    2791              :              careful not to emit the vtable when the key function is
    2792              :              inline.  An inline function can be defined in multiple
    2793              :              translation units.  If we were to emit the vtable in each
    2794              :              translation unit containing a definition, we would get
    2795              :              multiple definition errors at link-time.  */
    2796      1955116 :           if (method && (flag_weak || ! DECL_NONGNU_INLINE_P (method)))
    2797       588311 :             import_export = (DECL_REALLY_EXTERN (method) ? -1 : 1);
    2798              :         }
    2799              :     }
    2800              : 
    2801              :   /* When MULTIPLE_SYMBOL_SPACES is set, we cannot count on seeing
    2802              :      a definition anywhere else.  */
    2803      2152696 :   if (MULTIPLE_SYMBOL_SPACES && import_export == -1)
    2804              :     import_export = 0;
    2805              : 
    2806              :   /* Allow back ends the chance to overrule the decision.  */
    2807      2152696 :   if (targetm.cxx.import_export_class)
    2808            0 :     import_export = targetm.cxx.import_export_class (ctype, import_export);
    2809              : 
    2810      2152696 :   if (import_export)
    2811              :     {
    2812       589149 :       SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
    2813       589149 :       CLASSTYPE_INTERFACE_ONLY (ctype) = (import_export < 0);
    2814              :     }
    2815              : }
    2816              : 
    2817              : /* Return true if VAR has already been provided to the back end; in that
    2818              :    case VAR should not be modified further by the front end.  */
    2819              : static bool
    2820    105744623 : var_finalized_p (tree var)
    2821              : {
    2822            0 :   return varpool_node::get_create (var)->definition;
    2823              : }
    2824              : 
    2825              : /* DECL is a VAR_DECL or FUNCTION_DECL which, for whatever reason,
    2826              :    must be emitted in this translation unit.  Mark it as such.  */
    2827              : 
    2828              : void
    2829        50625 : mark_needed (tree decl)
    2830              : {
    2831              :   /* Don't output reflection variables.  */
    2832        50625 :   if (consteval_only_p (decl))
    2833              :     return;
    2834              : 
    2835        50617 :   TREE_USED (decl) = 1;
    2836        50617 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    2837              :     {
    2838              :       /* Extern inline functions don't become needed when referenced.
    2839              :          If we know a method will be emitted in other TU and no new
    2840              :          functions can be marked reachable, just use the external
    2841              :          definition.  */
    2842        42395 :       struct cgraph_node *node = cgraph_node::get_create (decl);
    2843        42395 :       node->forced_by_abi = true;
    2844              : 
    2845              :       /* #pragma interface can call mark_needed for
    2846              :           maybe-in-charge 'tors; mark the clones as well.  */
    2847        42395 :       tree clone;
    2848        50833 :       FOR_EACH_CLONE (clone, decl)
    2849         8438 :         mark_needed (clone);
    2850              :     }
    2851         8222 :   else if (VAR_P (decl))
    2852              :     {
    2853         8222 :       varpool_node *node = varpool_node::get_create (decl);
    2854              :       /* C++ frontend use mark_decl_references to force COMDAT variables
    2855              :          to be output that might appear dead otherwise.  */
    2856         8222 :       node->forced_by_abi = true;
    2857              :     }
    2858              : }
    2859              : 
    2860              : /* DECL is either a FUNCTION_DECL or a VAR_DECL.  This function
    2861              :    returns true if a definition of this entity should be provided in
    2862              :    this object file.  Callers use this function to determine whether
    2863              :    or not to let the back end know that a definition of DECL is
    2864              :    available in this translation unit.  */
    2865              : 
    2866              : bool
    2867    331524385 : decl_needed_p (tree decl)
    2868              : {
    2869    331524385 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
    2870              :   /* This function should only be called at the end of the translation
    2871              :      unit.  We cannot be sure of whether or not something will be
    2872              :      COMDAT until that point.  */
    2873    331524385 :   gcc_assert (at_eof);
    2874              : 
    2875              :   /* All entities with external linkage that are not COMDAT/EXTERN should be
    2876              :      emitted; they may be referred to from other object files.  */
    2877    331524385 :   if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_REALLY_EXTERN (decl))
    2878              :     return true;
    2879              : 
    2880              :   /* Functions marked "dllexport" must be emitted so that they are
    2881              :      visible to other DLLs.  */
    2882    331524105 :   if (flag_keep_inline_dllexport
    2883    331524105 :       && lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))
    2884              :     return true;
    2885              : 
    2886              :   /* When not optimizing, do not bother to produce definitions for extern
    2887              :      symbols.  */
    2888    409665060 :   if (DECL_REALLY_EXTERN (decl)
    2889            0 :       && ((TREE_CODE (decl) != FUNCTION_DECL
    2890            0 :            && !optimize)
    2891            0 :           || (TREE_CODE (decl) == FUNCTION_DECL
    2892            0 :               && !opt_for_fn (decl, optimize)))
    2893    331524105 :       && !lookup_attribute ("always_inline", decl))
    2894              :     return false;
    2895              : 
    2896              :   /* If this entity was used, let the back end see it; it will decide
    2897              :      whether or not to emit it into the object file.  */
    2898    331524105 :   if (TREE_USED (decl))
    2899              :     return true;
    2900              : 
    2901              :   /* Virtual functions might be needed for devirtualization.  */
    2902     68669133 :   if (flag_devirtualize
    2903     65997350 :       && TREE_CODE (decl) == FUNCTION_DECL
    2904    133460231 :       && DECL_VIRTUAL_P (decl))
    2905       691998 :     return true;
    2906              : 
    2907              :   /* Otherwise, DECL does not need to be emitted -- yet.  A subsequent
    2908              :      reference to DECL might cause it to be emitted later.  */
    2909              :   return false;
    2910              : }
    2911              : 
    2912              : /* If necessary, write out the vtables for the dynamic class CTYPE.
    2913              :    Returns true if any vtables were emitted.  */
    2914              : 
    2915              : static bool
    2916      3708560 : maybe_emit_vtables (tree ctype, vec<tree> &consteval_vtables)
    2917              : {
    2918      3708560 :   tree vtbl;
    2919      3708560 :   tree primary_vtbl;
    2920      3708560 :   int needed = 0;
    2921      3708560 :   varpool_node *current = NULL, *last = NULL;
    2922              : 
    2923              :   /* If the vtables for this class have already been emitted there is
    2924              :      nothing more to do.  */
    2925      3708560 :   primary_vtbl = CLASSTYPE_VTABLES (ctype);
    2926      3708560 :   if (var_finalized_p (primary_vtbl))
    2927              :     return false;
    2928              :   /* Ignore dummy vtables made by get_vtable_decl.  */
    2929      3708560 :   if (TREE_TYPE (primary_vtbl) == void_type_node)
    2930              :     return false;
    2931              : 
    2932              :   /* On some targets, we cannot determine the key method until the end
    2933              :      of the translation unit -- which is when this function is
    2934              :      called.  */
    2935      3708560 :   if (!targetm.cxx.key_method_may_be_inline ())
    2936            0 :     determine_key_method (ctype);
    2937              : 
    2938              :   /* See if any of the vtables are needed.  */
    2939      9074480 :   for (vtbl = CLASSTYPE_VTABLES (ctype); vtbl; vtbl = DECL_CHAIN (vtbl))
    2940              :     {
    2941      5365920 :       import_export_decl (vtbl);
    2942      5365920 :       if (DECL_NOT_REALLY_EXTERN (vtbl) && decl_needed_p (vtbl))
    2943              :         needed = 1;
    2944              :     }
    2945      3708560 :   if (!needed)
    2946              :     {
    2947              :       /* If the references to this class' vtables are optimized away,
    2948              :          still emit the appropriate debugging information.  See
    2949              :          dfs_debug_mark.  */
    2950      3353536 :       if (DECL_COMDAT (primary_vtbl)
    2951      3353536 :           && CLASSTYPE_DEBUG_REQUESTED (ctype))
    2952        38800 :         note_debug_info_needed (ctype);
    2953              :       return false;
    2954              :     }
    2955              : 
    2956              :   /* The ABI requires that we emit all of the vtables if we emit any
    2957              :      of them.  */
    2958       730485 :   for (vtbl = CLASSTYPE_VTABLES (ctype); vtbl; vtbl = DECL_CHAIN (vtbl))
    2959              :     {
    2960              :       /* Mark entities references from the virtual table as used.  */
    2961       375461 :       mark_vtable_entries (vtbl, consteval_vtables);
    2962              : 
    2963       375461 :       if (TREE_TYPE (DECL_INITIAL (vtbl)) == 0)
    2964              :         {
    2965            0 :           vec<tree, va_gc> *cleanups = NULL;
    2966            0 :           tree expr = store_init_value (vtbl, DECL_INITIAL (vtbl), &cleanups,
    2967              :                                         LOOKUP_NORMAL);
    2968              : 
    2969              :           /* It had better be all done at compile-time.  */
    2970            0 :           gcc_assert (!expr && !cleanups);
    2971              :         }
    2972              : 
    2973              :       /* Write it out.  */
    2974       375461 :       DECL_EXTERNAL (vtbl) = 0;
    2975       375461 :       rest_of_decl_compilation (vtbl, 1, 1);
    2976              : 
    2977              :       /* Because we're only doing syntax-checking, we'll never end up
    2978              :          actually marking the variable as written.  */
    2979       375461 :       if (flag_syntax_only)
    2980           33 :         TREE_ASM_WRITTEN (vtbl) = 1;
    2981       375428 :       else if (DECL_ONE_ONLY (vtbl))
    2982              :         {
    2983       374695 :           current = varpool_node::get_create (vtbl);
    2984       374695 :           if (last)
    2985        20343 :             current->add_to_same_comdat_group (last);
    2986              :           last = current;
    2987              :         }
    2988              :     }
    2989              : 
    2990              :   /* For abstract classes, the destructor has been removed from the
    2991              :      vtable (in class.cc's build_vtbl_initializer).  For a compiler-
    2992              :      generated destructor, it hence might not have been generated in
    2993              :      this translation unit - and with '#pragma interface' it might
    2994              :      never get generated.  */
    2995       355024 :   if (CLASSTYPE_PURE_VIRTUALS (ctype)
    2996       111818 :       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype)
    2997        70444 :       && !CLASSTYPE_LAZY_DESTRUCTOR (ctype)
    2998       425465 :       && DECL_DEFAULTED_IN_CLASS_P (CLASSTYPE_DESTRUCTOR (ctype)))
    2999           66 :     note_vague_linkage_fn (CLASSTYPE_DESTRUCTOR (ctype));
    3000              : 
    3001              :   /* Since we're writing out the vtable here, also write the debug
    3002              :      info.  */
    3003       355024 :   note_debug_info_needed (ctype);
    3004              : 
    3005       355024 :   return true;
    3006              : }
    3007              : 
    3008              : /* A special return value from type_visibility meaning internal
    3009              :    linkage.  */
    3010              : 
    3011              : enum { VISIBILITY_ANON = VISIBILITY_INTERNAL+1 };
    3012              : 
    3013              : static int expr_visibility (tree);
    3014              : static int type_visibility (tree);
    3015              : 
    3016              : /* walk_tree helper function for type_visibility.  */
    3017              : 
    3018              : static tree
    3019   4088975835 : min_vis_r (tree *tp, int *walk_subtrees, void *data)
    3020              : {
    3021   4088975835 :   int *vis_p = (int *)data;
    3022   4088975835 :   int this_vis = VISIBILITY_DEFAULT;
    3023   4088975835 :   if (! TYPE_P (*tp))
    3024    809375470 :     *walk_subtrees = 0;
    3025   3279600365 :   else if (OVERLOAD_TYPE_P (*tp)
    3026   4291366073 :            && !TREE_PUBLIC (TYPE_MAIN_DECL (*tp)))
    3027              :     {
    3028      1002843 :       this_vis = VISIBILITY_ANON;
    3029      1002843 :       *walk_subtrees = 0;
    3030              :     }
    3031   3278597522 :   else if (CLASS_TYPE_P (*tp))
    3032              :     {
    3033    982986054 :       this_vis = CLASSTYPE_VISIBILITY (*tp);
    3034    982986054 :       *walk_subtrees = 0;
    3035              :     }
    3036   2295611468 :   else if (TREE_CODE (*tp) == ARRAY_TYPE
    3037   2295611468 :            && uses_template_parms (TYPE_DOMAIN (*tp)))
    3038       419661 :     this_vis = expr_visibility (TYPE_MAX_VALUE (TYPE_DOMAIN (*tp)));
    3039              : 
    3040   4088975835 :   if (this_vis > *vis_p)
    3041      1692876 :     *vis_p = this_vis;
    3042              : 
    3043              :   /* Tell cp_walk_subtrees to look through typedefs.  */
    3044   4088975835 :   if (*walk_subtrees == 1)
    3045   2295611468 :     *walk_subtrees = 2;
    3046              : 
    3047   4088975835 :   return NULL;
    3048              : }
    3049              : 
    3050              : /* walk_tree helper function for expr_visibility.  */
    3051              : 
    3052              : static tree
    3053    263085656 : min_vis_expr_r (tree *tp, int *walk_subtrees, void *data)
    3054              : {
    3055    263085656 :   int *vis_p = (int *)data;
    3056    263085656 :   int tpvis = VISIBILITY_DEFAULT;
    3057              : 
    3058    263085656 :   tree t = *tp;
    3059    263085656 :   if (TREE_CODE (t) == PTRMEM_CST)
    3060         1372 :     t = PTRMEM_CST_MEMBER (t);
    3061              : 
    3062    263085656 :   if (TREE_CODE (t) == TEMPLATE_DECL)
    3063              :     {
    3064      7096176 :       if (DECL_ALIAS_TEMPLATE_P (t) || concept_definition_p (t))
    3065              :         /* FIXME: We don't maintain TREE_PUBLIC / DECL_VISIBILITY for
    3066              :            alias templates so we can't trust it here (PR107906).  Ditto
    3067              :            for concepts.  */
    3068              :         return NULL_TREE;
    3069              :       t = DECL_TEMPLATE_RESULT (t);
    3070              :       if (!t)
    3071              :         return NULL_TREE;
    3072              :     }
    3073              : 
    3074    262333795 :   switch (TREE_CODE (t))
    3075              :     {
    3076      8617343 :     case CAST_EXPR:
    3077      8617343 :     case IMPLICIT_CONV_EXPR:
    3078      8617343 :     case STATIC_CAST_EXPR:
    3079      8617343 :     case REINTERPRET_CAST_EXPR:
    3080      8617343 :     case CONST_CAST_EXPR:
    3081      8617343 :     case DYNAMIC_CAST_EXPR:
    3082      8617343 :     case NEW_EXPR:
    3083      8617343 :     case CONSTRUCTOR:
    3084      8617343 :     case LAMBDA_EXPR:
    3085      8617343 :     case TYPE_DECL:
    3086      8617343 :       tpvis = type_visibility (TREE_TYPE (t));
    3087      8617343 :       break;
    3088              : 
    3089         8333 :     case ADDR_EXPR:
    3090         8333 :       t = TREE_OPERAND (t, 0);
    3091         8333 :       if (VAR_P (t))
    3092              :         /* If a variable has its address taken, the lvalue-rvalue conversion is
    3093              :            not applied, so skip that case.  */
    3094         4785 :         goto addressable;
    3095              :       break;
    3096              : 
    3097      8997230 :     case VAR_DECL:
    3098      8997230 :     case FUNCTION_DECL:
    3099      8997230 :       if (decl_constant_var_p (t))
    3100              :         /* The ODR allows definitions in different TUs to refer to distinct
    3101              :            constant variables with internal or no linkage, so such a reference
    3102              :            shouldn't affect visibility if the lvalue-rvalue conversion is
    3103              :            applied (PR110323).  We still want to restrict visibility according
    3104              :            to the type of the declaration however.  */
    3105              :         {
    3106      5156095 :           tpvis = type_visibility (TREE_TYPE (t));
    3107      5156095 :           break;
    3108              :         }
    3109      3841135 :     addressable:
    3110              :       /* For _DECLs with no linkage refer to the linkage of the containing
    3111              :          entity that does have a name with linkage.  */
    3112      3846334 :       if (decl_linkage (t) == lk_none)
    3113        30668 :         tpvis = expr_visibility (DECL_CONTEXT (t));
    3114              :       /* Decls that have had their visibility constrained will report
    3115              :          as external linkage, but we still want to transitively constrain
    3116              :          if we refer to them, so just check TREE_PUBLIC instead.  */
    3117      3815666 :       else if (!TREE_PUBLIC (t))
    3118              :         tpvis = VISIBILITY_ANON;
    3119              :       else
    3120      3814080 :         tpvis = DECL_VISIBILITY (t);
    3121              :       break;
    3122              : 
    3123         2056 :     case FIELD_DECL:
    3124         2056 :       tpvis = type_visibility (DECL_CONTEXT (t));
    3125         2056 :       break;
    3126              : 
    3127         2050 :     case REFLECT_EXPR:
    3128         2050 :       tree r;
    3129         2050 :       r = REFLECT_EXPR_HANDLE (t);
    3130         2050 :       switch (REFLECT_EXPR_KIND (t))
    3131              :         {
    3132           48 :         case REFLECT_BASE:
    3133              :           /* For direct base class relationship, determine visibility
    3134              :              from both D and B types.  */
    3135           48 :           tpvis = type_visibility (BINFO_TYPE (r));
    3136           48 :           if (tpvis > *vis_p)
    3137            2 :             *vis_p = tpvis;
    3138           48 :           tpvis = type_visibility (direct_base_derived (r));
    3139           48 :           *walk_subtrees = 0;
    3140           48 :           break;
    3141           38 :         case REFLECT_DATA_MEMBER_SPEC:
    3142              :           /* For data member description determine visibility
    3143              :              from the type.  */
    3144           38 :           tpvis = type_visibility (TREE_VEC_ELT (r, 0));
    3145           38 :           *walk_subtrees = 0;
    3146           38 :           break;
    3147           90 :         case REFLECT_PARM:
    3148              :           /* For function parameter reflection determine visibility
    3149              :              based on parent_of.  */
    3150           90 :           tpvis = expr_visibility (DECL_CONTEXT (r));
    3151           90 :           *walk_subtrees = 0;
    3152           90 :           break;
    3153            6 :         case REFLECT_ANNOTATION:
    3154              :           /* Annotations are always local to the TU.  */
    3155            6 :           tpvis = VISIBILITY_ANON;
    3156            6 :           *walk_subtrees = 0;
    3157            6 :           break;
    3158           20 :         case REFLECT_OBJECT:
    3159           20 :           r = get_base_address (r);
    3160         1868 :           gcc_fallthrough ();
    3161         1868 :         default:
    3162         1868 :           if (TYPE_P (r))
    3163              :             {
    3164          362 :               tpvis = type_visibility (r);
    3165          362 :               *walk_subtrees = 0;
    3166          362 :               break;
    3167              :             }
    3168         1506 :           if (VAR_P (r) || TREE_CODE (r) == PARM_DECL)
    3169              :             {
    3170          414 :               t = r;
    3171          414 :               goto addressable;
    3172              :             }
    3173              :           break;
    3174              :         }
    3175              :       break;
    3176              : 
    3177              :     default:
    3178              :       break;
    3179              :     }
    3180              : 
    3181    262333795 :   if (tpvis > *vis_p)
    3182         3609 :     *vis_p = tpvis;
    3183              : 
    3184              :   return NULL_TREE;
    3185              : }
    3186              : 
    3187              : /* Returns the visibility of TYPE, which is the minimum visibility of its
    3188              :    component types.  */
    3189              : 
    3190              : static int
    3191   1181130520 : type_visibility (tree type)
    3192              : {
    3193   1181130520 :   int vis = VISIBILITY_DEFAULT;
    3194   1181130520 :   cp_walk_tree_without_duplicates (&type, min_vis_r, &vis);
    3195   1181130520 :   return vis;
    3196              : }
    3197              : 
    3198              : /* Returns the visibility of an expression EXPR that appears in the signature
    3199              :    of a function template, which is the minimum visibility of names that appear
    3200              :    in its mangling.  */
    3201              : 
    3202              : static int
    3203     88635299 : expr_visibility (tree expr)
    3204              : {
    3205     88635299 :   int vis = VISIBILITY_DEFAULT;
    3206     88635299 :   cp_walk_tree_without_duplicates (&expr, min_vis_expr_r, &vis);
    3207     88635299 :   return vis;
    3208              : }
    3209              : 
    3210              : /* Limit the visibility of DECL to VISIBILITY, if not explicitly
    3211              :    specified (or if VISIBILITY is static).  If TMPL is true, this
    3212              :    constraint is for a template argument, and takes precedence
    3213              :    over explicitly-specified visibility on the template.  */
    3214              : 
    3215              : static void
    3216     79134900 : constrain_visibility (tree decl, int visibility, bool tmpl)
    3217              : {
    3218     79134900 :   if (visibility == VISIBILITY_ANON)
    3219              :     {
    3220              :       /* extern "C" declarations aren't affected by the anonymous
    3221              :          namespace.  */
    3222      1448935 :       if (!DECL_EXTERN_C_P (decl))
    3223              :         {
    3224      1448759 :           TREE_PUBLIC (decl) = 0;
    3225      1448759 :           DECL_WEAK (decl) = 0;
    3226      1448759 :           DECL_COMMON (decl) = 0;
    3227      1448759 :           DECL_COMDAT (decl) = false;
    3228      1448759 :           if (VAR_OR_FUNCTION_DECL_P (decl))
    3229              :             {
    3230       445331 :               struct symtab_node *snode = symtab_node::get (decl);
    3231              : 
    3232       445331 :               if (snode)
    3233        37524 :                 snode->set_comdat_group (NULL);
    3234              :             }
    3235      1448759 :           DECL_INTERFACE_KNOWN (decl) = 1;
    3236      1448759 :           if (DECL_LANG_SPECIFIC (decl))
    3237       449169 :             DECL_NOT_REALLY_EXTERN (decl) = 1;
    3238              :         }
    3239              :     }
    3240     77685965 :   else if (visibility > DECL_VISIBILITY (decl)
    3241     77685965 :            && (tmpl || !DECL_VISIBILITY_SPECIFIED (decl)))
    3242              :     {
    3243          309 :       DECL_VISIBILITY (decl) = (enum symbol_visibility) visibility;
    3244              :       /* This visibility was not specified.  */
    3245          309 :       DECL_VISIBILITY_SPECIFIED (decl) = false;
    3246              :     }
    3247     79134900 : }
    3248              : 
    3249              : /* Constrain the visibility of DECL based on the visibility of its template
    3250              :    arguments.  */
    3251              : 
    3252              : static void
    3253    357445609 : constrain_visibility_for_template (tree decl, tree targs)
    3254              : {
    3255              :   /* If this is a template instantiation, check the innermost
    3256              :      template args for visibility constraints.  The outer template
    3257              :      args are covered by the class check.  */
    3258    357445609 :   tree args = INNERMOST_TEMPLATE_ARGS (targs);
    3259    357445609 :   int i;
    3260   1040697715 :   for (i = TREE_VEC_LENGTH (args); i > 0; --i)
    3261              :     {
    3262    683252106 :       int vis = 0;
    3263              : 
    3264    683252106 :       tree arg = TREE_VEC_ELT (args, i-1);
    3265    683252106 :       if (TYPE_P (arg))
    3266    596725837 :         vis = type_visibility (arg);
    3267              :       else
    3268     86526269 :         vis = expr_visibility (arg);
    3269    683252106 :       if (vis)
    3270       378860 :         constrain_visibility (decl, vis, true);
    3271              :     }
    3272    357445609 : }
    3273              : 
    3274              : /* Like c_determine_visibility, but with additional C++-specific
    3275              :    behavior.
    3276              : 
    3277              :    Function-scope entities can rely on the function's visibility because
    3278              :    it is set in start_preparsed_function.
    3279              : 
    3280              :    Class-scope entities cannot rely on the class's visibility until the end
    3281              :    of the enclosing class definition.
    3282              : 
    3283              :    Note that because namespaces have multiple independent definitions,
    3284              :    namespace visibility is handled elsewhere using the #pragma visibility
    3285              :    machinery rather than by decorating the namespace declaration.
    3286              : 
    3287              :    The goal is for constraints from the type to give a diagnostic, and
    3288              :    other constraints to be applied silently.  */
    3289              : 
    3290              : void
    3291    708121107 : determine_visibility (tree decl)
    3292              : {
    3293              :   /* Remember that all decls get VISIBILITY_DEFAULT when built.  */
    3294              : 
    3295              :   /* Only relevant for names with external linkage.  */
    3296    708121107 :   if (!TREE_PUBLIC (decl))
    3297              :     return;
    3298              : 
    3299              :   /* Cloned constructors and destructors get the same visibility as
    3300              :      the underlying function.  That should be set up in
    3301              :      maybe_clone_body.  */
    3302    657933081 :   gcc_assert (!DECL_CLONED_FUNCTION_P (decl));
    3303              : 
    3304    657933081 :   bool orig_visibility_specified = DECL_VISIBILITY_SPECIFIED (decl);
    3305    657933081 :   enum symbol_visibility orig_visibility = DECL_VISIBILITY (decl);
    3306              : 
    3307              :   /* The decl may be a template instantiation, which could influence
    3308              :      visibility.  */
    3309    657933081 :   tree template_decl = NULL_TREE;
    3310    657933081 :   if (TREE_CODE (decl) == TYPE_DECL)
    3311              :     {
    3312    182287510 :       if (CLASS_TYPE_P (TREE_TYPE (decl)))
    3313              :         {
    3314    179181210 :           if (CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)))
    3315    365303100 :             template_decl = decl;
    3316              :         }
    3317      3106300 :       else if (TYPE_TEMPLATE_INFO (TREE_TYPE (decl)))
    3318    365303100 :         template_decl = decl;
    3319              :     }
    3320    475645571 :   else if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    3321              :     template_decl = decl;
    3322              : 
    3323    657933081 :   if (TREE_CODE (decl) == TYPE_DECL
    3324    360332322 :       && LAMBDA_TYPE_P (TREE_TYPE (decl))
    3325    661265341 :       && CLASSTYPE_LAMBDA_EXPR (TREE_TYPE (decl)) != error_mark_node)
    3326      3325842 :     if (tree extra = LAMBDA_TYPE_EXTRA_SCOPE (TREE_TYPE (decl)))
    3327              :       {
    3328              :         /* The lambda's visibility is limited by that of its extra
    3329              :            scope.  */
    3330      1658611 :         int vis = 0;
    3331      1658611 :         if (TYPE_P (extra))
    3332            0 :           vis = type_visibility (extra);
    3333              :         else
    3334      1658611 :           vis = expr_visibility (extra);
    3335      1658611 :         constrain_visibility (decl, vis, false);
    3336              :       }
    3337              : 
    3338              :   /* If DECL is a member of a class, visibility specifiers on the
    3339              :      class can influence the visibility of the DECL.  */
    3340    657933081 :   tree class_type = NULL_TREE;
    3341    657933081 :   if (DECL_CLASS_SCOPE_P (decl))
    3342    333677045 :     class_type = DECL_CONTEXT (decl);
    3343              :   else
    3344              :     {
    3345              :       /* Not a class member.  */
    3346              : 
    3347              :       /* Virtual tables have DECL_CONTEXT set to their associated class,
    3348              :          so they are automatically handled above.  */
    3349    324256036 :       gcc_assert (!VAR_P (decl)
    3350              :                   || !DECL_VTABLE_OR_VTT_P (decl));
    3351              : 
    3352    324256036 :       if (DECL_FUNCTION_SCOPE_P (decl) && ! DECL_VISIBILITY_SPECIFIED (decl))
    3353              :         {
    3354              :           /* Local statics and classes get the visibility of their
    3355              :              containing function by default, except that
    3356              :              -fvisibility-inlines-hidden doesn't affect them.  */
    3357      2529750 :           tree fn = DECL_CONTEXT (decl);
    3358      2529750 :           if (DECL_VISIBILITY_SPECIFIED (fn))
    3359              :             {
    3360      2437660 :               DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
    3361      7312980 :               DECL_VISIBILITY_SPECIFIED (decl) =
    3362      2437660 :                 DECL_VISIBILITY_SPECIFIED (fn);
    3363              :             }
    3364              :           else
    3365              :             {
    3366        92090 :               if (DECL_CLASS_SCOPE_P (fn))
    3367        51383 :                 determine_visibility_from_class (decl, DECL_CONTEXT (fn));
    3368        40707 :               else if (determine_hidden_inline (fn))
    3369              :                 {
    3370            6 :                   DECL_VISIBILITY (decl) = default_visibility;
    3371           12 :                   DECL_VISIBILITY_SPECIFIED (decl) =
    3372            6 :                     visibility_options.inpragma;
    3373              :                 }
    3374              :               else
    3375              :                 {
    3376        40701 :                   DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
    3377       122103 :                   DECL_VISIBILITY_SPECIFIED (decl) =
    3378        40701 :                     DECL_VISIBILITY_SPECIFIED (fn);
    3379              :                 }
    3380              :             }
    3381              : 
    3382              :           /* Local classes in templates have CLASSTYPE_USE_TEMPLATE set,
    3383              :              but have no TEMPLATE_INFO, so don't try to check it.  */
    3384              :           template_decl = NULL_TREE;
    3385              :         }
    3386     49192156 :       else if (VAR_P (decl) && DECL_TINFO_P (decl)
    3387    326811462 :                && flag_visibility_ms_compat)
    3388              :         {
    3389              :           /* Under -fvisibility-ms-compat, types are visible by default,
    3390              :              even though their contents aren't.  */
    3391           84 :           tree underlying_type = TREE_TYPE (DECL_NAME (decl));
    3392           84 :           int underlying_vis = type_visibility (underlying_type);
    3393           84 :           if (underlying_vis == VISIBILITY_ANON
    3394           84 :               || (CLASS_TYPE_P (underlying_type)
    3395           69 :                   && CLASSTYPE_VISIBILITY_SPECIFIED (underlying_type)))
    3396           54 :             constrain_visibility (decl, underlying_vis, false);
    3397              :           else
    3398           30 :             DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    3399              :         }
    3400    321726202 :       else if (VAR_P (decl) && DECL_TINFO_P (decl))
    3401              :         {
    3402              :           /* tinfo visibility is based on the type it's for.  */
    3403      5085092 :           constrain_visibility
    3404      5085092 :             (decl, type_visibility (TREE_TYPE (DECL_NAME (decl))), false);
    3405              : 
    3406              :           /* Give the target a chance to override the visibility associated
    3407              :              with DECL.  */
    3408      5085092 :           if (TREE_PUBLIC (decl)
    3409      5083204 :               && !DECL_REALLY_EXTERN (decl)
    3410      5083204 :               && CLASS_TYPE_P (TREE_TYPE (DECL_NAME (decl)))
    3411     10137173 :               && !CLASSTYPE_VISIBILITY_SPECIFIED (TREE_TYPE (DECL_NAME (decl))))
    3412       113334 :             targetm.cxx.determine_class_data_visibility (decl);
    3413              :         }
    3414    316641110 :       else if (template_decl)
    3415              :         /* Template instantiations and specializations get visibility based
    3416              :            on their template unless they override it with an attribute.  */;
    3417    106502309 :       else if (! DECL_VISIBILITY_SPECIFIED (decl))
    3418              :         {
    3419     98172372 :           if (determine_hidden_inline (decl))
    3420           12 :             DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
    3421              :           else
    3422              :             {
    3423              :               /* Set default visibility to whatever the user supplied with
    3424              :                  #pragma GCC visibility or a namespace visibility attribute.  */
    3425     98172360 :               DECL_VISIBILITY (decl) = default_visibility;
    3426     98172360 :               DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
    3427              :             }
    3428              :         }
    3429              :     }
    3430              : 
    3431    447794280 :   if (template_decl)
    3432              :     {
    3433              :       /* If the specialization doesn't specify visibility, use the
    3434              :          visibility from the template.  */
    3435    364682187 :       tree tinfo = get_template_info (template_decl);
    3436    364682187 :       tree args = TI_ARGS (tinfo);
    3437    364682187 :       tree attribs = (TREE_CODE (decl) == TYPE_DECL
    3438    364682187 :                       ? TYPE_ATTRIBUTES (TREE_TYPE (decl))
    3439    364682187 :                       : DECL_ATTRIBUTES (decl));
    3440    364682187 :       tree attr = lookup_attribute ("visibility", attribs);
    3441              : 
    3442    364682187 :       if (args != error_mark_node)
    3443              :         {
    3444    364682187 :           tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
    3445              : 
    3446    364682187 :           if (!DECL_VISIBILITY_SPECIFIED (decl))
    3447              :             {
    3448    164632518 :               if (!attr
    3449    164632518 :                   && determine_hidden_inline (decl))
    3450           33 :                 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
    3451              :               else
    3452              :                 {
    3453    164632485 :                   DECL_VISIBILITY (decl) = DECL_VISIBILITY (pattern);
    3454    329264970 :                   DECL_VISIBILITY_SPECIFIED (decl)
    3455    164632485 :                     = DECL_VISIBILITY_SPECIFIED (pattern);
    3456              :                 }
    3457              :             }
    3458              : 
    3459    364682187 :           if (args
    3460              :               /* Template argument visibility outweighs #pragma or namespace
    3461              :                  visibility, but not an explicit attribute.  */
    3462    364682187 :               && !attr)
    3463              :             {
    3464    364682166 :               int depth = TMPL_ARGS_DEPTH (args);
    3465    364682166 :               if (DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (TI_TEMPLATE (tinfo)))
    3466              :                 /* Class template args don't affect template friends.  */;
    3467    361855824 :               else if (DECL_VISIBILITY_SPECIFIED (decl))
    3468              :                 {
    3469              :                   /* A class template member with explicit visibility
    3470              :                      overrides the class visibility, so we need to apply
    3471              :                      all the levels of template args directly.  */
    3472              :                   int i;
    3473    643121929 :                   for (i = 1; i <= depth; ++i)
    3474              :                     {
    3475    326467249 :                       tree lev = TMPL_ARGS_LEVEL (args, i);
    3476    326467249 :                       constrain_visibility_for_template (decl, lev);
    3477              :                     }
    3478              :                 }
    3479     45201144 :               else if (PRIMARY_TEMPLATE_P (TI_TEMPLATE (tinfo)))
    3480              :                 /* Limit visibility based on its template arguments.  */
    3481     30978360 :                 constrain_visibility_for_template (decl, args);
    3482              :             }
    3483              :         }
    3484              :     }
    3485              : 
    3486    657933081 :   if (class_type)
    3487    333677045 :     determine_visibility_from_class (decl, class_type);
    3488              : 
    3489    657933081 :   if (decl_internal_context_p (decl))
    3490              :     /* Names in an anonymous namespace get internal linkage.  */
    3491       305541 :     constrain_visibility (decl, VISIBILITY_ANON, false);
    3492    657627540 :   else if (TREE_CODE (decl) != TYPE_DECL)
    3493              :     {
    3494              :       /* Propagate anonymity from type to decl.  */
    3495    475476700 :       int tvis = type_visibility (TREE_TYPE (decl));
    3496    475476700 :       if (tvis == VISIBILITY_ANON
    3497    475476700 :           || ! DECL_VISIBILITY_SPECIFIED (decl))
    3498     70933578 :         constrain_visibility (decl, tvis, false);
    3499              :     }
    3500    182150840 :   else if (no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/true))
    3501              :     /* DR 757: A type without linkage shall not be used as the type of a
    3502              :        variable or function with linkage, unless
    3503              :        o the variable or function has extern "C" linkage (7.5 [dcl.link]), or
    3504              :        o the variable or function is not used (3.2 [basic.def.odr]) or is
    3505              :        defined in the same translation unit.
    3506              : 
    3507              :        Since non-extern "C" decls need to be defined in the same
    3508              :        translation unit, we can make the type internal.  */
    3509       773164 :     constrain_visibility (decl, VISIBILITY_ANON, false);
    3510              : 
    3511              :   /* If visibility changed and DECL already has DECL_RTL, ensure
    3512              :      symbol flags are updated.  */
    3513    657933081 :   if ((DECL_VISIBILITY (decl) != orig_visibility
    3514    656944722 :        || DECL_VISIBILITY_SPECIFIED (decl) != orig_visibility_specified)
    3515    346790244 :       && ((VAR_P (decl) && TREE_STATIC (decl))
    3516    321359000 :           || TREE_CODE (decl) == FUNCTION_DECL)
    3517    982013354 :       && DECL_RTL_SET_P (decl))
    3518            0 :     make_decl_rtl (decl);
    3519              : }
    3520              : 
    3521              : /* By default, static data members and function members receive
    3522              :    the visibility of their containing class.  */
    3523              : 
    3524              : static void
    3525    333728428 : determine_visibility_from_class (tree decl, tree class_type)
    3526              : {
    3527    333728428 :   if (DECL_VISIBILITY_SPECIFIED (decl))
    3528              :     return;
    3529              : 
    3530    167457186 :   if (determine_hidden_inline (decl))
    3531          145 :     DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
    3532              :   else
    3533              :     {
    3534              :       /* Default to the class visibility.  */
    3535    167457041 :       DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
    3536    334914082 :       DECL_VISIBILITY_SPECIFIED (decl)
    3537    167457041 :         = CLASSTYPE_VISIBILITY_SPECIFIED (class_type);
    3538              :     }
    3539              : 
    3540              :   /* Give the target a chance to override the visibility associated
    3541              :      with DECL.  */
    3542    167457186 :   if (VAR_P (decl)
    3543     16994732 :       && TREE_PUBLIC (decl)
    3544     16994720 :       && (DECL_TINFO_P (decl) || DECL_VTABLE_OR_VTT_P (decl))
    3545      2288364 :       && !DECL_REALLY_EXTERN (decl)
    3546    169745550 :       && !CLASSTYPE_VISIBILITY_SPECIFIED (class_type))
    3547        78198 :     targetm.cxx.determine_class_data_visibility (decl);
    3548              : }
    3549              : 
    3550              : /* Returns true iff DECL is an inline that should get hidden visibility
    3551              :    because of -fvisibility-inlines-hidden.  */
    3552              : 
    3553              : static bool
    3554    430302783 : determine_hidden_inline (tree decl)
    3555              : {
    3556    430302783 :   return (visibility_options.inlines_hidden
    3557              :           /* Don't do this for inline templates; specializations might not be
    3558              :              inline, and we don't want them to inherit the hidden
    3559              :              visibility.  We'll set it here for all inline instantiations.  */
    3560          410 :           && !processing_template_decl
    3561          386 :           && TREE_CODE (decl) == FUNCTION_DECL
    3562          297 :           && DECL_DECLARED_INLINE_P (decl)
    3563    430302994 :           && (! DECL_LANG_SPECIFIC (decl)
    3564          211 :               || ! DECL_EXPLICIT_INSTANTIATION (decl)));
    3565              : }
    3566              : 
    3567              : /* Constrain the visibility of a class TYPE based on the visibility of its
    3568              :    field types.  Warn if any fields require lesser visibility.  */
    3569              : 
    3570              : void
    3571     52457346 : constrain_class_visibility (tree type)
    3572              : {
    3573     52457346 :   tree binfo;
    3574     52457346 :   tree t;
    3575     52457346 :   int i;
    3576              : 
    3577     52457346 :   int vis = type_visibility (type);
    3578              : 
    3579     52457346 :   if (vis == VISIBILITY_ANON
    3580     52457346 :       || DECL_IN_SYSTEM_HEADER (TYPE_MAIN_DECL (type)))
    3581     52457346 :     return;
    3582              : 
    3583              :   /* Don't warn about visibility if the class has explicit visibility.  */
    3584     51096515 :   if (CLASSTYPE_VISIBILITY_SPECIFIED (type))
    3585     50242370 :     vis = VISIBILITY_INTERNAL;
    3586              : 
    3587    423110841 :   for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
    3588     37932061 :     if (TREE_CODE (t) == FIELD_DECL && TREE_TYPE (t) != error_mark_node
    3589    409946227 :         && !DECL_ARTIFICIAL (t))
    3590              :       {
    3591     13032916 :         tree ftype = strip_pointer_or_array_types (TREE_TYPE (t));
    3592     13032916 :         int subvis = type_visibility (ftype);
    3593              : 
    3594     13032916 :         if (subvis == VISIBILITY_ANON)
    3595              :           {
    3596          126 :             if (!in_main_input_context())
    3597              :               {
    3598           39 :                 tree nlt = no_linkage_check (ftype, /*relaxed_p=*/false);
    3599           39 :                 if (nlt)
    3600              :                   {
    3601            6 :                     if (same_type_p (TREE_TYPE (t), nlt))
    3602            6 :                       warning (OPT_Wsubobject_linkage, "\
    3603              : %qT has a field %q#D whose type has no linkage",
    3604              :                                type, t);
    3605              :                     else
    3606            0 :                       warning (OPT_Wsubobject_linkage, "\
    3607              : %qT has a field %qD whose type depends on the type %qT which has no linkage",
    3608              :                                type, t, nlt);
    3609              :                   }
    3610           33 :                 else if (cxx_dialect > cxx98
    3611           26 :                          && OVERLOAD_TYPE_P (ftype)
    3612           47 :                          && !decl_anon_ns_mem_p (ftype))
    3613            2 :                   warning (OPT_Wsubobject_linkage, "\
    3614              : %qT has a field %q#D whose type has internal linkage",
    3615              :                            type, t);
    3616              :                 else // In C++98 this can only happen with unnamed namespaces.
    3617           31 :                   warning (OPT_Wsubobject_linkage, "\
    3618              : %qT has a field %q#D whose type uses the anonymous namespace",
    3619              :                            type, t);
    3620              :               }
    3621              :           }
    3622     13032790 :         else if (MAYBE_CLASS_TYPE_P (ftype)
    3623      5033532 :                  && vis < VISIBILITY_HIDDEN
    3624      5033532 :                  && subvis >= VISIBILITY_HIDDEN)
    3625            6 :           warning (OPT_Wattributes, "\
    3626              : %qT declared with greater visibility than the type of its field %qD",
    3627              :                    type, t);
    3628              :       }
    3629              : 
    3630     51096515 :   binfo = TYPE_BINFO (type);
    3631     75673070 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, t); ++i)
    3632              :     {
    3633     24576555 :       tree btype = BINFO_TYPE (t);
    3634     24576555 :       int subvis = type_visibility (btype);
    3635              : 
    3636     24576555 :       if (subvis == VISIBILITY_ANON)
    3637              :         {
    3638           33 :           if (!in_main_input_context())
    3639              :             {
    3640           18 :               tree nlt = no_linkage_check (btype, /*relaxed_p=*/false);
    3641           18 :               if (nlt)
    3642              :                 {
    3643            6 :                   if (same_type_p (btype, nlt))
    3644            6 :                     warning (OPT_Wsubobject_linkage, "\
    3645              : %qT has a base %qT which has no linkage",
    3646              :                              type, btype);
    3647              :                   else
    3648            0 :                     warning (OPT_Wsubobject_linkage, "\
    3649              : %qT has a base %qT which depends on the type %qT which has no linkage",
    3650              :                              type, btype, nlt);
    3651              :                 }
    3652           12 :               else if (cxx_dialect > cxx98
    3653           12 :                        && !decl_anon_ns_mem_p (btype))
    3654            3 :                 warning (OPT_Wsubobject_linkage, "\
    3655              : %qT has a base %qT which has internal linkage",
    3656              :                          type, btype);
    3657              :               else // In C++98 this can only happen with unnamed namespaces.
    3658            9 :                 warning (OPT_Wsubobject_linkage, "\
    3659              : %qT has a base %qT which uses the anonymous namespace",
    3660              :                          type, btype);
    3661              :             }
    3662              :         }
    3663     24576522 :       else if (vis < VISIBILITY_HIDDEN
    3664     24576522 :                && subvis >= VISIBILITY_HIDDEN)
    3665            6 :         warning (OPT_Wattributes, "\
    3666              : %qT declared with greater visibility than its base %qT",
    3667            6 :                  type, TREE_TYPE (t));
    3668              :     }
    3669              : }
    3670              : 
    3671              : /* Functions for adjusting the visibility of a tagged type and its nested
    3672              :    types and declarations when it gets a name for linkage purposes from a
    3673              :    typedef.  */
    3674              : // FIXME: It is now a DR for such a class type to contain anything
    3675              : // other than C.  So at minimum most of this can probably be deleted.
    3676              : 
    3677              : /* First reset the visibility of all the types.  */
    3678              : 
    3679              : static void
    3680      1117330 : reset_type_linkage_1 (tree type)
    3681              : {
    3682      1117330 :   set_linkage_according_to_type (type, TYPE_MAIN_DECL (type));
    3683      1117330 :   if (CLASS_TYPE_P (type))
    3684      3738835 :     for (tree member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
    3685      2972015 :       if (DECL_IMPLICIT_TYPEDEF_P (member))
    3686       239329 :         reset_type_linkage_1 (TREE_TYPE (member));
    3687      1117330 : }
    3688              : 
    3689              : /* Then reset the visibility of any static data members or member
    3690              :    functions that use those types.  */
    3691              : 
    3692              : static void
    3693          103 : reset_decl_linkage (tree decl)
    3694              : {
    3695          103 :   if (TREE_PUBLIC (decl))
    3696              :     return;
    3697          103 :   if (DECL_CLONED_FUNCTION_P (decl))
    3698              :     return;
    3699           99 :   TREE_PUBLIC (decl) = true;
    3700           99 :   DECL_INTERFACE_KNOWN (decl) = false;
    3701           99 :   determine_visibility (decl);
    3702           99 :   tentative_decl_linkage (decl);
    3703              : }
    3704              : 
    3705              : void
    3706       878001 : reset_type_linkage (tree type)
    3707              : {
    3708       878001 :   reset_type_linkage_1 (type);
    3709       878001 :   if (CLASS_TYPE_P (type))
    3710              :     {
    3711       527503 :       if (tree vt = CLASSTYPE_VTABLES (type))
    3712              :         {
    3713           15 :           tree name = mangle_vtbl_for_type (type);
    3714           15 :           DECL_NAME (vt) = name;
    3715           15 :           SET_DECL_ASSEMBLER_NAME (vt, name);
    3716           15 :           reset_decl_linkage (vt);
    3717              :         }
    3718       527503 :       if (!ANON_AGGR_TYPE_P (type))
    3719       527366 :         if (tree ti = CLASSTYPE_TYPEINFO_VAR (type))
    3720              :           {
    3721           12 :             tree name = mangle_typeinfo_for_type (type);
    3722           12 :             DECL_NAME (ti) = name;
    3723           12 :             SET_DECL_ASSEMBLER_NAME (ti, name);
    3724           12 :             TREE_TYPE (name) = type;
    3725           12 :             reset_decl_linkage (ti);
    3726              :           }
    3727      2479397 :       for (tree m = TYPE_FIELDS (type); m; m = DECL_CHAIN (m))
    3728              :         {
    3729      1951894 :           tree mem = STRIP_TEMPLATE (m);
    3730      1951894 :           if (TREE_CODE (mem) == VAR_DECL || TREE_CODE (mem) == FUNCTION_DECL)
    3731           76 :             reset_decl_linkage (mem);
    3732      1951818 :           else if (DECL_IMPLICIT_TYPEDEF_P (mem))
    3733       125949 :             reset_type_linkage (TREE_TYPE (mem));
    3734              :         }
    3735              :     }
    3736       878001 : }
    3737              : 
    3738              : /* Set up our initial idea of what the linkage of DECL should be.  */
    3739              : 
    3740              : void
    3741     31466079 : tentative_decl_linkage (tree decl)
    3742              : {
    3743     31466079 :   if (DECL_INTERFACE_KNOWN (decl))
    3744              :     /* We've already made a decision as to how this function will
    3745              :        be handled.  */;
    3746     31465000 :   else if (vague_linkage_p (decl))
    3747              :     {
    3748     31463818 :       if (TREE_CODE (decl) == FUNCTION_DECL
    3749     31463818 :           && decl_defined_p (decl))
    3750              :         {
    3751     31439420 :           DECL_EXTERNAL (decl) = 1;
    3752     31439420 :           DECL_NOT_REALLY_EXTERN (decl) = 1;
    3753     31439420 :           note_vague_linkage_fn (decl);
    3754              :           /* A non-template inline function with external linkage will
    3755              :              always be COMDAT.  As we must eventually determine the
    3756              :              linkage of all functions, and as that causes writes to
    3757              :              the data mapped in from the PCH file, it's advantageous
    3758              :              to mark the functions at this point.  */
    3759     31439420 :           if (DECL_DECLARED_INLINE_P (decl))
    3760              :             {
    3761     31436624 :               if (!DECL_IMPLICIT_INSTANTIATION (decl)
    3762     31436624 :                   || DECL_DEFAULTED_FN (decl))
    3763              :                 {
    3764              :                   /* This function must have external linkage, as
    3765              :                      otherwise DECL_INTERFACE_KNOWN would have been
    3766              :                      set.  */
    3767     25914556 :                   gcc_assert (TREE_PUBLIC (decl));
    3768     25914556 :                   comdat_linkage (decl);
    3769     25914556 :                   DECL_INTERFACE_KNOWN (decl) = 1;
    3770              :                 }
    3771      5522068 :               else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl))
    3772              :                 /* For implicit instantiations of cdtors try to make
    3773              :                    it comdat, so that maybe_clone_body can use aliases.
    3774              :                    See PR113208.  */
    3775       708761 :                 maybe_make_one_only (decl);
    3776              :             }
    3777              :         }
    3778        24398 :       else if (VAR_P (decl))
    3779        24396 :         maybe_commonize_var (decl);
    3780              :     }
    3781     31466079 : }
    3782              : 
    3783              : /* For a polymorphic class type CTYPE, whether its vtables are emitted in a
    3784              :    unique object as per the ABI.  */
    3785              : 
    3786              : static bool
    3787         2851 : vtables_uniquely_emitted (tree ctype)
    3788              : {
    3789              :   /* If the class is templated, the tables are emitted in every object that
    3790              :      references any of them.  */
    3791         2851 :   if (CLASSTYPE_USE_TEMPLATE (ctype))
    3792              :     return false;
    3793              : 
    3794              :   /* Otherwise, if the class is attached to a module, the tables are uniquely
    3795              :      emitted in the object for the module unit in which it is defined.  */
    3796         2225 :   tree cdecl = TYPE_NAME (ctype);
    3797         2360 :   if (DECL_LANG_SPECIFIC (cdecl) && DECL_MODULE_ATTACH_P (cdecl))
    3798              :     return true;
    3799              : 
    3800              :   /* Otherwise, if the class has a key function, the tables are emitted in the
    3801              :      object for the TU containing the definition of the key function.  This is
    3802              :      unique if the key function is not inline.  */
    3803         2093 :   tree key_method = CLASSTYPE_KEY_METHOD (ctype);
    3804         4166 :   if (key_method && !DECL_NONGNU_INLINE_P (key_method))
    3805         2053 :     return true;
    3806              : 
    3807              :   /* Otherwise, the tables are emitted in every object that references
    3808              :      any of them.  */
    3809              :   return false;
    3810              : }
    3811              : 
    3812              : /* DECL is a FUNCTION_DECL or VAR_DECL.  If the object file linkage
    3813              :    for DECL has not already been determined, do so now by setting
    3814              :    DECL_EXTERNAL, DECL_COMDAT and other related flags.  Until this
    3815              :    function is called entities with vague linkage whose definitions
    3816              :    are available must have TREE_PUBLIC set.
    3817              : 
    3818              :    If this function decides to place DECL in COMDAT, it will set
    3819              :    appropriate flags -- but will not clear DECL_EXTERNAL.  It is up to
    3820              :    the caller to decide whether or not to clear DECL_EXTERNAL.  Some
    3821              :    callers defer that decision until it is clear that DECL is actually
    3822              :    required.  */
    3823              : 
    3824              : void
    3825    238957110 : import_export_decl (tree decl)
    3826              : {
    3827    238957110 :   bool comdat_p;
    3828    238957110 :   bool import_p;
    3829    238957110 :   tree class_type = NULL_TREE;
    3830              : 
    3831    238957110 :   if (DECL_INTERFACE_KNOWN (decl))
    3832              :     return;
    3833              : 
    3834              :   /* We cannot determine what linkage to give to an entity with vague
    3835              :      linkage until the end of the file.  For example, a virtual table
    3836              :      for a class will be defined if and only if the key method is
    3837              :      defined in this translation unit.  */
    3838     41625694 :   gcc_assert (at_eof);
    3839              :   /* Object file linkage for explicit instantiations is handled in
    3840              :      mark_decl_instantiated.  For static variables in functions with
    3841              :      vague linkage, maybe_commonize_var is used.
    3842              : 
    3843              :      Therefore, the only declarations that should be provided to this
    3844              :      function are those with external linkage that are:
    3845              : 
    3846              :      * implicit instantiations of function templates
    3847              : 
    3848              :      * inline functions
    3849              : 
    3850              :      * inline variables
    3851              : 
    3852              :      * implicit instantiations of static data members of class
    3853              :        templates
    3854              : 
    3855              :      * virtual tables
    3856              : 
    3857              :      * typeinfo objects
    3858              : 
    3859              :      Furthermore, all entities that reach this point must have a
    3860              :      definition available in this translation unit.
    3861              : 
    3862              :      The following assertions check these conditions.  */
    3863     41625694 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
    3864              :   /* Any code that creates entities with TREE_PUBLIC cleared should
    3865              :      also set DECL_INTERFACE_KNOWN.  */
    3866     41625694 :   gcc_assert (TREE_PUBLIC (decl));
    3867     41625694 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    3868     22475863 :     gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl)
    3869              :                 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
    3870              :                 || DECL_DECLARED_INLINE_P (decl));
    3871              :   else
    3872     19149831 :     gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl)
    3873              :                 || DECL_INLINE_VAR_P (decl)
    3874              :                 || DECL_VTABLE_OR_VTT_P (decl)
    3875              :                 || DECL_TINFO_P (decl));
    3876              :   /* Check that a definition of DECL is available in this translation
    3877              :      unit.  */
    3878     41625694 :   gcc_assert (!DECL_REALLY_EXTERN (decl));
    3879              : 
    3880              :   /* Assume that DECL will not have COMDAT linkage.  */
    3881     41625694 :   comdat_p = false;
    3882              :   /* Assume that DECL will not be imported into this translation
    3883              :      unit.  */
    3884     41625694 :   import_p = false;
    3885              : 
    3886     41625694 :   if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
    3887              :     {
    3888      1655740 :       class_type = DECL_CONTEXT (decl);
    3889      1655740 :       import_export_class (class_type);
    3890      1655740 :       if (CLASSTYPE_INTERFACE_KNOWN (class_type)
    3891      1655740 :           && CLASSTYPE_INTERFACE_ONLY (class_type))
    3892              :         import_p = true;
    3893       534442 :       else if ((!flag_weak || TARGET_WEAK_NOT_IN_ARCHIVE_TOC)
    3894       534442 :                && !vtables_uniquely_emitted (class_type))
    3895              :         /* The ABI historically required that all virtual tables be
    3896              :            emitted with COMDAT linkage.  However, on systems where
    3897              :            COMDAT symbols don't show up in the table of contents for
    3898              :            a static archive, or on systems without weak symbols (where
    3899              :            we approximate COMDAT linkage by using internal linkage),
    3900              :            the linker will report errors about undefined symbols because
    3901              :            it will not see the virtual table definition.  Therefore,
    3902              :            in the case that we know that the virtual table will be
    3903              :            emitted in only one translation unit, we make the virtual
    3904              :            table an ordinary definition with external linkage.  */
    3905            3 :         DECL_EXTERNAL (decl) = 0;
    3906       534439 :       else if (CLASSTYPE_INTERFACE_KNOWN (class_type))
    3907              :         {
    3908              :           /* CLASS_TYPE is being exported from this translation unit,
    3909              :              so DECL should be defined here.  */
    3910         2848 :           if (!flag_weak && CLASSTYPE_EXPLICIT_INSTANTIATION (class_type))
    3911              :             /* If a class is declared in a header with the "extern
    3912              :                template" extension, then it will not be instantiated,
    3913              :                even in translation units that would normally require
    3914              :                it.  Often such classes are explicitly instantiated in
    3915              :                one translation unit.  Therefore, the explicit
    3916              :                instantiation must be made visible to other translation
    3917              :                units.  */
    3918            0 :             DECL_EXTERNAL (decl) = 0;
    3919              :           else
    3920              :             {
    3921              :               /* The generic C++ ABI used to say that class data is always
    3922              :                  COMDAT, even if emitted in a unique object.  This is no
    3923              :                  longer true, but for now we continue to do so for
    3924              :                  compatibility with programs that are not strictly valid.
    3925              :                  However, some variants (e.g., the ARM EABI) explicitly say
    3926              :                  that class data only has COMDAT linkage if the class data
    3927              :                  might be emitted in more than one translation unit.
    3928              :                  When the key method can be inline and is inline, we still
    3929              :                  have to arrange for comdat even though
    3930              :                  class_data_always_comdat is false.  */
    3931         2848 :               if (!vtables_uniquely_emitted (class_type)
    3932         2848 :                   || targetm.cxx.class_data_always_comdat ())
    3933              :                 {
    3934              :                   /* The ABI requires COMDAT linkage.  Normally, we
    3935              :                      only emit COMDAT things when they are needed;
    3936              :                      make sure that we realize that this entity is
    3937              :                      indeed needed.  */
    3938         2848 :                   comdat_p = true;
    3939         2848 :                   mark_needed (decl);
    3940              :                 }
    3941              :             }
    3942              :         }
    3943       531591 :       else if (!flag_implicit_templates
    3944       531591 :                && CLASSTYPE_IMPLICIT_INSTANTIATION (class_type))
    3945              :         import_p = true;
    3946              :       else
    3947              :         comdat_p = true;
    3948              :     }
    3949     39969954 :   else if (VAR_P (decl) && DECL_TINFO_P (decl))
    3950              :     {
    3951      2304767 :       tree type = TREE_TYPE (DECL_NAME (decl));
    3952      2304767 :       if (CLASS_TYPE_P (type))
    3953              :         {
    3954      2301994 :           class_type = type;
    3955      2301994 :           import_export_class (type);
    3956      2301994 :           if (CLASSTYPE_INTERFACE_KNOWN (type)
    3957      1270041 :               && TYPE_CONTAINS_VPTR_P (type)
    3958      1269951 :               && CLASSTYPE_INTERFACE_ONLY (type)
    3959              :               /* If -fno-rtti was specified, then we cannot be sure
    3960              :                  that RTTI information will be emitted with the
    3961              :                  virtual table of the class, so we must emit it
    3962              :                  wherever it is used.  */
    3963      3568031 :               && flag_rtti)
    3964              :             import_p = true;
    3965              :           else
    3966              :             {
    3967      1036003 :               if (CLASSTYPE_INTERFACE_KNOWN (type)
    3968      1036003 :                   && !CLASSTYPE_INTERFACE_ONLY (type))
    3969              :                 {
    3970         3944 :                   comdat_p = (targetm.cxx.class_data_always_comdat ()
    3971         3944 :                               || !vtables_uniquely_emitted (class_type));
    3972         3944 :                   mark_needed (decl);
    3973         3944 :                   if (!flag_weak)
    3974              :                     {
    3975            0 :                       comdat_p = false;
    3976            0 :                       DECL_EXTERNAL (decl) = 0;
    3977              :                     }
    3978              :                 }
    3979              :               else
    3980              :                 comdat_p = true;
    3981              :             }
    3982              :         }
    3983              :       else
    3984              :         comdat_p = true;
    3985              :     }
    3986     37665187 :   else if (DECL_TEMPLOID_INSTANTIATION (decl))
    3987              :     {
    3988              :       /* DECL is an implicit instantiation of a function or static
    3989              :          data member.  */
    3990     37412294 :       if (flag_implicit_templates
    3991     37412294 :           || (flag_implicit_inline_templates
    3992        21124 :               && TREE_CODE (decl) == FUNCTION_DECL
    3993        16899 :               && DECL_DECLARED_INLINE_P (decl)))
    3994              :         comdat_p = true;
    3995              :       else
    3996              :         /* If we are not implicitly generating templates, then mark
    3997              :            this entity as undefined in this translation unit.  */
    3998              :         import_p = true;
    3999              :     }
    4000       252893 :   else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_FUNCTION_MEMBER_P (decl))
    4001              :     {
    4002       243549 :       if (!DECL_NONGNU_INLINE_P (decl))
    4003              :         {
    4004            0 :           tree ctype = DECL_CONTEXT (decl);
    4005            0 :           import_export_class (ctype);
    4006            0 :           if (CLASSTYPE_INTERFACE_KNOWN (ctype))
    4007              :             {
    4008            0 :               DECL_NOT_REALLY_EXTERN (decl)
    4009            0 :                 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
    4010            0 :                      || (DECL_DECLARED_INLINE_P (decl)
    4011            0 :                          && ! flag_implement_inlines
    4012            0 :                          && !DECL_VINDEX (decl)));
    4013              : 
    4014            0 :               if (!DECL_NOT_REALLY_EXTERN (decl))
    4015            0 :                 DECL_EXTERNAL (decl) = 1;
    4016              : 
    4017              :               /* Always make artificials weak.  */
    4018            0 :               if (DECL_ARTIFICIAL (decl) && flag_weak)
    4019              :                 comdat_p = true;
    4020              :               else
    4021            0 :                 maybe_make_one_only (decl);
    4022              :             }
    4023              :         }
    4024              :       else
    4025              :         comdat_p = true;
    4026              :     }
    4027              :   else
    4028              :     comdat_p = true;
    4029              : 
    4030         2851 :   if (import_p)
    4031              :     {
    4032              :       /* If we are importing DECL into this translation unit, mark is
    4033              :          an undefined here.  */
    4034      2394893 :       DECL_EXTERNAL (decl) = 1;
    4035      2394893 :       DECL_NOT_REALLY_EXTERN (decl) = 0;
    4036              :     }
    4037     39230801 :   else if (comdat_p)
    4038              :     {
    4039              :       /* If we decided to put DECL in COMDAT, mark it accordingly at
    4040              :          this point.  */
    4041     39230798 :       comdat_linkage (decl);
    4042              :     }
    4043              : 
    4044     41625694 :   DECL_INTERFACE_KNOWN (decl) = 1;
    4045              : }
    4046              : 
    4047              : /* Return an expression that performs the destruction of DECL, which
    4048              :    must be a VAR_DECL whose type has a non-trivial destructor, or is
    4049              :    an array whose (innermost) elements have a non-trivial destructor.  */
    4050              : 
    4051              : tree
    4052         1269 : build_cleanup (tree decl)
    4053              : {
    4054         1269 :   tree clean = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
    4055         1269 :   gcc_assert (clean != NULL_TREE);
    4056         1269 :   return clean;
    4057              : }
    4058              : 
    4059              : /* GUARD is a helper variable for DECL; make them have the same linkage and
    4060              :    visibility.  */
    4061              : 
    4062              : void
    4063        77418 : copy_linkage (tree guard, tree decl)
    4064              : {
    4065        77418 :   TREE_PUBLIC (guard) = TREE_PUBLIC (decl);
    4066        77418 :   TREE_STATIC (guard) = TREE_STATIC (decl);
    4067        77418 :   DECL_COMMON (guard) = DECL_COMMON (decl);
    4068        77418 :   DECL_COMDAT (guard) = DECL_COMDAT (decl);
    4069        77418 :   if (TREE_STATIC (guard))
    4070              :     {
    4071         6439 :       CP_DECL_THREAD_LOCAL_P (guard) = CP_DECL_THREAD_LOCAL_P (decl);
    4072         6439 :       set_decl_tls_model (guard, DECL_TLS_MODEL (decl));
    4073         6439 :       if (DECL_ONE_ONLY (decl))
    4074         4479 :         make_decl_one_only (guard, cxx_comdat_group (guard));
    4075         6439 :       if (TREE_PUBLIC (decl))
    4076         5261 :         DECL_WEAK (guard) = DECL_WEAK (decl);
    4077              :       /* Also check vague_linkage_p, as DECL_WEAK and DECL_ONE_ONLY might not
    4078              :          be set until import_export_decl at EOF.  */
    4079         6439 :       if (vague_linkage_p (decl))
    4080         4499 :         comdat_linkage (guard);
    4081         6439 :       DECL_VISIBILITY (guard) = DECL_VISIBILITY (decl);
    4082         6439 :       DECL_VISIBILITY_SPECIFIED (guard) = DECL_VISIBILITY_SPECIFIED (decl);
    4083         6439 :       if (!TREE_PUBLIC (decl))
    4084              :         {
    4085         1178 :           gcc_checking_assert (DECL_INTERFACE_KNOWN (decl));
    4086         1178 :           DECL_INTERFACE_KNOWN (guard) = 1;
    4087         1178 :           if (DECL_LANG_SPECIFIC (decl) && DECL_LANG_SPECIFIC (guard))
    4088          248 :             DECL_NOT_REALLY_EXTERN (guard) = DECL_NOT_REALLY_EXTERN (decl);
    4089              :         }
    4090              :     }
    4091        77418 : }
    4092              : 
    4093              : /* Returns the initialization guard variable for the variable DECL,
    4094              :    which has static storage duration.  */
    4095              : 
    4096              : tree
    4097         4834 : get_guard (tree decl)
    4098              : {
    4099         4834 :   tree sname = mangle_guard_variable (decl);
    4100         4834 :   tree guard = get_global_binding (sname);
    4101         4834 :   if (! guard)
    4102              :     {
    4103         4834 :       tree guard_type;
    4104              : 
    4105              :       /* We use a type that is big enough to contain a mutex as well
    4106              :          as an integer counter.  */
    4107         4834 :       guard_type = targetm.cxx.guard_type ();
    4108         4834 :       guard = build_decl (DECL_SOURCE_LOCATION (decl),
    4109              :                           VAR_DECL, sname, guard_type);
    4110              : 
    4111              :       /* The guard should have the same linkage as what it guards.  */
    4112         4834 :       copy_linkage (guard, decl);
    4113              : 
    4114         4834 :       DECL_ARTIFICIAL (guard) = 1;
    4115         4834 :       DECL_IGNORED_P (guard) = 1;
    4116         4834 :       TREE_USED (guard) = 1;
    4117         4834 :       pushdecl_top_level_and_finish (guard, NULL_TREE);
    4118              :     }
    4119         4834 :   return guard;
    4120              : }
    4121              : 
    4122              : /* Returns true if accessing the GUARD atomic is expensive,
    4123              :    i.e. involves a call to __sync_synchronize or similar.
    4124              :    In this case let __cxa_guard_acquire handle the atomics.  */
    4125              : 
    4126              : static bool
    4127         3708 : is_atomic_expensive_p (machine_mode mode)
    4128              : {
    4129         3708 :   if (!flag_inline_atomics)
    4130              :     return true;
    4131              : 
    4132         3708 :   if (!can_compare_and_swap_p (mode, false) || !can_atomic_load_p (mode))
    4133            0 :     return true;
    4134              : 
    4135              :   return false;
    4136              : }
    4137              : 
    4138              : /* Return an atomic load of src with the appropriate memory model.  */
    4139              : 
    4140              : static tree
    4141         3708 : build_atomic_load_type (tree src, HOST_WIDE_INT model, tree type)
    4142              : {
    4143         3708 :   tree ptr_type = build_pointer_type (type);
    4144         3708 :   tree mem_model = build_int_cst (integer_type_node, model);
    4145         3708 :   tree t, addr, val;
    4146         3708 :   unsigned int size;
    4147         3708 :   int fncode;
    4148              : 
    4149         3708 :   size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    4150              : 
    4151         3708 :   fncode = BUILT_IN_ATOMIC_LOAD_N + exact_log2 (size) + 1;
    4152         3708 :   t = builtin_decl_implicit ((enum built_in_function) fncode);
    4153              : 
    4154         3708 :   addr = build1 (ADDR_EXPR, ptr_type, src);
    4155         3708 :   val = build_call_expr (t, 2, addr, mem_model);
    4156         3708 :   return val;
    4157              : }
    4158              : 
    4159              : /* Return those bits of the GUARD variable that should be set when the
    4160              :    guarded entity is actually initialized.  */
    4161              : 
    4162              : static tree
    4163         2252 : get_guard_bits (tree guard)
    4164              : {
    4165         2252 :   if (!targetm.cxx.guard_mask_bit ())
    4166              :     {
    4167              :       /* We only set the first byte of the guard, in order to leave room
    4168              :          for a mutex in the high-order bits.  */
    4169         2252 :       guard = build1 (ADDR_EXPR,
    4170         2252 :                       build_pointer_type (TREE_TYPE (guard)),
    4171              :                       guard);
    4172         2252 :       guard = build1 (NOP_EXPR,
    4173              :                       build_pointer_type (char_type_node),
    4174              :                       guard);
    4175         2252 :       guard = build1 (INDIRECT_REF, char_type_node, guard);
    4176              :     }
    4177              : 
    4178         2252 :   return guard;
    4179              : }
    4180              : 
    4181              : /* Return an expression which determines whether or not the GUARD
    4182              :    variable has already been initialized.  */
    4183              : 
    4184              : tree
    4185         4834 : get_guard_cond (tree guard, bool thread_safe)
    4186              : {
    4187         4834 :   tree guard_value;
    4188              : 
    4189         4834 :   if (!thread_safe)
    4190         1126 :     guard = get_guard_bits (guard);
    4191              :   else
    4192              :     {
    4193         3708 :       tree type = targetm.cxx.guard_mask_bit ()
    4194         3708 :                   ? TREE_TYPE (guard) : char_type_node;
    4195              : 
    4196         3708 :       if (is_atomic_expensive_p (TYPE_MODE (type)))
    4197            0 :         guard = integer_zero_node;
    4198              :       else
    4199         3708 :         guard = build_atomic_load_type (guard, MEMMODEL_ACQUIRE, type);
    4200              :     }
    4201              : 
    4202              :   /* Mask off all but the low bit.  */
    4203         4834 :   if (targetm.cxx.guard_mask_bit ())
    4204              :     {
    4205            0 :       guard_value = integer_one_node;
    4206            0 :       if (!same_type_p (TREE_TYPE (guard_value), TREE_TYPE (guard)))
    4207            0 :         guard_value = fold_convert (TREE_TYPE (guard), guard_value);
    4208            0 :       guard = cp_build_binary_op (input_location,
    4209              :                                   BIT_AND_EXPR, guard, guard_value,
    4210              :                                   tf_warning_or_error);
    4211              :     }
    4212              : 
    4213         4834 :   guard_value = integer_zero_node;
    4214         4834 :   if (!same_type_p (TREE_TYPE (guard_value), TREE_TYPE (guard)))
    4215         4834 :     guard_value = fold_convert (TREE_TYPE (guard), guard_value);
    4216         4834 :   return cp_build_binary_op (input_location,
    4217              :                              EQ_EXPR, guard, guard_value,
    4218         4834 :                              tf_warning_or_error);
    4219              : }
    4220              : 
    4221              : /* Return an expression which sets the GUARD variable, indicating that
    4222              :    the variable being guarded has been initialized.  */
    4223              : 
    4224              : tree
    4225         1126 : set_guard (tree guard)
    4226              : {
    4227         1126 :   tree guard_init;
    4228              : 
    4229              :   /* Set the GUARD to one.  */
    4230         1126 :   guard = get_guard_bits (guard);
    4231         1126 :   guard_init = integer_one_node;
    4232         1126 :   if (!same_type_p (TREE_TYPE (guard_init), TREE_TYPE (guard)))
    4233         1126 :     guard_init = fold_convert (TREE_TYPE (guard), guard_init);
    4234         1126 :   return cp_build_modify_expr (input_location, guard, NOP_EXPR, guard_init,
    4235         1126 :                                tf_warning_or_error);
    4236              : }
    4237              : 
    4238              : /* Returns true iff we can tell that VAR does not have a dynamic
    4239              :    initializer.  */
    4240              : 
    4241              : static bool
    4242         2602 : var_defined_without_dynamic_init (tree var)
    4243              : {
    4244              :   /* constinit vars are guaranteed to not have dynamic initializer,
    4245              :      but still registering the destructor counts as dynamic initialization.  */
    4246         2602 :   if (DECL_DECLARED_CONSTINIT_P (var)
    4247           24 :       && COMPLETE_TYPE_P (TREE_TYPE (var))
    4248         2620 :       && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (var)))
    4249              :     return true;
    4250              :   /* If it's defined in another TU, we can't tell.  */
    4251         2590 :   if (DECL_EXTERNAL (var))
    4252              :     return false;
    4253              :   /* If it has a non-trivial destructor, registering the destructor
    4254              :      counts as dynamic initialization.  */
    4255         2343 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (var)))
    4256              :     return false;
    4257              :   /* If it's in this TU, its initializer has been processed, unless
    4258              :      it's a case of self-initialization, then DECL_INITIALIZED_P is
    4259              :      false while the initializer is handled by finish_id_expression.  */
    4260         2162 :   if (!DECL_INITIALIZED_P (var))
    4261              :     return false;
    4262              :   /* If it has no initializer or a constant one, it's not dynamic.  */
    4263         2156 :   return (!DECL_NONTRIVIALLY_INITIALIZED_P (var)
    4264         2156 :           || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var));
    4265              : }
    4266              : 
    4267              : /* Returns true iff VAR is a variable that needs uses to be
    4268              :    wrapped for possible dynamic initialization.  */
    4269              : 
    4270              : bool
    4271        77766 : var_needs_tls_wrapper (tree var)
    4272              : {
    4273        77766 :   return (!error_operand_p (var)
    4274        77763 :           && CP_DECL_THREAD_LOCAL_P (var)
    4275        77763 :           && !DECL_GNU_TLS_P (var)
    4276         2740 :           && !DECL_FUNCTION_SCOPE_P (var)
    4277        80368 :           && !var_defined_without_dynamic_init (var));
    4278              : }
    4279              : 
    4280              : /* Get the FUNCTION_DECL for the shared TLS init function for this
    4281              :    translation unit.  */
    4282              : 
    4283              : static tree
    4284          195 : get_local_tls_init_fn (location_t loc)
    4285              : {
    4286          195 :   tree sname = get_identifier ("__tls_init");
    4287          195 :   tree fn = get_global_binding (sname);
    4288          195 :   if (!fn)
    4289              :     {
    4290          123 :       fn = build_lang_decl_loc (loc, FUNCTION_DECL, sname,
    4291              :                                 build_function_type (void_type_node,
    4292              :                                                      void_list_node));
    4293          123 :       SET_DECL_LANGUAGE (fn, lang_c);
    4294          123 :       TREE_PUBLIC (fn) = false;
    4295          123 :       DECL_ARTIFICIAL (fn) = true;
    4296          123 :       mark_used (fn);
    4297          123 :       set_global_binding (fn);
    4298              :     }
    4299          195 :   return fn;
    4300              : }
    4301              : 
    4302              : /* Get a FUNCTION_DECL for the init function for the thread_local
    4303              :    variable VAR.  The init function will be an alias to the function
    4304              :    that initializes all the non-local TLS variables in the translation
    4305              :    unit.  The init function is only used by the wrapper function.  */
    4306              : 
    4307              : static tree
    4308         1282 : get_tls_init_fn (tree var)
    4309              : {
    4310              :   /* Only C++11 TLS vars need this init fn.  */
    4311         1282 :   if (!var_needs_tls_wrapper (var))
    4312              :     return NULL_TREE;
    4313              : 
    4314              :   /* If -fno-extern-tls-init, assume that we don't need to call
    4315              :      a tls init function for a variable defined in another TU.  */
    4316         1263 :   if (!flag_extern_tls_init && DECL_EXTERNAL (var))
    4317              :     return NULL_TREE;
    4318              : 
    4319              :   /* If the variable is internal, or if we can't generate aliases,
    4320              :      call the local init function directly.  */
    4321         1262 :   if (!TREE_PUBLIC (var) || !TARGET_SUPPORTS_ALIASES)
    4322           72 :     return get_local_tls_init_fn (DECL_SOURCE_LOCATION (var));
    4323              : 
    4324         1190 :   tree sname = mangle_tls_init_fn (var);
    4325         1190 :   tree fn = get_global_binding (sname);
    4326         1190 :   if (!fn)
    4327              :     {
    4328          765 :       fn = build_lang_decl (FUNCTION_DECL, sname,
    4329              :                             build_function_type (void_type_node,
    4330              :                                                  void_list_node));
    4331          765 :       SET_DECL_LANGUAGE (fn, lang_c);
    4332          765 :       TREE_PUBLIC (fn) = TREE_PUBLIC (var);
    4333          765 :       DECL_ARTIFICIAL (fn) = true;
    4334          765 :       DECL_CONTEXT (fn) = FROB_CONTEXT (global_namespace);
    4335          765 :       DECL_COMDAT (fn) = DECL_COMDAT (var);
    4336          765 :       DECL_EXTERNAL (fn) = DECL_EXTERNAL (var);
    4337          765 :       if (DECL_ONE_ONLY (var))
    4338            3 :         make_decl_one_only (fn, cxx_comdat_group (fn));
    4339          765 :       if (TREE_PUBLIC (var))
    4340              :         {
    4341          765 :           tree obtype = strip_array_types (non_reference (TREE_TYPE (var)));
    4342              :           /* If the variable is defined somewhere else and might have static
    4343              :              initialization, make the init function a weak reference.  */
    4344          765 :           if ((!TYPE_NEEDS_CONSTRUCTING (obtype)
    4345          603 :                || TYPE_HAS_CONSTEXPR_CTOR (obtype)
    4346          585 :                || TYPE_HAS_TRIVIAL_DFLT (obtype))
    4347          180 :               && TYPE_HAS_TRIVIAL_DESTRUCTOR (obtype)
    4348          927 :               && DECL_EXTERNAL (var))
    4349           51 :             declare_weak (fn);
    4350              :           else
    4351          714 :             DECL_WEAK (fn) = DECL_WEAK (var);
    4352              :         }
    4353          765 :       DECL_VISIBILITY (fn) = DECL_VISIBILITY (var);
    4354          765 :       DECL_VISIBILITY_SPECIFIED (fn) = DECL_VISIBILITY_SPECIFIED (var);
    4355          765 :       DECL_DLLIMPORT_P (fn) = DECL_DLLIMPORT_P (var);
    4356          765 :       DECL_IGNORED_P (fn) = 1;
    4357          765 :       mark_used (fn);
    4358              : 
    4359          765 :       DECL_BEFRIENDING_CLASSES (fn) = var;
    4360              : 
    4361          765 :       set_global_binding (fn);
    4362              :     }
    4363              :   return fn;
    4364              : }
    4365              : 
    4366              : /* Get a FUNCTION_DECL for the init wrapper function for the thread_local
    4367              :    variable VAR.  The wrapper function calls the init function (if any) for
    4368              :    VAR and then returns a reference to VAR.  The wrapper function is used
    4369              :    in place of VAR everywhere VAR is mentioned.  */
    4370              : 
    4371              : static tree
    4372        76469 : get_tls_wrapper_fn (tree var)
    4373              : {
    4374              :   /* Only C++11 TLS vars need this wrapper fn.  */
    4375        76469 :   if (!var_needs_tls_wrapper (var))
    4376              :     return NULL_TREE;
    4377              : 
    4378          749 :   tree sname = mangle_tls_wrapper_fn (var);
    4379          749 :   tree fn = get_global_binding (sname);
    4380          749 :   if (!fn)
    4381              :     {
    4382              :       /* A named rvalue reference is an lvalue, so the wrapper should
    4383              :          always return an lvalue reference.  */
    4384          586 :       tree type = non_reference (TREE_TYPE (var));
    4385          586 :       type = build_reference_type (type);
    4386          586 :       tree fntype = build_function_type (type, void_list_node);
    4387              : 
    4388          586 :       fn = build_lang_decl_loc (DECL_SOURCE_LOCATION (var),
    4389              :                                 FUNCTION_DECL, sname, fntype);
    4390          586 :       SET_DECL_LANGUAGE (fn, lang_c);
    4391          586 :       TREE_PUBLIC (fn) = TREE_PUBLIC (var);
    4392          586 :       DECL_ARTIFICIAL (fn) = true;
    4393          586 :       DECL_IGNORED_P (fn) = 1;
    4394          586 :       DECL_CONTEXT (fn) = FROB_CONTEXT (global_namespace);
    4395              :       /* The wrapper is inline and emitted everywhere var is used.  */
    4396          586 :       DECL_DECLARED_INLINE_P (fn) = true;
    4397          586 :       if (TREE_PUBLIC (var))
    4398              :         {
    4399          514 :           comdat_linkage (fn);
    4400              : #ifdef HAVE_GAS_HIDDEN
    4401              :           /* Make the wrapper bind locally; there's no reason to share
    4402              :              the wrapper between multiple shared objects.  */
    4403          514 :           DECL_VISIBILITY (fn) = VISIBILITY_INTERNAL;
    4404          514 :           DECL_VISIBILITY_SPECIFIED (fn) = true;
    4405              : #endif
    4406              :         }
    4407          586 :       if (!TREE_PUBLIC (fn))
    4408           72 :         DECL_INTERFACE_KNOWN (fn) = true;
    4409          586 :       mark_used (fn);
    4410          586 :       note_vague_linkage_fn (fn);
    4411              : 
    4412              : #if 0
    4413              :       /* We want CSE to commonize calls to the wrapper, but marking it as
    4414              :          pure is unsafe since it has side-effects.  I guess we need a new
    4415              :          ECF flag even weaker than ECF_PURE.  FIXME!  */
    4416              :       DECL_PURE_P (fn) = true;
    4417              : #endif
    4418              : 
    4419          586 :       DECL_BEFRIENDING_CLASSES (fn) = var;
    4420              : 
    4421          586 :       set_global_binding (fn);
    4422              :     }
    4423              :   return fn;
    4424              : }
    4425              : 
    4426              : /* If EXPR is a thread_local variable that should be wrapped by init
    4427              :    wrapper function, return a call to that function, otherwise return
    4428              :    NULL.  */
    4429              : 
    4430              : tree
    4431   1002919937 : maybe_get_tls_wrapper_call (tree expr)
    4432              : {
    4433   1002919937 :   if (VAR_P (expr)
    4434    345692523 :       && !processing_template_decl
    4435    145203657 :       && !cp_unevaluated_operand
    4436   1146254738 :       && CP_DECL_THREAD_LOCAL_P (expr))
    4437        76469 :     if (tree wrap = get_tls_wrapper_fn (expr))
    4438          749 :       return build_cxx_call (wrap, 0, NULL, tf_warning_or_error);
    4439              :   return NULL;
    4440              : }
    4441              : 
    4442              : /* At EOF, generate the definition for the TLS wrapper function FN:
    4443              : 
    4444              :    T& var_wrapper() {
    4445              :      if (init_fn) init_fn();
    4446              :      return var;
    4447              :    }  */
    4448              : 
    4449              : static void
    4450          586 : generate_tls_wrapper (tree fn)
    4451              : {
    4452          586 :   tree var = DECL_BEFRIENDING_CLASSES (fn);
    4453              : 
    4454          586 :   start_preparsed_function (fn, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
    4455          586 :   tree body = begin_function_body ();
    4456              :   /* Only call the init fn if there might be one.  */
    4457          586 :   if (tree init_fn = get_tls_init_fn (var))
    4458              :     {
    4459          566 :       tree if_stmt = NULL_TREE;
    4460              :       /* If init_fn is a weakref, make sure it exists before calling.  */
    4461          566 :       if (lookup_attribute ("weak", DECL_ATTRIBUTES (init_fn)))
    4462              :         {
    4463           51 :           if_stmt = begin_if_stmt ();
    4464           51 :           tree addr = cp_build_addr_expr (init_fn, tf_warning_or_error);
    4465           51 :           tree cond = cp_build_binary_op (DECL_SOURCE_LOCATION (var),
    4466              :                                           NE_EXPR, addr, nullptr_node,
    4467              :                                           tf_warning_or_error);
    4468           51 :           finish_if_stmt_cond (cond, if_stmt);
    4469              :         }
    4470          566 :       finish_expr_stmt (build_cxx_call
    4471              :                         (init_fn, 0, NULL, tf_warning_or_error));
    4472          566 :       if (if_stmt)
    4473              :         {
    4474           51 :           finish_then_clause (if_stmt);
    4475           51 :           finish_if_stmt (if_stmt);
    4476              :         }
    4477              :     }
    4478              :   else
    4479              :     /* If there's no initialization, the wrapper is a constant function.  */
    4480           20 :     TREE_READONLY (fn) = true;
    4481          586 :   finish_return_stmt (convert_from_reference (var));
    4482          586 :   finish_function_body (body);
    4483          586 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
    4484          586 : }
    4485              : 
    4486              : /* Start a global constructor or destructor function.  */
    4487              : 
    4488              : static tree
    4489         7676 : start_objects (bool initp, unsigned priority, bool has_body,
    4490              :                bool omp_target = false)
    4491              : {
    4492         7676 :   bool default_init = initp && priority == DEFAULT_INIT_PRIORITY;
    4493              :   /* FIXME: We may eventually want to treat OpenMP offload initializers
    4494              :      in modules specially as well.  */
    4495         7676 :   bool is_module_init = (default_init
    4496         7676 :                          && !omp_target
    4497         7676 :                          && module_global_init_needed ());
    4498         7676 :   tree name = NULL_TREE;
    4499              : 
    4500         7676 :   if (is_module_init)
    4501         2050 :     name = mangle_module_global_init (0);
    4502              :   else
    4503              :     {
    4504         5626 :       char type[14];
    4505              : 
    4506              :       /* We use `I' to indicate initialization and `D' to indicate
    4507              :          destruction.  */
    4508         5626 :       unsigned len;
    4509         5626 :       if (omp_target)
    4510              :         /* Use "off_" signifying "offload" here.  The name must be distinct
    4511              :            from the non-offload case.  The format of the name is scanned in
    4512              :            tree.cc/get_file_function_name, so stick to the same length for
    4513              :            both name variants.  */
    4514           15 :         len = sprintf (type, "off_%c", initp ? 'I' : 'D');
    4515              :       else
    4516         5620 :         len = sprintf (type, "sub_%c", initp ? 'I' : 'D');
    4517         5626 :       if (priority != DEFAULT_INIT_PRIORITY)
    4518              :         {
    4519           40 :           char joiner = '_';
    4520              : #ifdef JOINER
    4521           40 :           joiner = JOINER;
    4522              : #endif
    4523           40 :           type[len++] = joiner;
    4524           40 :           sprintf (type + len, "%.5u", priority);
    4525              :         }
    4526         5626 :       name = get_file_function_name (type);
    4527              :     }
    4528              : 
    4529         7676 :   tree fntype = build_function_type (void_type_node, void_list_node);
    4530         7676 :   tree fndecl = build_lang_decl (FUNCTION_DECL, name, fntype);
    4531              : 
    4532         7676 :   if (omp_target)
    4533              :     {
    4534           15 :       DECL_ATTRIBUTES (fndecl)
    4535           15 :         = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
    4536           15 :                      DECL_ATTRIBUTES (fndecl));
    4537           15 :       DECL_ATTRIBUTES (fndecl)
    4538           30 :         = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
    4539           15 :                      DECL_ATTRIBUTES (fndecl));
    4540              :     }
    4541              : 
    4542         7676 :   DECL_CONTEXT (fndecl) = FROB_CONTEXT (global_namespace);
    4543         7676 :   if (is_module_init)
    4544              :     {
    4545         2050 :       SET_DECL_ASSEMBLER_NAME (fndecl, name);
    4546         2050 :       TREE_PUBLIC (fndecl) = true;
    4547         2050 :       determine_visibility (fndecl);
    4548              :     }
    4549              :   else
    4550         5626 :     TREE_PUBLIC (fndecl) = 0;
    4551         7676 :   start_preparsed_function (fndecl, /*attrs=*/NULL_TREE, SF_PRE_PARSED);
    4552              : 
    4553              :   /* Mark as artificial because it's not explicitly in the user's
    4554              :      source code.  */
    4555         7676 :   DECL_ARTIFICIAL (current_function_decl) = 1;
    4556              : 
    4557              :   /* Mark this declaration as used to avoid spurious warnings.  */
    4558         7676 :   TREE_USED (current_function_decl) = 1;
    4559              : 
    4560              :   /* Mark this function as a global constructor or destructor.  */
    4561         7676 :   if (initp)
    4562         7667 :     DECL_GLOBAL_CTOR_P (current_function_decl) = 1;
    4563              :   else
    4564            9 :     DECL_GLOBAL_DTOR_P (current_function_decl) = 1;
    4565              : 
    4566         7676 :   tree body = begin_compound_stmt (BCS_FN_BODY);
    4567              : 
    4568         7676 :   if (is_module_init && has_body)
    4569              :     {
    4570              :       // If the function is going to be empty, don't emit idempotency.
    4571              :       // 'static bool __in_chrg = false;
    4572              :       // if (__inchrg) return;
    4573              :       // __inchrg = true
    4574           73 :       tree var = build_lang_decl (VAR_DECL, in_charge_identifier,
    4575              :                                   boolean_type_node);
    4576           73 :       DECL_CONTEXT (var) = fndecl;
    4577           73 :       DECL_ARTIFICIAL (var) = true;
    4578           73 :       TREE_STATIC (var) = true;
    4579           73 :       pushdecl (var);
    4580           73 :       cp_finish_decl (var, NULL_TREE, false, NULL_TREE, 0);
    4581              : 
    4582           73 :       tree if_stmt = begin_if_stmt ();
    4583           73 :       finish_if_stmt_cond (var, if_stmt);
    4584           73 :       finish_return_stmt (NULL_TREE);
    4585           73 :       finish_then_clause (if_stmt);
    4586           73 :       finish_if_stmt (if_stmt);
    4587              : 
    4588           73 :       tree assign = build2 (MODIFY_EXPR, boolean_type_node,
    4589              :                             var, boolean_true_node);
    4590           73 :       TREE_SIDE_EFFECTS (assign) = true;
    4591           73 :       finish_expr_stmt (assign);
    4592              :     }
    4593              : 
    4594         7676 :   return body;
    4595              : }
    4596              : 
    4597              : /* Finish a global constructor or destructor.  Add it to the global
    4598              :    ctors or dtors, if STARTP is true.  */
    4599              : 
    4600              : static tree
    4601         7673 : finish_objects (bool initp, unsigned priority, tree body, bool startp)
    4602              : {
    4603              :   /* Finish up.  */
    4604         7673 :   finish_compound_stmt (body);
    4605         7673 :   tree fn = finish_function (/*inline_p=*/false);
    4606              : 
    4607         7673 :   if (!startp)
    4608              :     ; // Neither ctor nor dtor I be.
    4609         5696 :   else if (initp)
    4610              :     {
    4611         5687 :       DECL_STATIC_CONSTRUCTOR (fn) = 1;
    4612         5687 :       decl_init_priority_insert (fn, priority);
    4613              :     }
    4614              :   else
    4615              :     {
    4616            9 :       DECL_STATIC_DESTRUCTOR (fn) = 1;
    4617            9 :       decl_fini_priority_insert (fn, priority);
    4618              :     }
    4619              : 
    4620         7673 :   return fn;
    4621              : }
    4622              : 
    4623              : /* The name of the function we create to handle initializations and
    4624              :    destructions for objects with static storage duration.  */
    4625              : #define SSDF_IDENTIFIER "__static_initialization_and_destruction"
    4626              : #define OMP_SSDF_IDENTIFIER "__omp_target_static_init_and_destruction"
    4627              : 
    4628              : /* Begins the generation of the function that will handle all
    4629              :    initialization or destruction of objects with static storage
    4630              :    duration at PRIORITY.
    4631              : 
    4632              :    It is assumed that this function will be called once for the host, and once
    4633              :    for an OpenMP offload target.  */
    4634              : 
    4635              : static tree
    4636         5705 : start_partial_init_fini_fn (bool initp, unsigned priority, unsigned count,
    4637              :                             bool omp_target)
    4638              : {
    4639         5705 :   char id[MAX (sizeof (SSDF_IDENTIFIER), sizeof (OMP_SSDF_IDENTIFIER))
    4640              :           + 1 /* \0 */ + 32];
    4641         5705 :   tree name;
    4642              : 
    4643              :   /* Create the identifier for this function.  It will be of the form
    4644              :      SSDF_IDENTIFIER_<number> if not omp_target and otherwise
    4645              :      OMP_SSDF_IDENTIFIER_<number>.  */
    4646         5705 :   sprintf (id, "%s_%u", omp_target ? OMP_SSDF_IDENTIFIER : SSDF_IDENTIFIER,
    4647              :            count);
    4648         5705 :   name = get_identifier (id);
    4649         5705 :   tree type = build_function_type (void_type_node, void_list_node);
    4650              : 
    4651              :   /* Create the FUNCTION_DECL itself.  */
    4652         5705 :   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
    4653         5705 :   TREE_PUBLIC (fn) = 0;
    4654         5705 :   DECL_ARTIFICIAL (fn) = 1;
    4655              : 
    4656         5705 :   if (omp_target)
    4657              :     {
    4658           15 :       DECL_ATTRIBUTES (fn)
    4659           15 :         = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
    4660           15 :                      DECL_ATTRIBUTES (fn));
    4661           15 :       DECL_ATTRIBUTES (fn)
    4662           30 :         = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
    4663           15 :                      DECL_ATTRIBUTES (fn));
    4664              :     }
    4665              : 
    4666         5705 :   int idx = initp + 2 * omp_target;
    4667              : 
    4668              :   /* Put this function in the list of functions to be called from the
    4669              :      static constructors and destructors.  */
    4670         5705 :   if (!static_init_fini_fns[idx])
    4671         5675 :     static_init_fini_fns[idx] = priority_map_t::create_ggc ();
    4672         5705 :   auto &slot = static_init_fini_fns[idx]->get_or_insert (priority);
    4673         5705 :   slot = tree_cons (fn, NULL_TREE, slot);
    4674              : 
    4675              :   /* Put the function in the global scope.  */
    4676         5705 :   pushdecl (fn);
    4677              : 
    4678              :   /* Start the function itself.  This is equivalent to declaring the
    4679              :      function as:
    4680              : 
    4681              :        static void __ssdf (int __initialize_p, init __priority_p);
    4682              : 
    4683              :      It is static because we only need to call this function from the
    4684              :      various constructor and destructor functions for this module.  */
    4685         5705 :   start_preparsed_function (fn, /*attrs=*/NULL_TREE, SF_PRE_PARSED);
    4686              : 
    4687              :   /* Set up the scope of the outermost block in the function.  */
    4688         5705 :   return begin_compound_stmt (BCS_FN_BODY);
    4689              : }
    4690              : 
    4691              : /* Finish the generation of the function which performs initialization
    4692              :    or destruction of objects with static storage duration.  */
    4693              : 
    4694              : static void
    4695         5705 : finish_partial_init_fini_fn (tree body)
    4696              : {
    4697              :   /* Close out the function.  */
    4698         5705 :   finish_compound_stmt (body);
    4699         5705 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
    4700         5705 : }
    4701              : 
    4702              : /* The effective initialization priority of a DECL.  */
    4703              : 
    4704              : #define DECL_EFFECTIVE_INIT_PRIORITY(decl)                                    \
    4705              :         ((!DECL_HAS_INIT_PRIORITY_P (decl) || DECL_INIT_PRIORITY (decl) == 0) \
    4706              :          ? DEFAULT_INIT_PRIORITY : DECL_INIT_PRIORITY (decl))
    4707              : 
    4708              : /* Whether a DECL needs a guard to protect it against multiple
    4709              :    initialization.  */
    4710              : 
    4711              : #define NEEDS_GUARD_P(decl) (TREE_PUBLIC (decl) && (DECL_COMMON (decl)      \
    4712              :                                                     || DECL_ONE_ONLY (decl) \
    4713              :                                                     || DECL_WEAK (decl)))
    4714              : 
    4715              : /* Walks the initializer list of a global variable and looks for
    4716              :    temporary variables (DECL_NAME() == NULL and DECL_ARTIFICIAL != 0)
    4717              :    and that have their DECL_CONTEXT() == NULL.  For each such
    4718              :    temporary variable, set their DECL_CONTEXT() to CTX -- the
    4719              :    initializing function. This is necessary because otherwise some
    4720              :    optimizers (enabled by -O2 -fprofile-arcs) might crash when trying
    4721              :    to refer to a temporary variable that does not have its
    4722              :    DECL_CONTEXT() properly set.  */
    4723              : 
    4724              : static tree
    4725       194227 : fix_temporary_vars_context_r (tree *node,
    4726              :                               int  * /*unused*/,
    4727              :                               void *ctx)
    4728              : {
    4729       194227 :   if (TREE_CODE (*node) == BIND_EXPR)
    4730          446 :     for (tree var = BIND_EXPR_VARS (*node); var; var = DECL_CHAIN (var))
    4731          223 :       if (VAR_P (var) && !DECL_NAME (var)
    4732          446 :           && DECL_ARTIFICIAL (var) && !DECL_CONTEXT (var))
    4733          223 :         DECL_CONTEXT (var) = tree (ctx);
    4734              : 
    4735       194227 :   return NULL_TREE;
    4736              : }
    4737              : 
    4738              : /* Set up to handle the initialization or destruction of DECL.  If
    4739              :    INITP is nonzero, we are initializing the variable.  Otherwise, we
    4740              :    are destroying it.  */
    4741              : 
    4742              : static void
    4743        11370 : one_static_initialization_or_destruction (bool initp, tree decl, tree init,
    4744              :                                           bool omp_target)
    4745              : {
    4746              :   /* If we are supposed to destruct and there's a trivial destructor,
    4747              :      nothing has to be done.  */
    4748        11370 :   gcc_checking_assert (init || !TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)));
    4749              : 
    4750              :   /* Trick the compiler into thinking we are at the file and line
    4751              :      where DECL was declared so that error-messages make sense, and so
    4752              :      that the debugger will show somewhat sensible file and line
    4753              :      information.  */
    4754        11370 :   input_location = DECL_SOURCE_LOCATION (decl);
    4755              : 
    4756              :   /* Make sure temporary variables in the initialiser all have
    4757              :      their DECL_CONTEXT() set to a value different from NULL_TREE.
    4758              :      This can happen when global variables initializers are built.
    4759              :      In that case, the DECL_CONTEXT() of the global variables _AND_ of all
    4760              :      the temporary variables that might have been generated in the
    4761              :      accompanying initializers is NULL_TREE, meaning the variables have been
    4762              :      declared in the global namespace.
    4763              :      What we want to do here is to fix that and make sure the DECL_CONTEXT()
    4764              :      of the temporaries are set to the current function decl.  */
    4765        11370 :   cp_walk_tree_without_duplicates (&init,
    4766              :                                    fix_temporary_vars_context_r,
    4767              :                                    current_function_decl);
    4768              : 
    4769              :   /* Because of:
    4770              : 
    4771              :        [class.access.spec]
    4772              : 
    4773              :        Access control for implicit calls to the constructors,
    4774              :        the conversion functions, or the destructor called to
    4775              :        create and destroy a static data member is performed as
    4776              :        if these calls appeared in the scope of the member's
    4777              :        class.
    4778              : 
    4779              :      we pretend we are in a static member function of the class of
    4780              :      which the DECL is a member.  */
    4781        11370 :   if (member_p (decl))
    4782              :     {
    4783         1559 :       DECL_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
    4784         1559 :       DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
    4785              :     }
    4786              : 
    4787              :   /* Assume we don't need a guard.  */
    4788        11370 :   tree guard_if_stmt = NULL_TREE;
    4789              : 
    4790              :   /* We need a guard if this is an object with external linkage that
    4791              :      might be initialized in more than one place.  (For example, a
    4792              :      static data member of a template, when the data member requires
    4793              :      construction.)  */
    4794        11370 :   if (NEEDS_GUARD_P (decl))
    4795              :     {
    4796          978 :       tree guard = get_guard (decl);
    4797          978 :       tree guard_cond;
    4798              : 
    4799          978 :       if (flag_use_cxa_atexit)
    4800              :         {
    4801              :           /* When using __cxa_atexit, we just check the GUARD as we
    4802              :              would for a local static.  We never try to destroy
    4803              :              anything from a static destructor.  */
    4804          978 :           gcc_assert (initp);
    4805          978 :           guard_cond = get_guard_cond (guard, false);
    4806              :         }
    4807              :       else
    4808              :         {
    4809              :           /* If we don't have __cxa_atexit, then we will be running
    4810              :              destructors from .fini sections, or their equivalents.
    4811              :              So, we need to know how many times we've tried to
    4812              :              initialize this object.  We do initializations only if
    4813              :              the GUARD was or becomes zero (initp vs !initp
    4814              :              respectively).  */
    4815            0 :           guard_cond = cp_build_unary_op (initp ? POSTINCREMENT_EXPR
    4816              :                                           : PREDECREMENT_EXPR,
    4817              :                                           guard,
    4818              :                                           /*noconvert=*/true,
    4819              :                                           tf_warning_or_error);
    4820            0 :           guard_cond = cp_build_binary_op (input_location, EQ_EXPR, guard_cond,
    4821              :                                            integer_zero_node,
    4822              :                                            tf_warning_or_error);
    4823              :         }
    4824              : 
    4825          978 :       guard_if_stmt = begin_if_stmt ();
    4826          978 :       finish_if_stmt_cond (guard_cond, guard_if_stmt);
    4827              : 
    4828          978 :       if (flag_use_cxa_atexit)
    4829              :         /* Set the GUARD now.  */
    4830          978 :         finish_expr_stmt (set_guard (guard));
    4831              :     }
    4832              : 
    4833              :   /* Perform the initialization or destruction.  */
    4834        11370 :   if (initp)
    4835              :     {
    4836        11355 :       if (init)
    4837              :         {
    4838        10629 :           finish_expr_stmt (init);
    4839        10629 :           if (sanitize_flags_p (SANITIZE_ADDRESS, decl))
    4840           28 :             if (varpool_node *vnode = varpool_node::get (decl))
    4841           28 :               vnode->dynamically_initialized = 1;
    4842              :         }
    4843              : 
    4844              :       /* If we're using __cxa_atexit, register a function that calls the
    4845              :          destructor for the object.  */
    4846        11355 :       if (flag_use_cxa_atexit)
    4847        11346 :         finish_expr_stmt (register_dtor_fn (decl, omp_target));
    4848              :     }
    4849              :   else
    4850           15 :     finish_expr_stmt (build_cleanup (decl));
    4851              : 
    4852              :   /* Finish the guard if-stmt, if necessary.  */
    4853        11370 :   if (guard_if_stmt)
    4854              :     {
    4855          978 :       finish_then_clause (guard_if_stmt);
    4856          978 :       finish_if_stmt (guard_if_stmt);
    4857              :     }
    4858              : 
    4859              :   /* Now that we're done with DECL we don't need to pretend to be a
    4860              :      member of its class any longer.  */
    4861        11370 :   DECL_CONTEXT (current_function_decl) = NULL_TREE;
    4862        11370 :   DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
    4863        11370 : }
    4864              : 
    4865              : /* Helper function for emit_partial_init_fini_fn and handle_tls_init.
    4866              :    For structured bindings, disable stmts_are_full_exprs_p ()
    4867              :    on STATIC_INIT_DECOMP_BASE_P nodes, re-enable it on the
    4868              :    first STATIC_INIT_DECOMP_NONBASE_P node and emit all the
    4869              :    STATIC_INIT_DECOMP_BASE_P and STATIC_INIT_DECOMP_NONBASE_P
    4870              :    consecutive nodes in a single STATEMENT_LIST wrapped with
    4871              :    CLEANUP_POINT_EXPR.  */
    4872              : 
    4873              : static inline tree
    4874        11370 : decomp_handle_one_var (tree node, tree sl, bool *saw_nonbase,
    4875              :                        int save_stmts_are_full_exprs_p)
    4876              : {
    4877        11439 :   if (sl && !*saw_nonbase && STATIC_INIT_DECOMP_NONBASE_P (node))
    4878              :     {
    4879           63 :       *saw_nonbase = true;
    4880           63 :       current_stmt_tree ()->stmts_are_full_exprs_p
    4881           63 :         = save_stmts_are_full_exprs_p;
    4882              :     }
    4883        11493 :   else if (sl && *saw_nonbase && !STATIC_INIT_DECOMP_NONBASE_P (node))
    4884              :     {
    4885           45 :       sl = pop_stmt_list (sl);
    4886           45 :       sl = maybe_cleanup_point_expr_void (sl);
    4887           45 :       add_stmt (sl);
    4888           45 :       sl = NULL_TREE;
    4889              :     }
    4890        22530 :   if (sl == NULL_TREE && STATIC_INIT_DECOMP_BASE_P (node))
    4891              :     {
    4892           63 :       sl = push_stmt_list ();
    4893           63 :       *saw_nonbase = false;
    4894           63 :       current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    4895              :     }
    4896        11370 :   return sl;
    4897              : }
    4898              : 
    4899              : /* Similarly helper called when the whole var list is processed.  */
    4900              : 
    4901              : static inline void
    4902         5773 : decomp_finalize_var_list (tree sl, int save_stmts_are_full_exprs_p)
    4903              : {
    4904         5773 :   if (sl)
    4905              :     {
    4906           18 :       current_stmt_tree ()->stmts_are_full_exprs_p
    4907           18 :         = save_stmts_are_full_exprs_p;
    4908           18 :       sl = pop_stmt_list (sl);
    4909           18 :       sl = maybe_cleanup_point_expr_void (sl);
    4910           18 :       add_stmt (sl);
    4911              :     }
    4912         5773 : }
    4913              : 
    4914              : /* Helper for emit_partial_init_fini_fn OpenMP target handling, called via
    4915              :    walk_tree.  Set DECL_CONTEXT on any automatic temporaries which still
    4916              :    have it NULL to id->src_fn, so that later copy_tree_body_r can remap those.
    4917              :    Otherwise DECL_CONTEXT would be set only during gimplification of the host
    4918              :    fn and when copy_tree_body_r doesn't remap those, we'd ICE during the
    4919              :    target fn gimplification because the same automatic VAR_DECL can't be
    4920              :    used in multiple functions (with the exception of nested functions).  */
    4921              : 
    4922              : static tree
    4923          303 : set_context_for_auto_vars_r (tree *tp, int *, void *data)
    4924              : {
    4925          303 :   copy_body_data *id = (copy_body_data *) data;
    4926          303 :   if (auto_var_in_fn_p (*tp, NULL_TREE) && DECL_ARTIFICIAL (*tp))
    4927           11 :     DECL_CONTEXT (*tp) = id->src_fn;
    4928          303 :   return NULL_TREE;
    4929              : }
    4930              : 
    4931              : /* Generate code to do the initialization or destruction of the decls in VARS,
    4932              :    a TREE_LIST of VAR_DECL with static storage duration.
    4933              :    Whether initialization or destruction is performed is specified by INITP.  */
    4934              : 
    4935              : static tree
    4936         5650 : emit_partial_init_fini_fn (bool initp, unsigned priority, tree vars,
    4937              :                            unsigned counter, location_t locus, tree host_fn)
    4938              : {
    4939         5650 :   input_location = locus;
    4940         5650 :   bool omp_target = (host_fn != NULL_TREE);
    4941         5650 :   tree body = start_partial_init_fini_fn (initp, priority, counter, omp_target);
    4942         5650 :   tree fndecl = current_function_decl;
    4943              : 
    4944         5650 :   tree nonhost_if_stmt = NULL_TREE;
    4945         5650 :   if (omp_target)
    4946              :     {
    4947           15 :       nonhost_if_stmt = begin_if_stmt ();
    4948              :       /* We add an "omp declare target nohost" attribute, but (for
    4949              :          now) we still get a copy of the constructor/destructor on
    4950              :          the host.  Make sure it does nothing unless we're on the
    4951              :          target device.  */
    4952           15 :       tree fn = builtin_decl_explicit (BUILT_IN_OMP_IS_INITIAL_DEVICE);
    4953           15 :       tree initial_dev = build_call_expr (fn, 0);
    4954           15 :       tree target_dev_p
    4955           15 :         = cp_build_binary_op (input_location, NE_EXPR, initial_dev,
    4956              :                               integer_one_node, tf_warning_or_error);
    4957           15 :       finish_if_stmt_cond (target_dev_p, nonhost_if_stmt);
    4958              :     }
    4959              : 
    4960         5650 :   tree sl = NULL_TREE;
    4961         5650 :   int save_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    4962         5650 :   bool saw_nonbase = false;
    4963        16225 :   for (tree node = vars; node; node = TREE_CHAIN (node))
    4964              :     {
    4965        10575 :       tree decl = TREE_VALUE (node);
    4966        10575 :       tree init = TREE_PURPOSE (node);
    4967        10575 :       sl = decomp_handle_one_var (node, sl, &saw_nonbase,
    4968              :                                   save_stmts_are_full_exprs_p);
    4969              :       /* We will emit 'init' twice, and it is modified in-place during
    4970              :          gimplification.  Make a copy here.  */
    4971        10575 :       if (omp_target)
    4972              :         {
    4973              :           /* We've already emitted INIT in the host version of the ctor/dtor
    4974              :              function.  We need to deep-copy it (including new versions of
    4975              :              local variables introduced, etc.) for use in the target
    4976              :              ctor/dtor function.  */
    4977           19 :           copy_body_data id;
    4978           19 :           hash_map<tree, tree> decl_map;
    4979           19 :           memset (&id, 0, sizeof (id));
    4980           19 :           id.src_fn = host_fn;
    4981           19 :           id.dst_fn = current_function_decl;
    4982           19 :           id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
    4983           19 :           id.decl_map = &decl_map;
    4984           19 :           id.copy_decl = copy_decl_no_change;
    4985           19 :           id.transform_call_graph_edges = CB_CGE_DUPLICATE;
    4986           19 :           id.transform_new_cfg = true;
    4987           19 :           id.transform_return_to_modify = false;
    4988           19 :           id.eh_lp_nr = 0;
    4989           19 :           walk_tree (&init, set_context_for_auto_vars_r, &id, NULL);
    4990           19 :           walk_tree (&init, copy_tree_body_r, &id, NULL);
    4991           19 :         }
    4992              :       /* Do one initialization or destruction.  */
    4993        10575 :       one_static_initialization_or_destruction (initp, decl, init, omp_target);
    4994              :     }
    4995         5650 :   decomp_finalize_var_list (sl, save_stmts_are_full_exprs_p);
    4996              : 
    4997         5650 :   if (omp_target)
    4998              :     {
    4999              :       /* Finish up nonhost if-stmt body.  */
    5000           15 :       finish_then_clause (nonhost_if_stmt);
    5001           15 :       finish_if_stmt (nonhost_if_stmt);
    5002              :     }
    5003              : 
    5004              :   /* Finish up the static storage duration function for this
    5005              :      round.  */
    5006         5650 :   input_location = locus;
    5007         5650 :   finish_partial_init_fini_fn (body);
    5008              : 
    5009         5650 :   return fndecl;
    5010              : }
    5011              : 
    5012              : /* VARS is a list of variables with static storage duration which may
    5013              :    need initialization and/or finalization.  Remove those variables
    5014              :    that don't really need to be initialized or finalized, and return
    5015              :    the resulting list.  The order in which the variables appear in
    5016              :    VARS is in reverse order of the order in which they should actually
    5017              :    be initialized.  That order is preserved.  */
    5018              : 
    5019              : static tree
    5020       295890 : prune_vars_needing_no_initialization (tree *vars)
    5021              : {
    5022       295890 :   tree *var = vars;
    5023       295890 :   tree result = NULL_TREE;
    5024              : 
    5025       307232 :   while (*var)
    5026              :     {
    5027        11342 :       tree t = *var;
    5028        11342 :       tree decl = TREE_VALUE (t);
    5029        11342 :       tree init = TREE_PURPOSE (t);
    5030              : 
    5031              :       /* Deal gracefully with error.  */
    5032        11342 :       if (error_operand_p (decl))
    5033              :         {
    5034            0 :           var = &TREE_CHAIN (t);
    5035            0 :           continue;
    5036              :         }
    5037              : 
    5038              :       /* The only things that can be initialized are variables.  */
    5039        11342 :       gcc_assert (VAR_P (decl));
    5040              : 
    5041              :       /* If this object is not defined, we don't need to do anything
    5042              :          here.  */
    5043        11342 :       if (DECL_EXTERNAL (decl))
    5044              :         {
    5045            0 :           gcc_checking_assert (!STATIC_INIT_DECOMP_BASE_P (t)
    5046              :                                && !STATIC_INIT_DECOMP_NONBASE_P (t));
    5047            0 :           var = &TREE_CHAIN (t);
    5048            0 :           continue;
    5049              :         }
    5050              : 
    5051              :       /* Also, if the initializer already contains errors, we can bail
    5052              :          out now.  */
    5053        10613 :       if (init && TREE_CODE (init) == TREE_LIST
    5054        11342 :           && value_member (error_mark_node, init))
    5055              :         {
    5056            0 :           var = &TREE_CHAIN (t);
    5057            0 :           continue;
    5058              :         }
    5059              : 
    5060              :       /* This variable is going to need initialization and/or
    5061              :          finalization, so we add it to the list.  */
    5062        11342 :       *var = TREE_CHAIN (t);
    5063        11342 :       TREE_CHAIN (t) = result;
    5064        11342 :       result = t;
    5065              :     }
    5066              : 
    5067       295890 :   return result;
    5068              : }
    5069              : 
    5070              : /* Split VAR_LIST by init priority and add into PARTS hash table.
    5071              :    This reverses the variable ordering.  */
    5072              : 
    5073              : void
    5074         5618 : partition_vars_for_init_fini (tree var_list, priority_map_t *(&parts)[4])
    5075              : {
    5076         5618 :   unsigned priority = 0;
    5077         5618 :   enum { none, base, nonbase } decomp_state = none;
    5078        16165 :   for (auto node = var_list; node; node = TREE_CHAIN (node))
    5079              :     {
    5080        10547 :       tree decl = TREE_VALUE (node);
    5081        10547 :       tree init = TREE_PURPOSE (node);
    5082        10547 :       bool has_cleanup = !TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl));
    5083        10547 :       if (decomp_state == base && STATIC_INIT_DECOMP_NONBASE_P (node))
    5084              :         decomp_state = nonbase;
    5085        10511 :       else if (decomp_state == nonbase && !STATIC_INIT_DECOMP_NONBASE_P (node))
    5086              :         decomp_state = none;
    5087        10526 :       if (decomp_state == none)
    5088        10439 :         priority = DECL_EFFECTIVE_INIT_PRIORITY (decl);
    5089              : 
    5090        10547 :       if (init || (flag_use_cxa_atexit && has_cleanup))
    5091              :         {
    5092              :           // Add to initialization list.
    5093        10541 :           if (!parts[true])
    5094         5612 :             parts[true] = priority_map_t::create_ggc ();
    5095        10541 :           auto &slot = parts[true]->get_or_insert (priority);
    5096        10541 :           slot = tree_cons (init, decl, slot);
    5097        10541 :           if (init
    5098         9833 :               && STATIC_INIT_DECOMP_BASE_P (node)
    5099        10577 :               && decomp_state == none)
    5100              :             {
    5101              :               /* If one or more STATIC_INIT_DECOMP_BASE_P with at least
    5102              :                  one init is followed by at least one
    5103              :                  STATIC_INIT_DECOMP_NONBASE_P with init, mark it in the
    5104              :                  resulting chain as well.  */
    5105           36 :               for (tree n = TREE_CHAIN (node); n; n = TREE_CHAIN (n))
    5106           36 :                 if (STATIC_INIT_DECOMP_BASE_P (n))
    5107            0 :                   continue;
    5108           36 :                 else if (STATIC_INIT_DECOMP_NONBASE_P (n))
    5109              :                   {
    5110           36 :                     if (TREE_PURPOSE (n))
    5111              :                       {
    5112              :                         decomp_state = base;
    5113              :                         break;
    5114              :                       }
    5115              :                     else
    5116            0 :                       continue;
    5117              :                   }
    5118              :                 else
    5119              :                   break;
    5120              :             }
    5121        10541 :           if (init && decomp_state == base)
    5122           36 :             STATIC_INIT_DECOMP_BASE_P (slot) = 1;
    5123        10505 :           else if (decomp_state == nonbase)
    5124          108 :             STATIC_INIT_DECOMP_NONBASE_P (slot) = 1;
    5125              :         }
    5126              : 
    5127        10547 :       if (!flag_use_cxa_atexit && has_cleanup)
    5128              :         {
    5129              :           // Add to finalization list.
    5130           15 :           if (!parts[false])
    5131            9 :             parts[false] = priority_map_t::create_ggc ();
    5132           15 :           auto &slot = parts[false]->get_or_insert (priority);
    5133           15 :           slot = tree_cons (NULL_TREE, decl, slot);
    5134              :         }
    5135              : 
    5136        10547 :       if (flag_openmp
    5137        10547 :           && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
    5138              :         {
    5139           19 :           priority_map_t **omp_parts = parts + 2;
    5140              : 
    5141           19 :           if (init || (flag_use_cxa_atexit && has_cleanup))
    5142              :             {
    5143              :               // Add to initialization list.
    5144           19 :               if (!omp_parts[true])
    5145           14 :                 omp_parts[true] = priority_map_t::create_ggc ();
    5146           19 :               auto &slot = omp_parts[true]->get_or_insert (priority);
    5147           19 :               slot = tree_cons (init, decl, slot);
    5148           19 :               if (init && decomp_state == base)
    5149            0 :                 STATIC_INIT_DECOMP_BASE_P (slot) = 1;
    5150           19 :               else if (decomp_state == nonbase)
    5151            0 :                 STATIC_INIT_DECOMP_NONBASE_P (slot) = 1;
    5152              :             }
    5153              : 
    5154           19 :           if (!flag_use_cxa_atexit && has_cleanup)
    5155              :             {
    5156              :               // Add to finalization list.
    5157            0 :               if (!omp_parts[false])
    5158            0 :                 omp_parts[false] = priority_map_t::create_ggc ();
    5159            0 :               auto &slot = omp_parts[false]->get_or_insert (priority);
    5160            0 :               slot = tree_cons (NULL_TREE, decl, slot);
    5161              :             }
    5162              :         }
    5163              :     }
    5164         5618 : }
    5165              : 
    5166              : /* Make sure we have told the back end about all the variables in
    5167              :    VARS.  */
    5168              : 
    5169              : static void
    5170         5741 : write_out_vars (tree vars)
    5171              : {
    5172         5741 :   tree v;
    5173              : 
    5174        17083 :   for (v = vars; v; v = TREE_CHAIN (v))
    5175              :     {
    5176        11342 :       tree var = TREE_VALUE (v);
    5177        11342 :       if (!var_finalized_p (var))
    5178              :         {
    5179          906 :           import_export_decl (var);
    5180          906 :           rest_of_decl_compilation (var, 1, 1);
    5181              :         }
    5182              :     }
    5183         5741 : }
    5184              : 
    5185              : /* Generate a static constructor or destructor that calls the given
    5186              :    init/fini fns at the indicated priority.  */
    5187              : 
    5188              : static void
    5189         7667 : generate_ctor_or_dtor_function (bool initp, unsigned priority,
    5190              :                                 tree fns, location_t locus, bool omp_target)
    5191              : {
    5192         7667 :   input_location = locus;
    5193         7667 :   tree body = start_objects (initp, priority, bool (fns), omp_target);
    5194              : 
    5195         7667 :   if (fns)
    5196              :     {
    5197              :       /* To make sure dynamic construction doesn't access globals from
    5198              :          other compilation units where they might not be yet
    5199              :          constructed, for -fsanitize=address insert
    5200              :          __asan_before_dynamic_init call that prevents access to
    5201              :          either all global variables that need construction in other
    5202              :          compilation units, or at least those that haven't been
    5203              :          initialized yet.  Variables that need dynamic construction in
    5204              :          the current compilation unit are kept accessible.  */
    5205         5690 :       if (initp && (flag_sanitize & SANITIZE_ADDRESS))
    5206           21 :         finish_expr_stmt (asan_dynamic_init_call (/*after_p=*/false));
    5207              : 
    5208              :       /* Call the static init/fini functions.  */
    5209        11395 :       for (tree node = fns; node; node = TREE_CHAIN (node))
    5210              :         {
    5211         5705 :           tree fn = TREE_PURPOSE (node);
    5212              : 
    5213              :           // We should never find a pure or constant cdtor.
    5214         5705 :           gcc_checking_assert (!(flags_from_decl_or_type (fn)
    5215              :                                  & (ECF_CONST | ECF_PURE)));
    5216              : 
    5217         5705 :           tree call = cp_build_function_call_nary (fn, tf_warning_or_error,
    5218              :                                                    NULL_TREE);
    5219         5705 :           finish_expr_stmt (call);
    5220              :         }
    5221              : 
    5222              :       /* Revert what __asan_before_dynamic_init did by calling
    5223              :          __asan_after_dynamic_init.  */
    5224         5690 :       if (initp && (flag_sanitize & SANITIZE_ADDRESS))
    5225           21 :         finish_expr_stmt (asan_dynamic_init_call (/*after_p=*/true));
    5226              :     }
    5227              : 
    5228              :   /* Close out the function, and arrange for it to be called at init
    5229              :      or fini time, if non-empty.  (Even non-nop module initializer
    5230              :      functions need this, as we cannot guarantee the module is
    5231              :      imported somewhere in the program.)  */
    5232         7667 :   expand_or_defer_fn (finish_objects (initp, priority, body, fns != NULL_TREE));
    5233         7667 : }
    5234              : 
    5235              : /* Return C++ property of T, based on given operation OP.  */
    5236              : 
    5237              : static int
    5238         1941 : cpp_check (tree t, cpp_operation op)
    5239              : {
    5240         1941 :   switch (op)
    5241              :     {
    5242            9 :       case HAS_DEPENDENT_TEMPLATE_ARGS:
    5243            9 :         {
    5244            9 :           tree ti = CLASSTYPE_TEMPLATE_INFO (t);
    5245            9 :           if (!ti)
    5246              :             return 0;
    5247            9 :           ++processing_template_decl;
    5248            9 :           const bool dep = any_dependent_template_arguments_p (TI_ARGS (ti));
    5249            9 :           --processing_template_decl;
    5250            9 :           return dep;
    5251              :         }
    5252          294 :       case IS_ABSTRACT:
    5253          294 :         return DECL_PURE_VIRTUAL_P (t);
    5254          165 :       case IS_ASSIGNMENT_OPERATOR:
    5255          165 :         return DECL_ASSIGNMENT_OPERATOR_P (t);
    5256          165 :       case IS_CONSTRUCTOR:
    5257          330 :         return DECL_CONSTRUCTOR_P (t);
    5258          165 :       case IS_DESTRUCTOR:
    5259          330 :         return DECL_DESTRUCTOR_P (t);
    5260          165 :       case IS_COPY_CONSTRUCTOR:
    5261          477 :         return DECL_COPY_CONSTRUCTOR_P (t);
    5262          165 :       case IS_MOVE_CONSTRUCTOR:
    5263          483 :         return DECL_MOVE_CONSTRUCTOR_P (t);
    5264          447 :       case IS_TEMPLATE:
    5265          447 :         return TREE_CODE (t) == TEMPLATE_DECL;
    5266          366 :       case IS_TRIVIAL:
    5267          366 :         return trivial_type_p (t);
    5268              :       default:
    5269              :         return 0;
    5270              :     }
    5271              : }
    5272              : 
    5273              : /* Collect source file references recursively, starting from NAMESPC.  */
    5274              : 
    5275              : static void
    5276           78 : collect_source_refs (tree namespc)
    5277              : {
    5278              :   /* Iterate over names in this name space.  */
    5279       184018 :   for (tree t = NAMESPACE_LEVEL (namespc)->names; t; t = TREE_CHAIN (t))
    5280       183940 :     if (DECL_IS_UNDECLARED_BUILTIN (t))
    5281              :       ;
    5282          240 :     else if (TREE_CODE (t) == NAMESPACE_DECL && !DECL_NAMESPACE_ALIAS (t))
    5283            3 :       collect_source_refs (t);
    5284              :     else
    5285          237 :       collect_source_ref (DECL_SOURCE_FILE (t));
    5286           78 : }
    5287              : 
    5288              : /* Collect decls relevant to SOURCE_FILE from all namespaces recursively,
    5289              :    starting from NAMESPC.  */
    5290              : 
    5291              : static void
    5292          228 : collect_ada_namespace (tree namespc, const char *source_file)
    5293              : {
    5294          228 :   tree decl = NAMESPACE_LEVEL (namespc)->names;
    5295              : 
    5296              :   /* Collect decls from this namespace.  This will skip
    5297              :      NAMESPACE_DECLs (both aliases and regular, it cannot tell).  */
    5298          228 :   collect_ada_nodes (decl, source_file);
    5299              : 
    5300              :   /* Now scan for namespace children, and dump them.  */
    5301       220196 :   for (; decl; decl = TREE_CHAIN (decl))
    5302       219740 :     if (TREE_CODE (decl) == NAMESPACE_DECL && !DECL_NAMESPACE_ALIAS (decl))
    5303          153 :       collect_ada_namespace (decl, source_file);
    5304          228 : }
    5305              : 
    5306              : /* Returns true iff there is a definition available for variable or
    5307              :    function DECL.  */
    5308              : 
    5309              : bool
    5310     84095401 : decl_defined_p (tree decl)
    5311              : {
    5312     84095401 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    5313     75701387 :     return (DECL_INITIAL (decl) != NULL_TREE
    5314              :             /* A pending instantiation of a friend temploid is defined.  */
    5315     75701387 :             || (DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
    5316      7696413 :                 && DECL_INITIAL (DECL_TEMPLATE_RESULT
    5317              :                                  (DECL_TI_TEMPLATE (decl)))));
    5318              :   else
    5319              :     {
    5320      8394014 :       gcc_assert (VAR_P (decl));
    5321      8394014 :       return (!DECL_EXTERNAL (decl)
    5322              :               /* An initialized variable is defined even if we've decided not
    5323              :                  to emit it, unless it's initialized within the class and not
    5324              :                  inline.  Note that finish_static_member_decl doesn't set
    5325              :                  DECL_IN_AGGR_P for inline variables, so we don't need to check
    5326              :                  DECL_INLINE_VAR_P here.  */
    5327      8394014 :               || (DECL_INITIAL (decl) && !DECL_IN_AGGR_P (decl)));
    5328              :     }
    5329              : }
    5330              : 
    5331              : /* Nonzero for a VAR_DECL whose value can be used in a constant expression.
    5332              : 
    5333              :       [expr.const]
    5334              : 
    5335              :       An integral constant-expression can only involve ... const
    5336              :       variables of integral or enumeration types initialized with
    5337              :       constant expressions ...
    5338              : 
    5339              :       C++0x also allows constexpr variables and temporaries initialized
    5340              :       with constant expressions.  We handle the former here, but the latter
    5341              :       are just folded away in cxx_eval_constant_expression.
    5342              : 
    5343              :    The standard does not require that the expression be non-volatile.
    5344              :    G++ implements the proposed correction in DR 457.  */
    5345              : 
    5346              : bool
    5347   1183518394 : decl_constant_var_p (tree decl)
    5348              : {
    5349   1183518394 :   if (!decl_maybe_constant_var_p (decl))
    5350              :     return false;
    5351              : 
    5352              :   /* We don't know if a template static data member is initialized with
    5353              :      a constant expression until we instantiate its initializer.  Even
    5354              :      in the case of a constexpr variable, we can't treat it as a
    5355              :      constant until its initializer is complete in case it's used in
    5356              :      its own initializer.  */
    5357    149470004 :   maybe_instantiate_decl (decl);
    5358    149467307 :   return DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl);
    5359              : }
    5360              : 
    5361              : /* Returns true if DECL could be a symbolic constant variable, depending on
    5362              :    its initializer.  */
    5363              : 
    5364              : bool
    5365   1561301882 : decl_maybe_constant_var_p (tree decl)
    5366              : {
    5367   1561301882 :   tree type = TREE_TYPE (decl);
    5368   1561301882 :   if (!VAR_P (decl))
    5369              :     return false;
    5370    743259855 :   if (DECL_DECLARED_CONSTEXPR_P (decl)
    5371    743259855 :       && (!TREE_THIS_VOLATILE (decl) || NULLPTR_TYPE_P (type)))
    5372              :     return true;
    5373    422979416 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    5374              :     /* A proxy isn't constant.  */
    5375              :     return false;
    5376    419846123 :   if (TYPE_REF_P (type))
    5377              :     /* References can be constant.  */;
    5378    413309331 :   else if (CP_TYPE_CONST_NON_VOLATILE_P (type)
    5379    413309331 :            && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    5380              :     /* And const integers.  */;
    5381              :   else
    5382              :     return false;
    5383              : 
    5384     87248690 :   if (DECL_INITIAL (decl)
    5385    135270780 :       && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
    5386              :     /* We know the initializer, and it isn't constant.  */
    5387     18533688 :     return false;
    5388              :   else
    5389              :     return true;
    5390              : }
    5391              : 
    5392              : /* Complain that DECL uses a type with no linkage.  In C++98 mode this is
    5393              :    called from grokfndecl and grokvardecl; in all modes it is called from
    5394              :    cp_write_global_declarations.  */
    5395              : 
    5396              : void
    5397      1576763 : no_linkage_error (tree decl)
    5398              : {
    5399      1576763 :   if (cxx_dialect >= cxx11
    5400      1576763 :       && (decl_defined_p (decl)
    5401              :           /* Treat templates which limit_bad_template_recursion decided
    5402              :              not to instantiate as if they were defined.  */
    5403          131 :           || (errorcount + sorrycount > 0
    5404           53 :               && DECL_LANG_SPECIFIC (decl)
    5405           53 :               && DECL_TEMPLATE_INFO (decl)
    5406           33 :               && warning_suppressed_p (decl /* What warning? */))))
    5407              :     /* In C++11 it's ok if the decl is defined.  */
    5408              :     return;
    5409              : 
    5410      1035027 :   if (DECL_LANG_SPECIFIC (decl) && DECL_MODULE_IMPORT_P (decl))
    5411              :     /* An imported decl is ok.  */
    5412              :     return;
    5413              : 
    5414              :   /* Metafunctions are magic and should be considered defined even though
    5415              :      they have no bodies.  ??? This can't be checked in decl_defined_p;
    5416              :      we'd get redefinition errors for some of our metafunctions.  */
    5417      1034982 :   if (TREE_CODE (decl) == FUNCTION_DECL && metafunction_p (decl))
    5418              :     return;
    5419              : 
    5420      1034976 :   tree t = no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false);
    5421      1034976 :   if (t == NULL_TREE)
    5422              :     /* The type that got us on no_linkage_decls must have gotten a name for
    5423              :        linkage purposes.  */;
    5424           74 :   else if (CLASS_TYPE_P (t) && TYPE_BEING_DEFINED (t))
    5425              :     // FIXME: This is now invalid, as a DR to c++98
    5426              :     /* The type might end up having a typedef name for linkage purposes.  */
    5427            0 :     vec_safe_push (no_linkage_decls, decl);
    5428          201 :   else if (TYPE_UNNAMED_P (t))
    5429              :     {
    5430           26 :       bool d = false;
    5431           26 :       auto_diagnostic_group grp;
    5432           26 :       if (cxx_dialect >= cxx11)
    5433              :         {
    5434              :           /* If t is declared in a module CMI, then decl could actually
    5435              :              be defined in a different TU, so don't warn since C++20.  */
    5436            9 :           tree relaxed = no_linkage_check (t, /*relaxed_p=*/true);
    5437            9 :           if (relaxed != NULL_TREE)
    5438            9 :             d = permerror (DECL_SOURCE_LOCATION (decl),
    5439              :                            "%q#D, declared using an unnamed type, "
    5440              :                            "is used but never defined", decl);
    5441            0 :           else if (cxx_dialect < cxx20)
    5442            0 :             d = pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__20_extensions,
    5443              :                          "%q#D, declared using an unnamed type, "
    5444              :                          "is used but not defined", decl);
    5445              :         }
    5446           17 :       else if (DECL_EXTERN_C_P (decl))
    5447              :         /* Allow this; it's pretty common in C.  */;
    5448           17 :       else if (VAR_P (decl))
    5449              :         /* DRs 132, 319 and 389 seem to indicate types with
    5450              :            no linkage can only be used to declare extern "C"
    5451              :            entities.  Since it's not always an error in the
    5452              :            ISO C++ 90 Standard, we only issue a warning.  */
    5453           16 :         d = warning_at (DECL_SOURCE_LOCATION (decl), 0, "unnamed type "
    5454              :                         "with no linkage used to declare variable %q#D with "
    5455              :                         "linkage", decl);
    5456              :       else
    5457            1 :         d = permerror (DECL_SOURCE_LOCATION (decl), "unnamed type with no "
    5458              :                        "linkage used to declare function %q#D with linkage",
    5459              :                        decl);
    5460           26 :       if (d && is_typedef_decl (TYPE_NAME (t)))
    5461            0 :         inform (DECL_SOURCE_LOCATION (TYPE_NAME (t)), "%q#D does not refer "
    5462              :                 "to the unqualified type, so it is not used for linkage",
    5463            0 :                 TYPE_NAME (t));
    5464              :       /* Suppress warning from check_global_declaration if needed.  */
    5465           26 :       if (d)
    5466           23 :         suppress_warning (decl, OPT_Wunused);
    5467           26 :     }
    5468           48 :   else if (cxx_dialect >= cxx11)
    5469              :     {
    5470           48 :       if (VAR_P (decl) || !DECL_PURE_VIRTUAL_P (decl))
    5471              :         {
    5472              :           /* Similarly for local types in a function with vague linkage or
    5473              :              defined in a module CMI, then decl could actually be defined
    5474              :              in a different TU, so don't warn since C++20.  */
    5475           45 :           bool d = false;
    5476           45 :           tree relaxed = no_linkage_check (t, /*relaxed_p=*/true);
    5477           45 :           if (relaxed != NULL_TREE)
    5478           30 :             d = permerror (DECL_SOURCE_LOCATION (decl),
    5479              :                            "%q#D, declared using local type "
    5480              :                            "%qT, is used but never defined", decl, t);
    5481           15 :           else if (cxx_dialect < cxx20)
    5482            3 :             d = pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__20_extensions,
    5483              :                          "%q#D, declared using local type "
    5484              :                          "%qT, is used but not defined here", decl, t);
    5485              :           /* Suppress warning from check_global_declaration if needed.  */
    5486           33 :           if (d)
    5487           33 :             suppress_warning (decl, OPT_Wunused);
    5488              :         }
    5489              :     }
    5490            0 :   else if (VAR_P (decl))
    5491            0 :     warning_at (DECL_SOURCE_LOCATION (decl), 0, "type %qT with no linkage "
    5492              :                 "used to declare variable %q#D with linkage", t, decl);
    5493              :   else
    5494            0 :     permerror (DECL_SOURCE_LOCATION (decl), "type %qT with no linkage used "
    5495              :                "to declare function %q#D with linkage", t, decl);
    5496              : }
    5497              : 
    5498              : /* Collect declarations from all namespaces relevant to SOURCE_FILE.  */
    5499              : 
    5500              : static void
    5501           75 : collect_all_refs (const char *source_file)
    5502              : {
    5503           75 :   collect_ada_namespace (global_namespace, source_file);
    5504           75 : }
    5505              : 
    5506              : /* Clear DECL_EXTERNAL for NODE.  */
    5507              : 
    5508              : static bool
    5509    155765516 : clear_decl_external (struct cgraph_node *node, void * /*data*/)
    5510              : {
    5511    155765516 :   DECL_EXTERNAL (node->decl) = 0;
    5512    155765516 :   return false;
    5513              : }
    5514              : 
    5515              : /* Build up the function to run dynamic initializers for thread_local
    5516              :    variables in this translation unit and alias the init functions for the
    5517              :    individual variables to it.  */
    5518              : 
    5519              : static void
    5520       147945 : handle_tls_init (void)
    5521              : {
    5522       147945 :   tree vars = prune_vars_needing_no_initialization (&tls_aggregates);
    5523       147945 :   if (vars == NULL_TREE)
    5524       147822 :     return;
    5525              : 
    5526          123 :   location_t loc = DECL_SOURCE_LOCATION (TREE_VALUE (vars));
    5527              : 
    5528          123 :   write_out_vars (vars);
    5529              : 
    5530          123 :   tree guard = build_decl (loc, VAR_DECL, get_identifier ("__tls_guard"),
    5531              :                            boolean_type_node);
    5532          123 :   TREE_PUBLIC (guard) = false;
    5533          123 :   TREE_STATIC (guard) = true;
    5534          123 :   DECL_ARTIFICIAL (guard) = true;
    5535          123 :   DECL_IGNORED_P (guard) = true;
    5536          123 :   TREE_USED (guard) = true;
    5537          123 :   CP_DECL_THREAD_LOCAL_P (guard) = true;
    5538          123 :   set_decl_tls_model (guard, decl_default_tls_model (guard));
    5539          123 :   pushdecl_top_level_and_finish (guard, NULL_TREE);
    5540              : 
    5541          123 :   tree fn = get_local_tls_init_fn (loc);
    5542          123 :   start_preparsed_function (fn, NULL_TREE, SF_PRE_PARSED);
    5543          123 :   tree body = begin_function_body ();
    5544          123 :   tree if_stmt = begin_if_stmt ();
    5545          123 :   tree cond = cp_build_unary_op (TRUTH_NOT_EXPR, guard, false,
    5546              :                                  tf_warning_or_error);
    5547          123 :   finish_if_stmt_cond (cond, if_stmt);
    5548          123 :   finish_expr_stmt (cp_build_modify_expr (loc, guard, NOP_EXPR,
    5549              :                                           boolean_true_node,
    5550              :                                           tf_warning_or_error));
    5551          123 :   tree sl = NULL_TREE;
    5552          123 :   int save_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    5553          123 :   bool saw_nonbase = false;
    5554          918 :   for (; vars; vars = TREE_CHAIN (vars))
    5555              :     {
    5556          795 :       tree var = TREE_VALUE (vars);
    5557          795 :       tree init = TREE_PURPOSE (vars);
    5558          795 :       sl = decomp_handle_one_var (vars, sl, &saw_nonbase,
    5559              :                                   save_stmts_are_full_exprs_p);
    5560          795 :       one_static_initialization_or_destruction (/*initp=*/true, var, init,
    5561              :                                                 false);
    5562              : 
    5563              :       /* Output init aliases even with -fno-extern-tls-init.  */
    5564          795 :       if (TARGET_SUPPORTS_ALIASES && TREE_PUBLIC (var))
    5565              :         {
    5566          696 :           tree single_init_fn = get_tls_init_fn (var);
    5567          696 :           if (single_init_fn == NULL_TREE)
    5568            0 :             continue;
    5569          696 :           cgraph_node *alias
    5570          696 :             = cgraph_node::get_create (fn)->create_same_body_alias
    5571          696 :                 (single_init_fn, fn);
    5572          696 :           gcc_assert (alias != NULL);
    5573              :         }
    5574              :     }
    5575          123 :   decomp_finalize_var_list (sl, save_stmts_are_full_exprs_p);
    5576              : 
    5577          123 :   finish_then_clause (if_stmt);
    5578          123 :   finish_if_stmt (if_stmt);
    5579          123 :   finish_function_body (body);
    5580          123 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
    5581              : }
    5582              : 
    5583              : /* We're at the end of compilation, so generate any mangling aliases that
    5584              :    we've been saving up, if DECL is going to be output and ID2 isn't
    5585              :    already taken by another declaration.  */
    5586              : 
    5587              : static void
    5588        38637 : generate_mangling_alias (tree decl, tree id2)
    5589              : {
    5590        38637 :   struct cgraph_node *n = NULL;
    5591              : 
    5592        38637 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    5593              :     {
    5594        38449 :       n = cgraph_node::get (decl);
    5595        38449 :       if (!n)
    5596              :         /* Don't create an alias to an unreferenced function.  */
    5597              :         return;
    5598              :     }
    5599              : 
    5600        38637 :   tree *slot
    5601        38637 :     = mangled_decls->find_slot_with_hash (id2, IDENTIFIER_HASH_VALUE (id2),
    5602              :                                           INSERT);
    5603              : 
    5604              :   /* If there's a declaration already using this mangled name,
    5605              :      don't create a compatibility alias that conflicts.  */
    5606        38637 :   if (*slot)
    5607              :     return;
    5608              : 
    5609        38607 :   tree alias = make_alias_for (decl, id2);
    5610        38607 :   *slot = alias;
    5611              : 
    5612        38607 :   DECL_IGNORED_P (alias) = 1;
    5613        38607 :   TREE_PUBLIC (alias) = TREE_PUBLIC (decl);
    5614        38607 :   DECL_VISIBILITY (alias) = DECL_VISIBILITY (decl);
    5615        38607 :   if (vague_linkage_p (decl))
    5616        38440 :     DECL_WEAK (alias) = 1;
    5617              : 
    5618        38607 :   if (n)
    5619        38419 :     n->create_same_body_alias (alias, decl);
    5620              :   else
    5621          188 :     varpool_node::create_extra_name_alias (alias, decl);
    5622              : }
    5623              : 
    5624              : /* Note that we might want to emit an alias with the symbol ID2 for DECL at
    5625              :    the end of translation, for compatibility across bugs in the mangling
    5626              :    implementation.  */
    5627              : 
    5628              : void
    5629        38661 : note_mangling_alias (tree decl, tree id2)
    5630              : {
    5631        38661 :   if (TARGET_SUPPORTS_ALIASES)
    5632              :     {
    5633        38661 :       if (!defer_mangling_aliases)
    5634        24848 :         generate_mangling_alias (decl, id2);
    5635              :       else
    5636              :         {
    5637        13813 :           vec_safe_push (mangling_aliases, decl);
    5638        13813 :           vec_safe_push (mangling_aliases, id2);
    5639              :         }
    5640              :     }
    5641        38661 : }
    5642              : 
    5643              : /* Emit all mangling aliases that were deferred up to this point.  */
    5644              : 
    5645              : void
    5646       100997 : generate_mangling_aliases ()
    5647              : {
    5648       114786 :   while (!vec_safe_is_empty (mangling_aliases))
    5649              :     {
    5650        13789 :       tree id2 = mangling_aliases->pop();
    5651        13789 :       tree decl = mangling_aliases->pop();
    5652        13789 :       generate_mangling_alias (decl, id2);
    5653              :     }
    5654       100997 :   defer_mangling_aliases = false;
    5655       100997 : }
    5656              : 
    5657              : /* Record a mangling of DECL, whose DECL_ASSEMBLER_NAME has just been
    5658              :    set.  NEED_WARNING is true if we must warn about collisions.  We do
    5659              :    this to spot changes in mangling that may require compatibility
    5660              :    aliases.  */
    5661              : 
    5662              : void
    5663     85654753 : record_mangling (tree decl, bool need_warning)
    5664              : {
    5665     85654753 :   if (!mangled_decls)
    5666        77818 :     mangled_decls = hash_table<mangled_decl_hash>::create_ggc (499);
    5667              : 
    5668     85654753 :   gcc_checking_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
    5669     85654753 :   tree id = DECL_ASSEMBLER_NAME_RAW (decl);
    5670     85654753 :   tree *slot
    5671     85654753 :     = mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE (id),
    5672              :                                           INSERT);
    5673              : 
    5674              :   /* If this is already an alias, cancel the alias, because the real
    5675              :      decl takes precedence.  */
    5676     85654753 :   if (*slot && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot))
    5677              :     {
    5678           27 :       if (symtab_node *n = symtab_node::get (*slot))
    5679              :         {
    5680           27 :           if (n->cpp_implicit_alias)
    5681              :             /* Actually removing the node isn't safe if other code is already
    5682              :                holding a pointer to it, so just neutralize it.  */
    5683           27 :             n->reset ();
    5684              :         }
    5685              :       else
    5686              :         /* analyze_functions might have already removed the alias from the
    5687              :            symbol table if it's internal.  */
    5688            0 :         gcc_checking_assert (!TREE_PUBLIC (*slot));
    5689              : 
    5690           27 :       *slot = NULL_TREE;
    5691              :     }
    5692              : 
    5693     85654753 :   if (!*slot)
    5694     85654545 :     *slot = decl;
    5695          208 :   else if (need_warning)
    5696              :     {
    5697            3 :       auto_diagnostic_group d;
    5698            3 :       error_at (DECL_SOURCE_LOCATION (decl),
    5699              :                 "mangling of %q#D as %qE conflicts with a previous mangle",
    5700              :                 decl, id);
    5701            3 :       inform (DECL_SOURCE_LOCATION (*slot),
    5702              :               "previous mangling %q#D", *slot);
    5703            3 :       inform (DECL_SOURCE_LOCATION (decl),
    5704              :               "a later %<-fabi-version=%> (or =0)"
    5705              :               " avoids this error with a change in mangling");
    5706            3 :       *slot = decl;
    5707            3 :     }
    5708     85654753 : }
    5709              : 
    5710              : /* The mangled name of DECL is being forcibly changed to NAME.  Remove
    5711              :    any existing knowledge of DECL's mangled name meaning DECL.  */
    5712              : 
    5713              : void
    5714    279662245 : overwrite_mangling (tree decl, tree name)
    5715              : {
    5716    279662245 :   if (tree id = DECL_ASSEMBLER_NAME_RAW (decl))
    5717       247557 :     if ((TREE_CODE (decl) == VAR_DECL
    5718       247452 :          || TREE_CODE (decl) == FUNCTION_DECL)
    5719       247557 :         && mangled_decls)
    5720       481750 :       if (tree *slot
    5721       240875 :           = mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE (id),
    5722              :                                                 NO_INSERT))
    5723       131363 :         if (*slot == decl)
    5724              :           {
    5725           81 :             mangled_decls->clear_slot (slot);
    5726              : 
    5727              :             /* If this is an alias, remove it from the symbol table.  */
    5728           81 :             if (DECL_ARTIFICIAL (decl) && DECL_IGNORED_P (decl))
    5729            0 :               if (symtab_node *n = symtab_node::get (decl))
    5730            0 :                 if (n->cpp_implicit_alias)
    5731            0 :                   n->remove ();
    5732              :           }
    5733              : 
    5734    279662245 :   DECL_ASSEMBLER_NAME_RAW (decl) = name;
    5735    279662245 : }
    5736              : 
    5737              : /* The entire file is now complete.  If requested, dump everything
    5738              :    to a file.  */
    5739              : 
    5740              : static void
    5741       101094 : dump_tu (void)
    5742              : {
    5743       101094 :   dump_flags_t flags;
    5744       101094 :   if (FILE *stream = dump_begin (raw_dump_id, &flags))
    5745              :     {
    5746            6 :       dump_node (global_namespace, flags & ~TDF_SLIM, stream);
    5747            6 :       dump_end (raw_dump_id, stream);
    5748              :     }
    5749       101094 : }
    5750              : 
    5751              : static location_t locus_at_end_of_parsing;
    5752              : 
    5753              : /* Check the deallocation functions for CODE to see if we want to warn that
    5754              :    only one was defined.  */
    5755              : 
    5756              : static void
    5757         1954 : maybe_warn_sized_delete (enum tree_code code)
    5758              : {
    5759         1954 :   tree sized = NULL_TREE;
    5760         1954 :   tree unsized = NULL_TREE;
    5761              : 
    5762        10786 :   for (ovl_iterator iter (get_global_binding (ovl_op_identifier (false, code)));
    5763        10786 :        iter; ++iter)
    5764              :     {
    5765         8832 :       tree fn = *iter;
    5766              :       /* We're only interested in usual deallocation functions.  */
    5767         8832 :       if (!usual_deallocation_fn_p (fn))
    5768         1016 :         continue;
    5769         7816 :       if (FUNCTION_ARG_CHAIN (fn) == void_list_node)
    5770              :         unsized = fn;
    5771              :       else
    5772         5858 :         sized = fn;
    5773              :     }
    5774         1954 :   if (DECL_INITIAL (unsized) && !DECL_INITIAL (sized))
    5775            6 :     warning_at (DECL_SOURCE_LOCATION (unsized), OPT_Wsized_deallocation,
    5776              :                 "the program should also define %qD", sized);
    5777         1948 :   else if (!DECL_INITIAL (unsized) && DECL_INITIAL (sized))
    5778            4 :     warning_at (DECL_SOURCE_LOCATION (sized), OPT_Wsized_deallocation,
    5779              :                 "the program should also define %qD", unsized);
    5780         1954 : }
    5781              : 
    5782              : /* Check the global deallocation functions to see if we want to warn about
    5783              :    defining unsized without sized (or vice versa).  */
    5784              : 
    5785              : static void
    5786       100997 : maybe_warn_sized_delete ()
    5787              : {
    5788       100997 :   if (!flag_sized_deallocation || !warn_sized_deallocation)
    5789              :     return;
    5790          977 :   maybe_warn_sized_delete (DELETE_EXPR);
    5791          977 :   maybe_warn_sized_delete (VEC_DELETE_EXPR);
    5792              : }
    5793              : 
    5794              : /* Earlier we left PTRMEM_CST in variable initializers alone so that we could
    5795              :    look them up when evaluating non-type template parameters.  Now we need to
    5796              :    lower them to something the back end can understand.  */
    5797              : 
    5798              : static void
    5799       100997 : lower_var_init ()
    5800              : {
    5801       100997 :   varpool_node *node;
    5802     34185088 :   FOR_EACH_VARIABLE (node)
    5803              :     {
    5804     34084091 :       tree d = node->decl;
    5805     34084091 :       if (tree init = DECL_INITIAL (d))
    5806     31576392 :         DECL_INITIAL (d) = cplus_expand_constant (init);
    5807              :     }
    5808       100997 : }
    5809              : 
    5810              : /* This routine is called at the end of compilation.
    5811              :    Its job is to create all the code needed to initialize and
    5812              :    destroy the global aggregates.  We do the destruction
    5813              :    first, since that way we only need to reverse the decls once.  */
    5814              : 
    5815              : void
    5816       101111 : c_parse_final_cleanups (void)
    5817              : {
    5818       101111 :   size_t i;
    5819       101111 :   tree decl;
    5820              : 
    5821       101111 :   locus_at_end_of_parsing = input_location;
    5822              :   /* We're done parsing.  */
    5823       101111 :   at_eof = 1;
    5824              : 
    5825              :   /* Bad parse errors.  Just forget about it.  */
    5826       202222 :   if (! global_bindings_p () || current_class_type
    5827       202222 :       || !vec_safe_is_empty (decl_namespace_list))
    5828          100 :     return;
    5829              : 
    5830              :   /* This is the point to write out a PCH if we're doing that.
    5831              :      In that case we do not want to do anything else.  */
    5832       101108 :   if (pch_file)
    5833              :     {
    5834              :       /* Mangle all symbols at PCH creation time.  */
    5835           97 :       symtab_node *node;
    5836        49582 :       FOR_EACH_SYMBOL (node)
    5837        49485 :         if (! is_a <varpool_node *> (node)
    5838        16324 :             || ! DECL_HARD_REGISTER (node->decl))
    5839        49485 :           DECL_ASSEMBLER_NAME (node->decl);
    5840           97 :       c_common_write_pch ();
    5841           97 :       dump_tu ();
    5842              :       /* Ensure even the callers don't try to finalize the CU.  */
    5843           97 :       flag_syntax_only = 1;
    5844           97 :       return;
    5845              :     }
    5846              : 
    5847       101011 :   timevar_stop (TV_PHASE_PARSING);
    5848       101011 :   timevar_start (TV_PHASE_DEFERRED);
    5849              : 
    5850       101011 :   symtab->process_same_body_aliases ();
    5851              : 
    5852              :   /* Handle -fdump-ada-spec[-slim] */
    5853       101011 :   if (flag_dump_ada_spec || flag_dump_ada_spec_slim)
    5854              :     {
    5855           75 :       collect_source_ref (main_input_filename);
    5856           75 :       if (!flag_dump_ada_spec_slim)
    5857           75 :         collect_source_refs (global_namespace);
    5858              : 
    5859           75 :       dump_ada_specs (collect_all_refs, cpp_check);
    5860              :     }
    5861              : 
    5862              :   /* FIXME - huh?  was  input_line -= 1;*/
    5863              : 
    5864              :   /* We now have to write out all the stuff we put off writing out.
    5865              :      These include:
    5866              : 
    5867              :        o Template specializations that we have not yet instantiated,
    5868              :          but which are needed.
    5869              :        o Initialization and destruction for non-local objects with
    5870              :          static storage duration.  (Local objects with static storage
    5871              :          duration are initialized when their scope is first entered,
    5872              :          and are cleaned up via atexit.)
    5873              :        o Virtual function tables.
    5874              : 
    5875              :      All of these may cause others to be needed.  For example,
    5876              :      instantiating one function may cause another to be needed, and
    5877              :      generating the initializer for an object may cause templates to be
    5878              :      instantiated, etc., etc.  */
    5879              : 
    5880       101011 :   emit_support_tinfos ();
    5881              : 
    5882              :   /* Track vtables we want to emit that refer to consteval functions.  */
    5883       101011 :   auto_vec<tree> consteval_vtables;
    5884              : 
    5885       101011 :   int retries = 0;
    5886       101011 :   unsigned ssdf_count = 0, omp_ssdf_count = 0;
    5887       249877 :   for (bool reconsider = true; reconsider; retries++)
    5888              :     {
    5889       148880 :       reconsider = false;
    5890              : 
    5891              :       /* If there are templates that we've put off instantiating, do
    5892              :          them now.  */
    5893       148880 :       instantiate_pending_templates (retries);
    5894       148866 :       ggc_collect ();
    5895              : 
    5896       148866 :       if (header_module_p ())
    5897              :         /* A header modules initializations are handled in its
    5898              :            importer.  */
    5899          921 :         continue;
    5900              : 
    5901              :       /* Emit wrappers where needed, and if that causes more to be added then
    5902              :          make sure we account for possible additional instantiations.  */
    5903       147945 :       if (flag_contracts)
    5904        32675 :         if (emit_contract_wrapper_func (/*done*/false))
    5905       147945 :           reconsider = true;
    5906              : 
    5907              :       /* Write out virtual tables as required.  Writing out the
    5908              :          virtual table for a template class may cause the
    5909              :          instantiation of members of that class.  If we write out
    5910              :          vtables then we remove the class from our list so we don't
    5911              :          have to look at it again.  */
    5912       147945 :       tree t;
    5913       147945 :       for (i = keyed_classes->length ();
    5914      3856505 :            keyed_classes->iterate (--i, &t);)
    5915      3708560 :         if (maybe_emit_vtables (t, consteval_vtables))
    5916              :           {
    5917       355024 :             reconsider = true;
    5918       355024 :             keyed_classes->unordered_remove (i);
    5919              :           }
    5920              :       /* The input_location may have been changed during marking of
    5921              :          vtable entries.  */
    5922       147945 :       input_location = locus_at_end_of_parsing;
    5923              : 
    5924              :       /* Write out needed type info variables.  We have to be careful
    5925              :          looping through unemitted decls, because emit_tinfo_decl may
    5926              :          cause other variables to be needed. New elements will be
    5927              :          appended, and we remove from the vector those that actually
    5928              :          get emitted.  */
    5929       147945 :       for (i = unemitted_tinfo_decls->length ();
    5930      6112942 :            unemitted_tinfo_decls->iterate (--i, &t);)
    5931      5964997 :         if (DECL_INITIAL (t) || emit_tinfo_decl (t))
    5932              :           {
    5933       442393 :             reconsider = true;
    5934       442393 :             unemitted_tinfo_decls->unordered_remove (i);
    5935              :           }
    5936              : 
    5937              :       /* The list of objects with static storage duration is built up
    5938              :          in reverse order.  We clear STATIC_AGGREGATES so that any new
    5939              :          aggregates added during the initialization of these will be
    5940              :          initialized in the correct order when we next come around the
    5941              :          loop.  */
    5942       147945 :       if (tree vars = prune_vars_needing_no_initialization (&static_aggregates))
    5943              :         {
    5944         5618 :           if (flag_openmp)
    5945              :             /* Add initializer information from VARS into
    5946              :                DYNAMIC_INITIALIZERS.  */
    5947          402 :             for (t = vars; t; t = TREE_CHAIN (t))
    5948          576 :               hash_map_safe_put<hm_ggc> (dynamic_initializers,
    5949          288 :                                          TREE_VALUE (t), TREE_PURPOSE (t));
    5950              : 
    5951              :           /* Make sure the back end knows about all the variables.  */
    5952         5618 :           write_out_vars (vars);
    5953              : 
    5954         5618 :           function_depth++; // Disable GC
    5955         5618 :           priority_map_t *parts[4] = {nullptr, nullptr, nullptr, nullptr};
    5956         5618 :           partition_vars_for_init_fini (vars, parts);
    5957         5618 :           tree host_init_fini[2] = { NULL_TREE, NULL_TREE };
    5958              : 
    5959        16854 :           for (unsigned initp = 2; initp--;)
    5960        11236 :             if (parts[initp])
    5961        16877 :               for (auto iter : *parts[initp])
    5962              :                 {
    5963         5635 :                   auto list = iter.second;
    5964         5635 :                   if (initp)
    5965              :                     // Partitioning kept the vars in reverse order.
    5966              :                     // We only want that for dtors.
    5967         5626 :                     list = nreverse (list);
    5968         5635 :                   host_init_fini[initp]
    5969         5635 :                     = emit_partial_init_fini_fn (initp, iter.first, list,
    5970              :                                                  ssdf_count++,
    5971              :                                                  locus_at_end_of_parsing,
    5972              :                                                  NULL_TREE);
    5973              :                 }
    5974              : 
    5975         5618 :           if (flag_openmp)
    5976              :             {
    5977              :               priority_map_t **omp_parts = parts + 2;
    5978          342 :               for (unsigned initp = 2; initp--;)
    5979          228 :                 if (omp_parts[initp])
    5980           43 :                   for (auto iter : *omp_parts[initp])
    5981              :                     {
    5982           15 :                       auto list = iter.second;
    5983           15 :                       if (initp)
    5984              :                         // Partitioning kept the vars in reverse order.
    5985              :                         // We only want that for dtors.
    5986           15 :                         list = nreverse (list);
    5987           15 :                       emit_partial_init_fini_fn (initp, iter.first, list,
    5988              :                                                  omp_ssdf_count++,
    5989              :                                                  locus_at_end_of_parsing,
    5990              :                                                  host_init_fini[initp]);
    5991              :                   }
    5992              :             }
    5993              : 
    5994         5618 :           function_depth--; // Re-enable GC
    5995              : 
    5996              :           /* All those initializations and finalizations might cause
    5997              :              us to need more inline functions, more template
    5998              :              instantiations, etc.  */
    5999         5618 :           reconsider = true;
    6000              :         }
    6001              : 
    6002              :       /* Now do the same for thread_local variables.  */
    6003       147945 :       handle_tls_init ();
    6004              : 
    6005              :       /* Go through the set of inline functions whose bodies have not
    6006              :          been emitted yet.  If out-of-line copies of these functions
    6007              :          are required, emit them.  */
    6008    195278146 :       FOR_EACH_VEC_SAFE_ELT (deferred_fns, i, decl)
    6009              :         {
    6010              :           /* Does it need synthesizing?  */
    6011    200863364 :           if (DECL_DEFAULTED_FN (decl) && ! DECL_INITIAL (decl)
    6012    194982262 :               && (! DECL_REALLY_EXTERN (decl) || possibly_inlined_p (decl)))
    6013              :             {
    6014              :               /* Even though we're already at the top-level, we push
    6015              :                  there again.  That way, when we pop back a few lines
    6016              :                  hence, all of our state is restored.  Otherwise,
    6017              :                  finish_function doesn't clean things up, and we end
    6018              :                  up with CURRENT_FUNCTION_DECL set.  */
    6019            6 :               push_to_top_level ();
    6020              :               /* The decl's location will mark where it was first
    6021              :                  needed.  Save that so synthesize method can indicate
    6022              :                  where it was needed from, in case of error  */
    6023            6 :               input_location = DECL_SOURCE_LOCATION (decl);
    6024            6 :               synthesize_method (decl);
    6025            6 :               pop_from_top_level ();
    6026            6 :               reconsider = true;
    6027              :             }
    6028              : 
    6029    194982256 :           if (!DECL_INITIAL (decl) && decl_tls_wrapper_p (decl))
    6030          586 :             generate_tls_wrapper (decl);
    6031              : 
    6032    194982256 :           if (!DECL_SAVED_TREE (decl))
    6033       230893 :             continue;
    6034              : 
    6035    194751363 :           cgraph_node *node = cgraph_node::get_create (decl);
    6036              : 
    6037              :           /* We lie to the back end, pretending that some functions
    6038              :              are not defined when they really are.  This keeps these
    6039              :              functions from being put out unnecessarily.  But, we must
    6040              :              stop lying when the functions are referenced, or if they
    6041              :              are not comdat since they need to be put out now.  If
    6042              :              DECL_INTERFACE_KNOWN, then we have already set
    6043              :              DECL_EXTERNAL appropriately, so there's no need to check
    6044              :              again, and we do not want to clear DECL_EXTERNAL if a
    6045              :              previous call to import_export_decl set it.
    6046              : 
    6047              :              This is done in a separate for cycle, because if some
    6048              :              deferred function is contained in another deferred
    6049              :              function later in deferred_fns varray,
    6050              :              rest_of_compilation would skip this function and we
    6051              :              really cannot expand the same function twice.  */
    6052    194751363 :           import_export_decl (decl);
    6053    194751363 :           if (DECL_NOT_REALLY_EXTERN (decl)
    6054    187749073 :               && DECL_INITIAL (decl)
    6055    382500436 :               && decl_needed_p (decl))
    6056              :             {
    6057    123406866 :               if (node->cpp_implicit_alias)
    6058     10971084 :                 node = node->get_alias_target ();
    6059              : 
    6060    123406866 :               node->call_for_symbol_thunks_and_aliases (clear_decl_external,
    6061              :                                                         NULL, true);
    6062              :               /* If we mark !DECL_EXTERNAL one of the symbols in some comdat
    6063              :                  group, we need to mark all symbols in the same comdat group
    6064              :                  that way.  */
    6065    123406866 :               if (node->same_comdat_group)
    6066     32334588 :                 for (cgraph_node *next
    6067     15945892 :                        = dyn_cast<cgraph_node *> (node->same_comdat_group);
    6068     32334588 :                      next != node;
    6069     32777392 :                      next = dyn_cast<cgraph_node *> (next->same_comdat_group))
    6070     16388696 :                   next->call_for_symbol_thunks_and_aliases (clear_decl_external,
    6071              :                                                             NULL, true);
    6072              :             }
    6073              : 
    6074              :           /* If we're going to need to write this function out, and
    6075              :              there's already a body for it, create RTL for it now.
    6076              :              (There might be no body if this is a method we haven't
    6077              :              gotten around to synthesizing yet.)  */
    6078    194751363 :           if (!DECL_EXTERNAL (decl)
    6079    126526827 :               && decl_needed_p (decl)
    6080    124135474 :               && !TREE_ASM_WRITTEN (decl)
    6081    227423762 :               && !DECL_IMMEDIATE_FUNCTION_P (decl)
    6082    302701446 :               && !node->definition)
    6083              :             {
    6084              :               /* We will output the function; no longer consider it in this
    6085              :                  loop.  */
    6086            0 :               DECL_DEFER_OUTPUT (decl) = 0;
    6087              :               /* Generate RTL for this function now that we know we
    6088              :                  need it.  */
    6089            0 :               expand_or_defer_fn (decl);
    6090            0 :               reconsider = true;
    6091              :             }
    6092              :         }
    6093              : 
    6094       147945 :       if (wrapup_namespace_globals ())
    6095          614 :         reconsider = true;
    6096              : 
    6097              :       /* Static data members are just like namespace-scope globals.  */
    6098    102172980 :       FOR_EACH_VEC_SAFE_ELT (pending_statics, i, decl)
    6099              :         {
    6100              :           /* Rewrite the REFLECT_EXPR with 0 so that the ME can process it.  */
    6101    102025035 :           if (flag_reflection && DECL_INITIAL (decl))
    6102      2370026 :             rewrite_null_reflection (DECL_INITIAL (decl));
    6103              : 
    6104    102025035 :           if (consteval_only_p (decl)
    6105    102024721 :               || var_finalized_p (decl)
    6106     26567985 :               || DECL_REALLY_EXTERN (decl)
    6107              :               /* Don't write it out if we haven't seen a definition.  */
    6108    117270269 :               || DECL_IN_AGGR_P (decl))
    6109     86786353 :             continue;
    6110     15238682 :           import_export_decl (decl);
    6111              :           /* If this static data member is needed, provide it to the
    6112              :              back end.  */
    6113     15238682 :           if (DECL_NOT_REALLY_EXTERN (decl) && decl_needed_p (decl))
    6114     15205243 :             DECL_EXTERNAL (decl) = 0;
    6115              :         }
    6116              : 
    6117       296811 :       if (vec_safe_length (pending_statics) != 0
    6118       119316 :           && wrapup_global_declarations (pending_statics->address (),
    6119        59658 :                                          pending_statics->length ()))
    6120              :         reconsider = true;
    6121              :     }
    6122              : 
    6123              :   /* All templates have been instantiated.  */
    6124       100997 :   at_eof = 2;
    6125              : 
    6126       100997 :   void *module_cookie = finish_module_processing (parse_in);
    6127              : 
    6128       100997 :   if (flag_contracts)
    6129              :     {
    6130              :       /* Keep these out of the module to avoid duplicate definitions.  */
    6131        25495 :       emit_contract_wrapper_func (/*done*/true);
    6132        25495 :       maybe_emit_violation_handler_wrappers ();
    6133              :     }
    6134              : 
    6135       100997 :   lower_var_init ();
    6136              : 
    6137       100997 :   generate_mangling_aliases ();
    6138              : 
    6139              :   /* All used inline functions must have a definition at this point.  */
    6140     51262670 :   FOR_EACH_VEC_SAFE_ELT (deferred_fns, i, decl)
    6141              :     {
    6142     51060676 :       if (/* Check online inline functions that were actually used.  */
    6143     83272197 :           DECL_ODR_USED (decl) && DECL_DECLARED_INLINE_P (decl)
    6144              :           /* If the definition actually was available here, then the
    6145              :              fact that the function was not defined merely represents
    6146              :              that for some reason (use of a template repository,
    6147              :              #pragma interface, etc.) we decided not to emit the
    6148              :              definition here.  */
    6149     32209965 :           && !DECL_INITIAL (decl)
    6150              :           /* A defaulted fn or TLS wrapper in a header module can be
    6151              :              synthesized on demand later.  (In non-header modules we
    6152              :              should have synthesized it above.)  */
    6153         9576 :           && !(header_module_p ()
    6154           16 :                && (DECL_DEFAULTED_FN (decl) || decl_tls_wrapper_p (decl)))
    6155              :           /* Metafunctions are never defined.  */
    6156         9570 :           && !metafunction_p (decl)
    6157              :           /* Don't complain if the template was defined.  */
    6158          771 :           && !(DECL_TEMPLOID_INSTANTIATION (decl)
    6159          685 :                && DECL_INITIAL (DECL_TEMPLATE_RESULT
    6160              :                                 (template_for_substitution (decl))))
    6161     83272197 :           && warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6162              :                          "inline function %qD used but never defined", decl))
    6163              :         /* Avoid a duplicate warning from check_global_declaration.  */
    6164           83 :         suppress_warning (decl, OPT_Wunused);
    6165              :     }
    6166              : 
    6167              :   /* So must decls that use a type with no linkage.  */
    6168       642841 :   FOR_EACH_VEC_SAFE_ELT (no_linkage_decls, i, decl)
    6169       541844 :     no_linkage_error (decl);
    6170              : 
    6171       100997 :   maybe_warn_sized_delete ();
    6172              : 
    6173              :   // Place the init fns in the right order.  We need to do this now,
    6174              :   // so that any module init will go at the start.
    6175       100997 :   if (static_init_fini_fns[true])
    6176        16841 :     for (auto iter : *static_init_fini_fns[true])
    6177         5623 :       iter.second = nreverse (iter.second);
    6178              : 
    6179       100997 :   if (flag_openmp && static_init_fini_fns[2 + true])
    6180           43 :     for (auto iter : *static_init_fini_fns[2 + true])
    6181           15 :       iter.second = nreverse (iter.second);
    6182              : 
    6183              :   /* Now we've instantiated all templates.  Now we can escalate the functions
    6184              :      we squirreled away earlier.  */
    6185       100997 :   process_and_check_pending_immediate_escalating_fns ();
    6186              : 
    6187              :   /* Then, do the Objective-C stuff.  This is where all the
    6188              :      Objective-C module stuff gets generated (symtab,
    6189              :      class/protocol/selector lists etc).  This must be done after C++
    6190              :      templates, destructors etc. so that selectors used in C++
    6191              :      templates are properly allocated.  */
    6192       100997 :   if (c_dialect_objc ())
    6193            0 :     objc_write_global_declarations ();
    6194              : 
    6195       100997 :   bool has_module_inits = module_determine_import_inits ();
    6196       100997 :   bool has_objc_init = c_dialect_objc () && objc_static_init_needed_p ();
    6197       100997 :   if (has_module_inits || has_objc_init)
    6198              :     {
    6199           55 :       input_location = locus_at_end_of_parsing;
    6200           55 :       tree body = start_partial_init_fini_fn (true, DEFAULT_INIT_PRIORITY,
    6201              :                                               ssdf_count++, false);
    6202              :       /* For Objective-C++, we may need to initialize metadata found
    6203              :          in this module.  This must be done _before_ any other static
    6204              :          initializations.  */
    6205           55 :       if (has_objc_init)
    6206            0 :         objc_generate_static_init_call (NULL_TREE);
    6207           55 :       if (has_module_inits)
    6208           55 :         module_add_import_initializers ();
    6209           55 :       input_location = locus_at_end_of_parsing;
    6210           55 :       finish_partial_init_fini_fn (body);
    6211              :     }
    6212              : 
    6213       100997 :   if (module_global_init_needed ())
    6214              :     {
    6215              :       // Make sure there's a default priority entry.
    6216         2050 :       if (!static_init_fini_fns[true])
    6217         1977 :         static_init_fini_fns[true] = priority_map_t::create_ggc ();
    6218         2050 :       if (static_init_fini_fns[true]->get_or_insert (DEFAULT_INIT_PRIORITY))
    6219       100997 :         has_module_inits = true;
    6220              : 
    6221              :       /* FIXME: We need to work out what static constructors on OpenMP offload
    6222              :          target in modules will look like.  */
    6223              :     }
    6224              : 
    6225              :   /* Generate initialization and destruction functions for all
    6226              :      priorities for which they are required.  They have C-language
    6227              :      linkage.  */
    6228       100997 :   push_lang_context (lang_name_c);
    6229       605982 :   for (unsigned initp = 4; initp--;)
    6230       403988 :     if (static_init_fini_fns[initp])
    6231              :       {
    6232        15319 :         for (auto iter : *static_init_fini_fns[initp])
    6233         7667 :           generate_ctor_or_dtor_function (initp & 1, iter.first, iter.second,
    6234              :                                           locus_at_end_of_parsing,
    6235         7667 :                                           (initp & 2) != 0);
    6236         7652 :         static_init_fini_fns[initp] = nullptr;
    6237              :       }
    6238       100997 :   pop_lang_context ();
    6239              : 
    6240       100997 :   fini_modules (parse_in, module_cookie, has_module_inits);
    6241              : 
    6242              :   /* Generate any missing aliases.  */
    6243       100997 :   maybe_apply_pending_pragma_weaks ();
    6244              : 
    6245       100997 :   if (flag_vtable_verify)
    6246              :     {
    6247            9 :       vtv_recover_class_info ();
    6248            9 :       vtv_compute_class_hierarchy_transitive_closure ();
    6249            9 :       vtv_build_vtable_verify_fndecl ();
    6250              :     }
    6251              : 
    6252       100997 :   perform_deferred_noexcept_checks ();
    6253              : 
    6254       100997 :   fini_constexpr ();
    6255       100997 :   cp_tree_c_finish_parsing ();
    6256       100997 :   clear_consteval_vfns (consteval_vtables);
    6257              : 
    6258              :   /* The entire file is now complete.  If requested, dump everything
    6259              :      to a file.  */
    6260       100997 :   dump_tu ();
    6261              : 
    6262       100997 :   if (flag_detailed_statistics)
    6263              :     {
    6264            0 :       dump_tree_statistics ();
    6265            0 :       dump_time_statistics ();
    6266              :     }
    6267              : 
    6268       100997 :   timevar_stop (TV_PHASE_DEFERRED);
    6269       100997 :   timevar_start (TV_PHASE_PARSING);
    6270              : 
    6271              :   /* Indicate that we're done with front end processing.  */
    6272       100997 :   at_eof = 3;
    6273       100997 : }
    6274              : 
    6275              : /* Perform any post compilation-proper cleanups for the C++ front-end.
    6276              :    This should really go away.  No front-end should need to do
    6277              :    anything past the compilation process.  */
    6278              : 
    6279              : void
    6280       100752 : cxx_post_compilation_parsing_cleanups (void)
    6281              : {
    6282       100752 :   timevar_start (TV_PHASE_LATE_PARSING_CLEANUPS);
    6283              : 
    6284       100752 :   if (flag_vtable_verify)
    6285              :     {
    6286              :       /* Generate the special constructor initialization function that
    6287              :          calls __VLTRegisterPairs, and give it a very high
    6288              :          initialization priority.  This must be done after
    6289              :          finalize_compilation_unit so that we have accurate
    6290              :          information about which vtable will actually be emitted.  */
    6291            9 :       vtv_generate_init_routine ();
    6292              :     }
    6293              : 
    6294       100752 :   input_location = locus_at_end_of_parsing;
    6295              : 
    6296       100752 :   if (flag_checking)
    6297       100743 :     validate_conversion_obstack ();
    6298              : 
    6299       100752 :   timevar_stop (TV_PHASE_LATE_PARSING_CLEANUPS);
    6300       100752 : }
    6301              : 
    6302              : /* FN is an OFFSET_REF, DOTSTAR_EXPR or MEMBER_REF indicating the
    6303              :    function to call in parse-tree form; it has not yet been
    6304              :    semantically analyzed.  ARGS are the arguments to the function.
    6305              :    They have already been semantically analyzed.  This may change
    6306              :    ARGS.  */
    6307              : 
    6308              : tree
    6309       371872 : build_offset_ref_call_from_tree (tree fn, vec<tree, va_gc> **args,
    6310              :                                  tsubst_flags_t complain)
    6311              : {
    6312       371872 :   tree orig_fn;
    6313       371872 :   vec<tree, va_gc> *orig_args = NULL;
    6314       371872 :   tree expr;
    6315       371872 :   tree object;
    6316              : 
    6317       371872 :   orig_fn = fn;
    6318       371872 :   object = TREE_OPERAND (fn, 0);
    6319              : 
    6320       371872 :   if (processing_template_decl)
    6321              :     {
    6322       285094 :       gcc_assert (TREE_CODE (fn) == DOTSTAR_EXPR
    6323              :                   || TREE_CODE (fn) == MEMBER_REF);
    6324       285094 :       if (type_dependent_expression_p (fn)
    6325       285094 :           || any_type_dependent_arguments_p (*args))
    6326       285055 :         return build_min_nt_call_vec (fn, *args);
    6327              : 
    6328           39 :       orig_args = make_tree_vector_copy (*args);
    6329              : 
    6330              :       /* Transform the arguments and add the implicit "this"
    6331              :          parameter.  */
    6332           39 :       if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
    6333              :         {
    6334           33 :           if (TREE_CODE (fn) == DOTSTAR_EXPR)
    6335           27 :             object = cp_build_addr_expr (object, complain);
    6336           33 :           vec_safe_insert (*args, 0, object);
    6337              :         }
    6338              :     }
    6339              : 
    6340              :   /* A qualified name corresponding to a bound pointer-to-member is
    6341              :      represented as an OFFSET_REF:
    6342              : 
    6343              :         struct B { void g(); };
    6344              :         void (B::*p)();
    6345              :         void B::g() { (this->*p)(); }  */
    6346        86817 :   if (TREE_CODE (fn) == OFFSET_REF)
    6347              :     {
    6348        86778 :       tree object_addr = cp_build_addr_expr (object, complain);
    6349        86778 :       fn = TREE_OPERAND (fn, 1);
    6350        86778 :       fn = get_member_function_from_ptrfunc (&object_addr, fn,
    6351              :                                              complain);
    6352        86778 :       vec_safe_insert (*args, 0, object_addr);
    6353              :     }
    6354              : 
    6355        86817 :   if (CLASS_TYPE_P (TREE_TYPE (fn)))
    6356            3 :     expr = build_op_call (fn, args, complain);
    6357              :   else
    6358        86814 :     expr = cp_build_function_call_vec (fn, args, complain);
    6359        86817 :   if (processing_template_decl && expr != error_mark_node)
    6360           39 :     expr = build_min_non_dep_call_vec (expr, orig_fn, orig_args);
    6361              : 
    6362        86817 :   if (orig_args != NULL)
    6363           39 :     release_tree_vector (orig_args);
    6364              : 
    6365              :   return expr;
    6366              : }
    6367              : 
    6368              : 
    6369              : void
    6370    377357752 : check_default_args (tree x)
    6371              : {
    6372    377357752 :   tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
    6373    377357752 :   bool saw_def = false;
    6374    377357752 :   bool noted_first_def = false;
    6375    377357752 :   int idx_of_first_default_arg = 0;
    6376    377357752 :   location_t loc_of_first_default_arg = UNKNOWN_LOCATION;
    6377    377357752 :   int i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
    6378    377357752 :   tree fndecl = STRIP_TEMPLATE (x);
    6379    377357752 :   auto_diagnostic_group d;
    6380   1405730993 :   for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
    6381              :     {
    6382    651015489 :       if (TREE_PURPOSE (arg))
    6383              :         {
    6384     11987743 :           if (!saw_def)
    6385              :             {
    6386      9001229 :               saw_def = true;
    6387      9001229 :               idx_of_first_default_arg = i;
    6388      9001229 :               location_t loc = get_fndecl_argument_location (fndecl, i);
    6389      9001229 :               if (loc != DECL_SOURCE_LOCATION (x))
    6390      9001189 :                 loc_of_first_default_arg = loc;
    6391              :             }
    6392              :         }
    6393    639027746 :       else if (saw_def && !PACK_EXPANSION_P (TREE_VALUE (arg)))
    6394              :         {
    6395          147 :           error_at (get_fndecl_argument_location (fndecl, i),
    6396              :                     "default argument missing for parameter %P of %q#D", i, x);
    6397          147 :           if (loc_of_first_default_arg != UNKNOWN_LOCATION
    6398          147 :               && !noted_first_def)
    6399              :             {
    6400          144 :               inform (loc_of_first_default_arg,
    6401              :                       "...following parameter %P which has a default argument",
    6402              :                       idx_of_first_default_arg);
    6403          144 :               noted_first_def = true;
    6404              :             }
    6405          147 :           TREE_PURPOSE (arg) = error_mark_node;
    6406              :         }
    6407              :     }
    6408    377357752 : }
    6409              : 
    6410              : /* Return true if function DECL can be inlined.  This is used to force
    6411              :    instantiation of methods that might be interesting for inlining.  */
    6412              : bool
    6413            3 : possibly_inlined_p (tree decl)
    6414              : {
    6415            3 :   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
    6416            3 :   if (DECL_UNINLINABLE (decl))
    6417              :     return false;
    6418            3 :   if (!optimize)
    6419            3 :     return DECL_DECLARED_INLINE_P (decl);
    6420              :   /* When optimizing, we might inline everything when flatten
    6421              :      attribute or heuristics inlining for size or autoinlining
    6422              :      is used.  */
    6423              :   return true;
    6424              : }
    6425              : 
    6426              : /* If DECL is a function or variable template specialization, instantiate
    6427              :    its definition now.  */
    6428              : 
    6429              : void
    6430    178860188 : maybe_instantiate_decl (tree decl)
    6431              : {
    6432       867820 :   if (VAR_OR_FUNCTION_DECL_P (decl)
    6433    178860188 :       && DECL_LANG_SPECIFIC (decl)
    6434    136181162 :       && DECL_TEMPLATE_INFO (decl)
    6435    285236447 :       && !uses_template_parms (DECL_TI_ARGS (decl)))
    6436              :     {
    6437              :       /* Instantiating a function will result in garbage collection.  We
    6438              :          must treat this situation as if we were within the body of a
    6439              :          function so as to avoid collecting live data only referenced from
    6440              :          the stack (such as overload resolution candidates).  */
    6441    101772146 :       ++function_depth;
    6442    101772146 :       instantiate_decl (decl, /*defer_ok=*/false,
    6443              :                         /*expl_inst_class_mem_p=*/false);
    6444    101769449 :       --function_depth;
    6445              :     }
    6446    178857491 : }
    6447              : 
    6448              : /* Error if the DECL is unavailable (unless this is currently suppressed).
    6449              :    Maybe warn if DECL is deprecated, subject to COMPLAIN.  Returns true if
    6450              :    an error or warning was emitted.  */
    6451              : 
    6452              : bool
    6453   4245140839 : cp_handle_deprecated_or_unavailable (tree decl, tsubst_flags_t complain)
    6454              : {
    6455   4245140839 :   if (!decl)
    6456              :     return false;
    6457              : 
    6458   4205157196 :   if ((complain & tf_error)
    6459   3831148874 :       && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
    6460              :     {
    6461   3088908726 :       if (TREE_UNAVAILABLE (decl))
    6462              :         {
    6463          252 :           error_unavailable_use (decl, NULL_TREE);
    6464          252 :           return true;
    6465              :         }
    6466              :       else
    6467              :         {
    6468              :           /* Perhaps this is an unavailable typedef.  */
    6469   3088908474 :           if (TYPE_P (decl)
    6470    820385829 :               && TYPE_NAME (decl)
    6471   3902796164 :               && TREE_UNAVAILABLE (TYPE_NAME (decl)))
    6472              :             {
    6473            6 :               decl = TYPE_NAME (decl);
    6474              :               /* Don't error within members of a unavailable type.  */
    6475            6 :               if (TYPE_P (decl)
    6476            6 :                   && currently_open_class (decl))
    6477              :                 return false;
    6478              : 
    6479            6 :               error_unavailable_use (decl, NULL_TREE);
    6480            6 :               return true;
    6481              :             }
    6482              :         }
    6483              :       /* Carry on to consider deprecatedness.  */
    6484              :     }
    6485              : 
    6486   4205156938 :   if (!(complain & tf_warning)
    6487   3786317510 :       || deprecated_state == DEPRECATED_SUPPRESS
    6488   3783843256 :       || deprecated_state == UNAVAILABLE_DEPRECATED_SUPPRESS)
    6489              :     return false;
    6490              : 
    6491   3047184440 :   if (!TREE_DEPRECATED (decl))
    6492              :     {
    6493              :       /* Perhaps this is a deprecated typedef.  */
    6494   3046511896 :       if (TYPE_P (decl) && TYPE_NAME (decl))
    6495    812453349 :         decl = TYPE_NAME (decl);
    6496              : 
    6497   3046511896 :       if (!TREE_DEPRECATED (decl))
    6498              :         return false;
    6499              :     }
    6500              : 
    6501              :   /* Don't warn within members of a deprecated type.  */
    6502       672552 :   if (TYPE_P (decl)
    6503       672552 :       && currently_open_class (decl))
    6504              :     return false;
    6505              : 
    6506       184556 :   bool warned = false;
    6507       184556 :   if (cxx_dialect >= cxx11
    6508       184465 :       && DECL_P (decl)
    6509       184338 :       && DECL_ARTIFICIAL (decl)
    6510        21081 :       && DECL_IOBJ_MEMBER_FUNCTION_P (decl)
    6511       205637 :       && copy_fn_p (decl))
    6512              :     {
    6513              :       /* Don't warn if the flag was disabled around the class definition
    6514              :          (c++/94492).  */
    6515        21069 :       if (warning_enabled_at (DECL_SOURCE_LOCATION (decl),
    6516        21069 :                               OPT_Wdeprecated_copy))
    6517              :         {
    6518           20 :           auto_diagnostic_group d;
    6519           20 :           tree ctx = DECL_CONTEXT (decl);
    6520           20 :           tree other = classtype_has_depr_implicit_copy (ctx);
    6521           20 :           int opt = (DECL_DESTRUCTOR_P (other)
    6522           20 :                      ? OPT_Wdeprecated_copy_dtor
    6523            0 :                      : OPT_Wdeprecated_copy);
    6524           20 :           warned = warning (opt, "implicitly-declared %qD is deprecated",
    6525              :                             decl);
    6526           20 :           if (warned)
    6527            4 :             inform (DECL_SOURCE_LOCATION (other),
    6528              :                     "because %qT has user-provided %qD",
    6529              :                     ctx, other);
    6530           20 :         }
    6531              :     }
    6532              :   else
    6533              :     {
    6534       163487 :       if (!warning_suppressed_at (input_location,
    6535              :                                   OPT_Wdeprecated_declarations))
    6536       156655 :         warned = warn_deprecated_use (decl, NULL_TREE);
    6537       163487 :       suppress_warning_at (input_location, OPT_Wdeprecated_declarations);
    6538              :     }
    6539              : 
    6540              :   return warned;
    6541              : }
    6542              : 
    6543              : /* Like above, but takes into account outer scopes.  */
    6544              : 
    6545              : void
    6546   1569156111 : cp_warn_deprecated_use_scopes (tree scope)
    6547              : {
    6548   1569156111 :   while (scope
    6549   2757171031 :          && scope != error_mark_node
    6550   5514341999 :          && scope != global_namespace)
    6551              :     {
    6552    264512288 :       if ((TREE_CODE (scope) == NAMESPACE_DECL || OVERLOAD_TYPE_P (scope))
    6553   1435203050 :           && cp_handle_deprecated_or_unavailable (scope))
    6554              :         return;
    6555   1188014920 :       if (TYPE_P (scope))
    6556    248980499 :         scope = CP_TYPE_CONTEXT (scope);
    6557              :       else
    6558    939034421 :         scope = CP_DECL_CONTEXT (scope);
    6559              :     }
    6560              : }
    6561              : 
    6562              : /* True if DECL or its enclosing scope have unbound template parameters.  */
    6563              : 
    6564              : bool
    6565    516174636 : decl_dependent_p (tree decl)
    6566              : {
    6567    516174636 :   tree orig_decl = decl;
    6568   1031706531 :   if (DECL_FUNCTION_SCOPE_P (decl)
    6569    233785178 :       || TREE_CODE (decl) == CONST_DECL
    6570    233785178 :       || TREE_CODE (decl) == USING_DECL
    6571    749959814 :       || TREE_CODE (decl) == FIELD_DECL)
    6572    282389458 :     decl = CP_DECL_CONTEXT (decl);
    6573    516174636 :   if (tree tinfo = get_template_info (decl))
    6574    445985868 :     if (any_dependent_template_arguments_p (TI_ARGS (tinfo)))
    6575              :       return true;
    6576    338939420 :   if (LAMBDA_FUNCTION_P (decl)
    6577    337334644 :       && dependent_type_p (DECL_CONTEXT (decl)))
    6578              :     return true;
    6579              :   /* for-range-declaration of expansion statement as well as variable
    6580              :      declarations in the expansion statement body when the expansion statement
    6581              :      is not inside a template still need to be treated as dependent during
    6582              :      parsing.  When the body is instantiated, in_expansion_stmt will be already
    6583              :      false.  */
    6584    335672114 :   if (VAR_P (orig_decl) && in_expansion_stmt && decl == current_function_decl)
    6585          618 :     return true;
    6586              :   return false;
    6587              : }
    6588              : 
    6589              : /* [basic.def.odr] A function is named [and therefore odr-used] by an
    6590              :    expression or conversion if it is the selected member of an overload set in
    6591              :    an overload resolution performed as part of forming that expression or
    6592              :    conversion, unless it is a pure virtual function and either the expression
    6593              :    is not an id-expression naming the function with an explicitly qualified
    6594              :    name or the expression forms a pointer to member.
    6595              : 
    6596              :    Mostly, we call mark_used in places that actually do something with a
    6597              :    function, like build_over_call.  But in a few places we end up with a
    6598              :    non-overloaded FUNCTION_DECL that we aren't going to do any more with, like
    6599              :    convert_to_void.  resolve_nondeduced_context is called in those places,
    6600              :    but it's also called in too many other places.  */
    6601              : 
    6602              : bool
    6603    480078834 : mark_single_function (tree expr, tsubst_flags_t complain)
    6604              : {
    6605    480078834 :   expr = maybe_undo_parenthesized_ref (expr);
    6606    480078834 :   expr = tree_strip_any_location_wrapper (expr);
    6607              : 
    6608    480078834 :   if (expr == error_mark_node)
    6609              :     return false;
    6610              : 
    6611    480077940 :   if (is_overloaded_fn (expr) == 1
    6612    129697786 :       && !mark_used (expr, complain)
    6613    480077975 :       && !(complain & tf_error))
    6614           15 :     return false;
    6615              :   return true;
    6616              : }
    6617              : 
    6618              : /* True iff we have started, but not finished, defining FUNCTION_DECL DECL.  */
    6619              : 
    6620              : bool
    6621     99967361 : fn_being_defined (tree decl)
    6622              : {
    6623              :   /* DECL_INITIAL is set to error_mark_node in grokfndecl for a definition, and
    6624              :      changed to BLOCK by poplevel at the end of the function.  */
    6625     99967361 :   return (TREE_CODE (decl) == FUNCTION_DECL
    6626     99967361 :           && DECL_INITIAL (decl) == error_mark_node);
    6627              : }
    6628              : 
    6629              : /* True if DECL is an instantiation of a function template currently being
    6630              :    defined.  */
    6631              : 
    6632              : bool
    6633    335671496 : fn_template_being_defined (tree decl)
    6634              : {
    6635    335671496 :   if (TREE_CODE (decl) != FUNCTION_DECL
    6636    164176689 :       || !DECL_LANG_SPECIFIC (decl)
    6637    164176689 :       || !DECL_TEMPLOID_INSTANTIATION (decl)
    6638    473192809 :       || DECL_TEMPLATE_INSTANTIATED (decl))
    6639              :     return false;
    6640     99967361 :   tree tinfo = DECL_TEMPLATE_INFO (decl);
    6641     99967361 :   tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
    6642     99967361 :   return fn_being_defined (pattern);
    6643              : }
    6644              : 
    6645              : /* Mark DECL (either a _DECL or a BASELINK) as "used" in the program.
    6646              :    If DECL is a specialization or implicitly declared class member,
    6647              :    generate the actual definition.  Return false if something goes
    6648              :    wrong, true otherwise.  */
    6649              : 
    6650              : bool
    6651   1417632647 : mark_used (tree decl, tsubst_flags_t complain /* = tf_warning_or_error */)
    6652              : {
    6653   1417632647 :   if (decl == error_mark_node)
    6654              :     return false;
    6655              : 
    6656              :   /* If we're just testing conversions or resolving overloads, we
    6657              :      don't want any permanent effects like forcing functions to be
    6658              :      output or instantiating templates.  */
    6659   1417632495 :   if ((complain & tf_conv))
    6660              :     return true;
    6661              : 
    6662              :   /* If DECL is a BASELINK for a single function, then treat it just
    6663              :      like the DECL for the function.  Otherwise, if the BASELINK is
    6664              :      for an overloaded function, we don't know which function was
    6665              :      actually used until after overload resolution.  */
    6666   1417592448 :   if (BASELINK_P (decl))
    6667              :     {
    6668        12295 :       tree fns = BASELINK_FUNCTIONS (decl);
    6669        12295 :       if (really_overloaded_fn (fns))
    6670              :         return true;
    6671        12183 :       fns = OVL_FIRST (fns);
    6672        12183 :       if (!mark_used (fns, complain))
    6673              :         return false;
    6674              :       /* We might have deduced its return type.  */
    6675        12174 :       TREE_TYPE (decl) = TREE_TYPE (fns);
    6676        12174 :       return true;
    6677              :     }
    6678              : 
    6679   1417580153 :   if (!DECL_P (decl))
    6680              :     return true;
    6681              : 
    6682              :   /* Set TREE_USED for the benefit of -Wunused.  */
    6683   1416583530 :   TREE_USED (decl) = true;
    6684              : 
    6685              :   /* And for structured bindings also the underlying decl.  */
    6686   1416583530 :   if (DECL_DECOMPOSITION_P (decl) && !DECL_DECOMP_IS_BASE (decl))
    6687       996619 :     TREE_USED (DECL_DECOMP_BASE (decl)) = true;
    6688              : 
    6689   1416583530 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    6690              :     return true;
    6691              : 
    6692   1416570541 :   if (DECL_CLONED_FUNCTION_P (decl))
    6693     21501481 :     TREE_USED (DECL_CLONED_FUNCTION (decl)) = 1;
    6694              : 
    6695              :   /* Mark enumeration types as used.  */
    6696   1416570541 :   if (TREE_CODE (decl) == CONST_DECL)
    6697     35567881 :     used_types_insert (DECL_CONTEXT (decl));
    6698              : 
    6699   1416570541 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    6700              :     {
    6701    325766436 :       if (DECL_MAYBE_DELETED (decl))
    6702              :         {
    6703        35920 :           ++function_depth;
    6704        35920 :           maybe_synthesize_method (decl);
    6705        35920 :           --function_depth;
    6706              :         }
    6707              : 
    6708    325766436 :       if (DECL_DELETED_FN (decl))
    6709              :         {
    6710         2877 :           if (DECL_ARTIFICIAL (decl)
    6711         1920 :               && DECL_CONV_FN_P (decl)
    6712         2889 :               && LAMBDA_TYPE_P (DECL_CONTEXT (decl)))
    6713              :             /* We mark a lambda conversion op as deleted if we can't
    6714              :                generate it properly; see maybe_add_lambda_conv_op.  */
    6715            6 :             sorry ("converting lambda that uses %<...%> to function pointer");
    6716         2871 :           else if (complain & tf_error)
    6717              :             {
    6718         2425 :               auto_diagnostic_group d;
    6719         2425 :               if (DECL_INITIAL (decl)
    6720         2425 :                   && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
    6721              :                 {
    6722           25 :                   escaped_string msg;
    6723           25 :                   msg.escape (TREE_STRING_POINTER (DECL_INITIAL (decl)));
    6724           25 :                   error ("use of deleted function %qD: %s",
    6725              :                          decl, (const char *) msg);
    6726           25 :                 }
    6727              :               else
    6728         2400 :                 error ("use of deleted function %qD", decl);
    6729         2425 :               if (!maybe_explain_implicit_delete (decl))
    6730          679 :                 inform (DECL_SOURCE_LOCATION (decl), "declared here");
    6731         2425 :             }
    6732              :           return false;
    6733              :         }
    6734              : 
    6735    325763559 :       if (!maybe_instantiate_noexcept (decl, complain))
    6736              :         return false;
    6737              :     }
    6738              : 
    6739   1416567577 :   if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_LOCAL_DECL_P (decl))
    6740              :     {
    6741        73581 :       if (!DECL_LANG_SPECIFIC (decl))
    6742              :         /* An unresolved dependent local extern.  */
    6743              :         return true;
    6744              : 
    6745        73581 :       DECL_ODR_USED (decl) = 1;
    6746        73581 :       auto alias = DECL_LOCAL_DECL_ALIAS (decl);
    6747        73581 :       if (!alias || alias == error_mark_node)
    6748              :         return true;
    6749              : 
    6750              :       /* Process the underlying decl.  */
    6751        73289 :       decl = alias;
    6752        73289 :       TREE_USED (decl) = true;
    6753              :     }
    6754              : 
    6755   1416567285 :   cp_handle_deprecated_or_unavailable (decl, complain);
    6756              : 
    6757              :   /* We can only check DECL_ODR_USED on variables or functions with
    6758              :      DECL_LANG_SPECIFIC set, and these are also the only decls that we
    6759              :      might need special handling for.  */
    6760    820727908 :   if (!VAR_OR_FUNCTION_DECL_P (decl)
    6761   1742330735 :       || DECL_THUNK_P (decl))
    6762              :     return true;
    6763              : 
    6764              :   /* We only want to do this processing once.  We don't need to keep trying
    6765              :      to instantiate inline templates, because unit-at-a-time will make sure
    6766              :      we get them compiled before functions that want to inline them.  */
    6767    921593935 :   if (DECL_LANG_SPECIFIC (decl) && DECL_ODR_USED (decl))
    6768              :     return true;
    6769              : 
    6770    510381699 :   if (flag_concepts && TREE_CODE (decl) == FUNCTION_DECL
    6771    679847823 :       && !constraints_satisfied_p (decl))
    6772              :     {
    6773           15 :       if (complain & tf_error)
    6774              :         {
    6775            6 :           auto_diagnostic_group d;
    6776            6 :           error ("use of function %qD with unsatisfied constraints",
    6777              :                  decl);
    6778            6 :           location_t loc = DECL_SOURCE_LOCATION (decl);
    6779            6 :           inform (loc, "declared here");
    6780            6 :           diagnose_constraints (loc, decl, NULL_TREE);
    6781            6 :         }
    6782              :       return false;
    6783              :     }
    6784              : 
    6785              :   /* If DECL has a deduced return type, we need to instantiate it now to
    6786              :      find out its type.  For OpenMP user defined reductions, we need them
    6787              :      instantiated for reduction clauses which inline them by hand directly.
    6788              :      OpenMP declared mappers are used implicitly so must be instantiated
    6789              :      before they can be detected.  */
    6790    516174636 :   if (undeduced_auto_decl (decl)
    6791    486805141 :       || (VAR_P (decl)
    6792    322639131 :           && VAR_HAD_UNKNOWN_BOUND (decl))
    6793    486784851 :       || (TREE_CODE (decl) == FUNCTION_DECL
    6794    164166010 :           && DECL_OMP_DECLARE_REDUCTION_P (decl))
    6795   1002959215 :       || (TREE_CODE (decl) == VAR_DECL
    6796    322618841 :           && DECL_LANG_SPECIFIC (decl)
    6797     77405921 :           && DECL_OMP_DECLARE_MAPPER_P (decl)))
    6798     29390166 :     maybe_instantiate_decl (decl);
    6799              : 
    6800    516174636 :   if (!decl_dependent_p (decl)
    6801              :       /* Don't require this yet for an instantiation of a function template
    6802              :          we're currently defining (c++/120555).  */
    6803    335671496 :       && !fn_template_being_defined (decl)
    6804    851721938 :       && !require_deduced_type (decl, complain))
    6805              :     return false;
    6806              : 
    6807    516172612 :   if (DECL_LANG_SPECIFIC (decl) == NULL)
    6808              :     return true;
    6809              : 
    6810    243208734 :   if (processing_template_decl || in_template_context)
    6811              :     return true;
    6812              : 
    6813              :   /* Check this too in case we're within instantiate_non_dependent_expr.  */
    6814    186503764 :   if (DECL_TEMPLATE_INFO (decl)
    6815    186503764 :       && uses_template_parms (DECL_TI_ARGS (decl)))
    6816              :     return true;
    6817              : 
    6818    186503764 :   if (builtin_pack_fn_p (decl))
    6819              :     {
    6820           12 :       if (complain & tf_error)
    6821            6 :         error ("use of built-in parameter pack %qD outside of a template",
    6822            6 :                DECL_NAME (decl));
    6823              :       return false;
    6824              :     }
    6825              : 
    6826              :   /* If we don't need a value, then we don't need to synthesize DECL.  */
    6827    186503752 :   if (cp_unevaluated_operand || in_discarded_stmt)
    6828              :     return true;
    6829              : 
    6830     50186003 :   DECL_ODR_USED (decl) = 1;
    6831     50186003 :   if (DECL_CLONED_FUNCTION_P (decl))
    6832      7524073 :     DECL_ODR_USED (DECL_CLONED_FUNCTION (decl)) = 1;
    6833              : 
    6834              :   /* DR 757: A type without linkage shall not be used as the type of a
    6835              :      variable or function with linkage, unless
    6836              :    o the variable or function has extern "C" linkage (7.5 [dcl.link]), or
    6837              :    o the variable or function is not used (3.2 [basic.def.odr]) or is
    6838              :    defined in the same translation unit.  */
    6839     50186003 :   if (cxx_dialect > cxx98
    6840     49986843 :       && decl_linkage (decl) != lk_none
    6841     46935551 :       && !DECL_EXTERN_C_P (decl)
    6842     42236965 :       && !DECL_ARTIFICIAL (decl)
    6843     40412974 :       && !decl_defined_p (decl)
    6844     80409128 :       && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
    6845       541942 :     vec_safe_push (no_linkage_decls, decl);
    6846              : 
    6847     50186003 :   if (TREE_CODE (decl) == FUNCTION_DECL
    6848     39094909 :       && DECL_DECLARED_INLINE_P (decl)
    6849     30164142 :       && !DECL_INITIAL (decl)
    6850     20255829 :       && !DECL_ARTIFICIAL (decl)
    6851     69846289 :       && !DECL_PURE_VIRTUAL_P (decl))
    6852              :     /* Remember it, so we can check it was defined.  */
    6853     19657780 :     note_vague_linkage_fn (decl);
    6854              : 
    6855              :   /* Is it a synthesized method that needs to be synthesized?  */
    6856     50186003 :   if (TREE_CODE (decl) == FUNCTION_DECL
    6857     39094909 :       && DECL_DEFAULTED_FN (decl)
    6858              :       /* A function defaulted outside the class is synthesized either by
    6859              :          cp_finish_decl or instantiate_decl.  */
    6860      1423241 :       && !DECL_DEFAULTED_OUTSIDE_CLASS_P (decl)
    6861     51609008 :       && ! DECL_INITIAL (decl))
    6862              :     {
    6863              :       /* Remember the current location for a function we will end up
    6864              :          synthesizing.  Then we can inform the user where it was
    6865              :          required in the case of error.  */
    6866      1218094 :       if (decl_remember_implicit_trigger_p (decl))
    6867       539414 :         DECL_SOURCE_LOCATION (decl) = input_location;
    6868              : 
    6869              :       /* Synthesizing an implicitly defined member function will result in
    6870              :          garbage collection.  We must treat this situation as if we were
    6871              :          within the body of a function so as to avoid collecting live data
    6872              :          on the stack (such as overload resolution candidates).
    6873              : 
    6874              :          We could just let c_parse_final_cleanups handle synthesizing
    6875              :          this function by adding it to deferred_fns, but doing
    6876              :          it at the use site produces better error messages.  */
    6877      1218094 :       ++function_depth;
    6878      1218094 :       synthesize_method (decl);
    6879      1218094 :       --function_depth;
    6880              :       /* If this is a synthesized method we don't need to
    6881              :          do the instantiation test below.  */
    6882              :     }
    6883     37876815 :   else if (VAR_OR_FUNCTION_DECL_P (decl)
    6884     48967909 :            && DECL_TEMPLATE_INFO (decl)
    6885     78623046 :            && (!DECL_EXPLICIT_INSTANTIATION (decl)
    6886      1179734 :                || always_instantiate_p (decl)))
    6887              :     /* If this is a function or variable that is an instance of some
    6888              :        template, we now know that we will need to actually do the
    6889              :        instantiation. We check that DECL is not an explicit
    6890              :        instantiation because that is not checked in instantiate_decl.
    6891              : 
    6892              :        We put off instantiating functions in order to improve compile
    6893              :        times.  Maintaining a stack of active functions is expensive,
    6894              :        and the inliner knows to instantiate any functions it might
    6895              :        need.  Therefore, we always try to defer instantiation.  */
    6896              :     {
    6897     29597065 :       ++function_depth;
    6898     29597065 :       instantiate_decl (decl, /*defer_ok=*/true,
    6899              :                         /*expl_inst_class_mem_p=*/false);
    6900     29588965 :       --function_depth;
    6901              :     }
    6902              : 
    6903              :   return true;
    6904              : }
    6905              : 
    6906              : tree
    6907            9 : vtv_start_verification_constructor_init_function (void)
    6908              : {
    6909            9 :   return start_objects (/*initp=*/true, MAX_RESERVED_INIT_PRIORITY - 1, true);
    6910              : }
    6911              : 
    6912              : tree
    6913            6 : vtv_finish_verification_constructor_init_function (tree body)
    6914              : {
    6915            6 :   return finish_objects (/*initp=*/true, MAX_RESERVED_INIT_PRIORITY - 1, body);
    6916              : }
    6917              : 
    6918              : #include "gt-cp-decl2.h"
        

Generated by: LCOV version 2.6-beta

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