LCOV - code coverage report
Current view: top level - gcc/cp - decl2.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 2213 2325 95.2 %
Date: 2020-03-28 11:57:23 Functions: 115 118 97.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Process declarations and variables for C++ compiler.
       2                 :            :    Copyright (C) 1988-2020 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                 :            : 
      52                 :            : /* Id for dumping the raw trees.  */
      53                 :            : int raw_dump_id;
      54                 :            :  
      55                 :            : extern cpp_reader *parse_in;
      56                 :            : 
      57                 :            : /* This structure contains information about the initializations
      58                 :            :    and/or destructions required for a particular priority level.  */
      59                 :            : typedef struct priority_info_s {
      60                 :            :   /* Nonzero if there have been any initializations at this priority
      61                 :            :      throughout the translation unit.  */
      62                 :            :   int initializations_p;
      63                 :            :   /* Nonzero if there have been any destructions at this priority
      64                 :            :      throughout the translation unit.  */
      65                 :            :   int destructions_p;
      66                 :            : } *priority_info;
      67                 :            : 
      68                 :            : static void mark_vtable_entries (tree);
      69                 :            : static bool maybe_emit_vtables (tree);
      70                 :            : static tree start_objects (int, int);
      71                 :            : static void finish_objects (int, int, tree);
      72                 :            : static tree start_static_storage_duration_function (unsigned);
      73                 :            : static void finish_static_storage_duration_function (tree);
      74                 :            : static priority_info get_priority_info (int);
      75                 :            : static void do_static_initialization_or_destruction (tree, bool);
      76                 :            : static void one_static_initialization_or_destruction (tree, tree, bool);
      77                 :            : static void generate_ctor_or_dtor_function (bool, int, location_t *);
      78                 :            : static int generate_ctor_and_dtor_functions_for_priority (splay_tree_node,
      79                 :            :                                                           void *);
      80                 :            : static tree prune_vars_needing_no_initialization (tree *);
      81                 :            : static void write_out_vars (tree);
      82                 :            : static void import_export_class (tree);
      83                 :            : static tree get_guard_bits (tree);
      84                 :            : static void determine_visibility_from_class (tree, tree);
      85                 :            : static bool determine_hidden_inline (tree);
      86                 :            : static void maybe_instantiate_decl (tree);
      87                 :            : 
      88                 :            : /* A list of static class variables.  This is needed, because a
      89                 :            :    static class variable can be declared inside the class without
      90                 :            :    an initializer, and then initialized, statically, outside the class.  */
      91                 :            : static GTY(()) vec<tree, va_gc> *pending_statics;
      92                 :            : 
      93                 :            : /* A list of functions which were declared inline, but which we
      94                 :            :    may need to emit outline anyway.  */
      95                 :            : static GTY(()) vec<tree, va_gc> *deferred_fns;
      96                 :            : 
      97                 :            : /* A list of decls that use types with no linkage, which we need to make
      98                 :            :    sure are defined.  */
      99                 :            : static GTY(()) vec<tree, va_gc> *no_linkage_decls;
     100                 :            : 
     101                 :            : /* A vector of alternating decls and identifiers, where the latter
     102                 :            :    is to be an alias for the former if the former is defined.  */
     103                 :            : static GTY(()) vec<tree, va_gc> *mangling_aliases;
     104                 :            : 
     105                 :            : /* hash traits for declarations.  Hashes single decls via
     106                 :            :    DECL_ASSEMBLER_NAME_RAW.  */
     107                 :            : 
     108                 :            : struct mangled_decl_hash : ggc_remove <tree>
     109                 :            : {
     110                 :            :   typedef tree value_type; /* A DECL.  */
     111                 :            :   typedef tree compare_type; /* An identifier.  */
     112                 :            : 
     113                 :   81994800 :   static hashval_t hash (const value_type decl)
     114                 :            :   {
     115                 :   81994800 :     return IDENTIFIER_HASH_VALUE (DECL_ASSEMBLER_NAME_RAW (decl));
     116                 :            :   }
     117                 :   89751000 :   static bool equal (const value_type existing, compare_type candidate)
     118                 :            :   {
     119                 :   89751000 :     tree name = DECL_ASSEMBLER_NAME_RAW (existing);
     120                 :   89751000 :     return candidate == name;
     121                 :            :   }
     122                 :            : 
     123                 :            :   static const bool empty_zero_p = true;
     124                 :         16 :   static inline void mark_empty (value_type &p) {p = NULL_TREE;}
     125                 :  158277000 :   static inline bool is_empty (value_type p) {return !p;}
     126                 :            : 
     127                 :   97895400 :   static bool is_deleted (value_type e)
     128                 :            :   {
     129                 :   97895400 :     return e == reinterpret_cast <value_type> (1);
     130                 :            :   }
     131                 :         46 :   static void mark_deleted (value_type &e)
     132                 :            :   {
     133                 :         46 :     e = reinterpret_cast <value_type> (1);
     134                 :            :   }
     135                 :            : };
     136                 :            : 
     137                 :            : /* A hash table of decls keyed by mangled name.  Used to figure out if
     138                 :            :    we need compatibility aliases.  */
     139                 :            : static GTY(()) hash_table<mangled_decl_hash> *mangled_decls;
     140                 :            : 
     141                 :            : /* Nonzero if we're done parsing and into end-of-file activities.  */
     142                 :            : 
     143                 :            : int at_eof;
     144                 :            : 
     145                 :            : /* True if note_mangling_alias should enqueue mangling aliases for
     146                 :            :    later generation, rather than emitting them right away.  */
     147                 :            : 
     148                 :            : bool defer_mangling_aliases = true;
     149                 :            : 
     150                 :            : 
     151                 :            : /* Return a member function type (a METHOD_TYPE), given FNTYPE (a
     152                 :            :    FUNCTION_TYPE), CTYPE (class type), and QUALS (the cv-qualifiers
     153                 :            :    that apply to the function).  */
     154                 :            : 
     155                 :            : tree
     156                 :    6059990 : build_memfn_type (tree fntype, tree ctype, cp_cv_quals quals,
     157                 :            :                   cp_ref_qualifier rqual)
     158                 :            : {
     159                 :    6059990 :   if (fntype == error_mark_node || ctype == error_mark_node)
     160                 :            :     return error_mark_node;
     161                 :            : 
     162                 :    6059990 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
     163                 :            : 
     164                 :    6059990 :   cp_cv_quals type_quals = quals & ~TYPE_QUAL_RESTRICT;
     165                 :    6059990 :   ctype = cp_build_qualified_type (ctype, type_quals);
     166                 :            : 
     167                 :    6059990 :   tree newtype
     168                 :    6059990 :     = build_method_type_directly (ctype, TREE_TYPE (fntype),
     169                 :    6059990 :                                   (TREE_CODE (fntype) == METHOD_TYPE
     170                 :       4912 :                                    ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
     171                 :    6055080 :                                    : TYPE_ARG_TYPES (fntype)));
     172                 :    6059990 :   if (tree attrs = TYPE_ATTRIBUTES (fntype))
     173                 :         86 :     newtype = cp_build_type_attribute_variant (newtype, attrs);
     174                 :    6059990 :   newtype = build_cp_fntype_variant (newtype, rqual,
     175                 :    6059990 :                                      TYPE_RAISES_EXCEPTIONS (fntype),
     176                 :    6059990 :                                      TYPE_HAS_LATE_RETURN_TYPE (fntype));
     177                 :            : 
     178                 :    6059990 :   return newtype;
     179                 :            : }
     180                 :            : 
     181                 :            : /* Return a variant of FNTYPE, a FUNCTION_TYPE or METHOD_TYPE, with its
     182                 :            :    return type changed to NEW_RET.  */
     183                 :            : 
     184                 :            : tree
     185                 :      52188 : change_return_type (tree new_ret, tree fntype)
     186                 :            : {
     187                 :      52188 :   if (new_ret == error_mark_node)
     188                 :            :     return fntype;
     189                 :            : 
     190                 :      52188 :   if (same_type_p (new_ret, TREE_TYPE (fntype)))
     191                 :            :     return fntype;
     192                 :            : 
     193                 :      52188 :   tree newtype;
     194                 :      52188 :   tree args = TYPE_ARG_TYPES (fntype);
     195                 :            : 
     196                 :      52188 :   if (TREE_CODE (fntype) == FUNCTION_TYPE)
     197                 :            :     {
     198                 :       4565 :       newtype = build_function_type (new_ret, args);
     199                 :       4565 :       newtype = apply_memfn_quals (newtype,
     200                 :            :                                    type_memfn_quals (fntype));
     201                 :            :     }
     202                 :            :   else
     203                 :      47623 :     newtype = build_method_type_directly
     204                 :      47623 :       (class_of_this_parm (fntype), new_ret, TREE_CHAIN (args));
     205                 :            : 
     206                 :      52188 :   if (tree attrs = TYPE_ATTRIBUTES (fntype))
     207                 :          2 :     newtype = cp_build_type_attribute_variant (newtype, attrs);
     208                 :      52188 :   newtype = cxx_copy_lang_qualifiers (newtype, fntype);
     209                 :            : 
     210                 :      52188 :   return newtype;
     211                 :            : }
     212                 :            : 
     213                 :            : /* Build a PARM_DECL of FN with NAME and TYPE, and set DECL_ARG_TYPE
     214                 :            :    appropriately.  */
     215                 :            : 
     216                 :            : tree
     217                 :   38947600 : cp_build_parm_decl (tree fn, tree name, tree type)
     218                 :            : {
     219                 :   38947600 :   tree parm = build_decl (input_location,
     220                 :            :                           PARM_DECL, name, type);
     221                 :   38947600 :   DECL_CONTEXT (parm) = fn;
     222                 :            : 
     223                 :            :   /* DECL_ARG_TYPE is only used by the back end and the back end never
     224                 :            :      sees templates.  */
     225                 :   38947600 :   if (!processing_template_decl)
     226                 :   21277200 :     DECL_ARG_TYPE (parm) = type_passed_as (type);
     227                 :            : 
     228                 :   38947600 :   return parm;
     229                 :            : }
     230                 :            : 
     231                 :            : /* Returns a PARM_DECL of FN for a parameter of the indicated TYPE, with the
     232                 :            :    indicated NAME.  */
     233                 :            : 
     234                 :            : tree
     235                 :   11146200 : build_artificial_parm (tree fn, tree name, tree type)
     236                 :            : {
     237                 :   11146200 :   tree parm = cp_build_parm_decl (fn, name, type);
     238                 :   11146200 :   DECL_ARTIFICIAL (parm) = 1;
     239                 :            :   /* All our artificial parms are implicitly `const'; they cannot be
     240                 :            :      assigned to.  */
     241                 :   11146200 :   TREE_READONLY (parm) = 1;
     242                 :   11146200 :   return parm;
     243                 :            : }
     244                 :            : 
     245                 :            : /* Constructors for types with virtual baseclasses need an "in-charge" flag
     246                 :            :    saying whether this constructor is responsible for initialization of
     247                 :            :    virtual baseclasses or not.  All destructors also need this "in-charge"
     248                 :            :    flag, which additionally determines whether or not the destructor should
     249                 :            :    free the memory for the object.
     250                 :            : 
     251                 :            :    This function adds the "in-charge" flag to member function FN if
     252                 :            :    appropriate.  It is called from grokclassfn and tsubst.
     253                 :            :    FN must be either a constructor or destructor.
     254                 :            : 
     255                 :            :    The in-charge flag follows the 'this' parameter, and is followed by the
     256                 :            :    VTT parm (if any), then the user-written parms.  */
     257                 :            : 
     258                 :            : void
     259                 :    7362430 : maybe_retrofit_in_chrg (tree fn)
     260                 :            : {
     261                 :    7362430 :   tree basetype, arg_types, parms, parm, fntype;
     262                 :            : 
     263                 :            :   /* If we've already add the in-charge parameter don't do it again.  */
     264                 :   14724900 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
     265                 :            :     return;
     266                 :            : 
     267                 :            :   /* When processing templates we can't know, in general, whether or
     268                 :            :      not we're going to have virtual baseclasses.  */
     269                 :    7362430 :   if (processing_template_decl)
     270                 :            :     return;
     271                 :            : 
     272                 :            :   /* We don't need an in-charge parameter for constructors that don't
     273                 :            :      have virtual bases.  */
     274                 :    5697710 :   if (DECL_CONSTRUCTOR_P (fn)
     275                 :   10154000 :       && !CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
     276                 :            :     return;
     277                 :            : 
     278                 :    1295010 :   arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn));
     279                 :    1295010 :   basetype = TREE_TYPE (TREE_VALUE (arg_types));
     280                 :    1295010 :   arg_types = TREE_CHAIN (arg_types);
     281                 :            : 
     282                 :    1295010 :   parms = DECL_CHAIN (DECL_ARGUMENTS (fn));
     283                 :            : 
     284                 :            :   /* If this is a subobject constructor or destructor, our caller will
     285                 :            :      pass us a pointer to our VTT.  */
     286                 :    1295010 :   if (CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
     287                 :            :     {
     288                 :      67593 :       parm = build_artificial_parm (fn, vtt_parm_identifier, vtt_parm_type);
     289                 :            : 
     290                 :            :       /* First add it to DECL_ARGUMENTS between 'this' and the real args...  */
     291                 :      67593 :       DECL_CHAIN (parm) = parms;
     292                 :      67593 :       parms = parm;
     293                 :            : 
     294                 :            :       /* ...and then to TYPE_ARG_TYPES.  */
     295                 :      67593 :       arg_types = hash_tree_chain (vtt_parm_type, arg_types);
     296                 :            : 
     297                 :     135186 :       DECL_HAS_VTT_PARM_P (fn) = 1;
     298                 :            :     }
     299                 :            : 
     300                 :            :   /* Then add the in-charge parm (before the VTT parm).  */
     301                 :    1295010 :   parm = build_artificial_parm (fn, in_charge_identifier, integer_type_node);
     302                 :    1295010 :   DECL_CHAIN (parm) = parms;
     303                 :    1295010 :   parms = parm;
     304                 :    1295010 :   arg_types = hash_tree_chain (integer_type_node, arg_types);
     305                 :            : 
     306                 :            :   /* Insert our new parameter(s) into the list.  */
     307                 :    1295010 :   DECL_CHAIN (DECL_ARGUMENTS (fn)) = parms;
     308                 :            : 
     309                 :            :   /* And rebuild the function type.  */
     310                 :    1295010 :   fntype = build_method_type_directly (basetype, TREE_TYPE (TREE_TYPE (fn)),
     311                 :            :                                        arg_types);
     312                 :    1295010 :   if (TYPE_ATTRIBUTES (TREE_TYPE (fn)))
     313                 :          0 :     fntype = (cp_build_type_attribute_variant
     314                 :          0 :               (fntype, TYPE_ATTRIBUTES (TREE_TYPE (fn))));
     315                 :    1295010 :   fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (fn));
     316                 :    1295010 :   TREE_TYPE (fn) = fntype;
     317                 :            : 
     318                 :            :   /* Now we've got the in-charge parameter.  */
     319                 :    2590030 :   DECL_HAS_IN_CHARGE_PARM_P (fn) = 1;
     320                 :            : }
     321                 :            : 
     322                 :            : /* Classes overload their constituent function names automatically.
     323                 :            :    When a function name is declared in a record structure,
     324                 :            :    its name is changed to it overloaded name.  Since names for
     325                 :            :    constructors and destructors can conflict, we place a leading
     326                 :            :    '$' for destructors.
     327                 :            : 
     328                 :            :    CNAME is the name of the class we are grokking for.
     329                 :            : 
     330                 :            :    FUNCTION is a FUNCTION_DECL.  It was created by `grokdeclarator'.
     331                 :            : 
     332                 :            :    FLAGS contains bits saying what's special about today's
     333                 :            :    arguments.  DTOR_FLAG == DESTRUCTOR.
     334                 :            : 
     335                 :            :    If FUNCTION is a destructor, then we must add the `auto-delete' field
     336                 :            :    as a second parameter.  There is some hair associated with the fact
     337                 :            :    that we must "declare" this variable in the manner consistent with the
     338                 :            :    way the rest of the arguments were declared.
     339                 :            : 
     340                 :            :    QUALS are the qualifiers for the this pointer.  */
     341                 :            : 
     342                 :            : void
     343                 :   10518900 : grokclassfn (tree ctype, tree function, enum overload_flags flags)
     344                 :            : {
     345                 :   10518900 :   tree fn_name = DECL_NAME (function);
     346                 :            : 
     347                 :            :   /* Even within an `extern "C"' block, members get C++ linkage.  See
     348                 :            :      [dcl.link] for details.  */
     349                 :   10518900 :   SET_DECL_LANGUAGE (function, lang_cplusplus);
     350                 :            : 
     351                 :   10518900 :   if (fn_name == NULL_TREE)
     352                 :            :     {
     353                 :          0 :       error ("name missing for member function");
     354                 :          0 :       fn_name = get_identifier ("<anonymous>");
     355                 :          0 :       DECL_NAME (function) = fn_name;
     356                 :            :     }
     357                 :            : 
     358                 :   10518900 :   DECL_CONTEXT (function) = ctype;
     359                 :            : 
     360                 :   10518900 :   if (flags == DTOR_FLAG)
     361                 :     996730 :     DECL_CXX_DESTRUCTOR_P (function) = 1;
     362                 :            : 
     363                 :   20041200 :   if (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))
     364                 :    4906300 :     maybe_retrofit_in_chrg (function);
     365                 :   10518900 : }
     366                 :            : 
     367                 :            : /* Create an ARRAY_REF, checking for the user doing things backwards
     368                 :            :    along the way.  DECLTYPE_P is for N3276, as in the parser.  */
     369                 :            : 
     370                 :            : tree
     371                 :     837835 : grok_array_decl (location_t loc, tree array_expr, tree index_exp,
     372                 :            :                  bool decltype_p)
     373                 :            : {
     374                 :     837835 :   tree type;
     375                 :     837835 :   tree expr;
     376                 :     837835 :   tree orig_array_expr = array_expr;
     377                 :     837835 :   tree orig_index_exp = index_exp;
     378                 :     837835 :   tree overload = NULL_TREE;
     379                 :            : 
     380                 :    2513340 :   if (error_operand_p (array_expr) || error_operand_p (index_exp))
     381                 :            :     return error_mark_node;
     382                 :            : 
     383                 :     837735 :   if (processing_template_decl)
     384                 :            :     {
     385                 :     393939 :       if (type_dependent_expression_p (array_expr)
     386                 :     393939 :           || type_dependent_expression_p (index_exp))
     387                 :     327724 :         return build_min_nt_loc (loc, ARRAY_REF, array_expr, index_exp,
     388                 :     327724 :                                  NULL_TREE, NULL_TREE);
     389                 :      66215 :       array_expr = build_non_dependent_expr (array_expr);
     390                 :      66215 :       index_exp = build_non_dependent_expr (index_exp);
     391                 :            :     }
     392                 :            : 
     393                 :     510011 :   type = TREE_TYPE (array_expr);
     394                 :     510011 :   gcc_assert (type);
     395                 :     510011 :   type = non_reference (type);
     396                 :            : 
     397                 :            :   /* If they have an `operator[]', use that.  */
     398                 :    1020020 :   if (MAYBE_CLASS_TYPE_P (type) || MAYBE_CLASS_TYPE_P (TREE_TYPE (index_exp)))
     399                 :            :     {
     400                 :      19237 :       tsubst_flags_t complain = tf_warning_or_error;
     401                 :      19237 :       if (decltype_p)
     402                 :         12 :         complain |= tf_decltype;
     403                 :      19237 :       expr = build_new_op (loc, ARRAY_REF, LOOKUP_NORMAL, array_expr,
     404                 :            :                            index_exp, NULL_TREE, &overload, complain);
     405                 :            :     }
     406                 :            :   else
     407                 :            :     {
     408                 :     490774 :       tree p1, p2, i1, i2;
     409                 :     490774 :       bool swapped = false;
     410                 :            : 
     411                 :            :       /* Otherwise, create an ARRAY_REF for a pointer or array type.
     412                 :            :          It is a little-known fact that, if `a' is an array and `i' is
     413                 :            :          an int, you can write `i[a]', which means the same thing as
     414                 :            :          `a[i]'.  */
     415                 :     490774 :       if (TREE_CODE (type) == ARRAY_TYPE || VECTOR_TYPE_P (type))
     416                 :            :         p1 = array_expr;
     417                 :            :       else
     418                 :     141868 :         p1 = build_expr_type_conversion (WANT_POINTER, array_expr, false);
     419                 :            : 
     420                 :     490774 :       if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
     421                 :            :         p2 = index_exp;
     422                 :            :       else
     423                 :     490754 :         p2 = build_expr_type_conversion (WANT_POINTER, index_exp, false);
     424                 :            : 
     425                 :     490774 :       i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr,
     426                 :            :                                        false);
     427                 :     490774 :       i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp,
     428                 :            :                                        false);
     429                 :            : 
     430                 :     490774 :       if ((p1 && i2) && (i1 && p2))
     431                 :          0 :         error ("ambiguous conversion for array subscript");
     432                 :            : 
     433                 :     490774 :       if (p1 && i2)
     434                 :            :         array_expr = p1, index_exp = i2;
     435                 :         50 :       else if (i1 && p2)
     436                 :            :         swapped = true, array_expr = p2, index_exp = i1;
     437                 :            :       else
     438                 :            :         {
     439                 :         28 :           error_at (loc, "invalid types %<%T[%T]%> for array subscript",
     440                 :         28 :                     type, TREE_TYPE (index_exp));
     441                 :         28 :           return error_mark_node;
     442                 :            :         }
     443                 :            : 
     444                 :     490746 :       if (array_expr == error_mark_node || index_exp == error_mark_node)
     445                 :          0 :         error ("ambiguous conversion for array subscript");
     446                 :            : 
     447                 :     490746 :       if (TYPE_PTR_P (TREE_TYPE (array_expr)))
     448                 :     141852 :         array_expr = mark_rvalue_use (array_expr);
     449                 :            :       else
     450                 :     348894 :         array_expr = mark_lvalue_use_nonread (array_expr);
     451                 :     490746 :       index_exp = mark_rvalue_use (index_exp);
     452                 :     490746 :       if (swapped
     453                 :         22 :           && flag_strong_eval_order == 2
     454                 :     490768 :           && (TREE_SIDE_EFFECTS (array_expr) || TREE_SIDE_EFFECTS (index_exp)))
     455                 :          6 :         expr = build_array_ref (input_location, index_exp, array_expr);
     456                 :            :       else
     457                 :     490740 :         expr = build_array_ref (input_location, array_expr, index_exp);
     458                 :            :     }
     459                 :     509983 :   if (processing_template_decl && expr != error_mark_node)
     460                 :            :     {
     461                 :      66215 :       if (overload != NULL_TREE)
     462                 :       1907 :         return (build_min_non_dep_op_overload
     463                 :       1907 :                 (ARRAY_REF, expr, overload, orig_array_expr, orig_index_exp));
     464                 :            : 
     465                 :      64308 :       return build_min_non_dep (ARRAY_REF, expr, orig_array_expr, orig_index_exp,
     466                 :      64308 :                                 NULL_TREE, NULL_TREE);
     467                 :            :     }
     468                 :            :   return expr;
     469                 :            : }
     470                 :            : 
     471                 :            : /* Given the cast expression EXP, checking out its validity.   Either return
     472                 :            :    an error_mark_node if there was an unavoidable error, return a cast to
     473                 :            :    void for trying to delete a pointer w/ the value 0, or return the
     474                 :            :    call to delete.  If DOING_VEC is true, we handle things differently
     475                 :            :    for doing an array delete.
     476                 :            :    Implements ARM $5.3.4.  This is called from the parser.  */
     477                 :            : 
     478                 :            : tree
     479                 :      59888 : delete_sanity (location_t loc, tree exp, tree size, bool doing_vec,
     480                 :            :                int use_global_delete, tsubst_flags_t complain)
     481                 :            : {
     482                 :      59888 :   tree t, type;
     483                 :            : 
     484                 :      59888 :   if (exp == error_mark_node)
     485                 :            :     return exp;
     486                 :            : 
     487                 :      59763 :   if (processing_template_decl)
     488                 :            :     {
     489                 :      31432 :       t = build_min (DELETE_EXPR, void_type_node, exp, size);
     490                 :      31432 :       DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
     491                 :      31432 :       DELETE_EXPR_USE_VEC (t) = doing_vec;
     492                 :      31432 :       TREE_SIDE_EFFECTS (t) = 1;
     493                 :      31432 :       SET_EXPR_LOCATION (t, loc);
     494                 :      31432 :       return t;
     495                 :            :     }
     496                 :            : 
     497                 :      28331 :   location_t exp_loc = cp_expr_loc_or_loc (exp, loc);
     498                 :            : 
     499                 :            :   /* An array can't have been allocated by new, so complain.  */
     500                 :      28331 :   if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
     501                 :      28331 :       && (complain & tf_warning))
     502                 :         24 :     warning_at (exp_loc, 0, "deleting array %q#E", exp);
     503                 :            : 
     504                 :      28331 :   t = build_expr_type_conversion (WANT_POINTER, exp, true);
     505                 :            : 
     506                 :      28331 :   if (t == NULL_TREE || t == error_mark_node)
     507                 :            :     {
     508                 :         28 :       if (complain & tf_error)
     509                 :         28 :         error_at (exp_loc,
     510                 :            :                   "type %q#T argument given to %<delete%>, expected pointer",
     511                 :         28 :                   TREE_TYPE (exp));
     512                 :         28 :       return error_mark_node;
     513                 :            :     }
     514                 :            : 
     515                 :      28303 :   type = TREE_TYPE (t);
     516                 :            : 
     517                 :            :   /* As of Valley Forge, you can delete a pointer to const.  */
     518                 :            : 
     519                 :            :   /* You can't delete functions.  */
     520                 :      28303 :   if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
     521                 :            :     {
     522                 :          8 :       if (complain & tf_error)
     523                 :          8 :         error_at (exp_loc,
     524                 :            :                   "cannot delete a function.  Only pointer-to-objects are "
     525                 :            :                   "valid arguments to %<delete%>");
     526                 :          8 :       return error_mark_node;
     527                 :            :     }
     528                 :            : 
     529                 :            :   /* Deleting ptr to void is undefined behavior [expr.delete/3].  */
     530                 :      28295 :   if (VOID_TYPE_P (TREE_TYPE (type)))
     531                 :            :     {
     532                 :         27 :       if (complain & tf_warning)
     533                 :         27 :         warning_at (exp_loc, OPT_Wdelete_incomplete,
     534                 :            :                     "deleting %qT is undefined", type);
     535                 :            :       doing_vec = 0;
     536                 :            :     }
     537                 :            : 
     538                 :            :   /* Deleting a pointer with the value zero is valid and has no effect.  */
     539                 :      28295 :   if (integer_zerop (t))
     540                 :          4 :     return build1_loc (loc, NOP_EXPR, void_type_node, t);
     541                 :            : 
     542                 :      28291 :   if (doing_vec)
     543                 :       2557 :     return build_vec_delete (loc, t, /*maxindex=*/NULL_TREE,
     544                 :            :                              sfk_deleting_destructor,
     545                 :       2557 :                              use_global_delete, complain);
     546                 :            :   else
     547                 :      25734 :     return build_delete (loc, type, t, sfk_deleting_destructor,
     548                 :            :                          LOOKUP_NORMAL, use_global_delete,
     549                 :      25734 :                          complain);
     550                 :            : }
     551                 :            : 
     552                 :            : /* Report an error if the indicated template declaration is not the
     553                 :            :    sort of thing that should be a member template.  */
     554                 :            : 
     555                 :            : void
     556                 :    1414800 : check_member_template (tree tmpl)
     557                 :            : {
     558                 :    1414800 :   tree decl;
     559                 :            : 
     560                 :    1414800 :   gcc_assert (TREE_CODE (tmpl) == TEMPLATE_DECL);
     561                 :    1414800 :   decl = DECL_TEMPLATE_RESULT (tmpl);
     562                 :            : 
     563                 :    1414800 :   if (TREE_CODE (decl) == FUNCTION_DECL
     564                 :     190590 :       || DECL_ALIAS_TEMPLATE_P (tmpl)
     565                 :    1495530 :       || (TREE_CODE (decl) == TYPE_DECL
     566                 :      80264 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE (decl))))
     567                 :            :     {
     568                 :            :       /* The parser rejects template declarations in local classes
     569                 :            :          (with the exception of generic lambdas).  */
     570                 :    1425980 :       gcc_assert (!current_function_decl || LAMBDA_FUNCTION_P (decl));
     571                 :            :       /* The parser rejects any use of virtual in a function template.  */
     572                 :    2638540 :       gcc_assert (!(TREE_CODE (decl) == FUNCTION_DECL
     573                 :            :                     && DECL_VIRTUAL_P (decl)));
     574                 :            : 
     575                 :            :       /* The debug-information generating code doesn't know what to do
     576                 :            :          with member templates.  */
     577                 :    1414330 :       DECL_IGNORED_P (tmpl) = 1;
     578                 :            :     }
     579                 :        465 :   else if (variable_template_p (tmpl))
     580                 :            :     /* OK */;
     581                 :            :   else
     582                 :          0 :     error ("template declaration of %q#D", decl);
     583                 :    1414800 : }
     584                 :            : 
     585                 :            : /* Sanity check: report error if this function FUNCTION is not
     586                 :            :    really a member of the class (CTYPE) it is supposed to belong to.
     587                 :            :    TEMPLATE_PARMS is used to specify the template parameters of a member
     588                 :            :    template passed as FUNCTION_DECL. If the member template is passed as a
     589                 :            :    TEMPLATE_DECL, it can be NULL since the parameters can be extracted
     590                 :            :    from the declaration. If the function is not a function template, it
     591                 :            :    must be NULL.
     592                 :            :    It returns the original declaration for the function, NULL_TREE if
     593                 :            :    no declaration was found, error_mark_node if an error was emitted.  */
     594                 :            : 
     595                 :            : tree
     596                 :     537710 : check_classfn (tree ctype, tree function, tree template_parms)
     597                 :            : {
     598                 :     537710 :   if (DECL_USE_TEMPLATE (function)
     599                 :     105159 :       && !(TREE_CODE (function) == TEMPLATE_DECL
     600                 :        757 :            && DECL_TEMPLATE_SPECIALIZATION (function))
     601                 :     642112 :       && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (function)))
     602                 :            :     /* Since this is a specialization of a member template,
     603                 :            :        we're not going to find the declaration in the class.
     604                 :            :        For example, in:
     605                 :            : 
     606                 :            :          struct S { template <typename T> void f(T); };
     607                 :            :          template <> void S::f(int);
     608                 :            : 
     609                 :            :        we're not going to find `S::f(int)', but there's no
     610                 :            :        reason we should, either.  We let our callers know we didn't
     611                 :            :        find the method, but we don't complain.  */
     612                 :            :     return NULL_TREE;
     613                 :            : 
     614                 :            :   /* Basic sanity check: for a template function, the template parameters
     615                 :            :      either were not passed, or they are the same of DECL_TEMPLATE_PARMS.  */
     616                 :     502591 :   if (TREE_CODE (function) == TEMPLATE_DECL)
     617                 :            :     {
     618                 :        777 :       if (template_parms
     619                 :       1534 :           && !comp_template_parms (template_parms,
     620                 :        757 :                                    DECL_TEMPLATE_PARMS (function)))
     621                 :            :         {
     622                 :          4 :           error ("template parameter lists provided don%'t match the "
     623                 :            :                  "template parameters of %qD", function);
     624                 :          4 :           return error_mark_node;
     625                 :            :         }
     626                 :        773 :       template_parms = DECL_TEMPLATE_PARMS (function);
     627                 :            :     }
     628                 :            : 
     629                 :            :   /* OK, is this a definition of a member template?  */
     630                 :     502587 :   bool is_template = (template_parms != NULL_TREE);
     631                 :            : 
     632                 :            :   /* [temp.mem]
     633                 :            : 
     634                 :            :      A destructor shall not be a member template.  */
     635                 :    1005170 :   if (DECL_DESTRUCTOR_P (function) && is_template)
     636                 :            :     {
     637                 :          8 :       error ("destructor %qD declared as member template", function);
     638                 :          8 :       return error_mark_node;
     639                 :            :     }
     640                 :            : 
     641                 :            :   /* We must enter the scope here, because conversion operators are
     642                 :            :      named by target type, and type equivalence relies on typenames
     643                 :            :      resolving within the scope of CTYPE.  */
     644                 :     502579 :   tree pushed_scope = push_scope (ctype);
     645                 :     502579 :   tree matched = NULL_TREE;
     646                 :     502579 :   tree fns = get_class_binding (ctype, DECL_NAME (function));
     647                 :            :   
     648                 :    2194590 :   for (ovl_iterator iter (fns); !matched && iter; ++iter)
     649                 :            :     {
     650                 :     846006 :       tree fndecl = *iter;
     651                 :            : 
     652                 :            :       /* A member template definition only matches a member template
     653                 :            :          declaration.  */
     654                 :     846006 :       if (is_template != (TREE_CODE (fndecl) == TEMPLATE_DECL))
     655                 :      38216 :         continue;
     656                 :            : 
     657                 :     807790 :       if (!DECL_DECLARES_FUNCTION_P (fndecl))
     658                 :       6685 :         continue;
     659                 :            : 
     660                 :     801105 :       tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
     661                 :     801105 :       tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
     662                 :            : 
     663                 :            :       /* We cannot simply call decls_match because this doesn't work
     664                 :            :          for static member functions that are pretending to be
     665                 :            :          methods, and because the name may have been changed by
     666                 :            :          asm("new_name").  */
     667                 :            : 
     668                 :            :       /* Get rid of the this parameter on functions that become
     669                 :            :          static.  */
     670                 :    1602210 :       if (DECL_STATIC_FUNCTION_P (fndecl)
     671                 :     801105 :           && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
     672                 :      22110 :         p1 = TREE_CHAIN (p1);
     673                 :            : 
     674                 :            :       /* ref-qualifier or absence of same must match.  */
     675                 :    1602210 :       if (type_memfn_rqual (TREE_TYPE (function))
     676                 :     801105 :           != type_memfn_rqual (TREE_TYPE (fndecl)))
     677                 :          6 :         continue;
     678                 :            : 
     679                 :            :       // Include constraints in the match.
     680                 :     801099 :       tree c1 = get_constraints (function);
     681                 :     801099 :       tree c2 = get_constraints (fndecl);
     682                 :            : 
     683                 :            :       /* While finding a match, same types and params are not enough
     684                 :            :          if the function is versioned.  Also check version ("target")
     685                 :            :          attributes.  */
     686                 :     801099 :       if (same_type_p (TREE_TYPE (TREE_TYPE (function)),
     687                 :            :                        TREE_TYPE (TREE_TYPE (fndecl)))
     688                 :     771013 :           && compparms (p1, p2)
     689                 :     502486 :           && !targetm.target_option.function_versions (function, fndecl)
     690                 :     502486 :           && (!is_template
     691                 :      66700 :               || comp_template_parms (template_parms,
     692                 :      66700 :                                       DECL_TEMPLATE_PARMS (fndecl)))
     693                 :     502478 :           && equivalent_constraints (c1, c2)
     694                 :     502464 :           && (DECL_TEMPLATE_SPECIALIZATION (function)
     695                 :     502464 :               == DECL_TEMPLATE_SPECIALIZATION (fndecl))
     696                 :    1303560 :           && (!DECL_TEMPLATE_SPECIALIZATION (function)
     697                 :      69765 :               || (DECL_TI_TEMPLATE (function) == DECL_TI_TEMPLATE (fndecl))))
     698                 :            :         matched = fndecl;
     699                 :            :     }
     700                 :            : 
     701                 :     502579 :   if (!matched)
     702                 :            :     {
     703                 :        115 :       if (!COMPLETE_TYPE_P (ctype))
     704                 :          8 :         cxx_incomplete_type_error (DECL_SOURCE_LOCATION (function),
     705                 :            :                                    function, ctype);
     706                 :            :       else
     707                 :            :         {
     708                 :        107 :           if (DECL_CONV_FN_P (function))
     709                 :          8 :             fns = get_class_binding (ctype, conv_op_identifier);
     710                 :            : 
     711                 :        107 :           error_at (DECL_SOURCE_LOCATION (function),
     712                 :            :                     "no declaration matches %q#D", function);
     713                 :        107 :           if (fns)
     714                 :         60 :             print_candidates (fns);
     715                 :         47 :           else if (DECL_CONV_FN_P (function))
     716                 :          4 :             inform (DECL_SOURCE_LOCATION (function),
     717                 :            :                     "no conversion operators declared");
     718                 :            :           else
     719                 :         43 :             inform (DECL_SOURCE_LOCATION (function),
     720                 :            :                     "no functions named %qD", function);
     721                 :        107 :           inform (DECL_SOURCE_LOCATION (TYPE_NAME (ctype)),
     722                 :            :                   "%#qT defined here", ctype);
     723                 :            :         }
     724                 :        115 :       matched = error_mark_node;
     725                 :            :     }
     726                 :            : 
     727                 :     502579 :   if (pushed_scope)
     728                 :     473247 :     pop_scope (pushed_scope);
     729                 :            : 
     730                 :            :   return matched;
     731                 :            : }
     732                 :            : 
     733                 :            : /* DECL is a function with vague linkage.  Remember it so that at the
     734                 :            :    end of the translation unit we can decide whether or not to emit
     735                 :            :    it.  */
     736                 :            : 
     737                 :            : void
     738                 :    6687800 : note_vague_linkage_fn (tree decl)
     739                 :            : {
     740                 :    6687800 :   if (processing_template_decl)
     741                 :            :     return;
     742                 :            : 
     743                 :    6687790 :   DECL_DEFER_OUTPUT (decl) = 1;
     744                 :    6687790 :   vec_safe_push (deferred_fns, decl);
     745                 :            : }
     746                 :            : 
     747                 :            : /* As above, but for variable template instantiations.  */
     748                 :            : 
     749                 :            : void
     750                 :     225745 : note_variable_template_instantiation (tree decl)
     751                 :            : {
     752                 :     225745 :   vec_safe_push (pending_statics, decl);
     753                 :     225745 : }
     754                 :            : 
     755                 :            : /* We have just processed the DECL, which is a static data member.
     756                 :            :    The other parameters are as for cp_finish_decl.  */
     757                 :            : 
     758                 :            : void
     759                 :    1360440 : finish_static_data_member_decl (tree decl,
     760                 :            :                                 tree init, bool init_const_expr_p,
     761                 :            :                                 tree asmspec_tree,
     762                 :            :                                 int flags)
     763                 :            : {
     764                 :    1360440 :   if (DECL_TEMPLATE_INSTANTIATED (decl))
     765                 :            :     /* We already needed to instantiate this, so the processing in this
     766                 :            :        function is unnecessary/wrong.  */
     767                 :            :     return;
     768                 :            : 
     769                 :    1360430 :   DECL_CONTEXT (decl) = current_class_type;
     770                 :            : 
     771                 :            :   /* We cannot call pushdecl here, because that would fill in the
     772                 :            :      TREE_CHAIN of our decl.  Instead, we modify cp_finish_decl to do
     773                 :            :      the right thing, namely, to put this decl out straight away.  */
     774                 :            : 
     775                 :    1360430 :   if (! processing_template_decl)
     776                 :    1181320 :     vec_safe_push (pending_statics, decl);
     777                 :            : 
     778                 :    1360430 :   if (LOCAL_CLASS_P (current_class_type)
     779                 :            :       /* We already complained about the template definition.  */
     780                 :    1360430 :       && !DECL_TEMPLATE_INSTANTIATION (decl))
     781                 :         20 :     permerror (DECL_SOURCE_LOCATION (decl),
     782                 :            :                "local class %q#T shall not have static data member %q#D",
     783                 :            :                current_class_type, decl);
     784                 :            :   else
     785                 :    2784650 :     for (tree t = current_class_type; TYPE_P (t);
     786                 :    4208890 :          t = CP_TYPE_CONTEXT (t))
     787                 :    1424260 :       if (TYPE_UNNAMED_P (t))
     788                 :            :         {
     789                 :         24 :           auto_diagnostic_group d;
     790                 :         24 :           if (permerror (DECL_SOURCE_LOCATION (decl),
     791                 :            :                          "static data member %qD in unnamed class", decl))
     792                 :         24 :             inform (DECL_SOURCE_LOCATION (TYPE_NAME (t)),
     793                 :            :                     "unnamed class defined here");
     794                 :         24 :           break;
     795                 :            :         }
     796                 :            : 
     797                 :    2061160 :   if (DECL_INLINE_VAR_P (decl) && !DECL_TEMPLATE_INSTANTIATION (decl))
     798                 :            :     /* An inline variable is immediately defined, so don't set DECL_IN_AGGR_P.
     799                 :            :        Except that if decl is a template instantiation, it isn't defined until
     800                 :            :        instantiate_decl.  */;
     801                 :            :   else
     802                 :     862303 :     DECL_IN_AGGR_P (decl) = 1;
     803                 :            : 
     804                 :    1360430 :   if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
     805                 :    1360430 :       && TYPE_DOMAIN (TREE_TYPE (decl)) == NULL_TREE)
     806                 :      12345 :     SET_VAR_HAD_UNKNOWN_BOUND (decl);
     807                 :            : 
     808                 :    1360430 :   if (init)
     809                 :            :     {
     810                 :            :       /* Similarly to start_decl_1, we want to complete the type in order
     811                 :            :          to do the right thing in cp_apply_type_quals_to_decl, possibly
     812                 :            :          clear TYPE_QUAL_CONST (c++/65579).  */
     813                 :    1019630 :       tree type = TREE_TYPE (decl) = complete_type (TREE_TYPE (decl));
     814                 :    1019630 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
     815                 :            :     }
     816                 :            : 
     817                 :    1360430 :   cp_finish_decl (decl, init, init_const_expr_p, asmspec_tree, flags);
     818                 :            : }
     819                 :            : 
     820                 :            : /* DECLARATOR and DECLSPECS correspond to a class member.  The other
     821                 :            :    parameters are as for cp_finish_decl.  Return the DECL for the
     822                 :            :    class member declared.  */
     823                 :            : 
     824                 :            : tree
     825                 :    7268540 : grokfield (const cp_declarator *declarator,
     826                 :            :            cp_decl_specifier_seq *declspecs,
     827                 :            :            tree init, bool init_const_expr_p,
     828                 :            :            tree asmspec_tree,
     829                 :            :            tree attrlist)
     830                 :            : {
     831                 :    7268540 :   tree value;
     832                 :    7268540 :   const char *asmspec = 0;
     833                 :    7268540 :   int flags;
     834                 :            : 
     835                 :    7268540 :   if (init
     836                 :    1551490 :       && TREE_CODE (init) == TREE_LIST
     837                 :          0 :       && TREE_VALUE (init) == error_mark_node
     838                 :    7268540 :       && TREE_CHAIN (init) == NULL_TREE)
     839                 :            :     init = NULL_TREE;
     840                 :            : 
     841                 :    7268540 :   value = grokdeclarator (declarator, declspecs, FIELD, init != 0, &attrlist);
     842                 :    7268530 :   if (! value || value == error_mark_node)
     843                 :            :     /* friend or constructor went bad.  */
     844                 :        416 :     return error_mark_node;
     845                 :    7268120 :   if (TREE_TYPE (value) == error_mark_node)
     846                 :            :     return value;
     847                 :            : 
     848                 :    7267940 :   if (TREE_CODE (value) == TYPE_DECL && init)
     849                 :            :     {
     850                 :          8 :       error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (value)),
     851                 :            :                 "typedef %qD is initialized (use %qs instead)",
     852                 :            :                 value, "decltype");
     853                 :          8 :       init = NULL_TREE;
     854                 :            :     }
     855                 :            : 
     856                 :            :   /* Pass friendly classes back.  */
     857                 :    7267940 :   if (value == void_type_node)
     858                 :            :     return value;
     859                 :            : 
     860                 :    7267940 :   if (DECL_NAME (value)
     861                 :    7267940 :       && TREE_CODE (DECL_NAME (value)) == TEMPLATE_ID_EXPR)
     862                 :            :     {
     863                 :          4 :       error_at (declarator->id_loc,
     864                 :            :                 "explicit template argument list not allowed");
     865                 :          4 :       return error_mark_node;
     866                 :            :     }
     867                 :            : 
     868                 :            :   /* Stash away type declarations.  */
     869                 :    7267930 :   if (TREE_CODE (value) == TYPE_DECL)
     870                 :            :     {
     871                 :    2398920 :       DECL_NONLOCAL (value) = 1;
     872                 :    2398920 :       DECL_CONTEXT (value) = current_class_type;
     873                 :            : 
     874                 :    2398920 :       if (attrlist)
     875                 :            :         {
     876                 :       4366 :           int attrflags = 0;
     877                 :            : 
     878                 :            :           /* If this is a typedef that names the class for linkage purposes
     879                 :            :              (7.1.3p8), apply any attributes directly to the type.  */
     880                 :       8732 :           if (OVERLOAD_TYPE_P (TREE_TYPE (value))
     881                 :       5091 :               && value == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (value))))
     882                 :            :             attrflags = ATTR_FLAG_TYPE_IN_PLACE;
     883                 :            : 
     884                 :       4366 :           cplus_decl_attributes (&value, attrlist, attrflags);
     885                 :            :         }
     886                 :            : 
     887                 :    2398920 :       if (decl_spec_seq_has_spec_p (declspecs, ds_typedef)
     888                 :    2398920 :           && TREE_TYPE (value) != error_mark_node
     889                 :    4797850 :           && TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (value))) != value)
     890                 :    2398000 :         set_underlying_type (value);
     891                 :            : 
     892                 :            :       /* It's important that push_template_decl below follows
     893                 :            :          set_underlying_type above so that the created template
     894                 :            :          carries the properly set type of VALUE.  */
     895                 :    2398920 :       if (processing_template_decl)
     896                 :    1939320 :         value = push_template_decl (value);
     897                 :            : 
     898                 :    2398920 :       record_locally_defined_typedef (value);
     899                 :    2398920 :       return value;
     900                 :            :     }
     901                 :            : 
     902                 :    4869010 :   int friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
     903                 :            : 
     904                 :    4869010 :   if (!friendp && DECL_IN_AGGR_P (value))
     905                 :            :     {
     906                 :          0 :       error ("%qD is already defined in %qT", value, DECL_CONTEXT (value));
     907                 :          0 :       return void_type_node;
     908                 :            :     }
     909                 :            : 
     910                 :    4869010 :   if (asmspec_tree && asmspec_tree != error_mark_node)
     911                 :        202 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
     912                 :            : 
     913                 :    4869010 :   if (init)
     914                 :            :     {
     915                 :    1551430 :       if (TREE_CODE (value) == FUNCTION_DECL)
     916                 :            :         {
     917                 :     498005 :           if (init == ridpointers[(int)RID_DELETE])
     918                 :            :             {
     919                 :     126571 :               if (friendp && decl_defined_p (value))
     920                 :            :                 {
     921                 :          3 :                   error ("redefinition of %q#D", value);
     922                 :          3 :                   inform (DECL_SOURCE_LOCATION (value),
     923                 :            :                           "%q#D previously defined here", value);
     924                 :            :                 }
     925                 :            :               else
     926                 :            :                 {
     927                 :     253136 :                   DECL_DELETED_FN (value) = 1;
     928                 :     126568 :                   DECL_DECLARED_INLINE_P (value) = 1;
     929                 :     126568 :                   DECL_INITIAL (value) = error_mark_node;
     930                 :            :                 }
     931                 :            :             }
     932                 :     371434 :           else if (init == ridpointers[(int)RID_DEFAULT])
     933                 :            :             {
     934                 :     333575 :               if (defaultable_fn_check (value))
     935                 :            :                 {
     936                 :     667076 :                   DECL_DEFAULTED_FN (value) = 1;
     937                 :     667076 :                   DECL_INITIALIZED_IN_CLASS_P (value) = 1;
     938                 :     333538 :                   DECL_DECLARED_INLINE_P (value) = 1;
     939                 :            :                 }
     940                 :            :             }
     941                 :      37859 :           else if (TREE_CODE (init) == DEFERRED_PARSE)
     942                 :          0 :             error ("invalid initializer for member function %qD", value);
     943                 :      37859 :           else if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE)
     944                 :            :             {
     945                 :      37848 :               if (integer_zerop (init))
     946                 :      75600 :                 DECL_PURE_VIRTUAL_P (value) = 1;
     947                 :         48 :               else if (error_operand_p (init))
     948                 :            :                 ; /* An error has already been reported.  */
     949                 :            :               else
     950                 :          0 :                 error ("invalid initializer for member function %qD",
     951                 :            :                        value);
     952                 :            :             }
     953                 :            :           else
     954                 :            :             {
     955                 :         11 :               gcc_assert (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE);
     956                 :         11 :               location_t iloc
     957                 :         11 :                 = cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (value));
     958                 :         11 :               if (friendp)
     959                 :          3 :                 error_at (iloc, "initializer specified for friend "
     960                 :            :                           "function %qD", value);
     961                 :            :               else
     962                 :          8 :                 error_at (iloc, "initializer specified for static "
     963                 :            :                           "member function %qD", value);
     964                 :            :             }
     965                 :            :         }
     966                 :    1053430 :       else if (TREE_CODE (value) == FIELD_DECL)
     967                 :            :         /* C++11 NSDMI, keep going.  */;
     968                 :    1019630 :       else if (!VAR_P (value))
     969                 :          0 :         gcc_unreachable ();
     970                 :            :     }
     971                 :            : 
     972                 :            :   /* Pass friend decls back.  */
     973                 :    4869010 :   if ((TREE_CODE (value) == FUNCTION_DECL
     974                 :    4869010 :        || TREE_CODE (value) == TEMPLATE_DECL)
     975                 :    4869010 :       && DECL_CONTEXT (value) != current_class_type)
     976                 :            :     return value;
     977                 :            : 
     978                 :            :   /* Need to set this before push_template_decl.  */
     979                 :    4807010 :   if (VAR_P (value))
     980                 :    1120380 :     DECL_CONTEXT (value) = current_class_type;
     981                 :            : 
     982                 :    4807010 :   if (processing_template_decl && VAR_OR_FUNCTION_DECL_P (value))
     983                 :            :     {
     984                 :    1112450 :       value = push_template_decl (value);
     985                 :    1112450 :       if (error_operand_p (value))
     986                 :            :         return error_mark_node;
     987                 :            :     }
     988                 :            : 
     989                 :    4807000 :   if (attrlist)
     990                 :      20670 :     cplus_decl_attributes (&value, attrlist, 0);
     991                 :            : 
     992                 :    4807410 :   if (init && DIRECT_LIST_INIT_P (init))
     993                 :            :     flags = LOOKUP_NORMAL;
     994                 :            :   else
     995                 :            :     flags = LOOKUP_IMPLICIT;
     996                 :            : 
     997                 :    4807000 :   if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
     998                 :         12 :     flags |= LOOKUP_CONSTINIT;
     999                 :            : 
    1000                 :    4807000 :   switch (TREE_CODE (value))
    1001                 :            :     {
    1002                 :    1120380 :     case VAR_DECL:
    1003                 :    1120380 :       finish_static_data_member_decl (value, init, init_const_expr_p,
    1004                 :            :                                       asmspec_tree, flags);
    1005                 :    1120380 :       return value;
    1006                 :            : 
    1007                 :    2003500 :     case FIELD_DECL:
    1008                 :    2003500 :       if (asmspec)
    1009                 :          8 :         error ("%<asm%> specifiers are not permitted on non-static data members");
    1010                 :    2003500 :       if (DECL_INITIAL (value) == error_mark_node)
    1011                 :          3 :         init = error_mark_node;
    1012                 :    2003500 :       cp_finish_decl (value, init, /*init_const_expr_p=*/false,
    1013                 :            :                       NULL_TREE, flags);
    1014                 :    2003500 :       DECL_IN_AGGR_P (value) = 1;
    1015                 :    2003500 :       return value;
    1016                 :            : 
    1017                 :    1683130 :     case  FUNCTION_DECL:
    1018                 :    1683130 :       if (asmspec)
    1019                 :         94 :         set_user_assembler_name (value, asmspec);
    1020                 :            : 
    1021                 :    1683130 :       cp_finish_decl (value,
    1022                 :            :                       /*init=*/NULL_TREE,
    1023                 :            :                       /*init_const_expr_p=*/false,
    1024                 :            :                       asmspec_tree, flags);
    1025                 :            : 
    1026                 :            :       /* Pass friends back this way.  */
    1027                 :    3366260 :       if (DECL_FRIEND_P (value))
    1028                 :          0 :         return void_type_node;
    1029                 :            : 
    1030                 :    1683130 :       DECL_IN_AGGR_P (value) = 1;
    1031                 :    1683130 :       return value;
    1032                 :            : 
    1033                 :          0 :     default:
    1034                 :          0 :       gcc_unreachable ();
    1035                 :            :     }
    1036                 :            :   return NULL_TREE;
    1037                 :            : }
    1038                 :            : 
    1039                 :            : /* Like `grokfield', but for bitfields.
    1040                 :            :    WIDTH is the width of the bitfield, a constant expression.
    1041                 :            :    The other parameters are as for grokfield.  */
    1042                 :            : 
    1043                 :            : tree
    1044                 :      45741 : grokbitfield (const cp_declarator *declarator,
    1045                 :            :               cp_decl_specifier_seq *declspecs, tree width, tree init,
    1046                 :            :               tree attrlist)
    1047                 :            : {
    1048                 :      45741 :   tree value = grokdeclarator (declarator, declspecs, BITFIELD,
    1049                 :      45741 :                                init != NULL_TREE, &attrlist);
    1050                 :            : 
    1051                 :      45741 :   if (value == error_mark_node)
    1052                 :            :     return NULL_TREE; /* friends went bad.  */
    1053                 :            : 
    1054                 :      45733 :   tree type = TREE_TYPE (value);
    1055                 :      45733 :   if (type == error_mark_node)
    1056                 :            :     return value;
    1057                 :            : 
    1058                 :            :   /* Pass friendly classes back.  */
    1059                 :      45684 :   if (VOID_TYPE_P (value))
    1060                 :          0 :     return void_type_node;
    1061                 :            : 
    1062                 :      45684 :   if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    1063                 :      45684 :       && (INDIRECT_TYPE_P (type) || !dependent_type_p (type)))
    1064                 :            :     {
    1065                 :         44 :       error_at (DECL_SOURCE_LOCATION (value),
    1066                 :            :                 "bit-field %qD with non-integral type %qT",
    1067                 :            :                 value, type);
    1068                 :         44 :       return error_mark_node;
    1069                 :            :     }
    1070                 :            : 
    1071                 :      45640 :   if (TREE_CODE (value) == TYPE_DECL)
    1072                 :            :     {
    1073                 :          8 :       error_at (DECL_SOURCE_LOCATION (value),
    1074                 :            :                 "cannot declare %qD to be a bit-field type", value);
    1075                 :          8 :       return NULL_TREE;
    1076                 :            :     }
    1077                 :            : 
    1078                 :            :   /* Usually, finish_struct_1 catches bitfields with invalid types.
    1079                 :            :      But, in the case of bitfields with function type, we confuse
    1080                 :            :      ourselves into thinking they are member functions, so we must
    1081                 :            :      check here.  */
    1082                 :      45632 :   if (TREE_CODE (value) == FUNCTION_DECL)
    1083                 :            :     {
    1084                 :          4 :       error_at (DECL_SOURCE_LOCATION (value),
    1085                 :            :                 "cannot declare bit-field %qD with function type", value);
    1086                 :          4 :       return NULL_TREE;
    1087                 :            :     }
    1088                 :            : 
    1089                 :      45628 :   if (TYPE_WARN_IF_NOT_ALIGN (type))
    1090                 :            :     {
    1091                 :         12 :       error_at (DECL_SOURCE_LOCATION (value), "cannot declare bit-field "
    1092                 :            :                 "%qD with %<warn_if_not_aligned%> type", value);
    1093                 :         12 :       return NULL_TREE;
    1094                 :            :     }
    1095                 :            : 
    1096                 :      45616 :   if (DECL_IN_AGGR_P (value))
    1097                 :            :     {
    1098                 :          0 :       error ("%qD is already defined in the class %qT", value,
    1099                 :          0 :              DECL_CONTEXT (value));
    1100                 :          0 :       return void_type_node;
    1101                 :            :     }
    1102                 :            : 
    1103                 :      45616 :   if (TREE_STATIC (value))
    1104                 :            :     {
    1105                 :          8 :       error_at (DECL_SOURCE_LOCATION (value),
    1106                 :            :                 "static member %qD cannot be a bit-field", value);
    1107                 :          8 :       return NULL_TREE;
    1108                 :            :     }
    1109                 :            : 
    1110                 :      45608 :   int flags = LOOKUP_IMPLICIT;
    1111                 :      45608 :   if (init && DIRECT_LIST_INIT_P (init))
    1112                 :            :     flags = LOOKUP_NORMAL;
    1113                 :      45608 :   cp_finish_decl (value, init, false, NULL_TREE, flags);
    1114                 :            : 
    1115                 :      45608 :   if (width != error_mark_node)
    1116                 :            :     {
    1117                 :            :       /* The width must be an integer type.  */
    1118                 :      45594 :       if (!type_dependent_expression_p (width)
    1119                 :      91175 :           && !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (width)))
    1120                 :         15 :         error ("width of bit-field %qD has non-integral type %qT", value,
    1121                 :         15 :                TREE_TYPE (width));
    1122                 :            :       else
    1123                 :            :         {
    1124                 :            :           /* Temporarily stash the width in DECL_BIT_FIELD_REPRESENTATIVE.
    1125                 :            :              check_bitfield_decl picks it from there later and sets DECL_SIZE
    1126                 :            :              accordingly.  */
    1127                 :      45579 :           DECL_BIT_FIELD_REPRESENTATIVE (value) = width;
    1128                 :      45579 :           SET_DECL_C_BIT_FIELD (value);
    1129                 :            :         }
    1130                 :            :     }
    1131                 :            : 
    1132                 :      45608 :   DECL_IN_AGGR_P (value) = 1;
    1133                 :            : 
    1134                 :      45608 :   if (attrlist)
    1135                 :        579 :     cplus_decl_attributes (&value, attrlist, /*flags=*/0);
    1136                 :            : 
    1137                 :      45608 :   return value;
    1138                 :            : }
    1139                 :            : 
    1140                 :            : 
    1141                 :            : /* Returns true iff ATTR is an attribute which needs to be applied at
    1142                 :            :    instantiation time rather than template definition time.  */
    1143                 :            : 
    1144                 :            : static bool
    1145                 :     167613 : is_late_template_attribute (tree attr, tree decl)
    1146                 :            : {
    1147                 :     167613 :   tree name = get_attribute_name (attr);
    1148                 :     167613 :   tree args = TREE_VALUE (attr);
    1149                 :     167613 :   const struct attribute_spec *spec = lookup_attribute_spec (name);
    1150                 :     167613 :   tree arg;
    1151                 :            : 
    1152                 :     167613 :   if (!spec)
    1153                 :            :     /* Unknown attribute.  */
    1154                 :            :     return false;
    1155                 :            : 
    1156                 :            :   /* Attribute weak handling wants to write out assembly right away.  */
    1157                 :     129683 :   if (is_attribute_p ("weak", name))
    1158                 :            :     return true;
    1159                 :            : 
    1160                 :            :   /* Attributes used and unused are applied directly to typedefs for the
    1161                 :            :      benefit of maybe_warn_unused_local_typedefs.  */
    1162                 :     129679 :   if (TREE_CODE (decl) == TYPE_DECL
    1163                 :     129679 :       && (is_attribute_p ("unused", name)
    1164                 :       4173 :           || is_attribute_p ("used", name)))
    1165                 :            :     return false;
    1166                 :            : 
    1167                 :            :   /* Attribute tls_model wants to modify the symtab.  */
    1168                 :     129651 :   if (is_attribute_p ("tls_model", name))
    1169                 :            :     return true;
    1170                 :            : 
    1171                 :            :   /* #pragma omp declare simd attribute needs to be always deferred.  */
    1172                 :     129647 :   if (flag_openmp
    1173                 :     129647 :       && is_attribute_p ("omp declare simd", name))
    1174                 :            :     return true;
    1175                 :            : 
    1176                 :            :   /* An attribute pack is clearly dependent.  */
    1177                 :     129555 :   if (args && PACK_EXPANSION_P (args))
    1178                 :            :     return true;
    1179                 :            : 
    1180                 :            :   /* If any of the arguments are dependent expressions, we can't evaluate
    1181                 :            :      the attribute until instantiation time.  */
    1182                 :     141017 :   for (arg = args; arg; arg = TREE_CHAIN (arg))
    1183                 :            :     {
    1184                 :      19733 :       tree t = TREE_VALUE (arg);
    1185                 :            : 
    1186                 :            :       /* If the first attribute argument is an identifier, only consider
    1187                 :            :          second and following arguments.  Attributes like mode, format,
    1188                 :            :          cleanup and several target specific attributes aren't late
    1189                 :            :          just because they have an IDENTIFIER_NODE as first argument.  */
    1190                 :      19711 :       if (arg == args && attribute_takes_identifier_p (name)
    1191                 :      19733 :           && identifier_p (t))
    1192                 :         20 :         continue;
    1193                 :            : 
    1194                 :      19713 :       if (value_dependent_expression_p (t))
    1195                 :            :         return true;
    1196                 :            :     }
    1197                 :            : 
    1198                 :     121284 :   if (TREE_CODE (decl) == TYPE_DECL
    1199                 :     117169 :       || TYPE_P (decl)
    1200                 :     100220 :       || spec->type_required)
    1201                 :            :     {
    1202                 :      46943 :       tree type = TYPE_P (decl) ? decl : TREE_TYPE (decl);
    1203                 :            : 
    1204                 :            :       /* We can't apply any attributes to a completely unknown type until
    1205                 :            :          instantiation time.  */
    1206                 :      31946 :       enum tree_code code = TREE_CODE (type);
    1207                 :      31946 :       if (code == TEMPLATE_TYPE_PARM
    1208                 :      31946 :           || code == BOUND_TEMPLATE_TEMPLATE_PARM
    1209                 :      29229 :           || code == TYPENAME_TYPE)
    1210                 :            :         return true;
    1211                 :            :       /* Also defer most attributes on dependent types.  This is not
    1212                 :            :          necessary in all cases, but is the better default.  */
    1213                 :      29215 :       else if (dependent_type_p (type)
    1214                 :            :                /* But some attributes specifically apply to templates.  */
    1215                 :      28431 :                && !is_attribute_p ("abi_tag", name)
    1216                 :      28399 :                && !is_attribute_p ("deprecated", name)
    1217                 :      45172 :                && !is_attribute_p ("visibility", name))
    1218                 :      15941 :         return true;
    1219                 :            :       else
    1220                 :            :         return false;
    1221                 :            :     }
    1222                 :            :   else
    1223                 :            :     return false;
    1224                 :            : }
    1225                 :            : 
    1226                 :            : /* ATTR_P is a list of attributes.  Remove any attributes which need to be
    1227                 :            :    applied at instantiation time and return them.  If IS_DEPENDENT is true,
    1228                 :            :    the declaration itself is dependent, so all attributes should be applied
    1229                 :            :    at instantiation time.  */
    1230                 :            : 
    1231                 :            : static tree
    1232                 :   16261400 : splice_template_attributes (tree *attr_p, tree decl)
    1233                 :            : {
    1234                 :   16261400 :   tree *p = attr_p;
    1235                 :   16261400 :   tree late_attrs = NULL_TREE;
    1236                 :   16261400 :   tree *q = &late_attrs;
    1237                 :            : 
    1238                 :   16261400 :   if (!p)
    1239                 :            :     return NULL_TREE;
    1240                 :            : 
    1241                 :   16429000 :   for (; *p; )
    1242                 :            :     {
    1243                 :     167613 :       if (is_late_template_attribute (*p, decl))
    1244                 :            :         {
    1245                 :      27043 :           ATTR_IS_DEPENDENT (*p) = 1;
    1246                 :      27043 :           *q = *p;
    1247                 :      27043 :           *p = TREE_CHAIN (*p);
    1248                 :      27043 :           q = &TREE_CHAIN (*q);
    1249                 :      27043 :           *q = NULL_TREE;
    1250                 :            :         }
    1251                 :            :       else
    1252                 :     140570 :         p = &TREE_CHAIN (*p);
    1253                 :            :     }
    1254                 :            : 
    1255                 :   16261400 :   return late_attrs;
    1256                 :            : }
    1257                 :            : 
    1258                 :            : /* Remove any late attributes from the list in ATTR_P and attach them to
    1259                 :            :    DECL_P.  */
    1260                 :            : 
    1261                 :            : static void
    1262                 :   16261400 : save_template_attributes (tree *attr_p, tree *decl_p, int flags)
    1263                 :            : {
    1264                 :   16261400 :   tree *q;
    1265                 :            : 
    1266                 :   16261400 :   if (attr_p && *attr_p == error_mark_node)
    1267                 :            :     return;
    1268                 :            : 
    1269                 :   16261400 :   tree late_attrs = splice_template_attributes (attr_p, *decl_p);
    1270                 :   16261400 :   if (!late_attrs)
    1271                 :            :     return;
    1272                 :            : 
    1273                 :      27024 :   if (DECL_P (*decl_p))
    1274                 :      16823 :     q = &DECL_ATTRIBUTES (*decl_p);
    1275                 :            :   else
    1276                 :      10201 :     q = &TYPE_ATTRIBUTES (*decl_p);
    1277                 :            : 
    1278                 :      27024 :   tree old_attrs = *q;
    1279                 :            : 
    1280                 :            :   /* Merge the late attributes at the beginning with the attribute
    1281                 :            :      list.  */
    1282                 :      27024 :   late_attrs = merge_attributes (late_attrs, *q);
    1283                 :      27024 :   if (*q != late_attrs
    1284                 :      27024 :       && !DECL_P (*decl_p)
    1285                 :      10201 :       && !(flags & ATTR_FLAG_TYPE_IN_PLACE))
    1286                 :            :     {
    1287                 :         25 :       if (!dependent_type_p (*decl_p))
    1288                 :          6 :         *decl_p = cp_build_type_attribute_variant (*decl_p, late_attrs);
    1289                 :            :       else
    1290                 :            :         {
    1291                 :         19 :           *decl_p = build_variant_type_copy (*decl_p);
    1292                 :         19 :           TYPE_ATTRIBUTES (*decl_p) = late_attrs;
    1293                 :            :         }
    1294                 :            :     }
    1295                 :            :   else
    1296                 :      26999 :     *q = late_attrs;
    1297                 :            : 
    1298                 :      27024 :   if (!DECL_P (*decl_p) && *decl_p == TYPE_MAIN_VARIANT (*decl_p))
    1299                 :            :     {
    1300                 :            :       /* We've added new attributes directly to the main variant, so
    1301                 :            :          now we need to update all of the other variants to include
    1302                 :            :          these new attributes.  */
    1303                 :      10182 :       tree variant;
    1304                 :      10512 :       for (variant = TYPE_NEXT_VARIANT (*decl_p); variant;
    1305                 :        165 :            variant = TYPE_NEXT_VARIANT (variant))
    1306                 :            :         {
    1307                 :        165 :           gcc_assert (TYPE_ATTRIBUTES (variant) == old_attrs);
    1308                 :        165 :           TYPE_ATTRIBUTES (variant) = TYPE_ATTRIBUTES (*decl_p);
    1309                 :            :         }
    1310                 :            :     }
    1311                 :            : }
    1312                 :            : 
    1313                 :            : /* True if ATTRS contains any dependent attributes that affect type
    1314                 :            :    identity.  */
    1315                 :            : 
    1316                 :            : bool
    1317                 :   90382600 : any_dependent_type_attributes_p (tree attrs)
    1318                 :            : {
    1319                 :   91294000 :   for (tree a = attrs; a; a = TREE_CHAIN (a))
    1320                 :     911517 :     if (ATTR_IS_DEPENDENT (a))
    1321                 :            :       {
    1322                 :      61531 :         const attribute_spec *as = lookup_attribute_spec (TREE_PURPOSE (a));
    1323                 :      61531 :         if (as && as->affects_type_identity)
    1324                 :            :           return true;
    1325                 :            :       }
    1326                 :            :   return false;
    1327                 :            : }
    1328                 :            : 
    1329                 :            : /* Return true iff ATTRS are acceptable attributes to be applied in-place
    1330                 :            :    to a typedef which gives a previously unnamed class or enum a name for
    1331                 :            :    linkage purposes.  */
    1332                 :            : 
    1333                 :            : bool
    1334                 :      84770 : attributes_naming_typedef_ok (tree attrs)
    1335                 :            : {
    1336                 :      87307 :   for (; attrs; attrs = TREE_CHAIN (attrs))
    1337                 :            :     {
    1338                 :       2541 :       tree name = get_attribute_name (attrs);
    1339                 :       2541 :       if (is_attribute_p ("vector_size", name))
    1340                 :            :         return false;
    1341                 :            :     }
    1342                 :            :   return true;
    1343                 :            : }
    1344                 :            : 
    1345                 :            : /* Like reconstruct_complex_type, but handle also template trees.  */
    1346                 :            : 
    1347                 :            : tree
    1348                 :      20387 : cp_reconstruct_complex_type (tree type, tree bottom)
    1349                 :            : {
    1350                 :      20387 :   tree inner, outer;
    1351                 :            : 
    1352                 :      20387 :   if (TYPE_PTR_P (type))
    1353                 :            :     {
    1354                 :         28 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1355                 :         56 :       outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
    1356                 :         28 :                                            TYPE_REF_CAN_ALIAS_ALL (type));
    1357                 :            :     }
    1358                 :      20359 :   else if (TYPE_REF_P (type))
    1359                 :            :     {
    1360                 :          4 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1361                 :          8 :       outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
    1362                 :          4 :                                              TYPE_REF_CAN_ALIAS_ALL (type));
    1363                 :            :     }
    1364                 :      20355 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    1365                 :            :     {
    1366                 :         36 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1367                 :         36 :       outer = build_cplus_array_type (inner, TYPE_DOMAIN (type));
    1368                 :            :       /* Don't call cp_build_qualified_type on ARRAY_TYPEs, the
    1369                 :            :          element type qualification will be handled by the recursive
    1370                 :            :          cp_reconstruct_complex_type call and cp_build_qualified_type
    1371                 :            :          for ARRAY_TYPEs changes the element type.  */
    1372                 :         36 :       return outer;
    1373                 :            :     }
    1374                 :      20319 :   else if (TREE_CODE (type) == FUNCTION_TYPE)
    1375                 :            :     {
    1376                 :         55 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1377                 :         55 :       outer = build_function_type (inner, TYPE_ARG_TYPES (type));
    1378                 :         55 :       outer = apply_memfn_quals (outer, type_memfn_quals (type));
    1379                 :            :     }
    1380                 :      20264 :   else if (TREE_CODE (type) == METHOD_TYPE)
    1381                 :            :     {
    1382                 :         16 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1383                 :            :       /* The build_method_type_directly() routine prepends 'this' to argument list,
    1384                 :            :          so we must compensate by getting rid of it.  */
    1385                 :         16 :       outer
    1386                 :            :         = build_method_type_directly
    1387                 :         16 :             (class_of_this_parm (type), inner,
    1388                 :         16 :              TREE_CHAIN (TYPE_ARG_TYPES (type)));
    1389                 :            :     }
    1390                 :      20248 :   else if (TREE_CODE (type) == OFFSET_TYPE)
    1391                 :            :     {
    1392                 :          4 :       inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom);
    1393                 :          4 :       outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
    1394                 :            :     }
    1395                 :            :   else
    1396                 :            :     return bottom;
    1397                 :            : 
    1398                 :        107 :   if (TYPE_ATTRIBUTES (type))
    1399                 :          0 :     outer = cp_build_type_attribute_variant (outer, TYPE_ATTRIBUTES (type));
    1400                 :        107 :   outer = cp_build_qualified_type (outer, cp_type_quals (type));
    1401                 :        107 :   outer = cxx_copy_lang_qualifiers (outer, type);
    1402                 :            : 
    1403                 :        107 :   return outer;
    1404                 :            : }
    1405                 :            : 
    1406                 :            : /* Replaces any constexpr expression that may be into the attributes
    1407                 :            :    arguments with their reduced value.  */
    1408                 :            : 
    1409                 :            : void
    1410                 :   33694000 : cp_check_const_attributes (tree attributes)
    1411                 :            : {
    1412                 :   33694000 :   if (attributes == error_mark_node)
    1413                 :            :     return;
    1414                 :            : 
    1415                 :            :   tree attr;
    1416                 :   38812900 :   for (attr = attributes; attr; attr = TREE_CHAIN (attr))
    1417                 :            :     {
    1418                 :    5118880 :       tree arg;
    1419                 :    9289840 :       for (arg = TREE_VALUE (attr); arg && TREE_CODE (arg) == TREE_LIST;
    1420                 :    2085480 :            arg = TREE_CHAIN (arg))
    1421                 :            :         {
    1422                 :    2085480 :           tree expr = TREE_VALUE (arg);
    1423                 :    2085480 :           if (EXPR_P (expr))
    1424                 :       1579 :             TREE_VALUE (arg) = fold_non_dependent_expr (expr);
    1425                 :            :         }
    1426                 :            :     }
    1427                 :            : }
    1428                 :            : 
    1429                 :            : /* Return true if TYPE is an OpenMP mappable type.
    1430                 :            :    If NOTES is non-zero, emit a note message for each problem.  */
    1431                 :            : static bool
    1432                 :      16259 : cp_omp_mappable_type_1 (tree type, bool notes)
    1433                 :            : {
    1434                 :      16259 :   bool result = true;
    1435                 :            : 
    1436                 :            :   /* Mappable type has to be complete.  */
    1437                 :      32510 :   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
    1438                 :            :     {
    1439                 :        172 :       if (notes && type != error_mark_node)
    1440                 :            :         {
    1441                 :         64 :           tree decl = TYPE_MAIN_DECL (type);
    1442                 :         72 :           inform ((decl ? DECL_SOURCE_LOCATION (decl) : input_location),
    1443                 :            :                   "incomplete type %qT is not mappable", type);
    1444                 :            :         }
    1445                 :      16259 :       result = false;
    1446                 :            :     }
    1447                 :            :   /* Arrays have mappable type if the elements have mappable type.  */
    1448                 :      26841 :   while (TREE_CODE (type) == ARRAY_TYPE)
    1449                 :      10582 :     type = TREE_TYPE (type);
    1450                 :            :   /* A mappable type cannot contain virtual members.  */
    1451                 :      16556 :   if (CLASS_TYPE_P (type) && CLASSTYPE_VTABLES (type))
    1452                 :            :     {
    1453                 :          8 :       if (notes)
    1454                 :          4 :         inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    1455                 :            :                 "type %qT with virtual members is not mappable", type);
    1456                 :            :       result = false;
    1457                 :            :     }
    1458                 :            :   /* All data members must be non-static.  */
    1459                 :      16556 :   if (CLASS_TYPE_P (type))
    1460                 :            :     {
    1461                 :        297 :       tree field;
    1462                 :       2978 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    1463                 :       2681 :         if (VAR_P (field))
    1464                 :            :           {
    1465                 :          8 :             if (notes)
    1466                 :          4 :               inform (DECL_SOURCE_LOCATION (field),
    1467                 :            :                       "static field %qD is not mappable", field);
    1468                 :            :             result = false;
    1469                 :            :           }
    1470                 :            :         /* All fields must have mappable types.  */
    1471                 :       2673 :         else if (TREE_CODE (field) == FIELD_DECL
    1472                 :       2673 :                  && !cp_omp_mappable_type_1 (TREE_TYPE (field), notes))
    1473                 :            :           result = false;
    1474                 :            :     }
    1475                 :      16259 :   return result;
    1476                 :            : }
    1477                 :            : 
    1478                 :            : /* Return true if TYPE is an OpenMP mappable type.  */
    1479                 :            : bool
    1480                 :      15595 : cp_omp_mappable_type (tree type)
    1481                 :            : {
    1482                 :      15595 :   return cp_omp_mappable_type_1 (type, false);
    1483                 :            : }
    1484                 :            : 
    1485                 :            : /* Return true if TYPE is an OpenMP mappable type.
    1486                 :            :    Emit an error messages if not.  */
    1487                 :            : bool
    1488                 :         68 : cp_omp_emit_unmappable_type_notes (tree type)
    1489                 :            : {
    1490                 :         68 :   return cp_omp_mappable_type_1 (type, true);
    1491                 :            : }
    1492                 :            : 
    1493                 :            : /* Return the last pushed declaration for the symbol DECL or NULL
    1494                 :            :    when no such declaration exists.  */
    1495                 :            : 
    1496                 :            : static tree
    1497                 :   33685100 : find_last_decl (tree decl)
    1498                 :            : {
    1499                 :   33685100 :   tree last_decl = NULL_TREE;
    1500                 :            : 
    1501                 :   58820400 :   if (tree name = DECL_P (decl) ? DECL_NAME (decl) : NULL_TREE)
    1502                 :            :     {
    1503                 :            :       /* Look up the declaration in its scope.  */
    1504                 :   25131500 :       tree pushed_scope = NULL_TREE;
    1505                 :   25131500 :       if (tree ctype = DECL_CONTEXT (decl))
    1506                 :   21587100 :         pushed_scope = push_scope (ctype);
    1507                 :            : 
    1508                 :   25131500 :       last_decl = lookup_name (name);
    1509                 :            : 
    1510                 :   25131500 :       if (pushed_scope)
    1511                 :   14934900 :         pop_scope (pushed_scope);
    1512                 :            : 
    1513                 :            :       /* The declaration may be a member conversion operator
    1514                 :            :          or a bunch of overfloads (handle the latter below).  */
    1515                 :   25131500 :       if (last_decl && BASELINK_P (last_decl))
    1516                 :       5489 :         last_decl = BASELINK_FUNCTIONS (last_decl);
    1517                 :            :     }
    1518                 :            : 
    1519                 :   33681400 :   if (!last_decl)
    1520                 :   27838600 :     return NULL_TREE;
    1521                 :            : 
    1522                 :    5846550 :   if (DECL_P (last_decl) || TREE_CODE (last_decl) == OVERLOAD)
    1523                 :            :     {
    1524                 :            :       /* A set of overloads of the same function.  */
    1525                 :   30794100 :       for (lkp_iterator iter (last_decl); iter; ++iter)
    1526                 :            :         {
    1527                 :   19898300 :           if (TREE_CODE (*iter) == OVERLOAD)
    1528                 :          0 :             continue;
    1529                 :            : 
    1530                 :   19898300 :           if (decls_match (decl, *iter, /*record_decls=*/false))
    1531                 :     795504 :             return *iter;
    1532                 :            :         }
    1533                 :    5050170 :       return NULL_TREE;
    1534                 :            :     }
    1535                 :            : 
    1536                 :            :   return NULL_TREE;
    1537                 :            : }
    1538                 :            : 
    1539                 :            : /* Like decl_attributes, but handle C++ complexity.  */
    1540                 :            : 
    1541                 :            : void
    1542                 :   33691300 : cplus_decl_attributes (tree *decl, tree attributes, int flags)
    1543                 :            : {
    1544                 :   33691300 :   if (*decl == NULL_TREE || *decl == void_type_node
    1545                 :   33691300 :       || *decl == error_mark_node)
    1546                 :            :     return;
    1547                 :            : 
    1548                 :            :   /* Add implicit "omp declare target" attribute if requested.  */
    1549                 :   33691200 :   if (scope_chain->omp_declare_target_attribute
    1550                 :   33691200 :       && ((VAR_P (*decl)
    1551                 :       1864 :            && (TREE_STATIC (*decl) || DECL_EXTERNAL (*decl)))
    1552                 :       2952 :           || TREE_CODE (*decl) == FUNCTION_DECL))
    1553                 :            :     {
    1554                 :       1288 :       if (VAR_P (*decl)
    1555                 :       1288 :           && DECL_CLASS_SCOPE_P (*decl))
    1556                 :          0 :         error ("%q+D static data member inside of declare target directive",
    1557                 :            :                *decl);
    1558                 :       1288 :       else if (VAR_P (*decl)
    1559                 :       1288 :                && (processing_template_decl
    1560                 :        124 :                    || !cp_omp_mappable_type (TREE_TYPE (*decl))))
    1561                 :         32 :         attributes = tree_cons (get_identifier ("omp declare target implicit"),
    1562                 :            :                                 NULL_TREE, attributes);
    1563                 :            :       else
    1564                 :            :         {
    1565                 :       1256 :           attributes = tree_cons (get_identifier ("omp declare target"),
    1566                 :            :                                   NULL_TREE, attributes);
    1567                 :       1256 :           attributes = tree_cons (get_identifier ("omp declare target block"),
    1568                 :            :                                   NULL_TREE, attributes);
    1569                 :            :         }
    1570                 :            :     }
    1571                 :            : 
    1572                 :   33691200 :   if (processing_template_decl)
    1573                 :            :     {
    1574                 :   16261400 :       if (check_for_bare_parameter_packs (attributes))
    1575                 :            :         return;
    1576                 :            : 
    1577                 :   16261400 :       save_template_attributes (&attributes, decl, flags);
    1578                 :            :     }
    1579                 :            : 
    1580                 :   33691200 :   cp_check_const_attributes (attributes);
    1581                 :            : 
    1582                 :   33691200 :   if (TREE_CODE (*decl) == TEMPLATE_DECL)
    1583                 :        757 :     decl = &DECL_TEMPLATE_RESULT (*decl);
    1584                 :            : 
    1585                 :   33691200 :   if (TREE_TYPE (*decl) && TYPE_PTRMEMFUNC_P (TREE_TYPE (*decl)))
    1586                 :            :     {
    1587                 :       6085 :       attributes
    1588                 :       6085 :         = decl_attributes (decl, attributes, flags | ATTR_FLAG_FUNCTION_NEXT);
    1589                 :       6085 :       decl_attributes (&TYPE_PTRMEMFUNC_FN_TYPE_RAW (TREE_TYPE (*decl)),
    1590                 :            :                        attributes, flags);
    1591                 :            :     }
    1592                 :            :   else
    1593                 :            :     {
    1594                 :   33685100 :       tree last_decl = find_last_decl (*decl);
    1595                 :   33685100 :       decl_attributes (decl, attributes, flags, last_decl);
    1596                 :            :     }
    1597                 :            : 
    1598                 :   33691200 :   if (TREE_CODE (*decl) == TYPE_DECL)
    1599                 :    2124870 :     SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (*decl), TREE_TYPE (*decl));
    1600                 :            : 
    1601                 :            :   /* Propagate deprecation out to the template.  */
    1602                 :   33691200 :   if (TREE_DEPRECATED (*decl))
    1603                 :     131585 :     if (tree ti = get_template_info (*decl))
    1604                 :            :       {
    1605                 :      98584 :         tree tmpl = TI_TEMPLATE (ti);
    1606                 :     111610 :         tree pattern = (TYPE_P (*decl) ? TREE_TYPE (tmpl)
    1607                 :      85558 :                         : DECL_TEMPLATE_RESULT (tmpl));
    1608                 :      98584 :         if (*decl == pattern)
    1609                 :      13329 :           TREE_DEPRECATED (tmpl) = true;
    1610                 :            :       }
    1611                 :            : }
    1612                 :            : 
    1613                 :            : /* Walks through the namespace- or function-scope anonymous union
    1614                 :            :    OBJECT, with the indicated TYPE, building appropriate VAR_DECLs.
    1615                 :            :    Returns one of the fields for use in the mangled name.  */
    1616                 :            : 
    1617                 :            : static tree
    1618                 :        360 : build_anon_union_vars (tree type, tree object)
    1619                 :            : {
    1620                 :        360 :   tree main_decl = NULL_TREE;
    1621                 :        360 :   tree field;
    1622                 :            : 
    1623                 :            :   /* Rather than write the code to handle the non-union case,
    1624                 :            :      just give an error.  */
    1625                 :        360 :   if (TREE_CODE (type) != UNION_TYPE)
    1626                 :            :     {
    1627                 :          8 :       error_at (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    1628                 :            :                 "anonymous struct not inside named type");
    1629                 :          8 :       return error_mark_node;
    1630                 :            :     }
    1631                 :            : 
    1632                 :       1307 :   for (field = TYPE_FIELDS (type);
    1633                 :       1307 :        field != NULL_TREE;
    1634                 :        955 :        field = DECL_CHAIN (field))
    1635                 :            :     {
    1636                 :        955 :       tree decl;
    1637                 :        955 :       tree ref;
    1638                 :            : 
    1639                 :        955 :       if (DECL_ARTIFICIAL (field))
    1640                 :        450 :         continue;
    1641                 :        505 :       if (TREE_CODE (field) != FIELD_DECL)
    1642                 :            :         {
    1643                 :          0 :           permerror (DECL_SOURCE_LOCATION (field),
    1644                 :            :                      "%q#D invalid; an anonymous union can only "
    1645                 :            :                      "have non-static data members", field);
    1646                 :          0 :           continue;
    1647                 :            :         }
    1648                 :            : 
    1649                 :        505 :       if (TREE_PRIVATE (field))
    1650                 :          8 :         permerror (DECL_SOURCE_LOCATION (field),
    1651                 :            :                    "private member %q#D in anonymous union", field);
    1652                 :        497 :       else if (TREE_PROTECTED (field))
    1653                 :          0 :         permerror (DECL_SOURCE_LOCATION (field),
    1654                 :            :                    "protected member %q#D in anonymous union", field);
    1655                 :            : 
    1656                 :        505 :       if (processing_template_decl)
    1657                 :         73 :         ref = build_min_nt_loc (UNKNOWN_LOCATION, COMPONENT_REF, object,
    1658                 :         73 :                                 DECL_NAME (field), NULL_TREE);
    1659                 :            :       else
    1660                 :        432 :         ref = build_class_member_access_expr (object, field, NULL_TREE,
    1661                 :            :                                               false, tf_warning_or_error);
    1662                 :            : 
    1663                 :        505 :       if (DECL_NAME (field))
    1664                 :            :         {
    1665                 :        474 :           tree base;
    1666                 :            : 
    1667                 :        474 :           decl = build_decl (input_location,
    1668                 :        474 :                              VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
    1669                 :        474 :           DECL_ANON_UNION_VAR_P (decl) = 1;
    1670                 :        474 :           DECL_ARTIFICIAL (decl) = 1;
    1671                 :            : 
    1672                 :        474 :           base = get_base_address (object);
    1673                 :        474 :           TREE_PUBLIC (decl) = TREE_PUBLIC (base);
    1674                 :        474 :           TREE_STATIC (decl) = TREE_STATIC (base);
    1675                 :        474 :           DECL_EXTERNAL (decl) = DECL_EXTERNAL (base);
    1676                 :            : 
    1677                 :        474 :           SET_DECL_VALUE_EXPR (decl, ref);
    1678                 :        474 :           DECL_HAS_VALUE_EXPR_P (decl) = 1;
    1679                 :            : 
    1680                 :        474 :           decl = pushdecl (decl);
    1681                 :            :         }
    1682                 :         31 :       else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    1683                 :         31 :         decl = build_anon_union_vars (TREE_TYPE (field), ref);
    1684                 :            :       else
    1685                 :            :         decl = 0;
    1686                 :            : 
    1687                 :        505 :       if (main_decl == NULL_TREE)
    1688                 :        337 :         main_decl = decl;
    1689                 :            :     }
    1690                 :            : 
    1691                 :            :   return main_decl;
    1692                 :            : }
    1693                 :            : 
    1694                 :            : /* Finish off the processing of a UNION_TYPE structure.  If the union is an
    1695                 :            :    anonymous union, then all members must be laid out together.  PUBLIC_P
    1696                 :            :    is nonzero if this union is not declared static.  */
    1697                 :            : 
    1698                 :            : void
    1699                 :        339 : finish_anon_union (tree anon_union_decl)
    1700                 :            : {
    1701                 :        339 :   tree type;
    1702                 :        339 :   tree main_decl;
    1703                 :        339 :   bool public_p;
    1704                 :            : 
    1705                 :        339 :   if (anon_union_decl == error_mark_node)
    1706                 :            :     return;
    1707                 :            : 
    1708                 :        329 :   type = TREE_TYPE (anon_union_decl);
    1709                 :        329 :   public_p = TREE_PUBLIC (anon_union_decl);
    1710                 :            : 
    1711                 :            :   /* The VAR_DECL's context is the same as the TYPE's context.  */
    1712                 :        329 :   DECL_CONTEXT (anon_union_decl) = DECL_CONTEXT (TYPE_NAME (type));
    1713                 :            : 
    1714                 :        658 :   if (TYPE_FIELDS (type) == NULL_TREE)
    1715                 :            :     return;
    1716                 :            : 
    1717                 :        329 :   if (public_p)
    1718                 :            :     {
    1719                 :          0 :       error ("namespace-scope anonymous aggregates must be static");
    1720                 :          0 :       return;
    1721                 :            :     }
    1722                 :            : 
    1723                 :        329 :   main_decl = build_anon_union_vars (type, anon_union_decl);
    1724                 :        329 :   if (main_decl == error_mark_node)
    1725                 :            :     return;
    1726                 :        305 :   if (main_decl == NULL_TREE)
    1727                 :            :     {
    1728                 :         15 :       pedwarn (input_location, 0, "anonymous union with no members");
    1729                 :         15 :       return;
    1730                 :            :     }
    1731                 :            : 
    1732                 :        290 :   if (!processing_template_decl)
    1733                 :            :     {
    1734                 :            :       /* Use main_decl to set the mangled name.  */
    1735                 :        246 :       DECL_NAME (anon_union_decl) = DECL_NAME (main_decl);
    1736                 :        246 :       maybe_commonize_var (anon_union_decl);
    1737                 :        391 :       if (TREE_STATIC (anon_union_decl) || DECL_EXTERNAL (anon_union_decl))
    1738                 :            :         {
    1739                 :        202 :           if (DECL_DISCRIMINATOR_P (anon_union_decl))
    1740                 :         52 :             determine_local_discriminator (anon_union_decl);
    1741                 :        101 :           mangle_decl (anon_union_decl);
    1742                 :            :         }
    1743                 :        246 :       DECL_NAME (anon_union_decl) = NULL_TREE;
    1744                 :            :     }
    1745                 :            : 
    1746                 :        290 :   pushdecl (anon_union_decl);
    1747                 :        290 :   cp_finish_decl (anon_union_decl, NULL_TREE, false, NULL_TREE, 0);
    1748                 :            : }
    1749                 :            : 
    1750                 :            : /* Auxiliary functions to make type signatures for
    1751                 :            :    `operator new' and `operator delete' correspond to
    1752                 :            :    what compiler will be expecting.  */
    1753                 :            : 
    1754                 :            : tree
    1755                 :      28823 : coerce_new_type (tree type, location_t loc)
    1756                 :            : {
    1757                 :      28823 :   int e = 0;
    1758                 :      28823 :   tree args = TYPE_ARG_TYPES (type);
    1759                 :            : 
    1760                 :      28823 :   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
    1761                 :            : 
    1762                 :      28823 :   if (!same_type_p (TREE_TYPE (type), ptr_type_node))
    1763                 :            :     {
    1764                 :          8 :       e = 1;
    1765                 :          8 :       error_at (loc, "%<operator new%> must return type %qT",
    1766                 :            :                 ptr_type_node);
    1767                 :            :     }
    1768                 :            : 
    1769                 :      28823 :   if (args && args != void_list_node)
    1770                 :            :     {
    1771                 :      28819 :       if (TREE_PURPOSE (args))
    1772                 :            :         {
    1773                 :            :           /* [basic.stc.dynamic.allocation]
    1774                 :            :              
    1775                 :            :              The first parameter shall not have an associated default
    1776                 :            :              argument.  */
    1777                 :         24 :           error_at (loc, "the first parameter of %<operator new%> cannot "
    1778                 :            :                     "have a default argument");
    1779                 :            :           /* Throw away the default argument.  */
    1780                 :         24 :           TREE_PURPOSE (args) = NULL_TREE;
    1781                 :            :         }
    1782                 :            : 
    1783                 :      28819 :       if (!same_type_p (TREE_VALUE (args), size_type_node))
    1784                 :            :         {
    1785                 :         12 :           e = 2;
    1786                 :         12 :           args = TREE_CHAIN (args);
    1787                 :            :         }
    1788                 :            :     }
    1789                 :            :   else
    1790                 :            :     e = 2;
    1791                 :            : 
    1792                 :         12 :   if (e == 2)
    1793                 :         16 :     permerror (loc, "%<operator new%> takes type %<size_t%> (%qT) "
    1794                 :            :                "as first parameter", size_type_node);
    1795                 :            : 
    1796                 :      28823 :   switch (e)
    1797                 :            :   {
    1798                 :         16 :     case 2:
    1799                 :         16 :       args = tree_cons (NULL_TREE, size_type_node, args);
    1800                 :            :       /* Fall through.  */
    1801                 :         24 :     case 1:
    1802                 :         24 :       type = (cxx_copy_lang_qualifiers
    1803                 :         24 :               (build_function_type (ptr_type_node, args),
    1804                 :            :                type));
    1805                 :            :       /* Fall through.  */
    1806                 :      28823 :     default:;
    1807                 :            :   }
    1808                 :      28823 :   return type;
    1809                 :            : }
    1810                 :            : 
    1811                 :            : void
    1812                 :      36409 : coerce_delete_type (tree decl, location_t loc)
    1813                 :            : {
    1814                 :      36409 :   int e = 0;
    1815                 :      36409 :   tree type = TREE_TYPE (decl);
    1816                 :      36409 :   tree args = TYPE_ARG_TYPES (type);
    1817                 :            : 
    1818                 :      36409 :   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
    1819                 :            : 
    1820                 :      36409 :   if (!same_type_p (TREE_TYPE (type), void_type_node))
    1821                 :            :     {
    1822                 :          8 :       e = 1;
    1823                 :          8 :       error_at (loc, "%<operator delete%> must return type %qT",
    1824                 :            :                 void_type_node);
    1825                 :            :     }
    1826                 :            : 
    1827                 :      36409 :   tree ptrtype = ptr_type_node;
    1828                 :      36409 :   if (destroying_delete_p (decl))
    1829                 :            :     {
    1830                 :         10 :       if (DECL_CLASS_SCOPE_P (decl))
    1831                 :            :         /* If the function is a destroying operator delete declared in class
    1832                 :            :            type C, the type of its first parameter shall be C*.  */
    1833                 :         10 :         ptrtype = build_pointer_type (DECL_CONTEXT (decl));
    1834                 :            :       else
    1835                 :            :         /* A destroying operator delete shall be a class member function named
    1836                 :            :            operator delete.  */
    1837                 :          0 :         error_at (loc,
    1838                 :            :                   "destroying %<operator delete%> must be a member function");
    1839                 :         10 :       const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (DECL_NAME (decl));
    1840                 :         10 :       if (op->flags & OVL_OP_FLAG_VEC)
    1841                 :          0 :         error_at (loc, "%<operator delete[]%> cannot be a destroying delete");
    1842                 :         10 :       if (!usual_deallocation_fn_p (decl))
    1843                 :          0 :         error_at (loc, "destroying %<operator delete%> must be a usual "
    1844                 :            :                   "deallocation function");
    1845                 :            :     }
    1846                 :            : 
    1847                 :      36405 :   if (!args || args == void_list_node
    1848                 :      72810 :       || !same_type_p (TREE_VALUE (args), ptrtype))
    1849                 :            :     {
    1850                 :         17 :       e = 2;
    1851                 :         17 :       if (args && args != void_list_node)
    1852                 :          9 :         args = TREE_CHAIN (args);
    1853                 :         17 :       error_at (loc, "%<operator delete%> takes type %qT as first parameter",
    1854                 :            :                 ptrtype);
    1855                 :            :     }
    1856                 :      36392 :   switch (e)
    1857                 :            :   {
    1858                 :         17 :     case 2:
    1859                 :         17 :       args = tree_cons (NULL_TREE, ptrtype, args);
    1860                 :            :       /* Fall through.  */
    1861                 :         25 :     case 1:
    1862                 :         25 :       type = (cxx_copy_lang_qualifiers
    1863                 :         25 :               (build_function_type (void_type_node, args),
    1864                 :            :                type));
    1865                 :            :       /* Fall through.  */
    1866                 :      36409 :     default:;
    1867                 :            :   }
    1868                 :            : 
    1869                 :      36409 :   TREE_TYPE (decl) = type;
    1870                 :      36409 : }
    1871                 :            : 
    1872                 :            : /* DECL is a VAR_DECL for a vtable: walk through the entries in the vtable
    1873                 :            :    and mark them as needed.  */
    1874                 :            : 
    1875                 :            : static void
    1876                 :     131968 : mark_vtable_entries (tree decl)
    1877                 :            : {
    1878                 :     131968 :   tree fnaddr;
    1879                 :     131968 :   unsigned HOST_WIDE_INT idx;
    1880                 :            : 
    1881                 :            :   /* It's OK for the vtable to refer to deprecated virtual functions.  */
    1882                 :     131968 :   warning_sentinel w(warn_deprecated_decl);
    1883                 :            : 
    1884                 :    6020300 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)),
    1885                 :            :                               idx, fnaddr)
    1886                 :            :     {
    1887                 :    2878180 :       tree fn;
    1888                 :            : 
    1889                 :    2878180 :       STRIP_NOPS (fnaddr);
    1890                 :            : 
    1891                 :    5022010 :       if (TREE_CODE (fnaddr) != ADDR_EXPR
    1892                 :    2878180 :           && TREE_CODE (fnaddr) != FDESC_EXPR)
    1893                 :            :         /* This entry is an offset: a virtual base class offset, a
    1894                 :            :            virtual call offset, an RTTI offset, etc.  */
    1895                 :    2143830 :         continue;
    1896                 :            : 
    1897                 :     734355 :       fn = TREE_OPERAND (fnaddr, 0);
    1898                 :     734355 :       TREE_ADDRESSABLE (fn) = 1;
    1899                 :            :       /* When we don't have vcall offsets, we output thunks whenever
    1900                 :            :          we output the vtables that contain them.  With vcall offsets,
    1901                 :            :          we know all the thunks we'll need when we emit a virtual
    1902                 :            :          function, so we emit the thunks there instead.  */
    1903                 :    1257960 :       if (DECL_THUNK_P (fn))
    1904                 :       4288 :         use_thunk (fn, /*emit_p=*/0);
    1905                 :            :       /* Set the location, as marking the function could cause
    1906                 :            :          instantiation.  We do not need to preserve the incoming
    1907                 :            :          location, as we're called from c_parse_final_cleanups, which
    1908                 :            :          takes care of that.  */
    1909                 :     734355 :       input_location = DECL_SOURCE_LOCATION (fn);
    1910                 :     734355 :       mark_used (fn);
    1911                 :            :     }
    1912                 :     131968 : }
    1913                 :            : 
    1914                 :            : /* Adjust the TLS model on variable DECL if need be, typically after
    1915                 :            :    the linkage of DECL has been modified.  */
    1916                 :            : 
    1917                 :            : static void
    1918                 :    1989880 : adjust_var_decl_tls_model (tree decl)
    1919                 :            : {
    1920                 :    1989880 :   if (CP_DECL_THREAD_LOCAL_P (decl)
    1921                 :    1989930 :       && !lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl)))
    1922                 :         49 :     set_decl_tls_model (decl, decl_default_tls_model (decl));
    1923                 :    1989880 : }
    1924                 :            : 
    1925                 :            : /* Set DECL up to have the closest approximation of "initialized common"
    1926                 :            :    linkage available.  */
    1927                 :            : 
    1928                 :            : void
    1929                 :   11657500 : comdat_linkage (tree decl)
    1930                 :            : {
    1931                 :   11657500 :   if (flag_weak)
    1932                 :   11657400 :     make_decl_one_only (decl, cxx_comdat_group (decl));
    1933                 :         31 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    1934                 :         39 :            || (VAR_P (decl) && DECL_ARTIFICIAL (decl)))
    1935                 :            :     /* We can just emit function and compiler-generated variables
    1936                 :            :        statically; having multiple copies is (for the most part) only
    1937                 :            :        a waste of space.
    1938                 :            : 
    1939                 :            :        There are two correctness issues, however: the address of a
    1940                 :            :        template instantiation with external linkage should be the
    1941                 :            :        same, independent of what translation unit asks for the
    1942                 :            :        address, and this will not hold when we emit multiple copies of
    1943                 :            :        the function.  However, there's little else we can do.
    1944                 :            : 
    1945                 :            :        Also, by default, the typeinfo implementation assumes that
    1946                 :            :        there will be only one copy of the string used as the name for
    1947                 :            :        each type.  Therefore, if weak symbols are unavailable, the
    1948                 :            :        run-time library should perform a more conservative check; it
    1949                 :            :        should perform a string comparison, rather than an address
    1950                 :            :        comparison.  */
    1951                 :         31 :     TREE_PUBLIC (decl) = 0;
    1952                 :            :   else
    1953                 :            :     {
    1954                 :            :       /* Static data member template instantiations, however, cannot
    1955                 :            :          have multiple copies.  */
    1956                 :          0 :       if (DECL_INITIAL (decl) == 0
    1957                 :          0 :           || DECL_INITIAL (decl) == error_mark_node)
    1958                 :          0 :         DECL_COMMON (decl) = 1;
    1959                 :          0 :       else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
    1960                 :            :         {
    1961                 :          0 :           DECL_COMMON (decl) = 1;
    1962                 :          0 :           DECL_INITIAL (decl) = error_mark_node;
    1963                 :            :         }
    1964                 :          0 :       else if (!DECL_EXPLICIT_INSTANTIATION (decl))
    1965                 :            :         {
    1966                 :            :           /* We can't do anything useful; leave vars for explicit
    1967                 :            :              instantiation.  */
    1968                 :          0 :           DECL_EXTERNAL (decl) = 1;
    1969                 :          0 :           DECL_NOT_REALLY_EXTERN (decl) = 0;
    1970                 :            :         }
    1971                 :            :     }
    1972                 :            : 
    1973                 :   11657500 :   if (TREE_PUBLIC (decl))
    1974                 :   11657400 :     DECL_COMDAT (decl) = 1;
    1975                 :            : 
    1976                 :   11657500 :   if (VAR_P (decl))
    1977                 :    1989470 :     adjust_var_decl_tls_model (decl);
    1978                 :   11657500 : }
    1979                 :            : 
    1980                 :            : /* For win32 we also want to put explicit instantiations in
    1981                 :            :    linkonce sections, so that they will be merged with implicit
    1982                 :            :    instantiations; otherwise we get duplicate symbol errors.
    1983                 :            :    For Darwin we do not want explicit instantiations to be
    1984                 :            :    linkonce.  */
    1985                 :            : 
    1986                 :            : void
    1987                 :      28853 : maybe_make_one_only (tree decl)
    1988                 :            : {
    1989                 :            :   /* We used to say that this was not necessary on targets that support weak
    1990                 :            :      symbols, because the implicit instantiations will defer to the explicit
    1991                 :            :      one.  However, that's not actually the case in SVR4; a strong definition
    1992                 :            :      after a weak one is an error.  Also, not making explicit
    1993                 :            :      instantiations one_only means that we can end up with two copies of
    1994                 :            :      some template instantiations.  */
    1995                 :      28853 :   if (! flag_weak)
    1996                 :            :     return;
    1997                 :            : 
    1998                 :            :   /* We can't set DECL_COMDAT on functions, or cp_finish_file will think
    1999                 :            :      we can get away with not emitting them if they aren't used.  We need
    2000                 :            :      to for variables so that cp_finish_decl will update their linkage,
    2001                 :            :      because their DECL_INITIAL may not have been set properly yet.  */
    2002                 :            : 
    2003                 :      28849 :   if (!TARGET_WEAK_NOT_IN_ARCHIVE_TOC
    2004                 :            :       || (! DECL_EXPLICIT_INSTANTIATION (decl)
    2005                 :            :           && ! DECL_TEMPLATE_SPECIALIZATION (decl)))
    2006                 :            :     {
    2007                 :      28849 :       make_decl_one_only (decl, cxx_comdat_group (decl));
    2008                 :            : 
    2009                 :      28849 :       if (VAR_P (decl))
    2010                 :            :         {
    2011                 :        412 :           varpool_node *node = varpool_node::get_create (decl);
    2012                 :        412 :           DECL_COMDAT (decl) = 1;
    2013                 :            :           /* Mark it needed so we don't forget to emit it.  */
    2014                 :        412 :           node->forced_by_abi = true;
    2015                 :        412 :           TREE_USED (decl) = 1;
    2016                 :            : 
    2017                 :        412 :           adjust_var_decl_tls_model (decl);
    2018                 :            :         }
    2019                 :            :     }
    2020                 :            : }
    2021                 :            : 
    2022                 :            : /* Returns true iff DECL, a FUNCTION_DECL or VAR_DECL, has vague linkage.
    2023                 :            :    This predicate will give the right answer during parsing of the
    2024                 :            :    function, which other tests may not.  */
    2025                 :            : 
    2026                 :            : bool
    2027                 :    3927040 : vague_linkage_p (tree decl)
    2028                 :            : {
    2029                 :    3927050 :   if (!TREE_PUBLIC (decl))
    2030                 :            :     {
    2031                 :            :       /* maybe_thunk_body clears TREE_PUBLIC and DECL_ABSTRACT_P on the
    2032                 :            :          maybe-in-charge 'tor variants; in that case we need to check one of
    2033                 :            :          the "clones" for the real linkage.  But only in that case; before
    2034                 :            :          maybe_clone_body we haven't yet copied the linkage to the clones.  */
    2035                 :       8147 :       if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl)
    2036                 :         40 :           && !DECL_ABSTRACT_P (decl)
    2037                 :          3 :           && DECL_CHAIN (decl)
    2038                 :       4094 :           && DECL_CLONED_FUNCTION_P (DECL_CHAIN (decl)))
    2039                 :    3927050 :         return vague_linkage_p (DECL_CHAIN (decl));
    2040                 :            : 
    2041                 :       4088 :       gcc_checking_assert (!DECL_COMDAT (decl));
    2042                 :            :       return false;
    2043                 :            :     }
    2044                 :            :   /* Unfortunately, import_export_decl has not always been called
    2045                 :            :      before the function is processed, so we cannot simply check
    2046                 :            :      DECL_COMDAT.  */
    2047                 :    3922960 :   if (DECL_COMDAT (decl)
    2048                 :     175120 :       || (TREE_CODE (decl) == FUNCTION_DECL
    2049                 :     174781 :           && DECL_DECLARED_INLINE_P (decl))
    2050                 :     138849 :       || (DECL_LANG_SPECIFIC (decl)
    2051                 :     138599 :           && DECL_TEMPLATE_INSTANTIATION (decl))
    2052                 :    3935070 :       || (VAR_P (decl) && DECL_INLINE_VAR_P (decl)))
    2053                 :            :     return true;
    2054                 :      11884 :   else if (DECL_FUNCTION_SCOPE_P (decl))
    2055                 :            :     /* A local static in an inline effectively has vague linkage.  */
    2056                 :          0 :     return (TREE_STATIC (decl)
    2057                 :          0 :             && vague_linkage_p (DECL_CONTEXT (decl)));
    2058                 :            :   else
    2059                 :            :     return false;
    2060                 :            : }
    2061                 :            : 
    2062                 :            : /* Determine whether or not we want to specifically import or export CTYPE,
    2063                 :            :    using various heuristics.  */
    2064                 :            : 
    2065                 :            : static void
    2066                 :    2119000 : import_export_class (tree ctype)
    2067                 :            : {
    2068                 :            :   /* -1 for imported, 1 for exported.  */
    2069                 :    2119000 :   int import_export = 0;
    2070                 :            : 
    2071                 :            :   /* It only makes sense to call this function at EOF.  The reason is
    2072                 :            :      that this function looks at whether or not the first non-inline
    2073                 :            :      non-abstract virtual member function has been defined in this
    2074                 :            :      translation unit.  But, we can't possibly know that until we've
    2075                 :            :      seen the entire translation unit.  */
    2076                 :    2119000 :   gcc_assert (at_eof);
    2077                 :            : 
    2078                 :    2119000 :   if (CLASSTYPE_INTERFACE_KNOWN (ctype))
    2079                 :            :     return;
    2080                 :            : 
    2081                 :            :   /* If MULTIPLE_SYMBOL_SPACES is set and we saw a #pragma interface,
    2082                 :            :      we will have CLASSTYPE_INTERFACE_ONLY set but not
    2083                 :            :      CLASSTYPE_INTERFACE_KNOWN.  In that case, we don't want to use this
    2084                 :            :      heuristic because someone will supply a #pragma implementation
    2085                 :            :      elsewhere, and deducing it here would produce a conflict.  */
    2086                 :     940868 :   if (CLASSTYPE_INTERFACE_ONLY (ctype))
    2087                 :            :     return;
    2088                 :            : 
    2089                 :     940868 :   if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype)))
    2090                 :            :     import_export = -1;
    2091                 :     940868 :   else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype)))
    2092                 :            :     import_export = 1;
    2093                 :     940868 :   else if (CLASSTYPE_IMPLICIT_INSTANTIATION (ctype)
    2094                 :     940868 :            && !flag_implicit_templates)
    2095                 :            :     /* For a template class, without -fimplicit-templates, check the
    2096                 :            :        repository.  If the virtual table is assigned to this
    2097                 :            :        translation unit, then export the class; otherwise, import
    2098                 :            :        it.  */
    2099                 :            :       import_export = -1;
    2100                 :    1880450 :   else if (TYPE_POLYMORPHIC_P (ctype))
    2101                 :            :     {
    2102                 :            :       /* The ABI specifies that the virtual table and associated
    2103                 :            :          information are emitted with the key method, if any.  */
    2104                 :     823988 :       tree method = CLASSTYPE_KEY_METHOD (ctype);
    2105                 :            :       /* If weak symbol support is not available, then we must be
    2106                 :            :          careful not to emit the vtable when the key function is
    2107                 :            :          inline.  An inline function can be defined in multiple
    2108                 :            :          translation units.  If we were to emit the vtable in each
    2109                 :            :          translation unit containing a definition, we would get
    2110                 :            :          multiple definition errors at link-time.  */
    2111                 :     823988 :       if (method && (flag_weak || ! DECL_DECLARED_INLINE_P (method)))
    2112                 :     351441 :         import_export = (DECL_REALLY_EXTERN (method) ? -1 : 1);
    2113                 :            :     }
    2114                 :            : 
    2115                 :            :   /* When MULTIPLE_SYMBOL_SPACES is set, we cannot count on seeing
    2116                 :            :      a definition anywhere else.  */
    2117                 :     940868 :   if (MULTIPLE_SYMBOL_SPACES && import_export == -1)
    2118                 :            :     import_export = 0;
    2119                 :            : 
    2120                 :            :   /* Allow back ends the chance to overrule the decision.  */
    2121                 :     940868 :   if (targetm.cxx.import_export_class)
    2122                 :          0 :     import_export = targetm.cxx.import_export_class (ctype, import_export);
    2123                 :            : 
    2124                 :     940868 :   if (import_export)
    2125                 :            :     {
    2126                 :     352085 :       SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
    2127                 :     352085 :       CLASSTYPE_INTERFACE_ONLY (ctype) = (import_export < 0);
    2128                 :            :     }
    2129                 :            : }
    2130                 :            : 
    2131                 :            : /* Return true if VAR has already been provided to the back end; in that
    2132                 :            :    case VAR should not be modified further by the front end.  */
    2133                 :            : static bool
    2134                 :   19607400 : var_finalized_p (tree var)
    2135                 :            : {
    2136                 :          0 :   return varpool_node::get_create (var)->definition;
    2137                 :            : }
    2138                 :            : 
    2139                 :            : /* DECL is a VAR_DECL or FUNCTION_DECL which, for whatever reason,
    2140                 :            :    must be emitted in this translation unit.  Mark it as such.  */
    2141                 :            : 
    2142                 :            : void
    2143                 :      44204 : mark_needed (tree decl)
    2144                 :            : {
    2145                 :      44204 :   TREE_USED (decl) = 1;
    2146                 :      44204 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    2147                 :            :     {
    2148                 :            :       /* Extern inline functions don't become needed when referenced.
    2149                 :            :          If we know a method will be emitted in other TU and no new
    2150                 :            :          functions can be marked reachable, just use the external
    2151                 :            :          definition.  */
    2152                 :      36239 :       struct cgraph_node *node = cgraph_node::get_create (decl);
    2153                 :      36239 :       node->forced_by_abi = true;
    2154                 :            : 
    2155                 :            :       /* #pragma interface can call mark_needed for
    2156                 :            :           maybe-in-charge 'tors; mark the clones as well.  */
    2157                 :      36239 :       tree clone;
    2158                 :      90729 :       FOR_EACH_CLONE (clone, decl)
    2159                 :       7373 :         mark_needed (clone);
    2160                 :            :     }
    2161                 :       7965 :   else if (VAR_P (decl))
    2162                 :            :     {
    2163                 :       7965 :       varpool_node *node = varpool_node::get_create (decl);
    2164                 :            :       /* C++ frontend use mark_decl_references to force COMDAT variables
    2165                 :            :          to be output that might appear dead otherwise.  */
    2166                 :       7965 :       node->forced_by_abi = true;
    2167                 :            :     }
    2168                 :      44204 : }
    2169                 :            : 
    2170                 :            : /* DECL is either a FUNCTION_DECL or a VAR_DECL.  This function
    2171                 :            :    returns true if a definition of this entity should be provided in
    2172                 :            :    this object file.  Callers use this function to determine whether
    2173                 :            :    or not to let the back end know that a definition of DECL is
    2174                 :            :    available in this translation unit.  */
    2175                 :            : 
    2176                 :            : bool
    2177                 :   71665100 : decl_needed_p (tree decl)
    2178                 :            : {
    2179                 :   71665100 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
    2180                 :            :   /* This function should only be called at the end of the translation
    2181                 :            :      unit.  We cannot be sure of whether or not something will be
    2182                 :            :      COMDAT until that point.  */
    2183                 :   71665100 :   gcc_assert (at_eof);
    2184                 :            : 
    2185                 :            :   /* All entities with external linkage that are not COMDAT/EXTERN should be
    2186                 :            :      emitted; they may be referred to from other object files.  */
    2187                 :  143249000 :   if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_REALLY_EXTERN (decl))
    2188                 :            :     return true;
    2189                 :            :   /* Functions marked "dllexport" must be emitted so that they are
    2190                 :            :      visible to other DLLs.  */
    2191                 :   71651300 :   if (flag_keep_inline_dllexport
    2192                 :  143303000 :       && lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))
    2193                 :            :     return true;
    2194                 :            : 
    2195                 :            :   /* When not optimizing, do not bother to produce definitions for extern
    2196                 :            :      symbols.  */
    2197                 :   95021600 :   if (DECL_REALLY_EXTERN (decl)
    2198                 :          0 :       && ((TREE_CODE (decl) != FUNCTION_DECL
    2199                 :          0 :            && !optimize)
    2200                 :          0 :           || (TREE_CODE (decl) == FUNCTION_DECL
    2201                 :          0 :               && !opt_for_fn (decl, optimize)))
    2202                 :   71651300 :       && !lookup_attribute ("always_inline", decl))
    2203                 :            :     return false;
    2204                 :            : 
    2205                 :            :   /* If this entity was used, let the back end see it; it will decide
    2206                 :            :      whether or not to emit it into the object file.  */
    2207                 :   71651300 :   if (TREE_USED (decl))
    2208                 :            :     return true;
    2209                 :            : 
    2210                 :            :   /* Virtual functions might be needed for devirtualization.  */
    2211                 :   19897500 :   if (flag_devirtualize
    2212                 :   19428500 :       && TREE_CODE (decl) == FUNCTION_DECL
    2213                 :   38888000 :       && DECL_VIRTUAL_P (decl))
    2214                 :     173130 :     return true;
    2215                 :            : 
    2216                 :            :   /* Otherwise, DECL does not need to be emitted -- yet.  A subsequent
    2217                 :            :      reference to DECL might cause it to be emitted later.  */
    2218                 :            :   return false;
    2219                 :            : }
    2220                 :            : 
    2221                 :            : /* If necessary, write out the vtables for the dynamic class CTYPE.
    2222                 :            :    Returns true if any vtables were emitted.  */
    2223                 :            : 
    2224                 :            : static bool
    2225                 :    1681200 : maybe_emit_vtables (tree ctype)
    2226                 :            : {
    2227                 :    1681200 :   tree vtbl;
    2228                 :    1681200 :   tree primary_vtbl;
    2229                 :    1681200 :   int needed = 0;
    2230                 :    1681200 :   varpool_node *current = NULL, *last = NULL;
    2231                 :            : 
    2232                 :            :   /* If the vtables for this class have already been emitted there is
    2233                 :            :      nothing more to do.  */
    2234                 :    1681200 :   primary_vtbl = CLASSTYPE_VTABLES (ctype);
    2235                 :    1681200 :   if (var_finalized_p (primary_vtbl))
    2236                 :            :     return false;
    2237                 :            :   /* Ignore dummy vtables made by get_vtable_decl.  */
    2238                 :    1681200 :   if (TREE_TYPE (primary_vtbl) == void_type_node)
    2239                 :            :     return false;
    2240                 :            : 
    2241                 :            :   /* On some targets, we cannot determine the key method until the end
    2242                 :            :      of the translation unit -- which is when this function is
    2243                 :            :      called.  */
    2244                 :    1681200 :   if (!targetm.cxx.key_method_may_be_inline ())
    2245                 :          0 :     determine_key_method (ctype);
    2246                 :            : 
    2247                 :            :   /* See if any of the vtables are needed.  */
    2248                 :    4224530 :   for (vtbl = CLASSTYPE_VTABLES (ctype); vtbl; vtbl = DECL_CHAIN (vtbl))
    2249                 :            :     {
    2250                 :    2543330 :       import_export_decl (vtbl);
    2251                 :    2543330 :       if (DECL_NOT_REALLY_EXTERN (vtbl) && decl_needed_p (vtbl))
    2252                 :            :         needed = 1;
    2253                 :            :     }
    2254                 :    1681200 :   if (!needed)
    2255                 :            :     {
    2256                 :            :       /* If the references to this class' vtables are optimized away,
    2257                 :            :          still emit the appropriate debugging information.  See
    2258                 :            :          dfs_debug_mark.  */
    2259                 :    1569640 :       if (DECL_COMDAT (primary_vtbl)
    2260                 :    1790540 :           && CLASSTYPE_DEBUG_REQUESTED (ctype))
    2261                 :       2086 :         note_debug_info_needed (ctype);
    2262                 :    1569640 :       return false;
    2263                 :            :     }
    2264                 :            : 
    2265                 :            :   /* The ABI requires that we emit all of the vtables if we emit any
    2266                 :            :      of them.  */
    2267                 :     243525 :   for (vtbl = CLASSTYPE_VTABLES (ctype); vtbl; vtbl = DECL_CHAIN (vtbl))
    2268                 :            :     {
    2269                 :            :       /* Mark entities references from the virtual table as used.  */
    2270                 :     131968 :       mark_vtable_entries (vtbl);
    2271                 :            : 
    2272                 :     131968 :       if (TREE_TYPE (DECL_INITIAL (vtbl)) == 0)
    2273                 :            :         {
    2274                 :          0 :           vec<tree, va_gc> *cleanups = NULL;
    2275                 :          0 :           tree expr = store_init_value (vtbl, DECL_INITIAL (vtbl), &cleanups,
    2276                 :            :                                         LOOKUP_NORMAL);
    2277                 :            : 
    2278                 :            :           /* It had better be all done at compile-time.  */
    2279                 :          0 :           gcc_assert (!expr && !cleanups);
    2280                 :            :         }
    2281                 :            : 
    2282                 :            :       /* Write it out.  */
    2283                 :     131968 :       DECL_EXTERNAL (vtbl) = 0;
    2284                 :     131968 :       rest_of_decl_compilation (vtbl, 1, 1);
    2285                 :            : 
    2286                 :            :       /* Because we're only doing syntax-checking, we'll never end up
    2287                 :            :          actually marking the variable as written.  */
    2288                 :     131968 :       if (flag_syntax_only)
    2289                 :         41 :         TREE_ASM_WRITTEN (vtbl) = 1;
    2290                 :     131927 :       else if (DECL_ONE_ONLY (vtbl))
    2291                 :            :         {
    2292                 :     131376 :           current = varpool_node::get_create (vtbl);
    2293                 :     131376 :           if (last)
    2294                 :      20331 :             current->add_to_same_comdat_group (last);
    2295                 :            :           last = current;
    2296                 :            :         }
    2297                 :            :     }
    2298                 :            : 
    2299                 :            :   /* For abstract classes, the destructor has been removed from the
    2300                 :            :      vtable (in class.c's build_vtbl_initializer).  For a compiler-
    2301                 :            :      generated destructor, it hence might not have been generated in
    2302                 :            :      this translation unit - and with '#pragma interface' it might
    2303                 :            :      never get generated.  */
    2304                 :     111557 :   if (CLASSTYPE_PURE_VIRTUALS (ctype)
    2305                 :      28046 :       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype)
    2306                 :      27266 :       && !CLASSTYPE_LAZY_DESTRUCTOR (ctype)
    2307                 :     166255 :       && DECL_DEFAULTED_IN_CLASS_P (CLASSTYPE_DESTRUCTOR (ctype)))
    2308                 :         47 :     note_vague_linkage_fn (CLASSTYPE_DESTRUCTOR (ctype));
    2309                 :            : 
    2310                 :            :   /* Since we're writing out the vtable here, also write the debug
    2311                 :            :      info.  */
    2312                 :     111557 :   note_debug_info_needed (ctype);
    2313                 :            : 
    2314                 :     111557 :   return true;
    2315                 :            : }
    2316                 :            : 
    2317                 :            : /* A special return value from type_visibility meaning internal
    2318                 :            :    linkage.  */
    2319                 :            : 
    2320                 :            : enum { VISIBILITY_ANON = VISIBILITY_INTERNAL+1 };
    2321                 :            : 
    2322                 :            : static int expr_visibility (tree);
    2323                 :            : static int type_visibility (tree);
    2324                 :            : 
    2325                 :            : /* walk_tree helper function for type_visibility.  */
    2326                 :            : 
    2327                 :            : static tree
    2328                 :  450802000 : min_vis_r (tree *tp, int *walk_subtrees, void *data)
    2329                 :            : {
    2330                 :  450802000 :   int *vis_p = (int *)data;
    2331                 :  450802000 :   if (! TYPE_P (*tp))
    2332                 :            :     {
    2333                 :   88951500 :       *walk_subtrees = 0;
    2334                 :            :     }
    2335                 :  361850000 :   else if (OVERLOAD_TYPE_P (*tp)
    2336                 :  477645000 :            && !TREE_PUBLIC (TYPE_MAIN_DECL (*tp)))
    2337                 :            :     {
    2338                 :     390649 :       *vis_p = VISIBILITY_ANON;
    2339                 :     390649 :       return *tp;
    2340                 :            :     }
    2341                 :  114942000 :   else if (CLASS_TYPE_P (*tp)
    2342                 :  475341000 :            && CLASSTYPE_VISIBILITY (*tp) > *vis_p)
    2343                 :     500816 :     *vis_p = CLASSTYPE_VISIBILITY (*tp);
    2344                 :  360959000 :   else if (TREE_CODE (*tp) == ARRAY_TYPE
    2345                 :  360959000 :            && uses_template_parms (TYPE_DOMAIN (*tp)))
    2346                 :            :     {
    2347                 :      65229 :       int evis = expr_visibility (TYPE_MAX_VALUE (TYPE_DOMAIN (*tp)));
    2348                 :      65229 :       if (evis > *vis_p)
    2349                 :          4 :         *vis_p = evis;
    2350                 :            :     }
    2351                 :            :   return NULL;
    2352                 :            : }
    2353                 :            : 
    2354                 :            : /* walk_tree helper function for expr_visibility.  */
    2355                 :            : 
    2356                 :            : static tree
    2357                 :   26898100 : min_vis_expr_r (tree *tp, int */*walk_subtrees*/, void *data)
    2358                 :            : {
    2359                 :   26898100 :   int *vis_p = (int *)data;
    2360                 :   26898100 :   int tpvis = VISIBILITY_DEFAULT;
    2361                 :            : 
    2362                 :   26898100 :   switch (TREE_CODE (*tp))
    2363                 :            :     {
    2364                 :      64464 :     case CAST_EXPR:
    2365                 :      64464 :     case IMPLICIT_CONV_EXPR:
    2366                 :      64464 :     case STATIC_CAST_EXPR:
    2367                 :      64464 :     case REINTERPRET_CAST_EXPR:
    2368                 :      64464 :     case CONST_CAST_EXPR:
    2369                 :      64464 :     case DYNAMIC_CAST_EXPR:
    2370                 :      64464 :     case NEW_EXPR:
    2371                 :      64464 :     case CONSTRUCTOR:
    2372                 :      64464 :     case LAMBDA_EXPR:
    2373                 :      64464 :       tpvis = type_visibility (TREE_TYPE (*tp));
    2374                 :      64464 :       break;
    2375                 :            : 
    2376                 :      87047 :     case VAR_DECL:
    2377                 :      87047 :     case FUNCTION_DECL:
    2378                 :      87047 :       if (! TREE_PUBLIC (*tp))
    2379                 :            :         tpvis = VISIBILITY_ANON;
    2380                 :            :       else
    2381                 :      70014 :         tpvis = DECL_VISIBILITY (*tp);
    2382                 :            :       break;
    2383                 :            : 
    2384                 :            :     default:
    2385                 :            :       break;
    2386                 :            :     }
    2387                 :            : 
    2388                 :   26898100 :   if (tpvis > *vis_p)
    2389                 :      17050 :     *vis_p = tpvis;
    2390                 :            : 
    2391                 :   26898100 :   return NULL_TREE;
    2392                 :            : }
    2393                 :            : 
    2394                 :            : /* Returns the visibility of TYPE, which is the minimum visibility of its
    2395                 :            :    component types.  */
    2396                 :            : 
    2397                 :            : static int
    2398                 :  136092000 : type_visibility (tree type)
    2399                 :            : {
    2400                 :  136092000 :   int vis = VISIBILITY_DEFAULT;
    2401                 :      64464 :   cp_walk_tree_without_duplicates (&type, min_vis_r, &vis);
    2402                 :      64464 :   return vis;
    2403                 :            : }
    2404                 :            : 
    2405                 :            : /* Returns the visibility of an expression EXPR that appears in the signature
    2406                 :            :    of a function template, which is the minimum visibility of names that appear
    2407                 :            :    in its mangling.  */
    2408                 :            : 
    2409                 :            : static int
    2410                 :   12844900 : expr_visibility (tree expr)
    2411                 :            : {
    2412                 :   12844900 :   int vis = VISIBILITY_DEFAULT;
    2413                 :      65229 :   cp_walk_tree_without_duplicates (&expr, min_vis_expr_r, &vis);
    2414                 :      65229 :   return vis;
    2415                 :            : }
    2416                 :            : 
    2417                 :            : /* Limit the visibility of DECL to VISIBILITY, if not explicitly
    2418                 :            :    specified (or if VISIBILITY is static).  If TMPL is true, this
    2419                 :            :    constraint is for a template argument, and takes precedence
    2420                 :            :    over explicitly-specified visibility on the template.  */
    2421                 :            : 
    2422                 :            : static void
    2423                 :   10023600 : constrain_visibility (tree decl, int visibility, bool tmpl)
    2424                 :            : {
    2425                 :   10023600 :   if (visibility == VISIBILITY_ANON)
    2426                 :            :     {
    2427                 :            :       /* extern "C" declarations aren't affected by the anonymous
    2428                 :            :          namespace.  */
    2429                 :     471687 :       if (!DECL_EXTERN_C_P (decl))
    2430                 :            :         {
    2431                 :     471508 :           TREE_PUBLIC (decl) = 0;
    2432                 :     471508 :           DECL_WEAK (decl) = 0;
    2433                 :     471508 :           DECL_COMMON (decl) = 0;
    2434                 :     471508 :           DECL_COMDAT (decl) = false;
    2435                 :     471508 :           if (VAR_OR_FUNCTION_DECL_P (decl))
    2436                 :            :             {
    2437                 :     186978 :               struct symtab_node *snode = symtab_node::get (decl);
    2438                 :            : 
    2439                 :     186978 :               if (snode)
    2440                 :       9484 :                 snode->set_comdat_group (NULL);
    2441                 :            :             }
    2442                 :     471508 :           DECL_INTERFACE_KNOWN (decl) = 1;
    2443                 :     471508 :           if (DECL_LANG_SPECIFIC (decl))
    2444                 :     181981 :             DECL_NOT_REALLY_EXTERN (decl) = 1;
    2445                 :            :         }
    2446                 :            :     }
    2447                 :    9551880 :   else if (visibility > DECL_VISIBILITY (decl)
    2448                 :    9551880 :            && (tmpl || !DECL_VISIBILITY_SPECIFIED (decl)))
    2449                 :            :     {
    2450                 :        426 :       DECL_VISIBILITY (decl) = (enum symbol_visibility) visibility;
    2451                 :            :       /* This visibility was not specified.  */
    2452                 :        426 :       DECL_VISIBILITY_SPECIFIED (decl) = false;
    2453                 :            :     }
    2454                 :   10023600 : }
    2455                 :            : 
    2456                 :            : /* Constrain the visibility of DECL based on the visibility of its template
    2457                 :            :    arguments.  */
    2458                 :            : 
    2459                 :            : static void
    2460                 :   50463500 : constrain_visibility_for_template (tree decl, tree targs)
    2461                 :            : {
    2462                 :            :   /* If this is a template instantiation, check the innermost
    2463                 :            :      template args for visibility constraints.  The outer template
    2464                 :            :      args are covered by the class check.  */
    2465                 :   50463500 :   tree args = INNERMOST_TEMPLATE_ARGS (targs);
    2466                 :   50463500 :   int i;
    2467                 :  143119000 :   for (i = TREE_VEC_LENGTH (args); i > 0; --i)
    2468                 :            :     {
    2469                 :   92655900 :       int vis = 0;
    2470                 :            : 
    2471                 :   92655900 :       tree arg = TREE_VEC_ELT (args, i-1);
    2472                 :   92655900 :       if (TYPE_P (arg))
    2473                 :   79876200 :         vis = type_visibility (arg);
    2474                 :            :       else
    2475                 :   12779700 :         vis = expr_visibility (arg);
    2476                 :   92655900 :       if (vis)
    2477                 :     242775 :         constrain_visibility (decl, vis, true);
    2478                 :            :     }
    2479                 :   50463500 : }
    2480                 :            : 
    2481                 :            : /* Like c_determine_visibility, but with additional C++-specific
    2482                 :            :    behavior.
    2483                 :            : 
    2484                 :            :    Function-scope entities can rely on the function's visibility because
    2485                 :            :    it is set in start_preparsed_function.
    2486                 :            : 
    2487                 :            :    Class-scope entities cannot rely on the class's visibility until the end
    2488                 :            :    of the enclosing class definition.
    2489                 :            : 
    2490                 :            :    Note that because namespaces have multiple independent definitions,
    2491                 :            :    namespace visibility is handled elsewhere using the #pragma visibility
    2492                 :            :    machinery rather than by decorating the namespace declaration.
    2493                 :            : 
    2494                 :            :    The goal is for constraints from the type to give a diagnostic, and
    2495                 :            :    other constraints to be applied silently.  */
    2496                 :            : 
    2497                 :            : void
    2498                 :   80524900 : determine_visibility (tree decl)
    2499                 :            : {
    2500                 :            :   /* Remember that all decls get VISIBILITY_DEFAULT when built.  */
    2501                 :            : 
    2502                 :            :   /* Only relevant for names with external linkage.  */
    2503                 :   80524900 :   if (!TREE_PUBLIC (decl))
    2504                 :            :     return;
    2505                 :            : 
    2506                 :            :   /* Cloned constructors and destructors get the same visibility as
    2507                 :            :      the underlying function.  That should be set up in
    2508                 :            :      maybe_clone_body.  */
    2509                 :   75154300 :   gcc_assert (!DECL_CLONED_FUNCTION_P (decl));
    2510                 :            : 
    2511                 :   75154300 :   bool orig_visibility_specified = DECL_VISIBILITY_SPECIFIED (decl);
    2512                 :   75154300 :   enum symbol_visibility orig_visibility = DECL_VISIBILITY (decl);
    2513                 :            : 
    2514                 :            :   /* The decl may be a template instantiation, which could influence
    2515                 :            :      visibilty.  */
    2516                 :   75154300 :   tree template_decl = NULL_TREE;
    2517                 :   75154300 :   if (TREE_CODE (decl) == TYPE_DECL)
    2518                 :            :     {
    2519                 :   31909300 :       if (CLASS_TYPE_P (TREE_TYPE (decl)))
    2520                 :            :         {
    2521                 :   30937200 :           if (CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)))
    2522                 :   27921900 :             template_decl = decl;
    2523                 :            :         }
    2524                 :     972151 :       else if (TYPE_TEMPLATE_INFO (TREE_TYPE (decl)))
    2525                 :     159545 :         template_decl = decl;
    2526                 :            :     }
    2527                 :   43245000 :   else if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    2528                 :            :     template_decl = decl;
    2529                 :            : 
    2530                 :            :   /* If DECL is a member of a class, visibility specifiers on the
    2531                 :            :      class can influence the visibility of the DECL.  */
    2532                 :   75154300 :   tree class_type = NULL_TREE;
    2533                 :   75154300 :   if (DECL_CLASS_SCOPE_P (decl))
    2534                 :   74807600 :     class_type = DECL_CONTEXT (decl);
    2535                 :            :   else
    2536                 :            :     {
    2537                 :            :       /* Not a class member.  */
    2538                 :            : 
    2539                 :            :       /* Virtual tables have DECL_CONTEXT set to their associated class,
    2540                 :            :          so they are automatically handled above.  */
    2541                 :   43889500 :       gcc_assert (!VAR_P (decl)
    2542                 :            :                   || !DECL_VTABLE_OR_VTT_P (decl));
    2543                 :            : 
    2544                 :   43889500 :       if (DECL_FUNCTION_SCOPE_P (decl) && ! DECL_VISIBILITY_SPECIFIED (decl))
    2545                 :            :         {
    2546                 :            :           /* Local statics and classes get the visibility of their
    2547                 :            :              containing function by default, except that
    2548                 :            :              -fvisibility-inlines-hidden doesn't affect them.  */
    2549                 :     346680 :           tree fn = DECL_CONTEXT (decl);
    2550                 :     346680 :           if (DECL_VISIBILITY_SPECIFIED (fn))
    2551                 :            :             {
    2552                 :     328545 :               DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
    2553                 :     328545 :               DECL_VISIBILITY_SPECIFIED (decl) = 
    2554                 :     328545 :                 DECL_VISIBILITY_SPECIFIED (fn);
    2555                 :            :             }
    2556                 :            :           else
    2557                 :            :             {
    2558                 :      18135 :               if (DECL_CLASS_SCOPE_P (fn))
    2559                 :       9210 :                 determine_visibility_from_class (decl, DECL_CONTEXT (fn));
    2560                 :       8925 :               else if (determine_hidden_inline (fn))
    2561                 :            :                 {
    2562                 :          8 :                   DECL_VISIBILITY (decl) = default_visibility;
    2563                 :          8 :                   DECL_VISIBILITY_SPECIFIED (decl) =
    2564                 :          8 :                     visibility_options.inpragma;
    2565                 :            :                 }
    2566                 :            :               else
    2567                 :            :                 {
    2568                 :       8917 :                   DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
    2569                 :       8917 :                   DECL_VISIBILITY_SPECIFIED (decl) =
    2570                 :       8917 :                     DECL_VISIBILITY_SPECIFIED (fn);
    2571                 :            :                 }
    2572                 :            :             }
    2573                 :            : 
    2574                 :            :           /* Local classes in templates have CLASSTYPE_USE_TEMPLATE set,
    2575                 :            :              but have no TEMPLATE_INFO, so don't try to check it.  */
    2576                 :            :           template_decl = NULL_TREE;
    2577                 :            :         }
    2578                 :    1745960 :       else if (VAR_P (decl) && DECL_TINFO_P (decl)
    2579                 :   44434100 :                && flag_visibility_ms_compat)
    2580                 :            :         {
    2581                 :            :           /* Under -fvisibility-ms-compat, types are visible by default,
    2582                 :            :              even though their contents aren't.  */
    2583                 :        112 :           tree underlying_type = TREE_TYPE (DECL_NAME (decl));
    2584                 :        112 :           int underlying_vis = type_visibility (underlying_type);
    2585                 :        112 :           if (underlying_vis == VISIBILITY_ANON
    2586                 :        204 :               || (CLASS_TYPE_P (underlying_type)
    2587                 :         92 :                   && CLASSTYPE_VISIBILITY_SPECIFIED (underlying_type)))
    2588                 :         64 :             constrain_visibility (decl, underlying_vis, false);
    2589                 :            :           else
    2590                 :         48 :             DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    2591                 :            :         }
    2592                 :   43542800 :       else if (VAR_P (decl) && DECL_TINFO_P (decl))
    2593                 :            :         {
    2594                 :            :           /* tinfo visibility is based on the type it's for.  */
    2595                 :     891091 :           constrain_visibility
    2596                 :     891091 :             (decl, type_visibility (TREE_TYPE (DECL_NAME (decl))), false);
    2597                 :            : 
    2598                 :            :           /* Give the target a chance to override the visibility associated
    2599                 :            :              with DECL.  */
    2600                 :     891091 :           if (TREE_PUBLIC (decl)
    2601                 :     889822 :               && !DECL_REALLY_EXTERN (decl)
    2602                 :     889822 :               && CLASS_TYPE_P (TREE_TYPE (DECL_NAME (decl)))
    2603                 :    1770010 :               && !CLASSTYPE_VISIBILITY_SPECIFIED (TREE_TYPE (DECL_NAME (decl))))
    2604                 :     106542 :             targetm.cxx.determine_class_data_visibility (decl);
    2605                 :            :         }
    2606                 :   42651700 :       else if (template_decl)
    2607                 :            :         /* Template instantiations and specializations get visibility based
    2608                 :            :            on their template unless they override it with an attribute.  */;
    2609                 :   10963300 :       else if (! DECL_VISIBILITY_SPECIFIED (decl))
    2610                 :            :         {
    2611                 :   10418400 :           if (determine_hidden_inline (decl))
    2612                 :          8 :             DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
    2613                 :            :           else
    2614                 :            :             {
    2615                 :            :               /* Set default visibility to whatever the user supplied with
    2616                 :            :                  #pragma GCC visibility or a namespace visibility attribute.  */
    2617                 :   10418400 :               DECL_VISIBILITY (decl) = default_visibility;
    2618                 :   10418400 :               DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
    2619                 :            :             }
    2620                 :            :         }
    2621                 :            :     }
    2622                 :            : 
    2623                 :   74807600 :   if (template_decl)
    2624                 :            :     {
    2625                 :            :       /* If the specialization doesn't specify visibility, use the
    2626                 :            :          visibility from the template.  */
    2627                 :   48883200 :       tree tinfo = get_template_info (template_decl);
    2628                 :   48883200 :       tree args = TI_ARGS (tinfo);
    2629                 :   48883200 :       tree attribs = (TREE_CODE (decl) == TYPE_DECL
    2630                 :   76704800 :                       ? TYPE_ATTRIBUTES (TREE_TYPE (decl))
    2631                 :   21061600 :                       : DECL_ATTRIBUTES (decl));
    2632                 :   48883200 :       tree attr = lookup_attribute ("visibility", attribs);
    2633                 :            :       
    2634                 :   48883200 :       if (args != error_mark_node)
    2635                 :            :         {
    2636                 :   48883200 :           tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
    2637                 :            : 
    2638                 :   48883200 :           if (!DECL_VISIBILITY_SPECIFIED (decl))
    2639                 :            :             {
    2640                 :   14858400 :               if (!attr
    2641                 :   14858400 :                   && determine_hidden_inline (decl))
    2642                 :         44 :                 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
    2643                 :            :               else
    2644                 :            :                 {
    2645                 :   14858400 :                   DECL_VISIBILITY (decl) = DECL_VISIBILITY (pattern);
    2646                 :   14858400 :                   DECL_VISIBILITY_SPECIFIED (decl)
    2647                 :   14858400 :                     = DECL_VISIBILITY_SPECIFIED (pattern);
    2648                 :            :                 }
    2649                 :            :             }
    2650                 :            : 
    2651                 :   48883200 :           if (args
    2652                 :            :               /* Template argument visibility outweighs #pragma or namespace
    2653                 :            :                  visibility, but not an explicit attribute.  */
    2654                 :   48883200 :               && !attr)
    2655                 :            :             {
    2656                 :   97766300 :               int depth = TMPL_ARGS_DEPTH (args);
    2657                 :   48883200 :               if (DECL_VISIBILITY_SPECIFIED (decl))
    2658                 :            :                 {
    2659                 :            :                   /* A class template member with explicit visibility
    2660                 :            :                      overrides the class visibility, so we need to apply
    2661                 :            :                      all the levels of template args directly.  */
    2662                 :            :                   int i;
    2663                 :   93098900 :                   for (i = 1; i <= depth; ++i)
    2664                 :            :                     {
    2665                 :   96502500 :                       tree lev = TMPL_ARGS_LEVEL (args, i);
    2666                 :   48251300 :                       constrain_visibility_for_template (decl, lev);
    2667                 :            :                     }
    2668                 :            :                 }
    2669                 :    4035520 :               else if (PRIMARY_TEMPLATE_P (TI_TEMPLATE (tinfo)))
    2670                 :            :                 /* Limit visibility based on its template arguments.  */
    2671                 :    2212220 :                 constrain_visibility_for_template (decl, args);
    2672                 :            :             }
    2673                 :            :         }
    2674                 :            :     }
    2675                 :            : 
    2676                 :   75154300 :   if (class_type)
    2677                 :   31264700 :     determine_visibility_from_class (decl, class_type);
    2678                 :            : 
    2679                 :   75154300 :   if (decl_anon_ns_mem_p (decl))
    2680                 :            :     /* Names in an anonymous namespace get internal linkage.
    2681                 :            :        This might change once we implement export.  */
    2682                 :     103310 :     constrain_visibility (decl, VISIBILITY_ANON, false);
    2683                 :   75051000 :   else if (TREE_CODE (decl) != TYPE_DECL)
    2684                 :            :     {
    2685                 :            :       /* Propagate anonymity from type to decl.  */
    2686                 :   43155600 :       int tvis = type_visibility (TREE_TYPE (decl));
    2687                 :   43155600 :       if (tvis == VISIBILITY_ANON
    2688                 :   86293800 :           || ! DECL_VISIBILITY_SPECIFIED (decl))
    2689                 :    8646640 :         constrain_visibility (decl, tvis, false);
    2690                 :            :     }
    2691                 :   31895400 :   else if (no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/true))
    2692                 :            :     /* DR 757: A type without linkage shall not be used as the type of a
    2693                 :            :        variable or function with linkage, unless
    2694                 :            :        o the variable or function has extern "C" linkage (7.5 [dcl.link]), or
    2695                 :            :        o the variable or function is not used (3.2 [basic.def.odr]) or is
    2696                 :            :        defined in the same translation unit.
    2697                 :            : 
    2698                 :            :        Since non-extern "C" decls need to be defined in the same
    2699                 :            :        translation unit, we can make the type internal.  */
    2700                 :     139686 :     constrain_visibility (decl, VISIBILITY_ANON, false);
    2701                 :            : 
    2702                 :            :   /* If visibility changed and DECL already has DECL_RTL, ensure
    2703                 :            :      symbol flags are updated.  */
    2704                 :   75154300 :   if ((DECL_VISIBILITY (decl) != orig_visibility
    2705                 :   74433800 :        || DECL_VISIBILITY_SPECIFIED (decl) != orig_visibility_specified)
    2706                 :   29293000 :       && ((VAR_P (decl) && TREE_STATIC (decl))
    2707                 :   27734300 :           || TREE_CODE (decl) == FUNCTION_DECL)
    2708                 :  100971000 :       && DECL_RTL_SET_P (decl))
    2709                 :          0 :     make_decl_rtl (decl);
    2710                 :            : }
    2711                 :            : 
    2712                 :            : /* By default, static data members and function members receive
    2713                 :            :    the visibility of their containing class.  */
    2714                 :            : 
    2715                 :            : static void
    2716                 :   31273900 : determine_visibility_from_class (tree decl, tree class_type)
    2717                 :            : {
    2718                 :   31273900 :   if (DECL_VISIBILITY_SPECIFIED (decl))
    2719                 :            :     return;
    2720                 :            : 
    2721                 :   14716400 :   if (determine_hidden_inline (decl))
    2722                 :        197 :     DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
    2723                 :            :   else
    2724                 :            :     {
    2725                 :            :       /* Default to the class visibility.  */
    2726                 :   14716200 :       DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
    2727                 :   14716200 :       DECL_VISIBILITY_SPECIFIED (decl)
    2728                 :   14716200 :         = CLASSTYPE_VISIBILITY_SPECIFIED (class_type);
    2729                 :            :     }
    2730                 :            : 
    2731                 :            :   /* Give the target a chance to override the visibility associated
    2732                 :            :      with DECL.  */
    2733                 :   14716400 :   if (VAR_P (decl)
    2734                 :   14716400 :       && TREE_PUBLIC (decl)
    2735                 :    1559500 :       && (DECL_TINFO_P (decl) || DECL_VTABLE_OR_VTT_P (decl))
    2736                 :     273885 :       && !DECL_REALLY_EXTERN (decl)
    2737                 :   14990300 :       && !CLASSTYPE_VISIBILITY_SPECIFIED (class_type))
    2738                 :      82816 :     targetm.cxx.determine_class_data_visibility (decl);
    2739                 :            : }
    2740                 :            : 
    2741                 :            : /* Returns true iff DECL is an inline that should get hidden visibility
    2742                 :            :    because of -fvisibility-inlines-hidden.  */
    2743                 :            : 
    2744                 :            : static bool
    2745                 :   40002200 : determine_hidden_inline (tree decl)
    2746                 :            : {
    2747                 :   40002200 :   return (visibility_options.inlines_hidden
    2748                 :            :           /* Don't do this for inline templates; specializations might not be
    2749                 :            :              inline, and we don't want them to inherit the hidden
    2750                 :            :              visibility.  We'll set it here for all inline instantiations.  */
    2751                 :        561 :           && !processing_template_decl
    2752                 :        529 :           && TREE_CODE (decl) == FUNCTION_DECL
    2753                 :        387 :           && DECL_DECLARED_INLINE_P (decl)
    2754                 :   40002500 :           && (! DECL_LANG_SPECIFIC (decl)
    2755                 :        277 :               || ! DECL_EXPLICIT_INSTANTIATION (decl)));
    2756                 :            : }
    2757                 :            : 
    2758                 :            : /* Constrain the visibility of a class TYPE based on the visibility of its
    2759                 :            :    field types.  Warn if any fields require lesser visibility.  */
    2760                 :            : 
    2761                 :            : void
    2762                 :   11678000 : constrain_class_visibility (tree type)
    2763                 :            : {
    2764                 :   11678000 :   tree binfo;
    2765                 :   11678000 :   tree t;
    2766                 :   11678000 :   int i;
    2767                 :            : 
    2768                 :   11678000 :   int vis = type_visibility (type);
    2769                 :            : 
    2770                 :   11678000 :   if (vis == VISIBILITY_ANON
    2771                 :   23177200 :       || DECL_IN_SYSTEM_HEADER (TYPE_MAIN_DECL (type)))
    2772                 :   11353300 :     return;
    2773                 :            : 
    2774                 :            :   /* Don't warn about visibility if the class has explicit visibility.  */
    2775                 :     324698 :   if (CLASSTYPE_VISIBILITY_SPECIFIED (type))
    2776                 :      31288 :     vis = VISIBILITY_INTERNAL;
    2777                 :            : 
    2778                 :    2537250 :   for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
    2779                 :     430437 :     if (TREE_CODE (t) == FIELD_DECL && TREE_TYPE (t) != error_mark_node
    2780                 :    2632440 :         && !DECL_ARTIFICIAL (t))
    2781                 :            :       {
    2782                 :     375987 :         tree ftype = strip_pointer_or_array_types (TREE_TYPE (t));
    2783                 :     375987 :         int subvis = type_visibility (ftype);
    2784                 :            : 
    2785                 :     375987 :         if (subvis == VISIBILITY_ANON)
    2786                 :            :           {
    2787                 :         98 :             if (!in_main_input_context())
    2788                 :            :               {
    2789                 :         36 :                 tree nlt = no_linkage_check (ftype, /*relaxed_p=*/false);
    2790                 :         36 :                 if (nlt)
    2791                 :            :                   {
    2792                 :          8 :                     if (same_type_p (TREE_TYPE (t), nlt))
    2793                 :          8 :                       warning (OPT_Wsubobject_linkage, "\
    2794                 :            : %qT has a field %qD whose type has no linkage",
    2795                 :            :                                type, t);
    2796                 :            :                     else
    2797                 :          0 :                       warning (OPT_Wsubobject_linkage, "\
    2798                 :            : %qT has a field %qD whose type depends on the type %qT which has no linkage",
    2799                 :            :                                type, t, nlt);
    2800                 :            :                   }
    2801                 :            :                 else
    2802                 :         28 :                   warning (OPT_Wsubobject_linkage, "\
    2803                 :            : %qT has a field %qD whose type uses the anonymous namespace",
    2804                 :            :                            type, t);
    2805                 :            :               }
    2806                 :            :           }
    2807                 :     461970 :         else if (MAYBE_CLASS_TYPE_P (ftype)
    2808                 :      85726 :                  && vis < VISIBILITY_HIDDEN
    2809                 :     461615 :                  && subvis >= VISIBILITY_HIDDEN)
    2810                 :          8 :           warning (OPT_Wattributes, "\
    2811                 :            : %qT declared with greater visibility than the type of its field %qD",
    2812                 :            :                    type, t);
    2813                 :            :       }
    2814                 :            : 
    2815                 :     324698 :   binfo = TYPE_BINFO (type);
    2816                 :     375315 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, t); ++i)
    2817                 :            :     {
    2818                 :      50617 :       int subvis = type_visibility (TREE_TYPE (t));
    2819                 :            : 
    2820                 :      50617 :       if (subvis == VISIBILITY_ANON)
    2821                 :            :         {
    2822                 :         34 :           if (!in_main_input_context())
    2823                 :            :             {
    2824                 :         20 :               tree nlt = no_linkage_check (TREE_TYPE (t), /*relaxed_p=*/false);
    2825                 :         20 :               if (nlt)
    2826                 :            :                 {
    2827                 :          8 :                   if (same_type_p (TREE_TYPE (t), nlt))
    2828                 :         16 :                     warning (OPT_Wsubobject_linkage, "\
    2829                 :            : %qT has a base %qT whose type has no linkage",
    2830                 :          8 :                              type, TREE_TYPE (t));
    2831                 :            :                   else
    2832                 :          0 :                     warning (OPT_Wsubobject_linkage, "\
    2833                 :            : %qT has a base %qT whose type depends on the type %qT which has no linkage",
    2834                 :          0 :                              type, TREE_TYPE (t), nlt);
    2835                 :            :                 }
    2836                 :            :               else
    2837                 :         24 :                 warning (OPT_Wsubobject_linkage, "\
    2838                 :            : %qT has a base %qT whose type uses the anonymous namespace",
    2839                 :         12 :                          type, TREE_TYPE (t));
    2840                 :            :             }
    2841                 :            :         }
    2842                 :      50583 :       else if (vis < VISIBILITY_HIDDEN
    2843                 :      50583 :                && subvis >= VISIBILITY_HIDDEN)
    2844                 :         16 :         warning (OPT_Wattributes, "\
    2845                 :            : %qT declared with greater visibility than its base %qT",
    2846                 :          8 :                  type, TREE_TYPE (t));
    2847                 :            :     }
    2848                 :            : }
    2849                 :            : 
    2850                 :            : /* Functions for adjusting the visibility of a tagged type and its nested
    2851                 :            :    types and declarations when it gets a name for linkage purposes from a
    2852                 :            :    typedef.  */
    2853                 :            : 
    2854                 :            : static void bt_reset_linkage_1 (binding_entry, void *);
    2855                 :            : static void bt_reset_linkage_2 (binding_entry, void *);
    2856                 :            : 
    2857                 :            : /* First reset the visibility of all the types.  */
    2858                 :            : 
    2859                 :            : static void
    2860                 :      92885 : reset_type_linkage_1 (tree type)
    2861                 :            : {
    2862                 :      92885 :   set_linkage_according_to_type (type, TYPE_MAIN_DECL (type));
    2863                 :     184494 :   if (CLASS_TYPE_P (type))
    2864                 :      91609 :     binding_table_foreach (CLASSTYPE_NESTED_UTDS (type),
    2865                 :            :                            bt_reset_linkage_1, NULL);
    2866                 :      92885 : }
    2867                 :            : static void
    2868                 :       8144 : bt_reset_linkage_1 (binding_entry b, void */*data*/)
    2869                 :            : {
    2870                 :       8144 :   reset_type_linkage_1 (b->type);
    2871                 :       8144 : }
    2872                 :            : 
    2873                 :            : /* Then reset the visibility of any static data members or member
    2874                 :            :    functions that use those types.  */
    2875                 :            : 
    2876                 :            : static void
    2877                 :         96 : reset_decl_linkage (tree decl)
    2878                 :            : {
    2879                 :         96 :   if (TREE_PUBLIC (decl))
    2880                 :            :     return;
    2881                 :         96 :   if (DECL_CLONED_FUNCTION_P (decl))
    2882                 :            :     return;
    2883                 :         96 :   TREE_PUBLIC (decl) = true;
    2884                 :         96 :   DECL_INTERFACE_KNOWN (decl) = false;
    2885                 :         96 :   determine_visibility (decl);
    2886                 :         96 :   tentative_decl_linkage (decl);
    2887                 :            : }
    2888                 :            : 
    2889                 :            : static void
    2890                 :      92885 : reset_type_linkage_2 (tree type)
    2891                 :            : {
    2892                 :     184494 :   if (CLASS_TYPE_P (type))
    2893                 :            :     {
    2894                 :      91609 :       if (tree vt = CLASSTYPE_VTABLES (type))
    2895                 :            :         {
    2896                 :         16 :           tree name = mangle_vtbl_for_type (type);
    2897                 :         16 :           DECL_NAME (vt) = name;
    2898                 :         16 :           SET_DECL_ASSEMBLER_NAME (vt, name);
    2899                 :         16 :           reset_decl_linkage (vt);
    2900                 :            :         }
    2901                 :      91609 :       if (tree ti = CLASSTYPE_TYPEINFO_VAR (type))
    2902                 :            :         {
    2903                 :         16 :           tree name = mangle_typeinfo_for_type (type);
    2904                 :         16 :           DECL_NAME (ti) = name;
    2905                 :         16 :           SET_DECL_ASSEMBLER_NAME (ti, name);
    2906                 :         16 :           TREE_TYPE (name) = type;
    2907                 :         16 :           reset_decl_linkage (ti);
    2908                 :            :         }
    2909                 :     421456 :       for (tree m = TYPE_FIELDS (type); m; m = DECL_CHAIN (m))
    2910                 :            :         {
    2911                 :     286721 :           tree mem = STRIP_TEMPLATE (m);
    2912                 :     286721 :           if (TREE_CODE (mem) == VAR_DECL || TREE_CODE (mem) == FUNCTION_DECL)
    2913                 :         64 :             reset_decl_linkage (mem);
    2914                 :            :         }
    2915                 :      91609 :       binding_table_foreach (CLASSTYPE_NESTED_UTDS (type),
    2916                 :            :                              bt_reset_linkage_2, NULL);
    2917                 :            :     }
    2918                 :      92885 : }
    2919                 :            : 
    2920                 :            : static void
    2921                 :       8144 : bt_reset_linkage_2 (binding_entry b, void */*data*/)
    2922                 :            : {
    2923                 :       8144 :   reset_type_linkage_2 (b->type);
    2924                 :       8144 : }
    2925                 :            : void
    2926                 :      84741 : reset_type_linkage (tree type)
    2927                 :            : {
    2928                 :      84741 :   reset_type_linkage_1 (type);
    2929                 :      84741 :   reset_type_linkage_2 (type);
    2930                 :      84741 : }
    2931                 :            : 
    2932                 :            : /* Set up our initial idea of what the linkage of DECL should be.  */
    2933                 :            : 
    2934                 :            : void
    2935                 :    1938760 : tentative_decl_linkage (tree decl)
    2936                 :            : {
    2937                 :    1938760 :   if (DECL_INTERFACE_KNOWN (decl))
    2938                 :            :     /* We've already made a decision as to how this function will
    2939                 :            :        be handled.  */;
    2940                 :    1938760 :   else if (vague_linkage_p (decl))
    2941                 :            :     {
    2942                 :    1938720 :       if (TREE_CODE (decl) == FUNCTION_DECL
    2943                 :    1938720 :           && decl_defined_p (decl))
    2944                 :            :         {
    2945                 :    1938720 :           DECL_EXTERNAL (decl) = 1;
    2946                 :    1938720 :           DECL_NOT_REALLY_EXTERN (decl) = 1;
    2947                 :    1938720 :           note_vague_linkage_fn (decl);
    2948                 :            :           /* A non-template inline function with external linkage will
    2949                 :            :              always be COMDAT.  As we must eventually determine the
    2950                 :            :              linkage of all functions, and as that causes writes to
    2951                 :            :              the data mapped in from the PCH file, it's advantageous
    2952                 :            :              to mark the functions at this point.  */
    2953                 :    1938720 :           if (DECL_DECLARED_INLINE_P (decl)
    2954                 :    1937420 :               && (!DECL_IMPLICIT_INSTANTIATION (decl)
    2955                 :    2173400 :                   || DECL_DEFAULTED_FN (decl)))
    2956                 :            :             {
    2957                 :            :               /* This function must have external linkage, as
    2958                 :            :                  otherwise DECL_INTERFACE_KNOWN would have been
    2959                 :            :                  set.  */
    2960                 :    1712910 :               gcc_assert (TREE_PUBLIC (decl));
    2961                 :    1712910 :               comdat_linkage (decl);
    2962                 :    1712910 :               DECL_INTERFACE_KNOWN (decl) = 1;
    2963                 :            :             }
    2964                 :            :         }
    2965                 :          8 :       else if (VAR_P (decl))
    2966                 :          8 :         maybe_commonize_var (decl);
    2967                 :            :     }
    2968                 :    1938760 : }
    2969                 :            : 
    2970                 :            : /* DECL is a FUNCTION_DECL or VAR_DECL.  If the object file linkage
    2971                 :            :    for DECL has not already been determined, do so now by setting
    2972                 :            :    DECL_EXTERNAL, DECL_COMDAT and other related flags.  Until this
    2973                 :            :    function is called entities with vague linkage whose definitions
    2974                 :            :    are available must have TREE_PUBLIC set.
    2975                 :            : 
    2976                 :            :    If this function decides to place DECL in COMDAT, it will set
    2977                 :            :    appropriate flags -- but will not clear DECL_EXTERNAL.  It is up to
    2978                 :            :    the caller to decide whether or not to clear DECL_EXTERNAL.  Some
    2979                 :            :    callers defer that decision until it is clear that DECL is actually
    2980                 :            :    required.  */
    2981                 :            : 
    2982                 :            : void
    2983                 :   57488100 : import_export_decl (tree decl)
    2984                 :            : {
    2985                 :   57488100 :   bool comdat_p;
    2986                 :   57488100 :   bool import_p;
    2987                 :   57488100 :   tree class_type = NULL_TREE;
    2988                 :            : 
    2989                 :   57488100 :   if (DECL_INTERFACE_KNOWN (decl))
    2990                 :            :     return;
    2991                 :            : 
    2992                 :            :   /* We cannot determine what linkage to give to an entity with vague
    2993                 :            :      linkage until the end of the file.  For example, a virtual table
    2994                 :            :      for a class will be defined if and only if the key method is
    2995                 :            :      defined in this translation unit.  */
    2996                 :    9534500 :   gcc_assert (at_eof);
    2997                 :            :   /* Object file linkage for explicit instantiations is handled in
    2998                 :            :      mark_decl_instantiated.  For static variables in functions with
    2999                 :            :      vague linkage, maybe_commonize_var is used.
    3000                 :            : 
    3001                 :            :      Therefore, the only declarations that should be provided to this
    3002                 :            :      function are those with external linkage that are:
    3003                 :            : 
    3004                 :            :      * implicit instantiations of function templates
    3005                 :            : 
    3006                 :            :      * inline function
    3007                 :            : 
    3008                 :            :      * implicit instantiations of static data members of class
    3009                 :            :        templates
    3010                 :            : 
    3011                 :            :      * virtual tables
    3012                 :            : 
    3013                 :            :      * typeinfo objects
    3014                 :            : 
    3015                 :            :      Furthermore, all entities that reach this point must have a
    3016                 :            :      definition available in this translation unit.
    3017                 :            : 
    3018                 :            :      The following assertions check these conditions.  */
    3019                 :    9534500 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
    3020                 :            :   /* Any code that creates entities with TREE_PUBLIC cleared should
    3021                 :            :      also set DECL_INTERFACE_KNOWN.  */
    3022                 :    9534500 :   gcc_assert (TREE_PUBLIC (decl));
    3023                 :    9534500 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    3024                 :    6871870 :     gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl)
    3025                 :            :                 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
    3026                 :            :                 || DECL_DECLARED_INLINE_P (decl));
    3027                 :            :   else
    3028                 :    4783880 :     gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl)
    3029                 :            :                 || DECL_VTABLE_OR_VTT_P (decl)
    3030                 :            :                 || DECL_TINFO_P (decl));
    3031                 :            :   /* Check that a definition of DECL is available in this translation
    3032                 :            :      unit.  */
    3033                 :    9534500 :   gcc_assert (!DECL_REALLY_EXTERN (decl));
    3034                 :            : 
    3035                 :            :   /* Assume that DECL will not have COMDAT linkage.  */
    3036                 :    9534500 :   comdat_p = false;
    3037                 :            :   /* Assume that DECL will not be imported into this translation
    3038                 :            :      unit.  */
    3039                 :    9534500 :   import_p = false;
    3040                 :            : 
    3041                 :    9534500 :   if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
    3042                 :            :     {
    3043                 :     934391 :       class_type = DECL_CONTEXT (decl);
    3044                 :     934391 :       import_export_class (class_type);
    3045                 :     934391 :       if (CLASSTYPE_INTERFACE_KNOWN (class_type)
    3046                 :     934391 :           && CLASSTYPE_INTERFACE_ONLY (class_type))
    3047                 :            :         import_p = true;
    3048                 :     209236 :       else if ((!flag_weak || TARGET_WEAK_NOT_IN_ARCHIVE_TOC)
    3049                 :          4 :                && !CLASSTYPE_USE_TEMPLATE (class_type)
    3050                 :          4 :                && CLASSTYPE_KEY_METHOD (class_type)
    3051                 :     209236 :                && !DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (class_type)))
    3052                 :            :         /* The ABI requires that all virtual tables be emitted with
    3053                 :            :            COMDAT linkage.  However, on systems where COMDAT symbols
    3054                 :            :            don't show up in the table of contents for a static
    3055                 :            :            archive, or on systems without weak symbols (where we
    3056                 :            :            approximate COMDAT linkage by using internal linkage), the
    3057                 :            :            linker will report errors about undefined symbols because
    3058                 :            :            it will not see the virtual table definition.  Therefore,
    3059                 :            :            in the case that we know that the virtual table will be
    3060                 :            :            emitted in only one translation unit, we make the virtual
    3061                 :            :            table an ordinary definition with external linkage.  */
    3062                 :          0 :         DECL_EXTERNAL (decl) = 0;
    3063                 :     209236 :       else if (CLASSTYPE_INTERFACE_KNOWN (class_type))
    3064                 :            :         {
    3065                 :            :           /* CLASS_TYPE is being exported from this translation unit,
    3066                 :            :              so DECL should be defined here.  */
    3067                 :       3107 :           if (!flag_weak && CLASSTYPE_EXPLICIT_INSTANTIATION (class_type))
    3068                 :            :             /* If a class is declared in a header with the "extern
    3069                 :            :                template" extension, then it will not be instantiated,
    3070                 :            :                even in translation units that would normally require
    3071                 :            :                it.  Often such classes are explicitly instantiated in
    3072                 :            :                one translation unit.  Therefore, the explicit
    3073                 :            :                instantiation must be made visible to other translation
    3074                 :            :                units.  */
    3075                 :          0 :             DECL_EXTERNAL (decl) = 0;
    3076                 :            :           else
    3077                 :            :             {
    3078                 :            :               /* The generic C++ ABI says that class data is always
    3079                 :            :                  COMDAT, even if there is a key function.  Some
    3080                 :            :                  variants (e.g., the ARM EABI) says that class data
    3081                 :            :                  only has COMDAT linkage if the class data might be
    3082                 :            :                  emitted in more than one translation unit.  When the
    3083                 :            :                  key method can be inline and is inline, we still have
    3084                 :            :                  to arrange for comdat even though
    3085                 :            :                  class_data_always_comdat is false.  */
    3086                 :       3107 :               if (!CLASSTYPE_KEY_METHOD (class_type)
    3087                 :       2480 :                   || DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (class_type))
    3088                 :       5562 :                   || targetm.cxx.class_data_always_comdat ())
    3089                 :            :                 {
    3090                 :            :                   /* The ABI requires COMDAT linkage.  Normally, we
    3091                 :            :                      only emit COMDAT things when they are needed;
    3092                 :            :                      make sure that we realize that this entity is
    3093                 :            :                      indeed needed.  */
    3094                 :       3107 :                   comdat_p = true;
    3095                 :       3107 :                   mark_needed (decl);
    3096                 :            :                 }
    3097                 :            :             }
    3098                 :            :         }
    3099                 :     206129 :       else if (!flag_implicit_templates
    3100                 :     206129 :                && CLASSTYPE_IMPLICIT_INSTANTIATION (class_type))
    3101                 :            :         import_p = true;
    3102                 :            :       else
    3103                 :            :         comdat_p = true;
    3104                 :            :     }
    3105                 :    8600100 :   else if (VAR_P (decl) && DECL_TINFO_P (decl))
    3106                 :            :     {
    3107                 :    1186870 :       tree type = TREE_TYPE (DECL_NAME (decl));
    3108                 :    2371590 :       if (CLASS_TYPE_P (type))
    3109                 :            :         {
    3110                 :    1184610 :           class_type = type;
    3111                 :    1184610 :           import_export_class (type);
    3112                 :    1184610 :           if (CLASSTYPE_INTERFACE_KNOWN (type)
    3113                 :     801957 :               && TYPE_POLYMORPHIC_P (type)
    3114                 :     801857 :               && CLASSTYPE_INTERFACE_ONLY (type)
    3115                 :            :               /* If -fno-rtti was specified, then we cannot be sure
    3116                 :            :                  that RTTI information will be emitted with the
    3117                 :            :                  virtual table of the class, so we must emit it
    3118                 :            :                  wherever it is used.  */
    3119                 :    1982220 :               && flag_rtti)
    3120                 :            :             import_p = true;
    3121                 :            :           else
    3122                 :            :             {
    3123                 :     387104 :               if (CLASSTYPE_INTERFACE_KNOWN (type)
    3124                 :     387104 :                   && !CLASSTYPE_INTERFACE_ONLY (type))
    3125                 :            :                 {
    3126                 :       4280 :                   comdat_p = (targetm.cxx.class_data_always_comdat ()
    3127                 :       4280 :                               || (CLASSTYPE_KEY_METHOD (type)
    3128                 :          0 :                                   && DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (type))));
    3129                 :       4280 :                   mark_needed (decl);
    3130                 :       4280 :                   if (!flag_weak)
    3131                 :            :                     {
    3132                 :          0 :                       comdat_p = false;
    3133                 :          0 :                       DECL_EXTERNAL (decl) = 0;
    3134                 :            :                     }
    3135                 :            :                 }
    3136                 :            :               else
    3137                 :            :                 comdat_p = true;
    3138                 :            :             }
    3139                 :            :         }
    3140                 :            :       else
    3141                 :            :         comdat_p = true;
    3142                 :            :     }
    3143                 :    7413240 :   else if (DECL_TEMPLOID_INSTANTIATION (decl))
    3144                 :            :     {
    3145                 :            :       /* DECL is an implicit instantiation of a function or static
    3146                 :            :          data member.  */
    3147                 :    7257330 :       if (flag_implicit_templates
    3148                 :    7257330 :           || (flag_implicit_inline_templates
    3149                 :      18949 :               && TREE_CODE (decl) == FUNCTION_DECL
    3150                 :      16895 :               && DECL_DECLARED_INLINE_P (decl)))
    3151                 :            :         comdat_p = true;
    3152                 :            :       else
    3153                 :            :         /* If we are not implicitly generating templates, then mark
    3154                 :            :            this entity as undefined in this translation unit.  */
    3155                 :            :         import_p = true;
    3156                 :            :     }
    3157                 :     156326 :   else if (DECL_FUNCTION_MEMBER_P (decl))
    3158                 :            :     {
    3159                 :     155480 :       if (!DECL_DECLARED_INLINE_P (decl))
    3160                 :            :         {
    3161                 :          0 :           tree ctype = DECL_CONTEXT (decl);
    3162                 :          0 :           import_export_class (ctype);
    3163                 :          0 :           if (CLASSTYPE_INTERFACE_KNOWN (ctype))
    3164                 :            :             {
    3165                 :          0 :               DECL_NOT_REALLY_EXTERN (decl)
    3166                 :          0 :                 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
    3167                 :          0 :                      || (DECL_DECLARED_INLINE_P (decl)
    3168                 :          0 :                          && ! flag_implement_inlines
    3169                 :          0 :                          && !DECL_VINDEX (decl)));
    3170                 :            : 
    3171                 :          0 :               if (!DECL_NOT_REALLY_EXTERN (decl))
    3172                 :          0 :                 DECL_EXTERNAL (decl) = 1;
    3173                 :            : 
    3174                 :            :               /* Always make artificials weak.  */
    3175                 :          0 :               if (DECL_ARTIFICIAL (decl) && flag_weak)
    3176                 :            :                 comdat_p = true;
    3177                 :            :               else
    3178                 :          0 :                 maybe_make_one_only (decl);
    3179                 :            :             }
    3180                 :            :         }
    3181                 :            :       else
    3182                 :            :         comdat_p = true;
    3183                 :            :     }
    3184                 :            :   else
    3185                 :            :     comdat_p = true;
    3186                 :            : 
    3187                 :       3107 :   if (import_p)
    3188                 :            :     {
    3189                 :            :       /* If we are importing DECL into this translation unit, mark is
    3190                 :            :          an undefined here.  */
    3191                 :    1527890 :       DECL_EXTERNAL (decl) = 1;
    3192                 :    1527890 :       DECL_NOT_REALLY_EXTERN (decl) = 0;
    3193                 :            :     }
    3194                 :    8006600 :   else if (comdat_p)
    3195                 :            :     {
    3196                 :            :       /* If we decided to put DECL in COMDAT, mark it accordingly at
    3197                 :            :          this point.  */
    3198                 :    8006600 :       comdat_linkage (decl);
    3199                 :            :     }
    3200                 :            : 
    3201                 :    9534500 :   DECL_INTERFACE_KNOWN (decl) = 1;
    3202                 :            : }
    3203                 :            : 
    3204                 :            : /* Return an expression that performs the destruction of DECL, which
    3205                 :            :    must be a VAR_DECL whose type has a non-trivial destructor, or is
    3206                 :            :    an array whose (innermost) elements have a non-trivial destructor.  */
    3207                 :            : 
    3208                 :            : tree
    3209                 :        822 : build_cleanup (tree decl)
    3210                 :            : {
    3211                 :        822 :   tree clean = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
    3212                 :        822 :   gcc_assert (clean != NULL_TREE);
    3213                 :        822 :   return clean;
    3214                 :            : }
    3215                 :            : 
    3216                 :            : /* GUARD is a helper variable for DECL; make them have the same linkage and
    3217                 :            :    visibility.  */
    3218                 :            : 
    3219                 :            : void
    3220                 :       3976 : copy_linkage (tree guard, tree decl)
    3221                 :            : {
    3222                 :       3976 :   TREE_PUBLIC (guard) = TREE_PUBLIC (decl);
    3223                 :       3976 :   TREE_STATIC (guard) = TREE_STATIC (decl);
    3224                 :       3976 :   DECL_COMMON (guard) = DECL_COMMON (decl);
    3225                 :       3976 :   DECL_COMDAT (guard) = DECL_COMDAT (decl);
    3226                 :       3976 :   if (TREE_STATIC (guard))
    3227                 :            :     {
    3228                 :       3787 :       CP_DECL_THREAD_LOCAL_P (guard) = CP_DECL_THREAD_LOCAL_P (decl);
    3229                 :       3787 :       set_decl_tls_model (guard, DECL_TLS_MODEL (decl));
    3230                 :       3787 :       if (DECL_ONE_ONLY (decl))
    3231                 :       2948 :         make_decl_one_only (guard, cxx_comdat_group (guard));
    3232                 :       3787 :       if (TREE_PUBLIC (decl))
    3233                 :       3266 :         DECL_WEAK (guard) = DECL_WEAK (decl);
    3234                 :            :       /* Also check vague_linkage_p, as DECL_WEAK and DECL_ONE_ONLY might not
    3235                 :            :          be set until import_export_decl at EOF.  */
    3236                 :       3787 :       if (vague_linkage_p (decl))
    3237                 :       2964 :         comdat_linkage (guard);
    3238                 :       3787 :       DECL_VISIBILITY (guard) = DECL_VISIBILITY (decl);
    3239                 :       3787 :       DECL_VISIBILITY_SPECIFIED (guard) = DECL_VISIBILITY_SPECIFIED (decl);
    3240                 :            :     }
    3241                 :       3976 : }
    3242                 :            : 
    3243                 :            : /* Returns the initialization guard variable for the variable DECL,
    3244                 :            :    which has static storage duration.  */
    3245                 :            : 
    3246                 :            : tree
    3247                 :       3352 : get_guard (tree decl)
    3248                 :            : {
    3249                 :       3352 :   tree sname;
    3250                 :       3352 :   tree guard;
    3251                 :            : 
    3252                 :       3352 :   sname = mangle_guard_variable (decl);
    3253                 :       3352 :   guard = get_global_binding (sname);
    3254                 :       3352 :   if (! guard)
    3255                 :            :     {
    3256                 :       3352 :       tree guard_type;
    3257                 :            : 
    3258                 :            :       /* We use a type that is big enough to contain a mutex as well
    3259                 :            :          as an integer counter.  */
    3260                 :       3352 :       guard_type = targetm.cxx.guard_type ();
    3261                 :       3352 :       guard = build_decl (DECL_SOURCE_LOCATION (decl),
    3262                 :            :                           VAR_DECL, sname, guard_type);
    3263                 :            : 
    3264                 :            :       /* The guard should have the same linkage as what it guards.  */
    3265                 :       3352 :       copy_linkage (guard, decl);
    3266                 :            : 
    3267                 :       3352 :       DECL_ARTIFICIAL (guard) = 1;
    3268                 :       3352 :       DECL_IGNORED_P (guard) = 1;
    3269                 :       3352 :       TREE_USED (guard) = 1;
    3270                 :       3352 :       pushdecl_top_level_and_finish (guard, NULL_TREE);
    3271                 :            :     }
    3272                 :       3352 :   return guard;
    3273                 :            : }
    3274                 :            : 
    3275                 :            : /* Return an atomic load of src with the appropriate memory model.  */
    3276                 :            : 
    3277                 :            : static tree
    3278                 :       2530 : build_atomic_load_byte (tree src, HOST_WIDE_INT model)
    3279                 :            : {
    3280                 :       2530 :   tree ptr_type = build_pointer_type (char_type_node);
    3281                 :       2530 :   tree mem_model = build_int_cst (integer_type_node, model);
    3282                 :       2530 :   tree t, addr, val;
    3283                 :       2530 :   unsigned int size;
    3284                 :       2530 :   int fncode;
    3285                 :            : 
    3286                 :       2530 :   size = tree_to_uhwi (TYPE_SIZE_UNIT (char_type_node));
    3287                 :            : 
    3288                 :       2530 :   fncode = BUILT_IN_ATOMIC_LOAD_N + exact_log2 (size) + 1;
    3289                 :       2530 :   t = builtin_decl_implicit ((enum built_in_function) fncode);
    3290                 :            : 
    3291                 :       2530 :   addr = build1 (ADDR_EXPR, ptr_type, src);
    3292                 :       2530 :   val = build_call_expr (t, 2, addr, mem_model);
    3293                 :       2530 :   return val;
    3294                 :            : }
    3295                 :            : 
    3296                 :            : /* Return those bits of the GUARD variable that should be set when the
    3297                 :            :    guarded entity is actually initialized.  */
    3298                 :            : 
    3299                 :            : static tree
    3300                 :       1644 : get_guard_bits (tree guard)
    3301                 :            : {
    3302                 :       1644 :   if (!targetm.cxx.guard_mask_bit ())
    3303                 :            :     {
    3304                 :            :       /* We only set the first byte of the guard, in order to leave room
    3305                 :            :          for a mutex in the high-order bits.  */
    3306                 :       3288 :       guard = build1 (ADDR_EXPR,
    3307                 :       1644 :                       build_pointer_type (TREE_TYPE (guard)),
    3308                 :            :                       guard);
    3309                 :       1644 :       guard = build1 (NOP_EXPR,
    3310                 :            :                       build_pointer_type (char_type_node),
    3311                 :            :                       guard);
    3312                 :       1644 :       guard = build1 (INDIRECT_REF, char_type_node, guard);
    3313                 :            :     }
    3314                 :            : 
    3315                 :       1644 :   return guard;
    3316                 :            : }
    3317                 :            : 
    3318                 :            : /* Return an expression which determines whether or not the GUARD
    3319                 :            :    variable has already been initialized.  */
    3320                 :            : 
    3321                 :            : tree
    3322                 :       3352 : get_guard_cond (tree guard, bool thread_safe)
    3323                 :            : {
    3324                 :       3352 :   tree guard_value;
    3325                 :            : 
    3326                 :       3352 :   if (!thread_safe)
    3327                 :        822 :     guard = get_guard_bits (guard);
    3328                 :            :   else
    3329                 :       2530 :     guard = build_atomic_load_byte (guard, MEMMODEL_ACQUIRE);
    3330                 :            : 
    3331                 :            :   /* Mask off all but the low bit.  */
    3332                 :       3352 :   if (targetm.cxx.guard_mask_bit ())
    3333                 :            :     {
    3334                 :          0 :       guard_value = integer_one_node;
    3335                 :          0 :       if (!same_type_p (TREE_TYPE (guard_value), TREE_TYPE (guard)))
    3336                 :          0 :         guard_value = fold_convert (TREE_TYPE (guard), guard_value);
    3337                 :          0 :       guard = cp_build_binary_op (input_location,
    3338                 :            :                                   BIT_AND_EXPR, guard, guard_value,
    3339                 :            :                                   tf_warning_or_error);
    3340                 :            :     }
    3341                 :            : 
    3342                 :       3352 :   guard_value = integer_zero_node;
    3343                 :       3352 :   if (!same_type_p (TREE_TYPE (guard_value), TREE_TYPE (guard)))
    3344                 :       3352 :     guard_value = fold_convert (TREE_TYPE (guard), guard_value);
    3345                 :       3352 :   return cp_build_binary_op (input_location,
    3346                 :            :                              EQ_EXPR, guard, guard_value,
    3347                 :       3352 :                              tf_warning_or_error);
    3348                 :            : }
    3349                 :            : 
    3350                 :            : /* Return an expression which sets the GUARD variable, indicating that
    3351                 :            :    the variable being guarded has been initialized.  */
    3352                 :            : 
    3353                 :            : tree
    3354                 :        822 : set_guard (tree guard)
    3355                 :            : {
    3356                 :        822 :   tree guard_init;
    3357                 :            : 
    3358                 :            :   /* Set the GUARD to one.  */
    3359                 :        822 :   guard = get_guard_bits (guard);
    3360                 :        822 :   guard_init = integer_one_node;
    3361                 :        822 :   if (!same_type_p (TREE_TYPE (guard_init), TREE_TYPE (guard)))
    3362                 :        822 :     guard_init = fold_convert (TREE_TYPE (guard), guard_init);
    3363                 :        822 :   return cp_build_modify_expr (input_location, guard, NOP_EXPR, guard_init,
    3364                 :        822 :                                tf_warning_or_error);
    3365                 :            : }
    3366                 :            : 
    3367                 :            : /* Returns true iff we can tell that VAR does not have a dynamic
    3368                 :            :    initializer.  */
    3369                 :            : 
    3370                 :            : static bool
    3371                 :       1532 : var_defined_without_dynamic_init (tree var)
    3372                 :            : {
    3373                 :            :   /* If it's defined in another TU, we can't tell.  */
    3374                 :       1532 :   if (DECL_EXTERNAL (var))
    3375                 :            :     return false;
    3376                 :            :   /* If it has a non-trivial destructor, registering the destructor
    3377                 :            :      counts as dynamic initialization.  */
    3378                 :       1465 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (var)))
    3379                 :            :     return false;
    3380                 :            :   /* If it's in this TU, its initializer has been processed, unless
    3381                 :            :      it's a case of self-initialization, then DECL_INITIALIZED_P is
    3382                 :            :      false while the initializer is handled by finish_id_expression.  */
    3383                 :       1401 :   if (!DECL_INITIALIZED_P (var))
    3384                 :            :     return false;
    3385                 :            :   /* If it has no initializer or a constant one, it's not dynamic.  */
    3386                 :       1395 :   return (!DECL_NONTRIVIALLY_INITIALIZED_P (var)
    3387                 :       1395 :           || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var));
    3388                 :            : }
    3389                 :            : 
    3390                 :            : /* Returns true iff VAR is a variable that needs uses to be
    3391                 :            :    wrapped for possible dynamic initialization.  */
    3392                 :            : 
    3393                 :            : static bool
    3394                 :      39429 : var_needs_tls_wrapper (tree var)
    3395                 :            : {
    3396                 :      78858 :   return (!error_operand_p (var)
    3397                 :      39426 :           && CP_DECL_THREAD_LOCAL_P (var)
    3398                 :      39426 :           && !DECL_GNU_TLS_P (var)
    3399                 :       1570 :           && !DECL_FUNCTION_SCOPE_P (var)
    3400                 :      40961 :           && !var_defined_without_dynamic_init (var));
    3401                 :            : }
    3402                 :            : 
    3403                 :            : /* Get the FUNCTION_DECL for the shared TLS init function for this
    3404                 :            :    translation unit.  */
    3405                 :            : 
    3406                 :            : static tree
    3407                 :         99 : get_local_tls_init_fn (location_t loc)
    3408                 :            : {
    3409                 :         99 :   tree sname = get_identifier ("__tls_init");
    3410                 :         99 :   tree fn = get_global_binding (sname);
    3411                 :         99 :   if (!fn)
    3412                 :            :     {
    3413                 :         96 :       fn = build_lang_decl_loc (loc, FUNCTION_DECL, sname,
    3414                 :            :                                 build_function_type (void_type_node,
    3415                 :            :                                                      void_list_node));
    3416                 :         96 :       SET_DECL_LANGUAGE (fn, lang_c);
    3417                 :         96 :       TREE_PUBLIC (fn) = false;
    3418                 :         96 :       DECL_ARTIFICIAL (fn) = true;
    3419                 :         96 :       mark_used (fn);
    3420                 :         96 :       set_global_binding (fn);
    3421                 :            :     }
    3422                 :         99 :   return fn;
    3423                 :            : }
    3424                 :            : 
    3425                 :            : /* Get a FUNCTION_DECL for the init function for the thread_local
    3426                 :            :    variable VAR.  The init function will be an alias to the function
    3427                 :            :    that initializes all the non-local TLS variables in the translation
    3428                 :            :    unit.  The init function is only used by the wrapper function.  */
    3429                 :            : 
    3430                 :            : static tree
    3431                 :        993 : get_tls_init_fn (tree var)
    3432                 :            : {
    3433                 :            :   /* Only C++11 TLS vars need this init fn.  */
    3434                 :        993 :   if (!var_needs_tls_wrapper (var))
    3435                 :            :     return NULL_TREE;
    3436                 :            : 
    3437                 :            :   /* If -fno-extern-tls-init, assume that we don't need to call
    3438                 :            :      a tls init function for a variable defined in another TU.  */
    3439                 :        987 :   if (!flag_extern_tls_init && DECL_EXTERNAL (var))
    3440                 :            :     return NULL_TREE;
    3441                 :            : 
    3442                 :            :   /* If the variable is internal, or if we can't generate aliases,
    3443                 :            :      call the local init function directly.  */
    3444                 :        985 :   if (!TREE_PUBLIC (var) || !TARGET_SUPPORTS_ALIASES)
    3445                 :          3 :     return get_local_tls_init_fn (DECL_SOURCE_LOCATION (var));
    3446                 :            : 
    3447                 :        982 :   tree sname = mangle_tls_init_fn (var);
    3448                 :        982 :   tree fn = get_global_binding (sname);
    3449                 :        982 :   if (!fn)
    3450                 :            :     {
    3451                 :        599 :       fn = build_lang_decl (FUNCTION_DECL, sname,
    3452                 :            :                             build_function_type (void_type_node,
    3453                 :            :                                                  void_list_node));
    3454                 :        599 :       SET_DECL_LANGUAGE (fn, lang_c);
    3455                 :        599 :       TREE_PUBLIC (fn) = TREE_PUBLIC (var);
    3456                 :        599 :       DECL_ARTIFICIAL (fn) = true;
    3457                 :        599 :       DECL_COMDAT (fn) = DECL_COMDAT (var);
    3458                 :        599 :       DECL_EXTERNAL (fn) = DECL_EXTERNAL (var);
    3459                 :        599 :       if (DECL_ONE_ONLY (var))
    3460                 :          3 :         make_decl_one_only (fn, cxx_comdat_group (fn));
    3461                 :        599 :       if (TREE_PUBLIC (var))
    3462                 :            :         {
    3463                 :        599 :           tree obtype = strip_array_types (non_reference (TREE_TYPE (var)));
    3464                 :            :           /* If the variable is defined somewhere else and might have static
    3465                 :            :              initialization, make the init function a weak reference.  */
    3466                 :        599 :           if ((!TYPE_NEEDS_CONSTRUCTING (obtype)
    3467                 :        549 :                || TYPE_HAS_CONSTEXPR_CTOR (obtype)
    3468                 :        540 :                || TYPE_HAS_TRIVIAL_DFLT (obtype))
    3469                 :         59 :               && TYPE_HAS_TRIVIAL_DESTRUCTOR (obtype)
    3470                 :        649 :               && DECL_EXTERNAL (var))
    3471                 :         22 :             declare_weak (fn);
    3472                 :            :           else
    3473                 :        577 :             DECL_WEAK (fn) = DECL_WEAK (var);
    3474                 :            :         }
    3475                 :        599 :       DECL_VISIBILITY (fn) = DECL_VISIBILITY (var);
    3476                 :        599 :       DECL_VISIBILITY_SPECIFIED (fn) = DECL_VISIBILITY_SPECIFIED (var);
    3477                 :        599 :       DECL_DLLIMPORT_P (fn) = DECL_DLLIMPORT_P (var);
    3478                 :        599 :       DECL_IGNORED_P (fn) = 1;
    3479                 :        599 :       mark_used (fn);
    3480                 :            : 
    3481                 :       1198 :       DECL_BEFRIENDING_CLASSES (fn) = var;
    3482                 :            : 
    3483                 :        599 :       set_global_binding (fn);
    3484                 :            :     }
    3485                 :            :   return fn;
    3486                 :            : }
    3487                 :            : 
    3488                 :            : /* Get a FUNCTION_DECL for the init wrapper function for the thread_local
    3489                 :            :    variable VAR.  The wrapper function calls the init function (if any) for
    3490                 :            :    VAR and then returns a reference to VAR.  The wrapper function is used
    3491                 :            :    in place of VAR everywhere VAR is mentioned.  */
    3492                 :            : 
    3493                 :            : static tree
    3494                 :      38436 : get_tls_wrapper_fn (tree var)
    3495                 :            : {
    3496                 :            :   /* Only C++11 TLS vars need this wrapper fn.  */
    3497                 :      38436 :   if (!var_needs_tls_wrapper (var))
    3498                 :            :     return NULL_TREE;
    3499                 :            : 
    3500                 :        447 :   tree sname = mangle_tls_wrapper_fn (var);
    3501                 :        447 :   tree fn = get_global_binding (sname);
    3502                 :        447 :   if (!fn)
    3503                 :            :     {
    3504                 :            :       /* A named rvalue reference is an lvalue, so the wrapper should
    3505                 :            :          always return an lvalue reference.  */
    3506                 :        426 :       tree type = non_reference (TREE_TYPE (var));
    3507                 :        426 :       type = build_reference_type (type);
    3508                 :        426 :       tree fntype = build_function_type (type, void_list_node);
    3509                 :            : 
    3510                 :        426 :       fn = build_lang_decl_loc (DECL_SOURCE_LOCATION (var),
    3511                 :            :                                 FUNCTION_DECL, sname, fntype);
    3512                 :        426 :       SET_DECL_LANGUAGE (fn, lang_c);
    3513                 :        426 :       TREE_PUBLIC (fn) = TREE_PUBLIC (var);
    3514                 :        426 :       DECL_ARTIFICIAL (fn) = true;
    3515                 :        426 :       DECL_IGNORED_P (fn) = 1;
    3516                 :            :       /* The wrapper is inline and emitted everywhere var is used.  */
    3517                 :        426 :       DECL_DECLARED_INLINE_P (fn) = true;
    3518                 :        426 :       if (TREE_PUBLIC (var))
    3519                 :            :         {
    3520                 :        423 :           comdat_linkage (fn);
    3521                 :            : #ifdef HAVE_GAS_HIDDEN
    3522                 :            :           /* Make the wrapper bind locally; there's no reason to share
    3523                 :            :              the wrapper between multiple shared objects.  */
    3524                 :        423 :           DECL_VISIBILITY (fn) = VISIBILITY_INTERNAL;
    3525                 :        423 :           DECL_VISIBILITY_SPECIFIED (fn) = true;
    3526                 :            : #endif
    3527                 :            :         }
    3528                 :        426 :       if (!TREE_PUBLIC (fn))
    3529                 :          3 :         DECL_INTERFACE_KNOWN (fn) = true;
    3530                 :        426 :       mark_used (fn);
    3531                 :        426 :       note_vague_linkage_fn (fn);
    3532                 :            : 
    3533                 :            : #if 0
    3534                 :            :       /* We want CSE to commonize calls to the wrapper, but marking it as
    3535                 :            :          pure is unsafe since it has side-effects.  I guess we need a new
    3536                 :            :          ECF flag even weaker than ECF_PURE.  FIXME!  */
    3537                 :            :       DECL_PURE_P (fn) = true;
    3538                 :            : #endif
    3539                 :            : 
    3540                 :        852 :       DECL_BEFRIENDING_CLASSES (fn) = var;
    3541                 :            : 
    3542                 :        426 :       set_global_binding (fn);
    3543                 :            :     }
    3544                 :            :   return fn;
    3545                 :            : }
    3546                 :            : 
    3547                 :            : /* If EXPR is a thread_local variable that should be wrapped by init
    3548                 :            :    wrapper function, return a call to that function, otherwise return
    3549                 :            :    NULL.  */
    3550                 :            : 
    3551                 :            : tree
    3552                 :   73935200 : maybe_get_tls_wrapper_call (tree expr)
    3553                 :            : {
    3554                 :   73935200 :   if (VAR_P (expr)
    3555                 :   22451300 :       && !processing_template_decl
    3556                 :   14809100 :       && !cp_unevaluated_operand
    3557                 :   88450700 :       && CP_DECL_THREAD_LOCAL_P (expr))
    3558                 :      38436 :     if (tree wrap = get_tls_wrapper_fn (expr))
    3559                 :        447 :       return build_cxx_call (wrap, 0, NULL, tf_warning_or_error);
    3560                 :            :   return NULL;
    3561                 :            : }
    3562                 :            : 
    3563                 :            : /* At EOF, generate the definition for the TLS wrapper function FN:
    3564                 :            : 
    3565                 :            :    T& var_wrapper() {
    3566                 :            :      if (init_fn) init_fn();
    3567                 :            :      return var;
    3568                 :            :    }  */
    3569                 :            : 
    3570                 :            : static void
    3571                 :        426 : generate_tls_wrapper (tree fn)
    3572                 :            : {
    3573                 :        852 :   tree var = DECL_BEFRIENDING_CLASSES (fn);
    3574                 :            : 
    3575                 :        426 :   start_preparsed_function (fn, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
    3576                 :        426 :   tree body = begin_function_body ();
    3577                 :            :   /* Only call the init fn if there might be one.  */
    3578                 :        426 :   if (tree init_fn = get_tls_init_fn (var))
    3579                 :            :     {
    3580                 :        418 :       tree if_stmt = NULL_TREE;
    3581                 :            :       /* If init_fn is a weakref, make sure it exists before calling.  */
    3582                 :        418 :       if (lookup_attribute ("weak", DECL_ATTRIBUTES (init_fn)))
    3583                 :            :         {
    3584                 :         22 :           if_stmt = begin_if_stmt ();
    3585                 :         22 :           tree addr = cp_build_addr_expr (init_fn, tf_warning_or_error);
    3586                 :         22 :           tree cond = cp_build_binary_op (DECL_SOURCE_LOCATION (var),
    3587                 :            :                                           NE_EXPR, addr, nullptr_node,
    3588                 :            :                                           tf_warning_or_error);
    3589                 :         22 :           finish_if_stmt_cond (cond, if_stmt);
    3590                 :            :         }
    3591                 :        418 :       finish_expr_stmt (build_cxx_call
    3592                 :            :                         (init_fn, 0, NULL, tf_warning_or_error));
    3593                 :        418 :       if (if_stmt)
    3594                 :            :         {
    3595                 :         22 :           finish_then_clause (if_stmt);
    3596                 :         22 :           finish_if_stmt (if_stmt);
    3597                 :            :         }
    3598                 :            :     }
    3599                 :            :   else
    3600                 :            :     /* If there's no initialization, the wrapper is a constant function.  */
    3601                 :          8 :     TREE_READONLY (fn) = true;
    3602                 :        426 :   finish_return_stmt (convert_from_reference (var));
    3603                 :        426 :   finish_function_body (body);
    3604                 :        426 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
    3605                 :        426 : }
    3606                 :            : 
    3607                 :            : /* Start the process of running a particular set of global constructors
    3608                 :            :    or destructors.  Subroutine of do_[cd]tors.  Also called from
    3609                 :            :    vtv_start_verification_constructor_init_function.  */
    3610                 :            : 
    3611                 :            : static tree
    3612                 :      10673 : start_objects (int method_type, int initp)
    3613                 :            : {
    3614                 :      10673 :   tree body;
    3615                 :      10673 :   tree fndecl;
    3616                 :      10673 :   char type[14];
    3617                 :            : 
    3618                 :            :   /* Make ctor or dtor function.  METHOD_TYPE may be 'I' or 'D'.  */
    3619                 :            : 
    3620                 :      10673 :   if (initp != DEFAULT_INIT_PRIORITY)
    3621                 :            :     {
    3622                 :         32 :       char joiner;
    3623                 :            : 
    3624                 :            : #ifdef JOINER
    3625                 :         32 :       joiner = JOINER;
    3626                 :            : #else
    3627                 :            :       joiner = '_';
    3628                 :            : #endif
    3629                 :            : 
    3630                 :         32 :       sprintf (type, "sub_%c%c%.5u", method_type, joiner, initp);
    3631                 :            :     }
    3632                 :            :   else
    3633                 :      10641 :     sprintf (type, "sub_%c", method_type);
    3634                 :            : 
    3635                 :      10673 :   fndecl = build_lang_decl (FUNCTION_DECL,
    3636                 :            :                             get_file_function_name (type),
    3637                 :            :                             build_function_type_list (void_type_node,
    3638                 :            :                                                       NULL_TREE));
    3639                 :      10673 :   start_preparsed_function (fndecl, /*attrs=*/NULL_TREE, SF_PRE_PARSED);
    3640                 :            : 
    3641                 :      10673 :   TREE_PUBLIC (current_function_decl) = 0;
    3642                 :            : 
    3643                 :            :   /* Mark as artificial because it's not explicitly in the user's
    3644                 :            :      source code.  */
    3645                 :      10673 :   DECL_ARTIFICIAL (current_function_decl) = 1;
    3646                 :            : 
    3647                 :            :   /* Mark this declaration as used to avoid spurious warnings.  */
    3648                 :      10673 :   TREE_USED (current_function_decl) = 1;
    3649                 :            : 
    3650                 :            :   /* Mark this function as a global constructor or destructor.  */
    3651                 :      10673 :   if (method_type == 'I')
    3652                 :      21330 :     DECL_GLOBAL_CTOR_P (current_function_decl) = 1;
    3653                 :            :   else
    3654                 :         16 :     DECL_GLOBAL_DTOR_P (current_function_decl) = 1;
    3655                 :            : 
    3656                 :      10673 :   body = begin_compound_stmt (BCS_FN_BODY);
    3657                 :            : 
    3658                 :      10673 :   return body;
    3659                 :            : }
    3660                 :            : 
    3661                 :            : /* Finish the process of running a particular set of global constructors
    3662                 :            :    or destructors.  Subroutine of do_[cd]tors.  */
    3663                 :            : 
    3664                 :            : static void
    3665                 :      10661 : finish_objects (int method_type, int initp, tree body)
    3666                 :            : {
    3667                 :      10661 :   tree fn;
    3668                 :            : 
    3669                 :            :   /* Finish up.  */
    3670                 :      10661 :   finish_compound_stmt (body);
    3671                 :      10661 :   fn = finish_function (/*inline_p=*/false);
    3672                 :            : 
    3673                 :      10661 :   if (method_type == 'I')
    3674                 :            :     {
    3675                 :      10653 :       DECL_STATIC_CONSTRUCTOR (fn) = 1;
    3676                 :      10653 :       decl_init_priority_insert (fn, initp);
    3677                 :            :     }
    3678                 :            :   else
    3679                 :            :     {
    3680                 :          8 :       DECL_STATIC_DESTRUCTOR (fn) = 1;
    3681                 :          8 :       decl_fini_priority_insert (fn, initp);
    3682                 :            :     }
    3683                 :            : 
    3684                 :      10661 :   expand_or_defer_fn (fn);
    3685                 :      10661 : }
    3686                 :            : 
    3687                 :            : /* The names of the parameters to the function created to handle
    3688                 :            :    initializations and destructions for objects with static storage
    3689                 :            :    duration.  */
    3690                 :            : #define INITIALIZE_P_IDENTIFIER "__initialize_p"
    3691                 :            : #define PRIORITY_IDENTIFIER "__priority"
    3692                 :            : 
    3693                 :            : /* The name of the function we create to handle initializations and
    3694                 :            :    destructions for objects with static storage duration.  */
    3695                 :            : #define SSDF_IDENTIFIER "__static_initialization_and_destruction"
    3696                 :            : 
    3697                 :            : /* The declaration for the __INITIALIZE_P argument.  */
    3698                 :            : static GTY(()) tree initialize_p_decl;
    3699                 :            : 
    3700                 :            : /* The declaration for the __PRIORITY argument.  */
    3701                 :            : static GTY(()) tree priority_decl;
    3702                 :            : 
    3703                 :            : /* The declaration for the static storage duration function.  */
    3704                 :            : static GTY(()) tree ssdf_decl;
    3705                 :            : 
    3706                 :            : /* All the static storage duration functions created in this
    3707                 :            :    translation unit.  */
    3708                 :            : static GTY(()) vec<tree, va_gc> *ssdf_decls;
    3709                 :            : 
    3710                 :            : /* A map from priority levels to information about that priority
    3711                 :            :    level.  There may be many such levels, so efficient lookup is
    3712                 :            :    important.  */
    3713                 :            : static splay_tree priority_info_map;
    3714                 :            : 
    3715                 :            : /* Begins the generation of the function that will handle all
    3716                 :            :    initialization and destruction of objects with static storage
    3717                 :            :    duration.  The function generated takes two parameters of type
    3718                 :            :    `int': __INITIALIZE_P and __PRIORITY.  If __INITIALIZE_P is
    3719                 :            :    nonzero, it performs initializations.  Otherwise, it performs
    3720                 :            :    destructions.  It only performs those initializations or
    3721                 :            :    destructions with the indicated __PRIORITY.  The generated function
    3722                 :            :    returns no value.
    3723                 :            : 
    3724                 :            :    It is assumed that this function will only be called once per
    3725                 :            :    translation unit.  */
    3726                 :            : 
    3727                 :            : static tree
    3728                 :      10650 : start_static_storage_duration_function (unsigned count)
    3729                 :            : {
    3730                 :      10650 :   tree type;
    3731                 :      10650 :   tree body;
    3732                 :      10650 :   char id[sizeof (SSDF_IDENTIFIER) + 1 /* '\0' */ + 32];
    3733                 :            : 
    3734                 :            :   /* Create the identifier for this function.  It will be of the form
    3735                 :            :      SSDF_IDENTIFIER_<number>.  */
    3736                 :      10650 :   sprintf (id, "%s_%u", SSDF_IDENTIFIER, count);
    3737                 :            : 
    3738                 :      10650 :   type = build_function_type_list (void_type_node,
    3739                 :            :                                    integer_type_node, integer_type_node,
    3740                 :            :                                    NULL_TREE);
    3741                 :            : 
    3742                 :            :   /* Create the FUNCTION_DECL itself.  */
    3743                 :      10650 :   ssdf_decl = build_lang_decl (FUNCTION_DECL,
    3744                 :            :                                get_identifier (id),
    3745                 :            :                                type);
    3746                 :      10650 :   TREE_PUBLIC (ssdf_decl) = 0;
    3747                 :      10650 :   DECL_ARTIFICIAL (ssdf_decl) = 1;
    3748                 :            : 
    3749                 :            :   /* Put this function in the list of functions to be called from the
    3750                 :            :      static constructors and destructors.  */
    3751                 :      10650 :   if (!ssdf_decls)
    3752                 :            :     {
    3753                 :      10642 :       vec_alloc (ssdf_decls, 32);
    3754                 :            : 
    3755                 :            :       /* Take this opportunity to initialize the map from priority
    3756                 :            :          numbers to information about that priority level.  */
    3757                 :      10642 :       priority_info_map = splay_tree_new (splay_tree_compare_ints,
    3758                 :            :                                           /*delete_key_fn=*/0,
    3759                 :            :                                           /*delete_value_fn=*/
    3760                 :            :                                           splay_tree_delete_pointers);
    3761                 :            : 
    3762                 :            :       /* We always need to generate functions for the
    3763                 :            :          DEFAULT_INIT_PRIORITY so enter it now.  That way when we walk
    3764                 :            :          priorities later, we'll be sure to find the
    3765                 :            :          DEFAULT_INIT_PRIORITY.  */
    3766                 :      10642 :       get_priority_info (DEFAULT_INIT_PRIORITY);
    3767                 :            :     }
    3768                 :            : 
    3769                 :      10650 :   vec_safe_push (ssdf_decls, ssdf_decl);
    3770                 :            : 
    3771                 :            :   /* Create the argument list.  */
    3772                 :      21300 :   initialize_p_decl = cp_build_parm_decl
    3773                 :      10650 :     (ssdf_decl, get_identifier (INITIALIZE_P_IDENTIFIER), integer_type_node);
    3774                 :      10650 :   TREE_USED (initialize_p_decl) = 1;
    3775                 :      21300 :   priority_decl = cp_build_parm_decl
    3776                 :      10650 :     (ssdf_decl, get_identifier (PRIORITY_IDENTIFIER), integer_type_node);
    3777                 :      10650 :   TREE_USED (priority_decl) = 1;
    3778                 :            : 
    3779                 :      10650 :   DECL_CHAIN (initialize_p_decl) = priority_decl;
    3780                 :      10650 :   DECL_ARGUMENTS (ssdf_decl) = initialize_p_decl;
    3781                 :            : 
    3782                 :            :   /* Put the function in the global scope.  */
    3783                 :      10650 :   pushdecl (ssdf_decl);
    3784                 :            : 
    3785                 :            :   /* Start the function itself.  This is equivalent to declaring the
    3786                 :            :      function as:
    3787                 :            : 
    3788                 :            :        static void __ssdf (int __initialize_p, init __priority_p);
    3789                 :            : 
    3790                 :            :      It is static because we only need to call this function from the
    3791                 :            :      various constructor and destructor functions for this module.  */
    3792                 :      10650 :   start_preparsed_function (ssdf_decl,
    3793                 :            :                             /*attrs=*/NULL_TREE,
    3794                 :            :                             SF_PRE_PARSED);
    3795                 :            : 
    3796                 :            :   /* Set up the scope of the outermost block in the function.  */
    3797                 :      10650 :   body = begin_compound_stmt (BCS_FN_BODY);
    3798                 :            : 
    3799                 :      10650 :   return body;
    3800                 :            : }
    3801                 :            : 
    3802                 :            : /* Finish the generation of the function which performs initialization
    3803                 :            :    and destruction of objects with static storage duration.  After
    3804                 :            :    this point, no more such objects can be created.  */
    3805                 :            : 
    3806                 :            : static void
    3807                 :      10650 : finish_static_storage_duration_function (tree body)
    3808                 :            : {
    3809                 :            :   /* Close out the function.  */
    3810                 :      10650 :   finish_compound_stmt (body);
    3811                 :      10650 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
    3812                 :      10650 : }
    3813                 :            : 
    3814                 :            : /* Return the information about the indicated PRIORITY level.  If no
    3815                 :            :    code to handle this level has yet been generated, generate the
    3816                 :            :    appropriate prologue.  */
    3817                 :            : 
    3818                 :            : static priority_info
    3819                 :      21311 : get_priority_info (int priority)
    3820                 :            : {
    3821                 :      21311 :   priority_info pi;
    3822                 :      21311 :   splay_tree_node n;
    3823                 :            : 
    3824                 :      21311 :   n = splay_tree_lookup (priority_info_map,
    3825                 :            :                          (splay_tree_key) priority);
    3826                 :      21311 :   if (!n)
    3827                 :            :     {
    3828                 :            :       /* Create a new priority information structure, and insert it
    3829                 :            :          into the map.  */
    3830                 :      10662 :       pi = XNEW (struct priority_info_s);
    3831                 :      10662 :       pi->initializations_p = 0;
    3832                 :      10662 :       pi->destructions_p = 0;
    3833                 :      10662 :       splay_tree_insert (priority_info_map,
    3834                 :            :                          (splay_tree_key) priority,
    3835                 :            :                          (splay_tree_value) pi);
    3836                 :            :     }
    3837                 :            :   else
    3838                 :      10649 :     pi = (priority_info) n->value;
    3839                 :            : 
    3840                 :      21311 :   return pi;
    3841                 :            : }
    3842                 :            : 
    3843                 :            : /* The effective initialization priority of a DECL.  */
    3844                 :            : 
    3845                 :            : #define DECL_EFFECTIVE_INIT_PRIORITY(decl)                                    \
    3846                 :            :         ((!DECL_HAS_INIT_PRIORITY_P (decl) || DECL_INIT_PRIORITY (decl) == 0) \
    3847                 :            :          ? DEFAULT_INIT_PRIORITY : DECL_INIT_PRIORITY (decl))
    3848                 :            : 
    3849                 :            : /* Whether a DECL needs a guard to protect it against multiple
    3850                 :            :    initialization.  */
    3851                 :            : 
    3852                 :            : #define NEEDS_GUARD_P(decl) (TREE_PUBLIC (decl) && (DECL_COMMON (decl)      \
    3853                 :            :                                                     || DECL_ONE_ONLY (decl) \
    3854                 :            :                                                     || DECL_WEAK (decl)))
    3855                 :            : 
    3856                 :            : /* Called from one_static_initialization_or_destruction(),
    3857                 :            :    via walk_tree.
    3858                 :            :    Walks the initializer list of a global variable and looks for
    3859                 :            :    temporary variables (DECL_NAME() == NULL and DECL_ARTIFICIAL != 0)
    3860                 :            :    and that have their DECL_CONTEXT() == NULL.
    3861                 :            :    For each such temporary variable, set their DECL_CONTEXT() to
    3862                 :            :    the current function. This is necessary because otherwise
    3863                 :            :    some optimizers (enabled by -O2 -fprofile-arcs) might crash
    3864                 :            :    when trying to refer to a temporary variable that does not have
    3865                 :            :    it's DECL_CONTECT() properly set.  */
    3866                 :            : static tree 
    3867                 :     279489 : fix_temporary_vars_context_r (tree *node,
    3868                 :            :                               int  * /*unused*/,
    3869                 :            :                               void * /*unused1*/)
    3870                 :            : {
    3871                 :     279489 :   gcc_assert (current_function_decl);
    3872                 :            : 
    3873                 :     279489 :   if (TREE_CODE (*node) == BIND_EXPR)
    3874                 :            :     {
    3875                 :        398 :       tree var;
    3876                 :            : 
    3877                 :        796 :       for (var = BIND_EXPR_VARS (*node); var; var = DECL_CHAIN (var))
    3878                 :        398 :         if (VAR_P (var)
    3879                 :        398 :           && !DECL_NAME (var)
    3880                 :        398 :           && DECL_ARTIFICIAL (var)
    3881                 :        796 :           && !DECL_CONTEXT (var))
    3882                 :        398 :           DECL_CONTEXT (var) = current_function_decl;
    3883                 :            :     }
    3884                 :            : 
    3885                 :     279489 :   return NULL_TREE;
    3886                 :            : }
    3887                 :            : 
    3888                 :            : /* Set up to handle the initialization or destruction of DECL.  If
    3889                 :            :    INITP is nonzero, we are initializing the variable.  Otherwise, we
    3890                 :            :    are destroying it.  */
    3891                 :            : 
    3892                 :            : static void
    3893                 :      14582 : one_static_initialization_or_destruction (tree decl, tree init, bool initp)
    3894                 :            : {
    3895                 :      14582 :   tree guard_if_stmt = NULL_TREE;
    3896                 :      14582 :   tree guard;
    3897                 :            : 
    3898                 :            :   /* If we are supposed to destruct and there's a trivial destructor,
    3899                 :            :      nothing has to be done.  */
    3900                 :      14582 :   if (!initp
    3901                 :      14590 :       && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
    3902                 :            :     return;
    3903                 :            : 
    3904                 :            :   /* Trick the compiler into thinking we are at the file and line
    3905                 :            :      where DECL was declared so that error-messages make sense, and so
    3906                 :            :      that the debugger will show somewhat sensible file and line
    3907                 :            :      information.  */
    3908                 :      14582 :   input_location = DECL_SOURCE_LOCATION (decl);
    3909                 :            : 
    3910                 :            :   /* Make sure temporary variables in the initialiser all have
    3911                 :            :      their DECL_CONTEXT() set to a value different from NULL_TREE.
    3912                 :            :      This can happen when global variables initializers are built.
    3913                 :            :      In that case, the DECL_CONTEXT() of the global variables _AND_ of all 
    3914                 :            :      the temporary variables that might have been generated in the
    3915                 :            :      accompanying initializers is NULL_TREE, meaning the variables have been
    3916                 :            :      declared in the global namespace.
    3917                 :            :      What we want to do here is to fix that and make sure the DECL_CONTEXT()
    3918                 :            :      of the temporaries are set to the current function decl.  */
    3919                 :      14582 :   cp_walk_tree_without_duplicates (&init,
    3920                 :            :                                    fix_temporary_vars_context_r,
    3921                 :            :                                    NULL);
    3922                 :            : 
    3923                 :            :   /* Because of:
    3924                 :            : 
    3925                 :            :        [class.access.spec]
    3926                 :            : 
    3927                 :            :        Access control for implicit calls to the constructors,
    3928                 :            :        the conversion functions, or the destructor called to
    3929                 :            :        create and destroy a static data member is performed as
    3930                 :            :        if these calls appeared in the scope of the member's
    3931                 :            :        class.
    3932                 :            : 
    3933                 :            :      we pretend we are in a static member function of the class of
    3934                 :            :      which the DECL is a member.  */
    3935                 :      14582 :   if (member_p (decl))
    3936                 :            :     {
    3937                 :       1238 :       DECL_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
    3938                 :       2476 :       DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
    3939                 :            :     }
    3940                 :            : 
    3941                 :            :   /* Assume we don't need a guard.  */
    3942                 :      14582 :   guard = NULL_TREE;
    3943                 :            :   /* We need a guard if this is an object with external linkage that
    3944                 :            :      might be initialized in more than one place.  (For example, a
    3945                 :            :      static data member of a template, when the data member requires
    3946                 :            :      construction.)  */
    3947                 :      28206 :   if (NEEDS_GUARD_P (decl))
    3948                 :            :     {
    3949                 :        774 :       tree guard_cond;
    3950                 :            : 
    3951                 :        774 :       guard = get_guard (decl);
    3952                 :            : 
    3953                 :            :       /* When using __cxa_atexit, we just check the GUARD as we would
    3954                 :            :          for a local static.  */
    3955                 :        774 :       if (flag_use_cxa_atexit)
    3956                 :            :         {
    3957                 :            :           /* When using __cxa_atexit, we never try to destroy
    3958                 :            :              anything from a static destructor.  */
    3959                 :        774 :           gcc_assert (initp);
    3960                 :        774 :           guard_cond = get_guard_cond (guard, false);
    3961                 :            :         }
    3962                 :            :       /* If we don't have __cxa_atexit, then we will be running
    3963                 :            :          destructors from .fini sections, or their equivalents.  So,
    3964                 :            :          we need to know how many times we've tried to initialize this
    3965                 :            :          object.  We do initializations only if the GUARD is zero,
    3966                 :            :          i.e., if we are the first to initialize the variable.  We do
    3967                 :            :          destructions only if the GUARD is one, i.e., if we are the
    3968                 :            :          last to destroy the variable.  */
    3969                 :          0 :       else if (initp)
    3970                 :          0 :         guard_cond
    3971                 :          0 :           = cp_build_binary_op (input_location,
    3972                 :            :                                 EQ_EXPR,
    3973                 :            :                                 cp_build_unary_op (PREINCREMENT_EXPR,
    3974                 :            :                                                    guard,
    3975                 :            :                                                    /*noconvert=*/true,
    3976                 :            :                                                    tf_warning_or_error),
    3977                 :            :                                 integer_one_node,
    3978                 :            :                                 tf_warning_or_error);
    3979                 :            :       else
    3980                 :          0 :         guard_cond
    3981                 :          0 :           = cp_build_binary_op (input_location,
    3982                 :            :                                 EQ_EXPR,
    3983                 :            :                                 cp_build_unary_op (PREDECREMENT_EXPR,
    3984                 :            :                                                    guard,
    3985                 :            :                                                    /*noconvert=*/true,
    3986                 :            :                                                    tf_warning_or_error),
    3987                 :            :                                 integer_zero_node,
    3988                 :            :                                 tf_warning_or_error);
    3989                 :            : 
    3990                 :        774 :       guard_if_stmt = begin_if_stmt ();
    3991                 :        774 :       finish_if_stmt_cond (guard_cond, guard_if_stmt);
    3992                 :            :     }
    3993                 :            : 
    3994                 :            : 
    3995                 :            :   /* If we're using __cxa_atexit, we have not already set the GUARD,
    3996                 :            :      so we must do so now.  */
    3997                 :      14582 :   if (guard && initp && flag_use_cxa_atexit)
    3998                 :        774 :     finish_expr_stmt (set_guard (guard));
    3999                 :            : 
    4000                 :            :   /* Perform the initialization or destruction.  */
    4001                 :      14582 :   if (initp)
    4002                 :            :     {
    4003                 :      14574 :       if (init)
    4004                 :            :         {
    4005                 :      14418 :           finish_expr_stmt (init);
    4006                 :      14418 :           if (sanitize_flags_p (SANITIZE_ADDRESS, decl))
    4007                 :            :             {
    4008                 :         14 :               varpool_node *vnode = varpool_node::get (decl);
    4009                 :         14 :               if (vnode)
    4010                 :         14 :                 vnode->dynamically_initialized = 1;
    4011                 :            :             }
    4012                 :            :         }
    4013                 :            : 
    4014                 :            :       /* If we're using __cxa_atexit, register a function that calls the
    4015                 :            :          destructor for the object.  */
    4016                 :      14574 :       if (flag_use_cxa_atexit)
    4017                 :      14566 :         finish_expr_stmt (register_dtor_fn (decl));
    4018                 :            :     }
    4019                 :            :   else
    4020                 :          8 :     finish_expr_stmt (build_cleanup (decl));
    4021                 :            : 
    4022                 :            :   /* Finish the guard if-stmt, if necessary.  */
    4023                 :      14582 :   if (guard)
    4024                 :            :     {
    4025                 :        774 :       finish_then_clause (guard_if_stmt);
    4026                 :        774 :       finish_if_stmt (guard_if_stmt);
    4027                 :            :     }
    4028                 :            : 
    4029                 :            :   /* Now that we're done with DECL we don't need to pretend to be a
    4030                 :            :      member of its class any longer.  */
    4031                 :      14582 :   DECL_CONTEXT (current_function_decl) = NULL_TREE;
    4032                 :      29164 :   DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
    4033                 :            : }
    4034                 :            : 
    4035                 :            : /* Generate code to do the initialization or destruction of the decls in VARS,
    4036                 :            :    a TREE_LIST of VAR_DECL with static storage duration.
    4037                 :            :    Whether initialization or destruction is performed is specified by INITP.  */
    4038                 :            : 
    4039                 :            : static void
    4040                 :      10658 : do_static_initialization_or_destruction (tree vars, bool initp)
    4041                 :            : {
    4042                 :      10658 :   tree node, init_if_stmt, cond;
    4043                 :            : 
    4044                 :            :   /* Build the outer if-stmt to check for initialization or destruction.  */
    4045                 :      10658 :   init_if_stmt = begin_if_stmt ();
    4046                 :      10658 :   cond = initp ? integer_one_node : integer_zero_node;
    4047                 :      10658 :   cond = cp_build_binary_op (input_location,
    4048                 :            :                              EQ_EXPR,
    4049                 :            :                              initialize_p_decl,
    4050                 :            :                              cond,
    4051                 :            :                              tf_warning_or_error);
    4052                 :      10658 :   finish_if_stmt_cond (cond, init_if_stmt);
    4053                 :            : 
    4054                 :            :   /* To make sure dynamic construction doesn't access globals from other
    4055                 :            :      compilation units where they might not be yet constructed, for
    4056                 :            :      -fsanitize=address insert __asan_before_dynamic_init call that
    4057                 :            :      prevents access to either all global variables that need construction
    4058                 :            :      in other compilation units, or at least those that haven't been
    4059                 :            :      initialized yet.  Variables that need dynamic construction in
    4060                 :            :      the current compilation unit are kept accessible.  */
    4061                 :      10658 :   if (initp && (flag_sanitize & SANITIZE_ADDRESS))
    4062                 :         14 :     finish_expr_stmt (asan_dynamic_init_call (/*after_p=*/false));
    4063                 :            : 
    4064                 :            :   node = vars;
    4065                 :      10669 :   do {
    4066                 :      10669 :     tree decl = TREE_VALUE (node);
    4067                 :      10669 :     tree priority_if_stmt;
    4068                 :      10669 :     int priority;
    4069                 :      10669 :     priority_info pi;
    4070                 :            : 
    4071                 :            :     /* If we don't need a destructor, there's nothing to do.  Avoid
    4072                 :            :        creating a possibly empty if-stmt.  */
    4073                 :      10677 :     if (!initp && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
    4074                 :            :       {
    4075                 :          0 :         node = TREE_CHAIN (node);
    4076                 :          0 :         continue;
    4077                 :            :       }
    4078                 :            : 
    4079                 :            :     /* Remember that we had an initialization or finalization at this
    4080                 :            :        priority.  */
    4081                 :      10669 :     priority = DECL_EFFECTIVE_INIT_PRIORITY (decl);
    4082                 :      10669 :     pi = get_priority_info (priority);
    4083                 :      10669 :     if (initp)
    4084                 :      10661 :       pi->initializations_p = 1;
    4085                 :            :     else
    4086                 :          8 :       pi->destructions_p = 1;
    4087                 :            : 
    4088                 :            :     /* Conditionalize this initialization on being in the right priority
    4089                 :            :        and being initializing/finalizing appropriately.  */
    4090                 :      10669 :     priority_if_stmt = begin_if_stmt ();
    4091                 :      10669 :     cond = cp_build_binary_op (input_location,
    4092                 :            :                                EQ_EXPR,
    4093                 :            :                                priority_decl,
    4094                 :            :                                build_int_cst (NULL_TREE, priority),
    4095                 :            :                                tf_warning_or_error);
    4096                 :      10669 :     finish_if_stmt_cond (cond, priority_if_stmt);
    4097                 :            : 
    4098                 :            :     /* Process initializers with same priority.  */
    4099                 :      14012 :     for (; node
    4100                 :      38736 :            && DECL_EFFECTIVE_INIT_PRIORITY (TREE_VALUE (node)) == priority;
    4101                 :      14012 :          node = TREE_CHAIN (node))
    4102                 :            :       /* Do one initialization or destruction.  */
    4103                 :      14012 :       one_static_initialization_or_destruction (TREE_VALUE (node),
    4104                 :      14012 :                                                 TREE_PURPOSE (node), initp);
    4105                 :            : 
    4106                 :            :     /* Finish up the priority if-stmt body.  */
    4107                 :      10669 :     finish_then_clause (priority_if_stmt);
    4108                 :      10669 :     finish_if_stmt (priority_if_stmt);
    4109                 :            : 
    4110                 :      10669 :   } while (node);
    4111                 :            : 
    4112                 :            :   /* Revert what __asan_before_dynamic_init did by calling
    4113                 :            :      __asan_after_dynamic_init.  */
    4114                 :      10658 :   if (initp && (flag_sanitize & SANITIZE_ADDRESS))
    4115                 :         14 :     finish_expr_stmt (asan_dynamic_init_call (/*after_p=*/true));
    4116                 :            : 
    4117                 :            :   /* Finish up the init/destruct if-stmt body.  */
    4118                 :      10658 :   finish_then_clause (init_if_stmt);
    4119                 :      10658 :   finish_if_stmt (init_if_stmt);
    4120                 :      10658 : }
    4121                 :            : 
    4122                 :            : /* VARS is a list of variables with static storage duration which may
    4123                 :            :    need initialization and/or finalization.  Remove those variables
    4124                 :            :    that don't really need to be initialized or finalized, and return
    4125                 :            :    the resulting list.  The order in which the variables appear in
    4126                 :            :    VARS is in reverse order of the order in which they should actually
    4127                 :            :    be initialized.  The list we return is in the unreversed order;
    4128                 :            :    i.e., the first variable should be initialized first.  */
    4129                 :            : 
    4130                 :            : static tree
    4131                 :     211396 : prune_vars_needing_no_initialization (tree *vars)
    4132                 :            : {
    4133                 :     211396 :   tree *var = vars;
    4134                 :     211396 :   tree result = NULL_TREE;
    4135                 :            : 
    4136                 :     225970 :   while (*var)
    4137                 :            :     {
    4138                 :      14574 :       tree t = *var;
    4139                 :      14574 :       tree decl = TREE_VALUE (t);
    4140                 :      14574 :       tree init = TREE_PURPOSE (t);
    4141                 :            : 
    4142                 :            :       /* Deal gracefully with error.  */
    4143                 :      29148 :       if (error_operand_p (decl))
    4144                 :            :         {
    4145                 :          0 :           var = &TREE_CHAIN (t);
    4146                 :          0 :           continue;
    4147                 :            :         }
    4148                 :            : 
    4149                 :            :       /* The only things that can be initialized are variables.  */
    4150                 :      14574 :       gcc_assert (VAR_P (decl));
    4151                 :            : 
    4152                 :            :       /* If this object is not defined, we don't need to do anything
    4153                 :            :          here.  */
    4154                 :      14574 :       if (DECL_EXTERNAL (decl))
    4155                 :            :         {
    4156                 :          0 :           var = &TREE_CHAIN (t);
    4157                 :          0 :           continue;
    4158                 :            :         }
    4159                 :            : 
    4160                 :            :       /* Also, if the initializer already contains errors, we can bail
    4161                 :            :          out now.  */
    4162                 :      14418 :       if (init && TREE_CODE (init) == TREE_LIST
    4163                 :      14574 :           && value_member (error_mark_node, init))
    4164                 :            :         {
    4165                 :          0 :           var = &TREE_CHAIN (t);
    4166                 :          0 :           continue;
    4167                 :            :         }
    4168                 :            : 
    4169                 :            :       /* This variable is going to need initialization and/or
    4170                 :            :          finalization, so we add it to the list.  */
    4171                 :      14574 :       *var = TREE_CHAIN (t);
    4172                 :      14574 :       TREE_CHAIN (t) = result;
    4173                 :      14574 :       result = t;
    4174                 :            :     }
    4175                 :            : 
    4176                 :     211396 :   return result;
    4177                 :            : }
    4178                 :            : 
    4179                 :            : /* Make sure we have told the back end about all the variables in
    4180                 :            :    VARS.  */
    4181                 :            : 
    4182                 :            : static void
    4183                 :      10746 : write_out_vars (tree vars)
    4184                 :            : {
    4185                 :      10746 :   tree v;
    4186                 :            : 
    4187                 :      25320 :   for (v = vars; v; v = TREE_CHAIN (v))
    4188                 :            :     {
    4189                 :      14574 :       tree var = TREE_VALUE (v);
    4190                 :      14574 :       if (!var_finalized_p (var))
    4191                 :            :         {
    4192                 :        573 :           import_export_decl (var);
    4193                 :        573 :           rest_of_decl_compilation (var, 1, 1);
    4194                 :            :         }
    4195                 :            :     }
    4196                 :      10746 : }
    4197                 :            : 
    4198                 :            : /* Generate a static constructor (if CONSTRUCTOR_P) or destructor
    4199                 :            :    (otherwise) that will initialize all global objects with static
    4200                 :            :    storage duration having the indicated PRIORITY.  */
    4201                 :            : 
    4202                 :            : static void
    4203                 :      10661 : generate_ctor_or_dtor_function (bool constructor_p, int priority,
    4204                 :            :                                 location_t *locus)
    4205                 :            : {
    4206                 :      10661 :   char function_key;
    4207                 :      10661 :   tree fndecl;
    4208                 :      10661 :   tree body;
    4209                 :      10661 :   size_t i;
    4210                 :            : 
    4211                 :      10661 :   input_location = *locus;
    4212                 :            :   /* ??? */
    4213                 :            :   /* Was: locus->line++; */
    4214                 :            : 
    4215                 :            :   /* We use `I' to indicate initialization and `D' to indicate
    4216                 :            :      destruction.  */
    4217                 :      10661 :   function_key = constructor_p ? 'I' : 'D';
    4218                 :            : 
    4219                 :            :   /* We emit the function lazily, to avoid generating empty
    4220                 :            :      global constructors and destructors.  */
    4221                 :      10661 :   body = NULL_TREE;
    4222                 :            : 
    4223                 :            :   /* For Objective-C++, we may need to initialize metadata found in this module.
    4224                 :            :      This must be done _before_ any other static initializations.  */
    4225                 :      10661 :   if (c_dialect_objc () && (priority == DEFAULT_INIT_PRIORITY)
    4226                 :      10661 :       && constructor_p && objc_static_init_needed_p ())
    4227                 :            :     {
    4228                 :          0 :       body = start_objects (function_key, priority);
    4229                 :          0 :       objc_generate_static_init_call (NULL_TREE);
    4230                 :            :     }
    4231                 :            : 
    4232                 :            :   /* Call the static storage duration function with appropriate
    4233                 :            :      arguments.  */
    4234                 :      21330 :   FOR_EACH_VEC_SAFE_ELT (ssdf_decls, i, fndecl)
    4235                 :            :     {
    4236                 :            :       /* Calls to pure or const functions will expand to nothing.  */
    4237                 :      10669 :       if (! (flags_from_decl_or_type (fndecl) & (ECF_CONST | ECF_PURE)))
    4238                 :            :         {
    4239                 :      10669 :           tree call;
    4240                 :            : 
    4241                 :      10669 :           if (! body)
    4242                 :      10661 :             body = start_objects (function_key, priority);
    4243                 :            : 
    4244                 :      10669 :           call = cp_build_function_call_nary (fndecl, tf_warning_or_error,
    4245                 :            :                                               build_int_cst (NULL_TREE,
    4246                 :            :                                                              constructor_p),
    4247                 :            :                                               build_int_cst (NULL_TREE,
    4248                 :            :                                                              priority),
    4249                 :            :                                               NULL_TREE);
    4250                 :      10669 :           finish_expr_stmt (call);
    4251                 :            :         }
    4252                 :            :     }
    4253                 :            : 
    4254                 :            :   /* Close out the function.  */
    4255                 :      10661 :   if (body)
    4256                 :      10661 :     finish_objects (function_key, priority, body);
    4257                 :      10661 : }
    4258                 :            : 
    4259                 :            : /* Generate constructor and destructor functions for the priority
    4260                 :            :    indicated by N.  */
    4261                 :            : 
    4262                 :            : static int
    4263                 :      10662 : generate_ctor_and_dtor_functions_for_priority (splay_tree_node n, void * data)
    4264                 :            : {
    4265                 :      10662 :   location_t *locus = (location_t *) data;
    4266                 :      10662 :   int priority = (int) n->key;
    4267                 :      10662 :   priority_info pi = (priority_info) n->value;
    4268                 :            : 
    4269                 :            :   /* Generate the functions themselves, but only if they are really
    4270                 :            :      needed.  */
    4271                 :      10662 :   if (pi->initializations_p)
    4272                 :      10653 :     generate_ctor_or_dtor_function (/*constructor_p=*/true, priority, locus);
    4273                 :      10662 :   if (pi->destructions_p)
    4274                 :          8 :     generate_ctor_or_dtor_function (/*constructor_p=*/false, priority, locus);
    4275                 :            : 
    4276                 :            :   /* Keep iterating.  */
    4277                 :      10662 :   return 0;
    4278                 :            : }
    4279                 :            : 
    4280                 :            : /* Return C++ property of T, based on given operation OP.  */
    4281                 :            : 
    4282                 :            : static int
    4283                 :       2704 : cpp_check (tree t, cpp_operation op)
    4284                 :            : {
    4285                 :       2704 :   switch (op)
    4286                 :            :     {
    4287                 :         12 :       case HAS_DEPENDENT_TEMPLATE_ARGS:
    4288                 :         12 :         {
    4289                 :         12 :           tree ti = CLASSTYPE_TEMPLATE_INFO (t);
    4290                 :         12 :           if (!ti)
    4291                 :            :             return 0;
    4292                 :         12 :           ++processing_template_decl;
    4293                 :         12 :           const bool dep = any_dependent_template_arguments_p (TI_ARGS (ti));
    4294                 :         12 :           --processing_template_decl;
    4295                 :         12 :           return dep;
    4296                 :            :         }
    4297                 :        432 :       case IS_ABSTRACT:
    4298                 :        864 :         return DECL_PURE_VIRTUAL_P (t);
    4299                 :        238 :       case IS_ASSIGNMENT_OPERATOR:
    4300                 :        238 :         return DECL_ASSIGNMENT_OPERATOR_P (t);
    4301                 :        238 :       case IS_CONSTRUCTOR:
    4302                 :        476 :         return DECL_CONSTRUCTOR_P (t);
    4303                 :        238 :       case IS_DESTRUCTOR:
    4304                 :        476 :         return DECL_DESTRUCTOR_P (t);
    4305                 :        238 :       case IS_COPY_CONSTRUCTOR:
    4306                 :        560 :         return DECL_COPY_CONSTRUCTOR_P (t);
    4307                 :        238 :       case IS_MOVE_CONSTRUCTOR:
    4308                 :        566 :         return DECL_MOVE_CONSTRUCTOR_P (t);
    4309                 :        614 :       case IS_TEMPLATE:
    4310                 :        614 :         return TREE_CODE (t) == TEMPLATE_DECL;
    4311                 :        456 :       case IS_TRIVIAL:
    4312                 :        456 :         return trivial_type_p (t);
    4313                 :            :       default:
    4314                 :            :         return 0;
    4315                 :            :     }
    4316                 :            : }
    4317                 :            : 
    4318                 :            : /* Collect source file references recursively, starting from NAMESPC.  */
    4319                 :            : 
    4320                 :            : static void 
    4321                 :        104 : collect_source_refs (tree namespc) 
    4322                 :            : {
    4323                 :            :   /* Iterate over names in this name space.  */
    4324                 :     183449 :   for (tree t = NAMESPACE_LEVEL (namespc)->names; t; t = TREE_CHAIN (t))
    4325                 :     183345 :     if (DECL_IS_BUILTIN (t))
    4326                 :            :       ;
    4327                 :        320 :     else if (TREE_CODE (t) == NAMESPACE_DECL && !DECL_NAMESPACE_ALIAS (t))
    4328                 :          4 :       collect_source_refs (t);
    4329                 :            :     else
    4330                 :        316 :       collect_source_ref (DECL_SOURCE_FILE (t));
    4331                 :        104 : }
    4332                 :            : 
    4333                 :            : /* Collect decls relevant to SOURCE_FILE from all namespaces recursively,
    4334                 :            :    starting from NAMESPC.  */
    4335                 :            : 
    4336                 :            : static void
    4337                 :        304 : collect_ada_namespace (tree namespc, const char *source_file)
    4338                 :            : {
    4339                 :        304 :   tree decl = NAMESPACE_LEVEL (namespc)->names;
    4340                 :            : 
    4341                 :            :   /* Collect decls from this namespace.  This will skip
    4342                 :            :      NAMESPACE_DECLs (both aliases and regular, it cannot tell).  */
    4343                 :        304 :   collect_ada_nodes (decl, source_file);
    4344                 :            : 
    4345                 :            :   /* Now scan for namespace children, and dump them.  */
    4346                 :     228499 :   for (; decl; decl = TREE_CHAIN (decl))
    4347                 :     228195 :     if (TREE_CODE (decl) == NAMESPACE_DECL && !DECL_NAMESPACE_ALIAS (decl))
    4348                 :        204 :       collect_ada_namespace (decl, source_file);
    4349                 :        304 : }
    4350                 :            : 
    4351                 :            : /* Returns true iff there is a definition available for variable or
    4352                 :            :    function DECL.  */
    4353                 :            : 
    4354                 :            : bool
    4355                 :    9426260 : decl_defined_p (tree decl)
    4356                 :            : {
    4357                 :    9426260 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    4358                 :    8966460 :     return (DECL_INITIAL (decl) != NULL_TREE
    4359                 :            :             /* A pending instantiation of a friend temploid is defined.  */
    4360                 :    8966460 :             || (DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
    4361                 :     408960 :                 && DECL_INITIAL (DECL_TEMPLATE_RESULT
    4362                 :            :                                  (DECL_TI_TEMPLATE (decl)))));
    4363                 :            :   else
    4364                 :            :     {
    4365                 :     459798 :       gcc_assert (VAR_P (decl));
    4366                 :     459798 :       return !DECL_EXTERNAL (decl);
    4367                 :            :     }
    4368                 :            : }
    4369                 :            : 
    4370                 :            : /* Nonzero for a VAR_DECL whose value can be used in a constant expression.
    4371                 :            : 
    4372                 :            :       [expr.const]
    4373                 :            : 
    4374                 :            :       An integral constant-expression can only involve ... const
    4375                 :            :       variables of integral or enumeration types initialized with
    4376                 :            :       constant expressions ...
    4377                 :            : 
    4378                 :            :       C++0x also allows constexpr variables and temporaries initialized
    4379                 :            :       with constant expressions.  We handle the former here, but the latter
    4380                 :            :       are just folded away in cxx_eval_constant_expression.
    4381                 :            : 
    4382                 :            :    The standard does not require that the expression be non-volatile.
    4383                 :            :    G++ implements the proposed correction in DR 457.  */
    4384                 :            : 
    4385                 :            : bool
    4386                 :  118220000 : decl_constant_var_p (tree decl)
    4387                 :            : {
    4388                 :  118220000 :   if (!decl_maybe_constant_var_p (decl))
    4389                 :            :     return false;
    4390                 :            : 
    4391                 :            :   /* We don't know if a template static data member is initialized with
    4392                 :            :      a constant expression until we instantiate its initializer.  Even
    4393                 :            :      in the case of a constexpr variable, we can't treat it as a
    4394                 :            :      constant until its initializer is complete in case it's used in
    4395                 :            :      its own initializer.  */
    4396                 :   16244000 :   maybe_instantiate_decl (decl);
    4397                 :   16244000 :   return DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl);
    4398                 :            : }
    4399                 :            : 
    4400                 :            : /* Returns true if DECL could be a symbolic constant variable, depending on
    4401                 :            :    its initializer.  */
    4402                 :            : 
    4403                 :            : bool
    4404                 :  176888000 : decl_maybe_constant_var_p (tree decl)
    4405                 :            : {
    4406                 :  176888000 :   tree type = TREE_TYPE (decl);
    4407                 :  176888000 :   if (!VAR_P (decl))
    4408                 :            :     return false;
    4409                 :   71666800 :   if (DECL_DECLARED_CONSTEXPR_P (decl) && !TREE_THIS_VOLATILE (decl))
    4410                 :            :     return true;
    4411                 :   28313400 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    4412                 :            :     /* A proxy isn't constant.  */
    4413                 :            :     return false;
    4414                 :   28299700 :   if (TYPE_REF_P (type))
    4415                 :            :     /* References can be constant.  */;
    4416                 :   27806700 :   else if (CP_TYPE_CONST_NON_VOLATILE_P (type)
    4417                 :   27806700 :            && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    4418                 :            :     /* And const integers.  */;
    4419                 :            :   else
    4420                 :            :     return false;
    4421                 :            : 
    4422                 :    7797050 :   if (DECL_INITIAL (decl)
    4423                 :   12703600 :       && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
    4424                 :            :     /* We know the initializer, and it isn't constant.  */
    4425                 :     827078 :     return false;
    4426                 :            :   else
    4427                 :            :     return true;
    4428                 :            : }
    4429                 :            : 
    4430                 :            : /* Complain that DECL uses a type with no linkage.  In C++98 mode this is
    4431                 :            :    called from grokfndecl and grokvardecl; in all modes it is called from
    4432                 :            :    cp_write_global_declarations.  */
    4433                 :            : 
    4434                 :            : void
    4435                 :     762331 : no_linkage_error (tree decl)
    4436                 :            : {
    4437                 :     762331 :   if (cxx_dialect >= cxx11
    4438                 :     762331 :       && (decl_defined_p (decl)
    4439                 :            :           /* Treat templates which limit_bad_template_recursion decided
    4440                 :            :              not to instantiate as if they were defined.  */
    4441                 :         21 :           || (errorcount + sorrycount > 0
    4442                 :         12 :               && DECL_LANG_SPECIFIC (decl)
    4443                 :         12 :               && DECL_TEMPLATE_INFO (decl)
    4444                 :          9 :               && TREE_NO_WARNING (decl))))
    4445                 :            :     /* In C++11 it's ok if the decl is defined.  */
    4446                 :            :     return;
    4447                 :     742200 :   tree t = no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false);
    4448                 :     742200 :   if (t == NULL_TREE)
    4449                 :            :     /* The type that got us on no_linkage_decls must have gotten a name for
    4450                 :            :        linkage purposes.  */;
    4451                 :         68 :   else if (CLASS_TYPE_P (t) && TYPE_BEING_DEFINED (t))
    4452                 :            :     /* The type might end up having a typedef name for linkage purposes.  */
    4453                 :          0 :     vec_safe_push (no_linkage_decls, decl);
    4454                 :         38 :   else if (TYPE_UNNAMED_P (t))
    4455                 :            :     {
    4456                 :         24 :       bool d = false;
    4457                 :         48 :       auto_diagnostic_group grp;
    4458                 :         24 :       if (cxx_dialect >= cxx11)
    4459                 :          3 :         d = permerror (DECL_SOURCE_LOCATION (decl), "%q#D, declared using "
    4460                 :            :                        "unnamed type, is used but never defined", decl);
    4461                 :         21 :       else if (DECL_EXTERN_C_P (decl))
    4462                 :            :         /* Allow this; it's pretty common in C.  */;
    4463                 :         20 :       else if (VAR_P (decl))
    4464                 :            :         /* DRs 132, 319 and 389 seem to indicate types with
    4465                 :            :            no linkage can only be used to declare extern "C"
    4466                 :            :            entities.  Since it's not always an error in the
    4467                 :            :            ISO C++ 90 Standard, we only issue a warning.  */
    4468                 :         16 :         d = warning_at (DECL_SOURCE_LOCATION (decl), 0, "unnamed type "
    4469                 :            :                         "with no linkage used to declare variable %q#D with "
    4470                 :            :                         "linkage", decl);
    4471                 :            :       else
    4472                 :          4 :         d = permerror (DECL_SOURCE_LOCATION (decl), "unnamed type with no "
    4473                 :            :                        "linkage used to declare function %q#D with linkage",
    4474                 :            :                        decl);
    4475                 :         44 :       if (d && is_typedef_decl (TYPE_NAME (t)))
    4476                 :          2 :         inform (DECL_SOURCE_LOCATION (TYPE_NAME (t)), "%q#D does not refer "
    4477                 :            :                 "to the unqualified type, so it is not used for linkage",
    4478                 :          1 :                 TYPE_NAME (t));
    4479                 :            :     }
    4480                 :         14 :   else if (cxx_dialect >= cxx11)
    4481                 :            :     {
    4482                 :         21 :       if (VAR_P (decl) || !DECL_PURE_VIRTUAL_P (decl))
    4483                 :          9 :         permerror (DECL_SOURCE_LOCATION (decl),
    4484                 :            :                    "%q#D, declared using local type "
    4485                 :            :                    "%qT, is used but never defined", decl, t);
    4486                 :            :     }
    4487                 :          2 :   else if (VAR_P (decl))
    4488                 :          1 :     warning_at (DECL_SOURCE_LOCATION (decl), 0, "type %qT with no linkage "
    4489                 :            :                 "used to declare variable %q#D with linkage", t, decl);
    4490                 :            :   else
    4491                 :          1 :     permerror (DECL_SOURCE_LOCATION (decl), "type %qT with no linkage used "
    4492                 :            :                "to declare function %q#D with linkage", t, decl);
    4493                 :            : }
    4494                 :            : 
    4495                 :            : /* Collect declarations from all namespaces relevant to SOURCE_FILE.  */
    4496                 :            : 
    4497                 :            : static void
    4498                 :        100 : collect_all_refs (const char *source_file)
    4499                 :            : {
    4500                 :        100 :   collect_ada_namespace (global_namespace, source_file);
    4501                 :        100 : }
    4502                 :            : 
    4503                 :            : /* Clear DECL_EXTERNAL for NODE.  */
    4504                 :            : 
    4505                 :            : static bool
    4506                 :   29399800 : clear_decl_external (struct cgraph_node *node, void * /*data*/)
    4507                 :            : {
    4508                 :   29399800 :   DECL_EXTERNAL (node->decl) = 0;
    4509                 :   29399800 :   return false;
    4510                 :            : }
    4511                 :            : 
    4512                 :            : /* Build up the function to run dynamic initializers for thread_local
    4513                 :            :    variables in this translation unit and alias the init functions for the
    4514                 :            :    individual variables to it.  */
    4515                 :            : 
    4516                 :            : static void
    4517                 :     105698 : handle_tls_init (void)
    4518                 :            : {
    4519                 :     105698 :   tree vars = prune_vars_needing_no_initialization (&tls_aggregates);
    4520                 :     105698 :   if (vars == NULL_TREE)
    4521                 :            :     return;
    4522                 :            : 
    4523                 :         96 :   location_t loc = DECL_SOURCE_LOCATION (TREE_VALUE (vars));
    4524                 :            : 
    4525                 :         96 :   write_out_vars (vars);
    4526                 :            : 
    4527                 :         96 :   tree guard = build_decl (loc, VAR_DECL, get_identifier ("__tls_guard"),
    4528                 :            :                            boolean_type_node);
    4529                 :         96 :   TREE_PUBLIC (guard) = false;
    4530                 :         96 :   TREE_STATIC (guard) = true;
    4531                 :         96 :   DECL_ARTIFICIAL (guard) = true;
    4532                 :         96 :   DECL_IGNORED_P (guard) = true;
    4533                 :         96 :   TREE_USED (guard) = true;
    4534                 :         96 :   CP_DECL_THREAD_LOCAL_P (guard) = true;
    4535                 :         96 :   set_decl_tls_model (guard, decl_default_tls_model (guard));
    4536                 :         96 :   pushdecl_top_level_and_finish (guard, NULL_TREE);
    4537                 :            : 
    4538                 :         96 :   tree fn = get_local_tls_init_fn (loc);
    4539                 :         96 :   start_preparsed_function (fn, NULL_TREE, SF_PRE_PARSED);
    4540                 :         96 :   tree body = begin_function_body ();
    4541                 :         96 :   tree if_stmt = begin_if_stmt ();
    4542                 :         96 :   tree cond = cp_build_unary_op (TRUTH_NOT_EXPR, guard, false,
    4543                 :            :                                  tf_warning_or_error);
    4544                 :         96 :   finish_if_stmt_cond (cond, if_stmt);
    4545                 :         96 :   finish_expr_stmt (cp_build_modify_expr (loc, guard, NOP_EXPR,
    4546                 :            :                                           boolean_true_node,
    4547                 :            :                                           tf_warning_or_error));
    4548                 :        666 :   for (; vars; vars = TREE_CHAIN (vars))
    4549                 :            :     {
    4550                 :        570 :       tree var = TREE_VALUE (vars);
    4551                 :        570 :       tree init = TREE_PURPOSE (vars);
    4552                 :        570 :       one_static_initialization_or_destruction (var, init, true);
    4553                 :            : 
    4554                 :            :       /* Output init aliases even with -fno-extern-tls-init.  */
    4555                 :        570 :       if (TARGET_SUPPORTS_ALIASES && TREE_PUBLIC (var))
    4556                 :            :         {
    4557                 :        567 :           tree single_init_fn = get_tls_init_fn (var);
    4558                 :        567 :           if (single_init_fn == NULL_TREE)
    4559                 :          0 :             continue;
    4560                 :        567 :           cgraph_node *alias
    4561                 :        567 :             = cgraph_node::get_create (fn)->create_same_body_alias
    4562                 :        567 :                 (single_init_fn, fn);
    4563                 :        567 :           gcc_assert (alias != NULL);
    4564                 :            :         }
    4565                 :            :     }
    4566                 :            : 
    4567                 :         96 :   finish_then_clause (if_stmt);
    4568                 :         96 :   finish_if_stmt (if_stmt);
    4569                 :         96 :   finish_function_body (body);
    4570                 :         96 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
    4571                 :            : }
    4572                 :            : 
    4573                 :            : /* We're at the end of compilation, so generate any mangling aliases that
    4574                 :            :    we've been saving up, if DECL is going to be output and ID2 isn't
    4575                 :            :    already taken by another declaration.  */
    4576                 :            : 
    4577                 :            : static void
    4578                 :      18433 : generate_mangling_alias (tree decl, tree id2)
    4579                 :            : {
    4580                 :      18433 :   struct cgraph_node *n = NULL;
    4581                 :            : 
    4582                 :      18433 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    4583                 :            :     {
    4584                 :      18324 :       n = cgraph_node::get (decl);
    4585                 :      18324 :       if (!n)
    4586                 :            :         /* Don't create an alias to an unreferenced function.  */
    4587                 :            :         return;
    4588                 :            :     }
    4589                 :            : 
    4590                 :      18433 :   tree *slot
    4591                 :      18433 :     = mangled_decls->find_slot_with_hash (id2, IDENTIFIER_HASH_VALUE (id2),
    4592                 :            :                                           INSERT);
    4593                 :            : 
    4594                 :            :   /* If there's a declaration already using this mangled name,
    4595                 :            :      don't create a compatibility alias that conflicts.  */
    4596                 :      18433 :   if (*slot)
    4597                 :            :     return;
    4598                 :            : 
    4599                 :      18433 :   tree alias = make_alias_for (decl, id2);
    4600                 :      18433 :   *slot = alias;
    4601                 :            : 
    4602                 :      18433 :   DECL_IGNORED_P (alias) = 1;
    4603                 :      18433 :   TREE_PUBLIC (alias) = TREE_PUBLIC (decl);
    4604                 :      18433 :   DECL_VISIBILITY (alias) = DECL_VISIBILITY (decl);
    4605                 :      18433 :   if (vague_linkage_p (decl))
    4606                 :      18215 :     DECL_WEAK (alias) = 1;
    4607                 :            : 
    4608                 :      18433 :   if (n)
    4609                 :      18324 :     n->create_same_body_alias (alias, decl);
    4610                 :            :   else
    4611                 :        109 :     varpool_node::create_extra_name_alias (alias, decl);
    4612                 :            : }
    4613                 :            : 
    4614                 :            : /* Note that we might want to emit an alias with the symbol ID2 for DECL at
    4615                 :            :    the end of translation, for compatibility across bugs in the mangling
    4616                 :            :    implementation.  */
    4617                 :            : 
    4618                 :            : void
    4619                 :      18433 : note_mangling_alias (tree decl, tree id2)
    4620                 :            : {
    4621                 :      18433 :   if (TARGET_SUPPORTS_ALIASES)
    4622                 :            :     {
    4623                 :      18433 :       if (!defer_mangling_aliases)
    4624                 :       6678 :         generate_mangling_alias (decl, id2);
    4625                 :            :       else
    4626                 :            :         {
    4627                 :      11755 :           vec_safe_push (mangling_aliases, decl);
    4628                 :      11755 :           vec_safe_push (mangling_aliases, id2);
    4629                 :            :         }
    4630                 :            :     }
    4631                 :      18433 : }
    4632                 :            : 
    4633                 :            : /* Emit all mangling aliases that were deferred up to this point.  */
    4634                 :            : 
    4635                 :            : void
    4636                 :      77684 : generate_mangling_aliases ()
    4637                 :            : {
    4638                 :      89439 :   while (!vec_safe_is_empty (mangling_aliases))
    4639                 :            :     {
    4640                 :      11755 :       tree id2 = mangling_aliases->pop();
    4641                 :      11755 :       tree decl = mangling_aliases->pop();
    4642                 :      11755 :       generate_mangling_alias (decl, id2);
    4643                 :            :     }
    4644                 :      77684 :   defer_mangling_aliases = false;
    4645                 :      77684 : }
    4646                 :            : 
    4647                 :            : /* Record a mangling of DECL, whose DECL_ASSEMBLER_NAME has just been
    4648                 :            :    set.  NEED_WARNING is true if we must warn about collisions.  We do
    4649                 :            :    this to spot changes in mangling that may require compatibility
    4650                 :            :    aliases.  */
    4651                 :            : 
    4652                 :            : void
    4653                 :   11456700 : record_mangling (tree decl, bool need_warning)
    4654                 :            : {
    4655                 :   11456700 :   if (!mangled_decls)
    4656                 :      53307 :     mangled_decls = hash_table<mangled_decl_hash>::create_ggc (499);
    4657                 :            : 
    4658                 :   11456700 :   gcc_checking_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
    4659                 :   11456700 :   tree id = DECL_ASSEMBLER_NAME_RAW (decl);
    4660                 :   11456700 :   tree *slot
    4661                 :   11456700 :     = mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE (id),
    4662                 :            :                                           INSERT);
    4663                 :            : 
    4664                 :            :   /* If this is already an alias, remove the alias, because the real
    4665                 :            :      decl takes precedence.  */
    4666                 :   11456700 :   if (*slot && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot))
    4667                 :          0 :     if (symtab_node *n = symtab_node::get (*slot))
    4668                 :          0 :       if (n->cpp_implicit_alias)
    4669                 :            :         {
    4670                 :          0 :           n->remove ();
    4671                 :          0 :           *slot = NULL_TREE;
    4672                 :            :         }
    4673                 :            : 
    4674                 :   11456700 :   if (!*slot)
    4675                 :   11456500 :     *slot = decl;
    4676                 :        225 :   else if (need_warning)
    4677                 :            :     {
    4678                 :          4 :       error_at (DECL_SOURCE_LOCATION (decl),
    4679                 :            :                 "mangling of %q#D as %qE conflicts with a previous mangle",
    4680                 :            :                 decl, id);
    4681                 :          4 :       inform (DECL_SOURCE_LOCATION (*slot),
    4682                 :            :               "previous mangling %q#D", *slot);
    4683                 :          4 :       inform (DECL_SOURCE_LOCATION (decl),
    4684                 :            :               "a later %<-fabi-version=%> (or =0)"
    4685                 :            :               " avoids this error with a change in mangling");
    4686                 :          4 :       *slot = decl;
    4687                 :            :     }
    4688                 :   11456700 : }
    4689                 :            : 
    4690                 :            : /* The mangled name of DECL is being forcibly changed to NAME.  Remove
    4691                 :            :    any existing knowledge of DECL's mangled name meaning DECL.  */
    4692                 :            : 
    4693                 :            : void
    4694                 :   94041300 : overwrite_mangling (tree decl, tree name)
    4695                 :            : {
    4696                 :   94041300 :   if (tree id = DECL_ASSEMBLER_NAME_RAW (decl))
    4697                 :     100400 :     if ((TREE_CODE (decl) == VAR_DECL
    4698                 :     100307 :          || TREE_CODE (decl) == FUNCTION_DECL)
    4699                 :     100400 :         && mangled_decls)
    4700                 :     191622 :       if (tree *slot
    4701                 :      95811 :           = mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE (id),
    4702                 :            :                                                 NO_INSERT))
    4703                 :      67263 :         if (*slot == decl)
    4704                 :            :           {
    4705                 :         46 :             mangled_decls->clear_slot (slot);
    4706                 :            : 
    4707                 :            :             /* If this is an alias, remove it from the symbol table.  */
    4708                 :         46 :             if (DECL_ARTIFICIAL (decl) && DECL_IGNORED_P (decl))
    4709                 :          0 :               if (symtab_node *n = symtab_node::get (decl))
    4710                 :          0 :                 if (n->cpp_implicit_alias)
    4711                 :          0 :                   n->remove ();
    4712                 :            :           }
    4713                 :            : 
    4714                 :   94041300 :   DECL_ASSEMBLER_NAME_RAW (decl) = name;
    4715                 :   94041300 : }
    4716                 :            : 
    4717                 :            : /* The entire file is now complete.  If requested, dump everything
    4718                 :            :    to a file.  */
    4719                 :            : 
    4720                 :            : static void
    4721                 :      77743 : dump_tu (void)
    4722                 :            : {
    4723                 :      77743 :   dump_flags_t flags;
    4724                 :      77743 :   if (FILE *stream = dump_begin (raw_dump_id, &flags))
    4725                 :            :     {
    4726                 :          4 :       dump_node (global_namespace, flags & ~TDF_SLIM, stream);
    4727                 :          4 :       dump_end (raw_dump_id, stream);
    4728                 :            :     }
    4729                 :      77743 : }
    4730                 :            : 
    4731                 :            : static location_t locus_at_end_of_parsing;
    4732                 :            : 
    4733                 :            : /* Check the deallocation functions for CODE to see if we want to warn that
    4734                 :            :    only one was defined.  */
    4735                 :            : 
    4736                 :            : static void
    4737                 :        818 : maybe_warn_sized_delete (enum tree_code code)
    4738                 :            : {
    4739                 :        818 :   tree sized = NULL_TREE;
    4740                 :        818 :   tree unsized = NULL_TREE;
    4741                 :            : 
    4742                 :       3826 :   for (ovl_iterator iter (get_global_binding (ovl_op_identifier (false, code)));
    4743                 :       3826 :        iter; ++iter)
    4744                 :            :     {
    4745                 :       3008 :       tree fn = *iter;
    4746                 :            :       /* We're only interested in usual deallocation functions.  */
    4747                 :       3008 :       if (!usual_deallocation_fn_p (fn))
    4748                 :        592 :         continue;
    4749                 :       2416 :       if (FUNCTION_ARG_CHAIN (fn) == void_list_node)
    4750                 :            :         unsized = fn;
    4751                 :            :       else
    4752                 :       1598 :         sized = fn;
    4753                 :            :     }
    4754                 :        825 :   if (DECL_INITIAL (unsized) && !DECL_INITIAL (sized))
    4755                 :          7 :     warning_at (DECL_SOURCE_LOCATION (unsized), OPT_Wsized_deallocation,
    4756                 :            :                 "the program should also define %qD", sized);
    4757                 :       1622 :   else if (!DECL_INITIAL (unsized) && DECL_INITIAL (sized))
    4758                 :          4 :     warning_at (DECL_SOURCE_LOCATION (sized), OPT_Wsized_deallocation,
    4759                 :            :                 "the program should also define %qD", unsized);
    4760                 :        818 : }
    4761                 :            : 
    4762                 :            : /* Check the global deallocation functions to see if we want to warn about
    4763                 :            :    defining unsized without sized (or vice versa).  */
    4764                 :            : 
    4765                 :            : static void
    4766                 :      77684 : maybe_warn_sized_delete ()
    4767                 :            : {
    4768                 :      77684 :   if (!flag_sized_deallocation || !warn_sized_deallocation)
    4769                 :            :     return;
    4770                 :        409 :   maybe_warn_sized_delete (DELETE_EXPR);
    4771                 :        409 :   maybe_warn_sized_delete (VEC_DELETE_EXPR);
    4772                 :            : }
    4773                 :            : 
    4774                 :            : /* Earlier we left PTRMEM_CST in variable initializers alone so that we could
    4775                 :            :    look them up when evaluating non-type template parameters.  Now we need to
    4776                 :            :    lower them to something the back end can understand.  */
    4777                 :            : 
    4778                 :            : static void
    4779                 :      77684 : lower_var_init ()
    4780                 :            : {
    4781                 :      77684 :   varpool_node *node;
    4782                 :   15711000 :   FOR_EACH_VARIABLE (node)
    4783                 :            :     {
    4784                 :    7777820 :       tree d = node->decl;
    4785                 :    7777820 :       if (tree init = DECL_INITIAL (d))
    4786                 :    6567000 :         DECL_INITIAL (d) = cplus_expand_constant (init);
    4787                 :            :     }
    4788                 :      77684 : }
    4789                 :            : 
    4790                 :            : /* This routine is called at the end of compilation.
    4791                 :            :    Its job is to create all the code needed to initialize and
    4792                 :            :    destroy the global aggregates.  We do the destruction
    4793                 :            :    first, since that way we only need to reverse the decls once.  */
    4794                 :            : 
    4795                 :            : void
    4796                 :      77761 : c_parse_final_cleanups (void)
    4797                 :            : {
    4798                 :      77761 :   tree vars;
    4799                 :      77761 :   bool reconsider;
    4800                 :      77761 :   size_t i;
    4801                 :      77761 :   unsigned ssdf_count = 0;
    4802                 :      77761 :   int retries = 0;
    4803                 :      77761 :   tree decl;
    4804                 :            : 
    4805                 :      77761 :   locus_at_end_of_parsing = input_location;
    4806                 :      77761 :   at_eof = 1;
    4807                 :            : 
    4808                 :            :   /* Bad parse errors.  Just forget about it.  */
    4809                 :     155522 :   if (! global_bindings_p () || current_class_type
    4810                 :     155522 :       || !vec_safe_is_empty (decl_namespace_list))
    4811                 :      77746 :     return;
    4812                 :            : 
    4813                 :            :   /* This is the point to write out a PCH if we're doing that.
    4814                 :            :      In that case we do not want to do anything else.  */
    4815                 :      77758 :   if (pch_file)
    4816                 :            :     {
    4817                 :            :       /* Mangle all symbols at PCH creation time.  */
    4818                 :         59 :       symtab_node *node;
    4819                 :      21301 :       FOR_EACH_SYMBOL (node)
    4820                 :      21242 :         if (! is_a <varpool_node *> (node)
    4821                 :        586 :             || ! DECL_HARD_REGISTER (node->decl))
    4822                 :      21242 :           DECL_ASSEMBLER_NAME (node->decl);
    4823                 :         59 :       c_common_write_pch ();
    4824                 :         59 :       dump_tu ();
    4825                 :            :       /* Ensure even the callers don't try to finalize the CU.  */
    4826                 :         59 :       flag_syntax_only = 1;
    4827                 :         59 :       return;
    4828                 :            :     }
    4829                 :            : 
    4830                 :      77699 :   timevar_stop (TV_PHASE_PARSING);
    4831                 :      77699 :   timevar_start (TV_PHASE_DEFERRED);
    4832                 :            : 
    4833                 :      77699 :   symtab->process_same_body_aliases ();
    4834                 :            : 
    4835                 :            :   /* Handle -fdump-ada-spec[-slim] */
    4836                 :      77699 :   if (flag_dump_ada_spec || flag_dump_ada_spec_slim)
    4837                 :            :     {
    4838                 :        100 :       collect_source_ref (main_input_filename);
    4839                 :        100 :       if (!flag_dump_ada_spec_slim)
    4840                 :        100 :         collect_source_refs (global_namespace);
    4841                 :            : 
    4842                 :        100 :       dump_ada_specs (collect_all_refs, cpp_check);
    4843                 :            :     }
    4844                 :            : 
    4845                 :            :   /* FIXME - huh?  was  input_line -= 1;*/
    4846                 :            : 
    4847                 :            :   /* We now have to write out all the stuff we put off writing out.
    4848                 :            :      These include:
    4849                 :            : 
    4850                 :            :        o Template specializations that we have not yet instantiated,
    4851                 :            :          but which are needed.
    4852                 :            :        o Initialization and destruction for non-local objects with
    4853                 :            :          static storage duration.  (Local objects with static storage
    4854                 :            :          duration are initialized when their scope is first entered,
    4855                 :            :          and are cleaned up via atexit.)
    4856                 :            :        o Virtual function tables.
    4857                 :            : 
    4858                 :            :      All of these may cause others to be needed.  For example,
    4859                 :            :      instantiating one function may cause another to be needed, and
    4860                 :            :      generating the initializer for an object may cause templates to be
    4861                 :            :      instantiated, etc., etc.  */
    4862                 :            : 
    4863                 :      77699 :   emit_support_tinfos ();
    4864                 :            : 
    4865                 :     211411 :   do
    4866                 :            :     {
    4867                 :     105713 :       tree t;
    4868                 :     105713 :       tree decl;
    4869                 :            : 
    4870                 :     105713 :       reconsider = false;
    4871                 :            : 
    4872                 :            :       /* If there are templates that we've put off instantiating, do
    4873                 :            :          them now.  */
    4874                 :     105713 :       instantiate_pending_templates (retries);
    4875                 :     105698 :       ggc_collect ();
    4876                 :            : 
    4877                 :            :       /* Write out virtual tables as required.  Writing out the
    4878                 :            :          virtual table for a template class may cause the
    4879                 :            :          instantiation of members of that class.  If we write out
    4880                 :            :          vtables then we remove the class from our list so we don't
    4881                 :            :          have to look at it again.  */
    4882                 :     105698 :       for (i = keyed_classes->length ();
    4883                 :    3573790 :            keyed_classes->iterate (--i, &t);)
    4884                 :    1681200 :         if (maybe_emit_vtables (t))
    4885                 :            :           {
    4886                 :     111557 :             reconsider = true;
    4887                 :    1898450 :             keyed_classes->unordered_remove (i);
    4888                 :            :           }
    4889                 :            :       /* The input_location may have been changed during marking of
    4890                 :            :          vtable entries.  */
    4891                 :     105698 :       input_location = locus_at_end_of_parsing;
    4892                 :            : 
    4893                 :            :       /* Write out needed type info variables.  We have to be careful
    4894                 :            :          looping through unemitted decls, because emit_tinfo_decl may
    4895                 :            :          cause other variables to be needed. New elements will be
    4896                 :            :          appended, and we remove from the vector those that actually
    4897                 :            :          get emitted.  */
    4898                 :     105698 :       for (i = unemitted_tinfo_decls->length ();
    4899                 :    5742900 :            unemitted_tinfo_decls->iterate (--i, &t);)
    4900                 :    2765750 :         if (emit_tinfo_decl (t))
    4901                 :            :           {
    4902                 :     159000 :             reconsider = true;
    4903                 :    3030450 :             unemitted_tinfo_decls->unordered_remove (i);
    4904                 :            :           }
    4905                 :            : 
    4906                 :            :       /* The list of objects with static storage duration is built up
    4907                 :            :          in reverse order.  We clear STATIC_AGGREGATES so that any new
    4908                 :            :          aggregates added during the initialization of these will be
    4909                 :            :          initialized in the correct order when we next come around the
    4910                 :            :          loop.  */
    4911                 :     105698 :       vars = prune_vars_needing_no_initialization (&static_aggregates);
    4912                 :            : 
    4913                 :     105698 :       if (vars)
    4914                 :            :         {
    4915                 :            :           /* We need to start a new initialization function each time
    4916                 :            :              through the loop.  That's because we need to know which
    4917                 :            :              vtables have been referenced, and TREE_SYMBOL_REFERENCED
    4918                 :            :              isn't computed until a function is finished, and written
    4919                 :            :              out.  That's a deficiency in the back end.  When this is
    4920                 :            :              fixed, these initialization functions could all become
    4921                 :            :              inline, with resulting performance improvements.  */
    4922                 :      10650 :           tree ssdf_body;
    4923                 :            : 
    4924                 :            :           /* Make sure the back end knows about all the variables.  */
    4925                 :      10650 :           write_out_vars (vars);
    4926                 :            : 
    4927                 :            :           /* Set the line and file, so that it is obviously not from
    4928                 :            :              the source file.  */
    4929                 :      10650 :           input_location = locus_at_end_of_parsing;
    4930                 :      10650 :           ssdf_body = start_static_storage_duration_function (ssdf_count);
    4931                 :            : 
    4932                 :            :           /* First generate code to do all the initializations.  */
    4933                 :      10650 :           if (vars)
    4934                 :      10650 :             do_static_initialization_or_destruction (vars, /*initp=*/true);
    4935                 :            : 
    4936                 :            :           /* Then, generate code to do all the destructions.  Do these
    4937                 :            :              in reverse order so that the most recently constructed
    4938                 :            :              variable is the first destroyed.  If we're using
    4939                 :            :              __cxa_atexit, then we don't need to do this; functions
    4940                 :            :              were registered at initialization time to destroy the
    4941                 :            :              local statics.  */
    4942                 :      10650 :           if (!flag_use_cxa_atexit && vars)
    4943                 :            :             {
    4944                 :          8 :               vars = nreverse (vars);
    4945                 :          8 :               do_static_initialization_or_destruction (vars, /*initp=*/false);
    4946                 :            :             }
    4947                 :            :           else
    4948                 :      10650 :             vars = NULL_TREE;
    4949                 :            : 
    4950                 :            :           /* Finish up the static storage duration function for this
    4951                 :            :              round.  */
    4952                 :      10650 :           input_location = locus_at_end_of_parsing;
    4953                 :      10650 :           finish_static_storage_duration_function (ssdf_body);
    4954                 :            : 
    4955                 :            :           /* All those initializations and finalizations might cause
    4956                 :            :              us to need more inline functions, more template
    4957                 :            :              instantiations, etc.  */
    4958                 :      10650 :           reconsider = true;
    4959                 :      10650 :           ssdf_count++;
    4960                 :            :           /* ??? was:  locus_at_end_of_parsing.line++; */
    4961                 :            :         }
    4962                 :            : 
    4963                 :            :       /* Now do the same for thread_local variables.  */
    4964                 :     105698 :       handle_tls_init ();
    4965                 :            : 
    4966                 :            :       /* Go through the set of inline functions whose bodies have not
    4967                 :            :          been emitted yet.  If out-of-line copies of these functions
    4968                 :            :          are required, emit them.  */
    4969                 :   52143500 :       FOR_EACH_VEC_SAFE_ELT (deferred_fns, i, decl)
    4970                 :            :         {
    4971                 :            :           /* Does it need synthesizing?  */
    4972                 :  105612000 :           if (DECL_DEFAULTED_FN (decl) && ! DECL_INITIAL (decl)
    4973                 :   52038000 :               && (! DECL_REALLY_EXTERN (decl) || possibly_inlined_p (decl)))
    4974                 :            :             {
    4975                 :            :               /* Even though we're already at the top-level, we push
    4976                 :            :                  there again.  That way, when we pop back a few lines
    4977                 :            :                  hence, all of our state is restored.  Otherwise,
    4978                 :            :                  finish_function doesn't clean things up, and we end
    4979                 :            :                  up with CURRENT_FUNCTION_DECL set.  */
    4980                 :        224 :               push_to_top_level ();
    4981                 :            :               /* The decl's location will mark where it was first
    4982                 :            :                  needed.  Save that so synthesize method can indicate
    4983                 :            :                  where it was needed from, in case of error  */
    4984                 :        224 :               input_location = DECL_SOURCE_LOCATION (decl);
    4985                 :        224 :               synthesize_method (decl);
    4986                 :        224 :               pop_from_top_level ();
    4987                 :        224 :               reconsider = true;
    4988                 :            :             }
    4989                 :            : 
    4990                 :   52037800 :           if (!DECL_INITIAL (decl) && decl_tls_wrapper_p (decl))
    4991                 :        426 :             generate_tls_wrapper (decl);
    4992                 :            : 
    4993                 :   52037800 :           if (!DECL_SAVED_TREE (decl))
    4994                 :    5915440 :             continue;
    4995                 :            : 
    4996                 :   46122400 :           cgraph_node *node = cgraph_node::get_create (decl);
    4997                 :            : 
    4998                 :            :           /* We lie to the back end, pretending that some functions
    4999                 :            :              are not defined when they really are.  This keeps these
    5000                 :            :              functions from being put out unnecessarily.  But, we must
    5001                 :            :              stop lying when the functions are referenced, or if they
    5002                 :            :              are not comdat since they need to be put out now.  If
    5003                 :            :              DECL_INTERFACE_KNOWN, then we have already set
    5004                 :            :              DECL_EXTERNAL appropriately, so there's no need to check
    5005                 :            :              again, and we do not want to clear DECL_EXTERNAL if a
    5006                 :            :              previous call to import_export_decl set it.
    5007                 :            : 
    5008                 :            :              This is done in a separate for cycle, because if some
    5009                 :            :              deferred function is contained in another deferred
    5010                 :            :              function later in deferred_fns varray,
    5011                 :            :              rest_of_compilation would skip this function and we
    5012                 :            :              really cannot expand the same function twice.  */
    5013                 :   46122400 :           import_export_decl (decl);
    5014                 :   46122400 :           if (DECL_NOT_REALLY_EXTERN (decl)
    5015                 :   44788300 :               && DECL_INITIAL (decl)
    5016                 :   90910700 :               && decl_needed_p (decl))
    5017                 :            :             {
    5018                 :   25526100 :               if (node->cpp_implicit_alias)
    5019                 :          0 :                 node = node->get_alias_target ();
    5020                 :            : 
    5021                 :   25526100 :               node->call_for_symbol_thunks_and_aliases (clear_decl_external,
    5022                 :            :                                                       NULL, true);
    5023                 :            :               /* If we mark !DECL_EXTERNAL one of the symbols in some comdat
    5024                 :            :                  group, we need to mark all symbols in the same comdat group
    5025                 :            :                  that way.  */
    5026                 :   25526100 :               if (node->same_comdat_group)
    5027                 :    3871370 :                 for (cgraph_node *next
    5028                 :    5753000 :                        = dyn_cast<cgraph_node *> (node->same_comdat_group);
    5029                 :    3871370 :                      next != node;
    5030                 :    5861120 :                      next = dyn_cast<cgraph_node *> (next->same_comdat_group))
    5031                 :    1989750 :                   next->call_for_symbol_thunks_and_aliases (clear_decl_external,
    5032                 :            :                                                           NULL, true);
    5033                 :            :             }
    5034                 :            : 
    5035                 :            :           /* If we're going to need to write this function out, and
    5036                 :            :              there's already a body for it, create RTL for it now.
    5037                 :            :              (There might be no body if this is a method we haven't
    5038                 :            :              gotten around to synthesizing yet.)  */
    5039                 :   46122400 :           if (!DECL_EXTERNAL (decl)
    5040                 :   25595800 :               && decl_needed_p (decl)
    5041                 :   25595800 :               && !TREE_ASM_WRITTEN (decl)
    5042                 :   70877100 :               && !node->definition)
    5043                 :            :             {
    5044                 :            :               /* We will output the function; no longer consider it in this
    5045                 :            :                  loop.  */
    5046                 :          0 :               DECL_DEFER_OUTPUT (decl) = 0;
    5047                 :            :               /* Generate RTL for this function now that we know we
    5048                 :            :                  need it.  */
    5049                 :          0 :               expand_or_defer_fn (decl);
    5050                 :          0 :               reconsider = true;
    5051                 :            :             }
    5052                 :            :         }
    5053                 :            : 
    5054                 :     105698 :       if (wrapup_namespace_globals ())
    5055                 :        194 :         reconsider = true;
    5056                 :            : 
    5057                 :            :       /* Static data members are just like namespace-scope globals.  */
    5058                 :   18017400 :       FOR_EACH_VEC_SAFE_ELT (pending_statics, i, decl)
    5059                 :            :         {
    5060                 :   33840600 :           if (var_finalized_p (decl) || DECL_REALLY_EXTERN (decl)
    5061                 :            :               /* Don't write it out if we haven't seen a definition.  */
    5062                 :   18462700 :               || DECL_IN_AGGR_P (decl))
    5063                 :   17362300 :             continue;
    5064                 :     549355 :           import_export_decl (decl);
    5065                 :            :           /* If this static data member is needed, provide it to the
    5066                 :            :              back end.  */
    5067                 :     549355 :           if (DECL_NOT_REALLY_EXTERN (decl) && decl_needed_p (decl))
    5068                 :     547278 :             DECL_EXTERNAL (decl) = 0;
    5069                 :            :         }
    5070                 :     105698 :       if (vec_safe_length (pending_statics) != 0
    5071                 :      33947 :           && wrapup_global_declarations (pending_statics->address (),
    5072                 :      33947 :                                          pending_statics->length ()))
    5073                 :      11157 :         reconsider = true;
    5074                 :            : 
    5075                 :     105698 :       retries++;
    5076                 :            :     }
    5077                 :            :   while (reconsider);
    5078                 :            : 
    5079                 :      77684 :   lower_var_init ();
    5080                 :            : 
    5081                 :      77684 :   generate_mangling_aliases ();
    5082                 :            : 
    5083                 :            :   /* All used inline functions must have a definition at this point.  */
    5084                 :   17690400 :   FOR_EACH_VEC_SAFE_ELT (deferred_fns, i, decl)
    5085                 :            :     {
    5086                 :   17612800 :       if (/* Check online inline functions that were actually used.  */
    5087                 :   45247300 :           DECL_ODR_USED (decl) && DECL_DECLARED_INLINE_P (decl)
    5088                 :            :           /* If the definition actually was available here, then the
    5089                 :            :              fact that the function was not defined merely represents
    5090                 :            :              that for some reason (use of a template repository,
    5091                 :            :              #pragma interface, etc.) we decided not to emit the
    5092                 :            :              definition here.  */
    5093                 :   10021200 :           && !DECL_INITIAL (decl)
    5094                 :            :           /* Don't complain if the template was defined.  */
    5095                 :        297 :           && !(DECL_TEMPLATE_INSTANTIATION (decl)
    5096                 :        232 :                && DECL_INITIAL (DECL_TEMPLATE_RESULT
    5097                 :            :                                 (template_for_substitution (decl))))
    5098                 :   17612800 :           && warning_at (DECL_SOURCE_LOCATION (decl), 0,
    5099                 :            :                          "inline function %qD used but never defined", decl))
    5100                 :            :         /* Avoid a duplicate warning from check_global_declaration.  */
    5101                 :         44 :         TREE_NO_WARNING (decl) = 1;
    5102                 :            :     }
    5103                 :            : 
    5104                 :            :   /* So must decls that use a type with no linkage.  */
    5105                 :      97830 :   FOR_EACH_VEC_SAFE_ELT (no_linkage_decls, i, decl)
    5106                 :      20146 :     no_linkage_error (decl);
    5107                 :            : 
    5108                 :      77684 :   maybe_warn_sized_delete ();
    5109                 :            : 
    5110                 :            :   /* Then, do the Objective-C stuff.  This is where all the
    5111                 :            :      Objective-C module stuff gets generated (symtab,
    5112                 :            :      class/protocol/selector lists etc).  This must be done after C++
    5113                 :            :      templates, destructors etc. so that selectors used in C++
    5114                 :            :      templates are properly allocated.  */
    5115                 :      77684 :   if (c_dialect_objc ())
    5116                 :          0 :     objc_write_global_declarations ();
    5117                 :            : 
    5118                 :            :   /* We give C linkage to static constructors and destructors.  */
    5119                 :      77684 :   push_lang_context (lang_name_c);
    5120                 :            : 
    5121                 :            :   /* Generate initialization and destruction functions for all
    5122                 :            :      priorities for which they are required.  */
    5123                 :      77684 :   if (priority_info_map)
    5124                 :      10642 :     splay_tree_foreach (priority_info_map,
    5125                 :            :                         generate_ctor_and_dtor_functions_for_priority,
    5126                 :            :                         /*data=*/&locus_at_end_of_parsing);
    5127                 :      67042 :   else if (c_dialect_objc () && objc_static_init_needed_p ())
    5128                 :            :     /* If this is obj-c++ and we need a static init, call
    5129                 :            :        generate_ctor_or_dtor_function.  */
    5130                 :          0 :     generate_ctor_or_dtor_function (/*constructor_p=*/true,
    5131                 :            :                                     DEFAULT_INIT_PRIORITY,
    5132                 :            :                                     &locus_at_end_of_parsing);
    5133                 :            : 
    5134                 :            :   /* We're done with the splay-tree now.  */
    5135                 :      77684 :   if (priority_info_map)
    5136                 :      10642 :     splay_tree_delete (priority_info_map);
    5137                 :            : 
    5138                 :            :   /* Generate any missing aliases.  */
    5139                 :      77684 :   maybe_apply_pending_pragma_weaks ();
    5140                 :            : 
    5141                 :            :   /* We're done with static constructors, so we can go back to "C++"
    5142                 :            :      linkage now.  */
    5143                 :      77684 :   pop_lang_context ();
    5144                 :            : 
    5145                 :      77684 :   if (flag_vtable_verify)
    5146                 :            :     {
    5147                 :         12 :       vtv_recover_class_info ();
    5148                 :         12 :       vtv_compute_class_hierarchy_transitive_closure ();
    5149                 :         12 :       vtv_build_vtable_verify_fndecl ();
    5150                 :            :     }
    5151                 :            : 
    5152                 :      77684 :   perform_deferred_noexcept_checks ();
    5153                 :            : 
    5154                 :      77684 :   fini_constexpr ();
    5155                 :            : 
    5156                 :            :   /* The entire file is now complete.  If requested, dump everything
    5157                 :            :      to a file.  */
    5158                 :      77684 :   dump_tu ();
    5159                 :            : 
    5160                 :      77684 :   if (flag_detailed_statistics)
    5161                 :            :     {
    5162                 :          0 :       dump_tree_statistics ();
    5163                 :          0 :       dump_time_statistics ();
    5164                 :            :     }
    5165                 :            : 
    5166                 :      77684 :   timevar_stop (TV_PHASE_DEFERRED);
    5167                 :      77684 :   timevar_start (TV_PHASE_PARSING);
    5168                 :            : 
    5169                 :            :   /* Indicate that we're done with front end processing.  */
    5170                 :      77684 :   at_eof = 2;
    5171                 :            : }
    5172                 :            : 
    5173                 :            : /* Perform any post compilation-proper cleanups for the C++ front-end.
    5174                 :            :    This should really go away.  No front-end should need to do
    5175                 :            :    anything past the compilation process.  */
    5176                 :            : 
    5177                 :            : void
    5178                 :      77614 : cxx_post_compilation_parsing_cleanups (void)
    5179                 :            : {
    5180                 :      77614 :   timevar_start (TV_PHASE_LATE_PARSING_CLEANUPS);
    5181                 :            : 
    5182                 :      77614 :   if (flag_vtable_verify)
    5183                 :            :     {
    5184                 :            :       /* Generate the special constructor initialization function that
    5185                 :            :          calls __VLTRegisterPairs, and give it a very high
    5186                 :            :          initialization priority.  This must be done after
    5187                 :            :          finalize_compilation_unit so that we have accurate
    5188                 :            :          information about which vtable will actually be emitted.  */
    5189                 :         12 :       vtv_generate_init_routine ();
    5190                 :            :     }
    5191                 :            : 
    5192                 :      77614 :   input_location = locus_at_end_of_parsing;
    5193                 :            : 
    5194                 :      77614 :   if (flag_checking)
    5195                 :      77610 :     validate_conversion_obstack ();
    5196                 :            : 
    5197                 :      77614 :   timevar_stop (TV_PHASE_LATE_PARSING_CLEANUPS);
    5198                 :      77614 : }
    5199                 :            : 
    5200                 :            : /* FN is an OFFSET_REF, DOTSTAR_EXPR or MEMBER_REF indicating the
    5201                 :            :    function to call in parse-tree form; it has not yet been
    5202                 :            :    semantically analyzed.  ARGS are the arguments to the function.
    5203                 :            :    They have already been semantically analyzed.  This may change
    5204                 :            :    ARGS.  */
    5205                 :            : 
    5206                 :            : tree
    5207                 :     112313 : build_offset_ref_call_from_tree (tree fn, vec<tree, va_gc> **args,
    5208                 :            :                                  tsubst_flags_t complain)
    5209                 :            : {
    5210                 :     112313 :   tree orig_fn;
    5211                 :     112313 :   vec<tree, va_gc> *orig_args = NULL;
    5212                 :     112313 :   tree expr;
    5213                 :     112313 :   tree object;
    5214                 :            : 
    5215                 :     112313 :   orig_fn = fn;
    5216                 :     112313 :   object = TREE_OPERAND (fn, 0);
    5217                 :            : 
    5218                 :     112313 :   if (processing_template_decl)
    5219                 :            :     {
    5220                 :      72615 :       gcc_assert (TREE_CODE (fn) == DOTSTAR_EXPR
    5221                 :            :                   || TREE_CODE (fn) == MEMBER_REF);
    5222                 :      72615 :       if (type_dependent_expression_p (fn)
    5223                 :      72615 :           || any_type_dependent_arguments_p (*args))
    5224                 :      72572 :         return build_min_nt_call_vec (fn, *args);
    5225                 :            : 
    5226                 :         43 :       orig_args = make_tree_vector_copy (*args);
    5227                 :            : 
    5228                 :            :       /* Transform the arguments and add the implicit "this"
    5229                 :            :          parameter.  That must be done before the FN is transformed
    5230                 :            :          because we depend on the form of FN.  */
    5231                 :         43 :       make_args_non_dependent (*args);
    5232                 :         43 :       object = build_non_dependent_expr (object);
    5233                 :         43 :       if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
    5234                 :            :         {
    5235                 :         35 :           if (TREE_CODE (fn) == DOTSTAR_EXPR)
    5236                 :         29 :             object = cp_build_addr_expr (object, complain);
    5237                 :         35 :           vec_safe_insert (*args, 0, object);
    5238                 :            :         }
    5239                 :            :       /* Now that the arguments are done, transform FN.  */
    5240                 :         43 :       fn = build_non_dependent_expr (fn);
    5241                 :            :     }
    5242                 :            : 
    5243                 :            :   /* A qualified name corresponding to a bound pointer-to-member is
    5244                 :            :      represented as an OFFSET_REF:
    5245                 :            : 
    5246                 :            :         struct B { void g(); };
    5247                 :            :         void (B::*p)();
    5248                 :            :         void B::g() { (this->*p)(); }  */
    5249                 :      39741 :   if (TREE_CODE (fn) == OFFSET_REF)
    5250                 :            :     {
    5251                 :      39698 :       tree object_addr = cp_build_addr_expr (object, complain);
    5252                 :      39698 :       fn = TREE_OPERAND (fn, 1);
    5253                 :      39698 :       fn = get_member_function_from_ptrfunc (&object_addr, fn,
    5254                 :            :                                              complain);
    5255                 :      39698 :       vec_safe_insert (*args, 0, object_addr);
    5256                 :            :     }
    5257                 :            : 
    5258                 :      39741 :   if (CLASS_TYPE_P (TREE_TYPE (fn)))
    5259                 :          4 :     expr = build_op_call (fn, args, complain);
    5260                 :            :   else
    5261                 :      39737 :     expr = cp_build_function_call_vec (fn, args, complain);
    5262                 :      39741 :   if (processing_template_decl && expr != error_mark_node)
    5263                 :         43 :     expr = build_min_non_dep_call_vec (expr, orig_fn, orig_args);
    5264                 :            : 
    5265                 :      39741 :   if (orig_args != NULL)
    5266                 :         43 :     release_tree_vector (orig_args);
    5267                 :            : 
    5268                 :            :   return expr;
    5269                 :            : }
    5270                 :            : 
    5271                 :            : 
    5272                 :            : void
    5273                 :  172901000 : check_default_args (tree x)
    5274                 :            : {
    5275                 :  172901000 :   tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
    5276                 :  172901000 :   bool saw_def = false;
    5277                 :  172901000 :   bool noted_first_def = false;
    5278                 :  172901000 :   int idx_of_first_default_arg = 0;
    5279                 :  172901000 :   location_t loc_of_first_default_arg = UNKNOWN_LOCATION;
    5280                 :  172901000 :   int i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
    5281                 :  172901000 :   tree fndecl = STRIP_TEMPLATE (x);
    5282                 :  345802000 :   auto_diagnostic_group d;
    5283                 :  451152000 :   for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
    5284                 :            :     {
    5285                 :  278251000 :       if (TREE_PURPOSE (arg))
    5286                 :            :         {
    5287                 :     556674 :           if (!saw_def)
    5288                 :            :             {
    5289                 :     444017 :               saw_def = true;
    5290                 :     444017 :               idx_of_first_default_arg = i;
    5291                 :     444017 :               location_t loc = get_fndecl_argument_location (fndecl, i);
    5292                 :     444017 :               if (loc != DECL_SOURCE_LOCATION (x))
    5293                 :     443987 :                 loc_of_first_default_arg = loc;
    5294                 :            :             }
    5295                 :            :         }
    5296                 :  277695000 :       else if (saw_def && !PACK_EXPANSION_P (TREE_VALUE (arg)))
    5297                 :            :         {
    5298                 :        196 :           error_at (get_fndecl_argument_location (fndecl, i),
    5299                 :            :                     "default argument missing for parameter %P of %q#D", i, x);
    5300                 :        196 :           if (loc_of_first_default_arg != UNKNOWN_LOCATION
    5301                 :        196 :               && !noted_first_def)
    5302                 :            :             {
    5303                 :        192 :               inform (loc_of_first_default_arg,
    5304                 :            :                       "...following parameter %P which has a default argument",
    5305                 :            :                       idx_of_first_default_arg);
    5306                 :        192 :               noted_first_def = true;
    5307                 :            :             }
    5308                 :        196 :           TREE_PURPOSE (arg) = error_mark_node;
    5309                 :            :         }
    5310                 :            :     }
    5311                 :  172901000 : }
    5312                 :            : 
    5313                 :            : /* Return true if function DECL can be inlined.  This is used to force
    5314                 :            :    instantiation of methods that might be interesting for inlining.  */
    5315                 :            : bool
    5316                 :          6 : possibly_inlined_p (tree decl)
    5317                 :            : {
    5318                 :          6 :   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
    5319                 :          6 :   if (DECL_UNINLINABLE (decl))
    5320                 :            :     return false;
    5321                 :          6 :   if (!optimize)
    5322                 :          6 :     return DECL_DECLARED_INLINE_P (decl);
    5323                 :            :   /* When optimizing, we might inline everything when flatten
    5324                 :            :      attribute or heuristics inlining for size or autoinlining
    5325                 :            :      is used.  */
    5326                 :            :   return true;
    5327                 :            : }
    5328                 :            : 
    5329                 :            : /* Normally, we can wait until instantiation-time to synthesize DECL.
    5330                 :            :    However, if DECL is a static data member initialized with a constant
    5331                 :            :    or a constexpr function, we need it right now because a reference to
    5332                 :            :    such a data member or a call to such function is not value-dependent.
    5333                 :            :    For a function that uses auto in the return type, we need to instantiate
    5334                 :            :    it to find out its type.  For OpenMP user defined reductions, we need
    5335                 :            :    them instantiated for reduction clauses which inline them by hand
    5336                 :            :    directly.  */
    5337                 :            : 
    5338                 :            : static void
    5339                 :   38854100 : maybe_instantiate_decl (tree decl)
    5340                 :            : {
    5341                 :   38854100 :   if (DECL_LANG_SPECIFIC (decl)
    5342                 :   37954800 :       && DECL_TEMPLATE_INFO (decl)
    5343                 :   30847900 :       && (decl_maybe_constant_var_p (decl)
    5344                 :   15271600 :           || (TREE_CODE (decl) == FUNCTION_DECL
    5345                 :   15163600 :               && DECL_OMP_DECLARE_REDUCTION_P (decl))
    5346                 :   15271600 :           || undeduced_auto_decl (decl))
    5347                 :   15596000 :       && !DECL_DECLARED_CONCEPT_P (decl)
    5348                 :   54450100 :       && !uses_template_parms (DECL_TI_ARGS (decl)))
    5349                 :            :     {
    5350                 :            :       /* Instantiating a function will result in garbage collection.  We
    5351                 :            :          must treat this situation as if we were within the body of a
    5352                 :            :          function so as to avoid collecting live data only referenced from
    5353                 :            :          the stack (such as overload resolution candidates).  */
    5354                 :   15144700 :       ++function_depth;
    5355                 :   15144700 :       instantiate_decl (decl, /*defer_ok=*/false,
    5356                 :            :                         /*expl_inst_class_mem_p=*/false);
    5357                 :   15133900 :       --function_depth;
    5358                 :            :     }
    5359                 :   38843300 : }
    5360                 :            : 
    5361                 :            : /* Maybe warn if DECL is deprecated, subject to COMPLAIN.  Returns whether or
    5362                 :            :    not a warning was emitted.  */
    5363                 :            : 
    5364                 :            : bool
    5365                 :  311523000 : cp_warn_deprecated_use (tree decl, tsubst_flags_t complain)
    5366                 :            : {
    5367                 :  311523000 :   if (!(complain & tf_warning) || !decl
    5368                 :  264081000 :       || deprecated_state == DEPRECATED_SUPPRESS)
    5369                 :            :     return false;
    5370                 :            : 
    5371                 :  217658000 :   if (!TREE_DEPRECATED (decl))
    5372                 :            :     {
    5373                 :            :       /* Perhaps this is a deprecated typedef.  */
    5374                 :  217645000 :       if (TYPE_P (decl) && TYPE_NAME (decl))
    5375                 :  217645000 :         decl = TYPE_NAME (decl);
    5376                 :            : 
    5377                 :  217645000 :       if (!TREE_DEPRECATED (decl))
    5378                 :            :         return false;
    5379                 :            :     }
    5380                 :            : 
    5381                 :            :   /* Don't warn within members of a deprecated type.  */
    5382                 :      12943 :   if (TYPE_P (decl)
    5383                 :      12943 :       && currently_open_class (decl))
    5384                 :            :     return false;
    5385                 :            : 
    5386                 :      12506 :   bool warned = false;
    5387                 :      12506 :   if (cxx_dialect >= cxx11
    5388                 :      12400 :       && DECL_P (decl)
    5389                 :      12337 :       && DECL_ARTIFICIAL (decl)
    5390                 :      11420 :       && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl)
    5391                 :      23926 :       && copy_fn_p (decl))
    5392                 :            :     {
    5393                 :      11420 :       if (warn_deprecated_copy
    5394                 :            :           /* Don't warn about system library classes (c++/86342).  */
    5395                 :      11447 :           && (!DECL_IN_SYSTEM_HEADER (decl)
    5396                 :          9 :               || global_dc->dc_warn_system_headers))
    5397                 :            :         {
    5398                 :         36 :           auto_diagnostic_group d;
    5399                 :         18 :           tree ctx = DECL_CONTEXT (decl);
    5400                 :         18 :           tree other = classtype_has_depr_implicit_copy (ctx);
    5401                 :         18 :           int opt = (DECL_DESTRUCTOR_P (other)
    5402                 :         18 :                      ? OPT_Wdeprecated_copy_dtor
    5403                 :         18 :                      : OPT_Wdeprecated_copy);
    5404                 :         18 :           warned = warning (opt, "implicitly-declared %qD is deprecated",
    5405                 :            :                             decl);
    5406                 :         18 :           if (warned)
    5407                 :          6 :             inform (DECL_SOURCE_LOCATION (other),
    5408                 :            :                     "because %qT has user-provided %qD",
    5409                 :            :                     ctx, other);
    5410                 :            :         }
    5411                 :            :     }
    5412                 :            :   else
    5413                 :       1086 :     warned = warn_deprecated_use (decl, NULL_TREE);
    5414                 :            : 
    5415                 :            :   return warned;
    5416                 :            : }
    5417                 :            : 
    5418                 :            : /* Like above, but takes into account outer scopes.  */
    5419                 :            : 
    5420                 :            : void
    5421                 :   94127100 : cp_warn_deprecated_use_scopes (tree scope)
    5422                 :            : {
    5423                 :  143800000 :   while (scope
    5424                 :  143800000 :          && scope != error_mark_node
    5425                 :  143800000 :          && scope != global_namespace)
    5426                 :            :     {
    5427                 :   49673000 :       if (cp_warn_deprecated_use (scope))
    5428                 :            :         return;
    5429                 :   49672900 :       if (TYPE_P (scope))
    5430                 :   11492000 :         scope = CP_TYPE_CONTEXT (scope);
    5431                 :            :       else
    5432                 :  181981000 :         scope = CP_DECL_CONTEXT (scope);
    5433                 :            :     }
    5434                 :            : }
    5435                 :            : 
    5436                 :            : /* True if DECL or its enclosing scope have unbound template parameters.  */
    5437                 :            : 
    5438                 :            : bool
    5439                 :   63075000 : decl_dependent_p (tree decl)
    5440                 :            : {
    5441                 :  122995000 :   if (DECL_FUNCTION_SCOPE_P (decl)
    5442                 :   14019800 :       || TREE_CODE (decl) == CONST_DECL
    5443                 :   10987400 :       || TREE_CODE (decl) == USING_DECL
    5444                 :   74062400 :       || TREE_CODE (decl) == FIELD_DECL)
    5445                 :   58707800 :     decl = CP_DECL_CONTEXT (decl);
    5446                 :   63075000 :   if (tree tinfo = get_template_info (decl))
    5447                 :   46946100 :     if (any_dependent_template_arguments_p (TI_ARGS (tinfo)))
    5448                 :            :       return true;
    5449                 :   43700000 :   if (LAMBDA_FUNCTION_P (decl)
    5450                 :   42133700 :       && dependent_type_p (DECL_CONTEXT (decl)))
    5451                 :          0 :     return true;
    5452                 :            :   return false;
    5453                 :            : }
    5454                 :            : 
    5455                 :            : /* Mark DECL (either a _DECL or a BASELINK) as "used" in the program.
    5456                 :            :    If DECL is a specialization or implicitly declared class member,
    5457                 :            :    generate the actual definition.  Return false if something goes
    5458                 :            :    wrong, true otherwise.  */
    5459                 :            : 
    5460                 :            : bool
    5461                 :  145739000 : mark_used (tree decl, tsubst_flags_t complain)
    5462                 :            : {
    5463                 :            :   /* If we're just testing conversions or resolving overloads, we
    5464                 :            :      don't want any permanent effects like forcing functions to be
    5465                 :            :      output or instantiating templates.  */
    5466                 :  145739000 :   if ((complain & tf_conv))
    5467                 :            :     return true;
    5468                 :            : 
    5469                 :            :   /* If DECL is a BASELINK for a single function, then treat it just
    5470                 :            :      like the DECL for the function.  Otherwise, if the BASELINK is
    5471                 :            :      for an overloaded function, we don't know which function was
    5472                 :            :      actually used until after overload resolution.  */
    5473                 :  145706000 :   if (BASELINK_P (decl))
    5474                 :            :     {
    5475                 :    1807120 :       decl = BASELINK_FUNCTIONS (decl);
    5476                 :    1807120 :       if (really_overloaded_fn (decl))
    5477                 :            :         return true;
    5478                 :     725936 :       decl = OVL_FIRST (decl);
    5479                 :            :     }
    5480                 :            : 
    5481                 :  144625000 :   if (!DECL_P (decl))
    5482                 :            :     return true;
    5483                 :            : 
    5484                 :            :   /* Set TREE_USED for the benefit of -Wunused.  */
    5485                 :  144625000 :   TREE_USED (decl) = 1;
    5486                 :            :   /* And for structured bindings also the underlying decl.  */
    5487                 :  144625000 :   if (DECL_DECOMPOSITION_P (decl) && DECL_DECOMP_BASE (decl))
    5488                 :      11594 :     TREE_USED (DECL_DECOMP_BASE (decl)) = 1;
    5489                 :            : 
    5490                 :  144625000 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    5491                 :            :     return true;
    5492                 :            : 
    5493                 :  144625000 :   if (DECL_CLONED_FUNCTION_P (decl))
    5494                 :    4298280 :     TREE_USED (DECL_CLONED_FUNCTION (decl)) = 1;
    5495                 :            : 
    5496                 :            :   /* Mark enumeration types as used.  */
    5497                 :  144625000 :   if (TREE_CODE (decl) == CONST_DECL)
    5498                 :    3032410 :     used_types_insert (DECL_CONTEXT (decl));
    5499                 :            : 
    5500                 :  144625000 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5501                 :  144625000 :       && DECL_MAYBE_DELETED (decl))
    5502                 :            :     {
    5503                 :            :       /* ??? Switch other defaulted functions to use DECL_MAYBE_DELETED?  */
    5504                 :        110 :       gcc_assert (special_function_p (decl) == sfk_comparison);
    5505                 :            : 
    5506                 :        110 :       ++function_depth;
    5507                 :        110 :       synthesize_method (decl);
    5508                 :        110 :       --function_depth;
    5509                 :            :     }
    5510                 :            : 
    5511                 :  144625000 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5512                 :  144625000 :       && !maybe_instantiate_noexcept (decl, complain))
    5513                 :            :     return false;
    5514                 :            : 
    5515                 :  144625000 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5516                 :  144625000 :       && DECL_DELETED_FN (decl))
    5517                 :            :     {
    5518                 :       1974 :       if (DECL_ARTIFICIAL (decl)
    5519                 :       1666 :           && DECL_CONV_FN_P (decl)
    5520                 :       1980 :           && LAMBDA_TYPE_P (DECL_CONTEXT (decl)))
    5521                 :            :         /* We mark a lambda conversion op as deleted if we can't
    5522                 :            :            generate it properly; see maybe_add_lambda_conv_op.  */
    5523                 :          6 :         sorry ("converting lambda that uses %<...%> to function pointer");
    5524                 :       1968 :       else if (complain & tf_error)
    5525                 :            :         {
    5526                 :       1959 :           error ("use of deleted function %qD", decl);
    5527                 :       1959 :           if (!maybe_explain_implicit_delete (decl))
    5528                 :        285 :             inform (DECL_SOURCE_LOCATION (decl), "declared here");
    5529                 :            :         }
    5530                 :       1974 :       return false;
    5531                 :            :     }
    5532                 :            : 
    5533                 :  144623000 :   cp_warn_deprecated_use (decl, complain);
    5534                 :            : 
    5535                 :            :   /* We can only check DECL_ODR_USED on variables or functions with
    5536                 :            :      DECL_LANG_SPECIFIC set, and these are also the only decls that we
    5537                 :            :      might need special handling for.  */
    5538                 :   93436000 :   if (!VAR_OR_FUNCTION_DECL_P (decl)
    5539                 :   97091200 :       || DECL_LANG_SPECIFIC (decl) == NULL
    5540                 :  226180000 :       || DECL_THUNK_P (decl))
    5541                 :            :     {
    5542                 :   63075000 :       if (!decl_dependent_p (decl)
    5543                 :   63075000 :           && !require_deduced_type (decl, complain))
    5544                 :            :         return false;
    5545                 :   63075000 :       return true;
    5546                 :            :     }
    5547                 :            : 
    5548                 :            :   /* We only want to do this processing once.  We don't need to keep trying
    5549                 :            :      to instantiate inline templates, because unit-at-a-time will make sure
    5550                 :            :      we get them compiled before functions that want to inline them.  */
    5551                 :  127443000 :   if (DECL_ODR_USED (decl))
    5552                 :            :     return true;
    5553                 :            : 
    5554                 :            :   /* Normally, we can wait until instantiation-time to synthesize DECL.
    5555                 :            :      However, if DECL is a static data member initialized with a constant
    5556                 :            :      or a constexpr function, we need it right now because a reference to
    5557                 :            :      such a data member or a call to such function is not value-dependent.
    5558                 :            :      For a function that uses auto in the return type, we need to instantiate
    5559                 :            :      it to find out its type.  For OpenMP user defined reductions, we need
    5560                 :            :      them instantiated for reduction clauses which inline them by hand
    5561                 :            :      directly.  */
    5562                 :   22610100 :   maybe_instantiate_decl (decl);
    5563                 :            : 
    5564                 :   10266900 :   if (flag_concepts && TREE_CODE (decl) == FUNCTION_DECL
    5565                 :   30855300 :       && !constraints_satisfied_p (decl))
    5566                 :            :     {
    5567                 :        125 :       if (complain & tf_error)
    5568                 :            :         {
    5569                 :        250 :           auto_diagnostic_group d;
    5570                 :        125 :           error ("use of function %qD with unsatisfied constraints",
    5571                 :            :                  decl);
    5572                 :        125 :           location_t loc = DECL_SOURCE_LOCATION (decl);
    5573                 :        125 :           inform (loc, "declared here");
    5574                 :        125 :           diagnose_constraints (loc, decl, NULL_TREE);
    5575                 :            :         }
    5576                 :        125 :       return false;
    5577                 :            :     }
    5578                 :            : 
    5579                 :   22599100 :   if (processing_template_decl || in_template_function ())
    5580                 :    2663630 :     return true;
    5581                 :            : 
    5582                 :            :   /* Check this too in case we're within instantiate_non_dependent_expr.  */
    5583                 :   19935500 :   if (DECL_TEMPLATE_INFO (decl)
    5584                 :   19935500 :       && uses_template_parms (DECL_TI_ARGS (decl)))
    5585                 :            :     return true;
    5586                 :            : 
    5587                 :   19908700 :   if (!require_deduced_type (decl, complain))
    5588                 :            :     return false;
    5589                 :            : 
    5590                 :   19908500 :   if (builtin_pack_fn_p (decl))
    5591                 :            :     {
    5592                 :         12 :       error ("use of built-in parameter pack %qD outside of a template",
    5593                 :          6 :              DECL_NAME (decl));
    5594                 :          6 :       return false;
    5595                 :            :     }
    5596                 :            : 
    5597                 :            :   /* If we don't need a value, then we don't need to synthesize DECL.  */
    5598                 :   19908500 :   if (cp_unevaluated_operand || in_discarded_stmt)
    5599                 :            :     return true;
    5600                 :            : 
    5601                 :   16991500 :   DECL_ODR_USED (decl) = 1;
    5602                 :    8959430 :   if (DECL_CLONED_FUNCTION_P (decl))
    5603                 :    3664390 :     DECL_ODR_USED (DECL_CLONED_FUNCTION (decl)) = 1;
    5604                 :            : 
    5605                 :            :   /* DR 757: A type without linkage shall not be used as the type of a
    5606                 :            :      variable or function with linkage, unless
    5607                 :            :    o the variable or function has extern "C" linkage (7.5 [dcl.link]), or
    5608                 :            :    o the variable or function is not used (3.2 [basic.def.odr]) or is
    5609                 :            :    defined in the same translation unit.  */
    5610                 :    8959430 :   if (cxx_dialect > cxx98
    5611                 :    8827560 :       && decl_linkage (decl) != lk_none
    5612                 :    8270830 :       && !DECL_EXTERN_C_P (decl)
    5613                 :    7322830 :       && !DECL_ARTIFICIAL (decl)
    5614                 :    6794220 :       && !decl_defined_p (decl)
    5615                 :   14516500 :       && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
    5616                 :            :     {
    5617                 :      20146 :       if (is_local_extern (decl))
    5618                 :            :         /* There's no way to define a local extern, and adding it to
    5619                 :            :            the vector interferes with GC, so give an error now.  */
    5620                 :          0 :         no_linkage_error (decl);
    5621                 :            :       else
    5622                 :      20146 :         vec_safe_push (no_linkage_decls, decl);
    5623                 :            :     }
    5624                 :            : 
    5625                 :    8959430 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5626                 :    8032020 :       && DECL_DECLARED_INLINE_P (decl)
    5627                 :    6205020 :       && !DECL_INITIAL (decl)
    5628                 :    4922080 :       && !DECL_ARTIFICIAL (decl)
    5629                 :   13702800 :       && !DECL_PURE_VIRTUAL_P (decl))
    5630                 :            :     /* Remember it, so we can check it was defined.  */
    5631                 :    4743400 :     note_vague_linkage_fn (decl);
    5632                 :            : 
    5633                 :            :   /* Is it a synthesized method that needs to be synthesized?  */
    5634                 :    8959430 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5635                 :    8032020 :       && DECL_DEFAULTED_FN (decl)
    5636                 :            :       /* A function defaulted outside the class is synthesized either by
    5637                 :            :          cp_finish_decl or instantiate_decl.  */
    5638                 :     272630 :       && !DECL_DEFAULTED_OUTSIDE_CLASS_P (decl)
    5639                 :    9231960 :       && ! DECL_INITIAL (decl))
    5640                 :            :     {
    5641                 :            :       /* Defer virtual destructors so that thunks get the right
    5642                 :            :          linkage.  */
    5643                 :     252226 :       if (DECL_VIRTUAL_P (decl) && !at_eof)
    5644                 :            :         {
    5645                 :       5211 :           note_vague_linkage_fn (decl);
    5646                 :       5211 :           return true;
    5647                 :            :         }
    5648                 :            : 
    5649                 :            :       /* Remember the current location for a function we will end up
    5650                 :            :          synthesizing.  Then we can inform the user where it was
    5651                 :            :          required in the case of error.  */
    5652                 :     247015 :       if (decl_remember_implicit_trigger_p (decl))
    5653                 :     144131 :         DECL_SOURCE_LOCATION (decl) = input_location;
    5654                 :            : 
    5655                 :            :       /* Synthesizing an implicitly defined member function will result in
    5656                 :            :          garbage collection.  We must treat this situation as if we were
    5657                 :            :          within the body of a function so as to avoid collecting live data
    5658                 :            :          on the stack (such as overload resolution candidates).
    5659                 :            : 
    5660                 :            :          We could just let c_parse_final_cleanups handle synthesizing
    5661                 :            :          this function by adding it to deferred_fns, but doing
    5662                 :            :          it at the use site produces better error messages.  */
    5663                 :     247015 :       ++function_depth;
    5664                 :     247015 :       synthesize_method (decl);
    5665                 :     247015 :       --function_depth;
    5666                 :            :       /* If this is a synthesized method we don't need to
    5667                 :            :          do the instantiation test below.  */
    5668                 :            :     }
    5669                 :    8707210 :   else if (VAR_OR_FUNCTION_DECL_P (decl)
    5670                 :    8707210 :            && DECL_TEMPLATE_INFO (decl)
    5671                 :    5832600 :            && !DECL_DECLARED_CONCEPT_P (decl)
    5672                 :   14539800 :            && (!DECL_EXPLICIT_INSTANTIATION (decl)
    5673                 :     511202 :                || always_instantiate_p (decl)))
    5674                 :            :     /* If this is a function or variable that is an instance of some
    5675                 :            :        template, we now know that we will need to actually do the
    5676                 :            :        instantiation. We check that DECL is not an explicit
    5677                 :            :        instantiation because that is not checked in instantiate_decl.
    5678                 :            : 
    5679                 :            :        We put off instantiating functions in order to improve compile
    5680                 :            :        times.  Maintaining a stack of active functions is expensive,
    5681                 :            :        and the inliner knows to instantiate any functions it might
    5682                 :            :        need.  Therefore, we always try to defer instantiation.  */
    5683                 :            :     {
    5684                 :    5775880 :       ++function_depth;
    5685                 :    5775880 :       instantiate_decl (decl, /*defer_ok=*/true,
    5686                 :            :                         /*expl_inst_class_mem_p=*/false);
    5687                 :    5775880 :       --function_depth;
    5688                 :            :     }
    5689                 :            : 
    5690                 :            :   return true;
    5691                 :            : }
    5692                 :            : 
    5693                 :            : bool
    5694                 :   36451400 : mark_used (tree decl)
    5695                 :            : {
    5696                 :   36451400 :   return mark_used (decl, tf_warning_or_error);
    5697                 :            : }
    5698                 :            : 
    5699                 :            : tree
    5700                 :         12 : vtv_start_verification_constructor_init_function (void)
    5701                 :            : {
    5702                 :         12 :   return start_objects ('I', MAX_RESERVED_INIT_PRIORITY - 1);
    5703                 :            : }
    5704                 :            : 
    5705                 :            : tree
    5706                 :          5 : vtv_finish_verification_constructor_init_function (tree function_body)
    5707                 :            : {
    5708                 :          5 :   tree fn;
    5709                 :            : 
    5710                 :          5 :   finish_compound_stmt (function_body);
    5711                 :          5 :   fn = finish_function (/*inline_p=*/false);
    5712                 :          5 :   DECL_STATIC_CONSTRUCTOR (fn) = 1;
    5713                 :          5 :   decl_init_priority_insert (fn, MAX_RESERVED_INIT_PRIORITY - 1);
    5714                 :            : 
    5715                 :          5 :   return fn;
    5716                 :            : }
    5717                 :            : 
    5718                 :            : #include "gt-cp-decl2.h"

Generated by: LCOV version 1.0

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 --enable-host-shared. GCC test suite is run with the built compiler.