LCOV - code coverage report
Current view: top level - gcc - ipa-free-lang-data.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 95.6 % 543 519
Test Date: 2026-03-28 14:25:54 Functions: 100.0 % 25 25
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Pass to free or clear language-specific data structures from
       2              :    the IL before they reach the middle end.
       3              : 
       4              :    Copyright (C) 1987-2026 Free Software Foundation, Inc.
       5              : 
       6              :    This file is part of GCC.
       7              : 
       8              :    GCC is free software; you can redistribute it and/or modify it under
       9              :    the terms of the GNU General Public License as published by the Free
      10              :    Software Foundation; either version 3, or (at your option) any later
      11              :    version.
      12              : 
      13              :    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      14              :    WARRANTY; without even the implied warranty of MERCHANTABILITY or
      15              :    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      16              :    for more details.
      17              : 
      18              :    You should have received a copy of the GNU General Public License
      19              :    along with GCC; see the file COPYING3.  If not see
      20              :    <http://www.gnu.org/licenses/>.  */
      21              : 
      22              : /* This file contains the low level primitives for operating on tree nodes,
      23              :    including allocation, list operations, interning of identifiers,
      24              :    construction of data type nodes and statement nodes,
      25              :    and construction of type conversion nodes.  It also contains
      26              :    tables index by tree code that describe how to take apart
      27              :    nodes of that code.
      28              : 
      29              :    It is intended to be language-independent but can occasionally
      30              :    calls language-dependent routines.  */
      31              : 
      32              : #include "config.h"
      33              : #include "system.h"
      34              : #include "coretypes.h"
      35              : #include "backend.h"
      36              : #include "target.h"
      37              : #include "tree.h"
      38              : #include "gimple.h"
      39              : #include "tree-pass.h"
      40              : #include "ssa.h"
      41              : #include "cgraph.h"
      42              : #include "diagnostic.h"
      43              : #include "alias.h"
      44              : #include "attribs.h"
      45              : #include "langhooks.h"
      46              : #include "gimple-iterator.h"
      47              : #include "langhooks-def.h"
      48              : #include "tree-diagnostic.h"
      49              : #include "except.h"
      50              : #include "ipa-utils.h"
      51              : 
      52              : namespace {
      53              : 
      54              : /* Data used when collecting DECLs and TYPEs for language data removal.  */
      55              : 
      56              : class free_lang_data_d
      57              : {
      58              : public:
      59       232107 :   free_lang_data_d () : decls (100), types (100) {}
      60              : 
      61              :   /* Worklist to avoid excessive recursion.  */
      62              :   auto_vec<tree> worklist;
      63              : 
      64              :   /* Set of traversed objects.  Used to avoid duplicate visits.  */
      65              :   hash_set<tree> pset;
      66              : 
      67              :   /* Array of symbols to process with free_lang_data_in_decl.  */
      68              :   auto_vec<tree> decls;
      69              : 
      70              :   /* Array of types to process with free_lang_data_in_type.  */
      71              :   auto_vec<tree> types;
      72              : };
      73              : 
      74              : 
      75              : /* Add type or decl T to one of the list of tree nodes that need their
      76              :    language data removed.  The lists are held inside FLD.  */
      77              : 
      78              : static void
      79      2889503 : add_tree_to_fld_list (tree t, class free_lang_data_d *fld)
      80              : {
      81      2889503 :   if (DECL_P (t))
      82      2020757 :     fld->decls.safe_push (t);
      83       868746 :   else if (TYPE_P (t))
      84       868746 :     fld->types.safe_push (t);
      85              :   else
      86            0 :     gcc_unreachable ();
      87      2889503 : }
      88              : 
      89              : /* Push tree node T into FLD->WORKLIST.  */
      90              : 
      91              : static inline void
      92     34414999 : fld_worklist_push (tree t, class free_lang_data_d *fld)
      93              : {
      94     55424932 :   if (t && !is_lang_specific (t) && !fld->pset.contains (t))
      95      5434126 :     fld->worklist.safe_push ((t));
      96     34414999 : }
      97              : 
      98              : 
      99              : 
     100              : /* Return simplified TYPE_NAME of TYPE.  */
     101              : 
     102              : static tree
     103      1055689 : fld_simplified_type_name (tree type)
     104              : {
     105      1055689 :   if (!TYPE_NAME (type) || TREE_CODE (TYPE_NAME (type)) != TYPE_DECL)
     106       849296 :     return TYPE_NAME (type);
     107              :   /* Drop TYPE_DECLs in TYPE_NAME in favor of the identifier in the
     108              :      TYPE_DECL if the type doesn't have linkage.
     109              :      this must match fld_  */
     110       206393 :   if (type != TYPE_MAIN_VARIANT (type)
     111       206393 :       || (!DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (type))
     112        83410 :           && (TREE_CODE (type) != RECORD_TYPE
     113         7808 :               || !TYPE_BINFO (type)
     114            0 :               || !BINFO_VTABLE (TYPE_BINFO (type)))))
     115       161533 :     return DECL_NAME (TYPE_NAME (type));
     116        44860 :   return TYPE_NAME (type);
     117              : }
     118              : 
     119              : /* Do same comparsion as check_qualified_type skipping lang part of type
     120              :    and be more permissive about type names: we only care that names are
     121              :    same (for diagnostics) and that ODR names are the same.
     122              :    If INNER_TYPE is non-NULL, be sure that TREE_TYPE match it.  */
     123              : 
     124              : static bool
     125       103421 : fld_type_variant_equal_p (tree t, tree v, tree inner_type)
     126              : {
     127       103421 :   if (TYPE_QUALS (t) != TYPE_QUALS (v)
     128              :       /* We want to match incomplete variants with complete types.
     129              :          In this case we need to ignore alignment.   */
     130        86705 :       || ((!RECORD_OR_UNION_TYPE_P (t) || COMPLETE_TYPE_P (v))
     131        64438 :           && (TYPE_ALIGN (t) != TYPE_ALIGN (v)
     132        64424 :               || TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (v)))
     133        86691 :       || fld_simplified_type_name (t) != fld_simplified_type_name (v)
     134        72510 :       || !attribute_list_equal (TYPE_ATTRIBUTES (t),
     135        72510 :                                 TYPE_ATTRIBUTES (v))
     136       175931 :       || (inner_type && TREE_TYPE (v) != inner_type))
     137        30911 :     return false;
     138              : 
     139              :   return true;
     140              : }
     141              : 
     142              : /* Find variant of FIRST that match T and create new one if necessary.
     143              :    Set TREE_TYPE to INNER_TYPE if non-NULL.  */
     144              : 
     145              : static tree
     146        72510 : fld_type_variant (tree first, tree t, class free_lang_data_d *fld,
     147              :                   tree inner_type = NULL)
     148              : {
     149        72510 :   if (first == TYPE_MAIN_VARIANT (t))
     150              :     return t;
     151        94796 :   for (tree v = first; v; v = TYPE_NEXT_VARIANT (v))
     152        88060 :     if (fld_type_variant_equal_p (t, v, inner_type))
     153              :       {
     154        65774 :         if (flag_checking)
     155        74399 :           for (tree v2 = TYPE_NEXT_VARIANT (v); v2; v2 = TYPE_NEXT_VARIANT (v2))
     156         8625 :             gcc_assert (!fld_type_variant_equal_p (t, v2, inner_type));
     157        65774 :         return v;
     158              :       }
     159         6736 :   tree v = build_variant_type_copy (first);
     160         6736 :   TYPE_READONLY (v) = TYPE_READONLY (t);
     161         6736 :   TYPE_VOLATILE (v) = TYPE_VOLATILE (t);
     162         6736 :   TYPE_ATOMIC (v) = TYPE_ATOMIC (t);
     163         6736 :   TYPE_RESTRICT (v) = TYPE_RESTRICT (t);
     164         6736 :   TYPE_ADDR_SPACE (v) = TYPE_ADDR_SPACE (t);
     165         6736 :   TYPE_NAME (v) = TYPE_NAME (t);
     166         6736 :   TYPE_ATTRIBUTES (v) = TYPE_ATTRIBUTES (t);
     167         6736 :   TYPE_CANONICAL (v) = TYPE_CANONICAL (t);
     168              :   /* Variants of incomplete types should have alignment
     169              :      set to BITS_PER_UNIT.  Do not copy the actual alignment.  */
     170         6736 :   if (!RECORD_OR_UNION_TYPE_P (v) || COMPLETE_TYPE_P (v))
     171              :     {
     172         1554 :       SET_TYPE_ALIGN (v, TYPE_ALIGN (t));
     173         1554 :       TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t);
     174              :     }
     175         6736 :   if (inner_type)
     176           20 :     TREE_TYPE (v) = inner_type;
     177         6736 :   gcc_checking_assert (fld_type_variant_equal_p (t,v, inner_type));
     178         6736 :   if (!fld->pset.add (v))
     179         6736 :     add_tree_to_fld_list (v, fld);
     180              :   return v;
     181              : }
     182              : 
     183              : /* Map complete types to incomplete types.  */
     184              : 
     185              : static hash_map<tree, tree> *fld_incomplete_types;
     186              : 
     187              : /* Map types to simplified types.  */
     188              : 
     189              : static hash_map<tree, tree> *fld_simplified_types;
     190              : 
     191              : /* Produce variant of T whose TREE_TYPE is T2. If it is main variant,
     192              :    use MAP to prevent duplicates.  */
     193              : 
     194              : static tree
     195         2861 : fld_process_array_type (tree t, tree t2, hash_map<tree, tree> *map,
     196              :                         class free_lang_data_d *fld)
     197              : {
     198         2861 :   if (TREE_TYPE (t) == t2)
     199              :     return t;
     200              : 
     201          104 :   if (TYPE_MAIN_VARIANT (t) != t)
     202              :     {
     203           20 :       return fld_type_variant
     204           20 :         (fld_process_array_type (TYPE_MAIN_VARIANT (t),
     205           20 :                                  TYPE_MAIN_VARIANT (t2), map, fld),
     206           20 :          t, fld, t2);
     207              :     }
     208              : 
     209           84 :   bool existed;
     210           84 :   tree &array
     211           84 :     = map->get_or_insert (t, &existed);
     212           84 :   if (!existed)
     213              :     {
     214           29 :       array
     215           29 :         = build_array_type_1 (t2, TYPE_DOMAIN (t), TYPE_TYPELESS_STORAGE (t),
     216              :                               false, false);
     217           29 :       TYPE_CANONICAL (array) = TYPE_CANONICAL (t);
     218           29 :       if (!fld->pset.add (array))
     219           29 :         add_tree_to_fld_list (array, fld);
     220              :     }
     221           84 :   return array;
     222              : }
     223              : 
     224              : /* Return CTX after removal of contexts that are not relevant  */
     225              : 
     226              : static tree
     227      1910854 : fld_decl_context (tree ctx)
     228              : {
     229              :   /* Variably modified types are needed for tree_is_indexable to decide
     230              :      whether the type needs to go to local or global section.
     231              :      This code is semi-broken but for now it is easiest to keep contexts
     232              :      as expected.  */
     233      1766087 :   if (ctx && TYPE_P (ctx)
     234      1946815 :       && !variably_modified_type_p (ctx, NULL_TREE))
     235              :     {
     236        76977 :       while (ctx && TYPE_P (ctx))
     237        41016 :         ctx = TYPE_CONTEXT (ctx);
     238              :     }
     239      1910854 :   return ctx;
     240              : }
     241              : 
     242              : /* For T being aggregate type try to turn it into an incomplete variant.
     243              :    Return T if no simplification is possible.  */
     244              : 
     245              : static tree
     246       364882 : fld_incomplete_type_of (tree t, class free_lang_data_d *fld)
     247              : {
     248       364882 :   if (!t)
     249              :     return NULL;
     250       364882 :   if (POINTER_TYPE_P (t))
     251              :     {
     252       178362 :       tree t2 = fld_incomplete_type_of (TREE_TYPE (t), fld);
     253       178362 :       if (t2 != TREE_TYPE (t))
     254              :         {
     255        57310 :           tree first;
     256        57310 :           if (TREE_CODE (t) == POINTER_TYPE)
     257        46587 :             first = build_pointer_type_for_mode (t2, TYPE_MODE (t),
     258        46587 :                                                  TYPE_REF_CAN_ALIAS_ALL (t));
     259              :           else
     260        10723 :             first = build_reference_type_for_mode (t2, TYPE_MODE (t),
     261        10723 :                                                    TYPE_REF_CAN_ALIAS_ALL (t));
     262        57310 :           gcc_assert (TYPE_CANONICAL (t2) != t2
     263              :                       && TYPE_CANONICAL (t2) == TYPE_CANONICAL (TREE_TYPE (t)));
     264        57310 :           if (!fld->pset.add (first))
     265        19699 :             add_tree_to_fld_list (first, fld);
     266        57310 :           return fld_type_variant (first, t, fld);
     267              :         }
     268              :       return t;
     269              :     }
     270       186520 :   if (TREE_CODE (t) == ARRAY_TYPE)
     271         2841 :     return fld_process_array_type (t,
     272         2841 :                                    fld_incomplete_type_of (TREE_TYPE (t), fld),
     273         2841 :                                    fld_incomplete_types, fld);
     274       183679 :   if ((!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
     275       183679 :       || !COMPLETE_TYPE_P (t))
     276              :     return t;
     277        70822 :   if (TYPE_MAIN_VARIANT (t) == t)
     278              :     {
     279        55642 :       bool existed;
     280        55642 :       tree &copy
     281        55642 :         = fld_incomplete_types->get_or_insert (t, &existed);
     282              : 
     283        55642 :       if (!existed)
     284              :         {
     285        13444 :           copy = build_distinct_type_copy (t);
     286              : 
     287              :           /* It is possible that type was not seen by free_lang_data yet.  */
     288        13444 :           if (!fld->pset.add (copy))
     289        13444 :             add_tree_to_fld_list (copy, fld);
     290        13444 :           TYPE_SIZE (copy) = NULL;
     291        13444 :           TYPE_USER_ALIGN (copy) = 0;
     292        13444 :           TYPE_SIZE_UNIT (copy) = NULL;
     293        13444 :           TYPE_CANONICAL (copy) = TYPE_CANONICAL (t);
     294        13444 :           TREE_ADDRESSABLE (copy) = 0;
     295        13444 :           if (AGGREGATE_TYPE_P (t))
     296              :             {
     297        13372 :               SET_TYPE_MODE (copy, VOIDmode);
     298        13372 :               SET_TYPE_ALIGN (copy, BITS_PER_UNIT);
     299        13372 :               TYPE_TYPELESS_STORAGE (copy) = 0;
     300        13372 :               TYPE_FIELDS (copy) = NULL;
     301        13372 :               TYPE_BINFO (copy) = NULL;
     302        13372 :               TYPE_FINAL_P (copy) = 0;
     303        13372 :               TYPE_EMPTY_P (copy) = 0;
     304              :             }
     305              :           else
     306              :             {
     307           72 :               TYPE_VALUES (copy) = NULL;
     308           72 :               ENUM_IS_OPAQUE (copy) = 0;
     309           72 :               ENUM_IS_SCOPED (copy) = 0;
     310              :             }
     311              : 
     312              :           /* Build copy of TYPE_DECL in TYPE_NAME if necessary.
     313              :              This is needed for ODR violation warnings to come out right (we
     314              :              want duplicate TYPE_DECLs whenever the type is duplicated because
     315              :              of ODR violation.  Because lang data in the TYPE_DECL may not
     316              :              have been freed yet, rebuild it from scratch and copy relevant
     317              :              fields.  */
     318        13444 :           TYPE_NAME (copy) = fld_simplified_type_name (copy);
     319        13444 :           tree name = TYPE_NAME (copy);
     320              : 
     321        13444 :           if (name && TREE_CODE (name) == TYPE_DECL)
     322              :             {
     323         8610 :               gcc_checking_assert (TREE_TYPE (name) == t);
     324         8610 :               tree name2 = build_decl (DECL_SOURCE_LOCATION (name), TYPE_DECL,
     325         8610 :                                        DECL_NAME (name), copy);
     326         8610 :               if (DECL_ASSEMBLER_NAME_SET_P (name))
     327         8610 :                 SET_DECL_ASSEMBLER_NAME (name2, DECL_ASSEMBLER_NAME (name));
     328         8610 :               SET_DECL_ALIGN (name2, 0);
     329         8610 :               DECL_CONTEXT (name2) = fld_decl_context
     330         8610 :                 (DECL_CONTEXT (name));
     331         8610 :               TYPE_NAME (copy) = name2;
     332              :             }
     333              :         }
     334        55642 :       return copy;
     335              :     }
     336        15180 :   return (fld_type_variant
     337        15180 :           (fld_incomplete_type_of (TYPE_MAIN_VARIANT (t), fld), t, fld));
     338              : }
     339              : 
     340              : /* Simplify type T for scenarios where we do not need complete pointer
     341              :    types.  */
     342              : 
     343              : static tree
     344      1199125 : fld_simplified_type (tree t, class free_lang_data_d *fld)
     345              : {
     346      1199125 :   if (!t)
     347              :     return t;
     348      1199125 :   if (POINTER_TYPE_P (t))
     349       168499 :     return fld_incomplete_type_of (t, fld);
     350              :   /* FIXME: This triggers verification error, see PR88140.  */
     351              : #if 0
     352              :   if (TREE_CODE (t) == ARRAY_TYPE)
     353              :     return fld_process_array_type (t, fld_simplified_type (TREE_TYPE (t), fld),
     354              :                                    fld_simplified_types, fld);
     355              : #endif
     356              :   return t;
     357              : }
     358              : 
     359              : /* Reset the expression *EXPR_P, a size or position.
     360              : 
     361              :    ??? We could reset all non-constant sizes or positions.  But it's cheap
     362              :    enough to not do so and refrain from adding workarounds to dwarf2out.cc.
     363              : 
     364              :    We need to reset self-referential sizes or positions because they cannot
     365              :    be gimplified and thus can contain a CALL_EXPR after the gimplification
     366              :    is finished, which will run afoul of LTO streaming.  And they need to be
     367              :    reset to something essentially dummy but not constant, so as to preserve
     368              :    the properties of the object they are attached to.  */
     369              : 
     370              : static inline void
     371      6192555 : free_lang_data_in_one_sizepos (tree *expr_p)
     372              : {
     373      6192555 :   tree expr = *expr_p;
     374      6192555 :   if (CONTAINS_PLACEHOLDER_P (expr))
     375            0 :     *expr_p = build0 (PLACEHOLDER_EXPR, TREE_TYPE (expr));
     376      6192555 : }
     377              : 
     378              : 
     379              : /* Reset all the fields in a binfo node BINFO.  We only keep
     380              :    BINFO_VTABLE, which is used by gimple_fold_obj_type_ref.  */
     381              : 
     382              : static void
     383        38621 : free_lang_data_in_binfo (tree binfo)
     384              : {
     385        38621 :   unsigned i;
     386        38621 :   tree t;
     387              : 
     388        38621 :   gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
     389              : 
     390        38621 :   BINFO_VIRTUALS (binfo) = NULL_TREE;
     391        38621 :   BINFO_BASE_ACCESSES (binfo) = NULL;
     392        38621 :   BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
     393        38621 :   BINFO_SUBVTT_INDEX (binfo) = NULL_TREE;
     394        38621 :   BINFO_VPTR_FIELD (binfo) = NULL_TREE;
     395        38621 :   TREE_PUBLIC (binfo) = 0;
     396              : 
     397        52927 :   FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo), i, t)
     398        14306 :     free_lang_data_in_binfo (t);
     399        38621 : }
     400              : 
     401              : 
     402              : /* Reset all language specific information still present in TYPE.  */
     403              : 
     404              : static void
     405       868863 : free_lang_data_in_type (tree type, class free_lang_data_d *fld)
     406              : {
     407       868863 :   gcc_assert (TYPE_P (type));
     408              : 
     409              :   /* Give the FE a chance to remove its own data first.  */
     410       868863 :   lang_hooks.free_lang_data (type);
     411              : 
     412       868863 :   TREE_LANG_FLAG_0 (type) = 0;
     413       868863 :   TREE_LANG_FLAG_1 (type) = 0;
     414       868863 :   TREE_LANG_FLAG_2 (type) = 0;
     415       868863 :   TREE_LANG_FLAG_3 (type) = 0;
     416       868863 :   TREE_LANG_FLAG_4 (type) = 0;
     417       868863 :   TREE_LANG_FLAG_5 (type) = 0;
     418       868863 :   TREE_LANG_FLAG_6 (type) = 0;
     419              : 
     420       868863 :   TYPE_NEEDS_CONSTRUCTING (type) = 0;
     421              : 
     422              :   /* Purge non-marked variants from the variants chain, so that they
     423              :      don't reappear in the IL after free_lang_data.  */
     424       868863 :   while (TYPE_NEXT_VARIANT (type)
     425      1329280 :          && !fld->pset.contains (TYPE_NEXT_VARIANT (type)))
     426              :     {
     427       460417 :       tree t = TYPE_NEXT_VARIANT (type);
     428       460417 :       TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (t);
     429              :       /* Turn the removed types into distinct types.  */
     430       460417 :       TYPE_MAIN_VARIANT (t) = t;
     431       460417 :       TYPE_NEXT_VARIANT (t) = NULL_TREE;
     432              :     }
     433              : 
     434       868863 :   if (TREE_CODE (type) == FUNCTION_TYPE)
     435              :     {
     436       131201 :       TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
     437              :       /* Remove the const and volatile qualifiers from arguments.  The
     438              :          C++ front end removes them, but the C front end does not,
     439              :          leading to false ODR violation errors when merging two
     440              :          instances of the same function signature compiled by
     441              :          different front ends.  */
     442       600230 :       for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
     443              :         {
     444       469029 :           tree arg_type = TREE_VALUE (p);
     445       469029 :           if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type))
     446              :             {
     447          301 :               int quals = TYPE_QUALS (arg_type)
     448              :                 & ~TYPE_QUAL_CONST
     449          301 :                 & ~TYPE_QUAL_VOLATILE;
     450          301 :               TREE_VALUE (p) = build_qualified_type (arg_type, quals);
     451          301 :               if (!fld->pset.add (TREE_VALUE (p)))
     452          117 :                 free_lang_data_in_type (TREE_VALUE (p), fld);
     453              :             }
     454       469029 :           TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
     455              :           /* C++ FE uses TREE_PURPOSE to store initial values.  */
     456       469029 :           TREE_PURPOSE (p) = NULL;
     457              :         }
     458              :     }
     459              :   else if (TREE_CODE (type) == METHOD_TYPE)
     460              :     {
     461        31279 :       TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
     462       118465 :       for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
     463              :         {
     464              :           /* C++ FE uses TREE_PURPOSE to store initial values.  */
     465        87186 :           TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
     466        87186 :           TREE_PURPOSE (p) = NULL;
     467              :         }
     468              :     }
     469              :   else if (RECORD_OR_UNION_TYPE_P (type))
     470              :     {
     471              :       /* Remove members that are not FIELD_DECLs from the field list
     472              :          of an aggregate.  These occur in C++.  */
     473       515871 :       for (tree *prev = &TYPE_FIELDS (type), member; (member = *prev);)
     474       427397 :         if (TREE_CODE (member) == FIELD_DECL)
     475       137768 :           prev = &DECL_CHAIN (member);
     476              :         else
     477       289629 :           *prev = DECL_CHAIN (member);
     478              : 
     479        88474 :       TYPE_VFIELD (type) = NULL_TREE;
     480              : 
     481        88474 :       if (TYPE_BINFO (type))
     482              :         {
     483        24315 :           free_lang_data_in_binfo (TYPE_BINFO (type));
     484              :           /* We need to preserve link to bases and virtual table for all
     485              :              polymorphic types to make devirtualization machinery working.  */
     486        24315 :           if (!BINFO_VTABLE (TYPE_BINFO (type)))
     487        22056 :             TYPE_BINFO (type) = NULL;
     488              :         }
     489              :     }
     490              :   else if (INTEGRAL_TYPE_P (type)
     491              :            || SCALAR_FLOAT_TYPE_P (type)
     492              :            || FIXED_POINT_TYPE_P (type))
     493              :     {
     494       154485 :       if (TREE_CODE (type) == ENUMERAL_TYPE)
     495              :         {
     496         1202 :           ENUM_IS_OPAQUE (type) = 0;
     497         1202 :           ENUM_IS_SCOPED (type) = 0;
     498              :           /* Type values are used only for C++ ODR checking.  Drop them
     499              :              for all type variants and non-ODR types.
     500              :              For ODR types the data is freed in free_odr_warning_data.  */
     501         1202 :           if (!TYPE_VALUES (type))
     502              :             ;
     503         1028 :           else if (TYPE_MAIN_VARIANT (type) != type
     504          695 :                    || !type_with_linkage_p (type)
     505         1373 :                    || type_in_anonymous_namespace_p (type))
     506          687 :             TYPE_VALUES (type) = NULL;
     507              :           else
     508          341 :             register_odr_enum (type);
     509              :         }
     510       154485 :       free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type));
     511       154485 :       free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type));
     512              :     }
     513              : 
     514       868863 :   TYPE_LANG_SLOT_1 (type) = NULL_TREE;
     515              : 
     516       868863 :   free_lang_data_in_one_sizepos (&TYPE_SIZE (type));
     517       868863 :   free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type));
     518              : 
     519       868863 :   if (TYPE_CONTEXT (type)
     520       868863 :       && TREE_CODE (TYPE_CONTEXT (type)) == BLOCK)
     521              :     {
     522            0 :       tree ctx = TYPE_CONTEXT (type);
     523            0 :       do
     524              :         {
     525            0 :           ctx = BLOCK_SUPERCONTEXT (ctx);
     526              :         }
     527            0 :       while (ctx && TREE_CODE (ctx) == BLOCK);
     528            0 :       TYPE_CONTEXT (type) = ctx;
     529              :     }
     530              : 
     531       868863 :   TYPE_STUB_DECL (type) = NULL;
     532       868863 :   TYPE_NAME (type) = fld_simplified_type_name (type);
     533       868863 : }
     534              : 
     535              : /* Reset all language specific information still present in symbol
     536              :    DECL.  */
     537              : 
     538              : static void
     539      2020757 : free_lang_data_in_decl (tree decl, class free_lang_data_d *fld)
     540              : {
     541      2020757 :   gcc_assert (DECL_P (decl));
     542              : 
     543              :   /* Give the FE a chance to remove its own data first.  */
     544      2020757 :   lang_hooks.free_lang_data (decl);
     545              : 
     546      2020757 :   TREE_LANG_FLAG_0 (decl) = 0;
     547      2020757 :   TREE_LANG_FLAG_1 (decl) = 0;
     548      2020757 :   TREE_LANG_FLAG_2 (decl) = 0;
     549      2020757 :   TREE_LANG_FLAG_3 (decl) = 0;
     550      2020757 :   TREE_LANG_FLAG_4 (decl) = 0;
     551      2020757 :   TREE_LANG_FLAG_5 (decl) = 0;
     552      2020757 :   TREE_LANG_FLAG_6 (decl) = 0;
     553              : 
     554      2020757 :   free_lang_data_in_one_sizepos (&DECL_SIZE (decl));
     555      2020757 :   free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl));
     556      2020757 :   if (TREE_CODE (decl) == FIELD_DECL)
     557              :     {
     558       104345 :       DECL_FCONTEXT (decl) = NULL;
     559       104345 :       free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl));
     560       104345 :       if (TREE_CODE (DECL_CONTEXT (decl)) == QUAL_UNION_TYPE)
     561            0 :         DECL_QUALIFIER (decl) = NULL_TREE;
     562              :     }
     563              : 
     564      2020757 :   if (TREE_CODE (decl) == FUNCTION_DECL)
     565              :     {
     566       376085 :       struct cgraph_node *node;
     567              :       /* Frontends do not set TREE_ADDRESSABLE on public variables even though
     568              :          the address may be taken in other unit, so this flag has no practical
     569              :          use for middle-end.
     570              : 
     571              :          It would make more sense if frontends set TREE_ADDRESSABLE to 0 only
     572              :          for public objects that indeed cannot be adressed, but it is not
     573              :          the case.  Set the flag to true so we do not get merge failures for
     574              :          i.e. virtual tables between units that take address of it and
     575              :          units that don't.  */
     576       376085 :       if (TREE_PUBLIC (decl))
     577       363809 :         TREE_ADDRESSABLE (decl) = true;
     578       376085 :       TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
     579       376085 :       if (!(node = cgraph_node::get (decl))
     580       376085 :           || (!node->definition && !node->clones))
     581              :         {
     582       248579 :           if (node)
     583       236881 :             node->release_body ();
     584              :           else
     585              :             {
     586        11698 :               release_function_body (decl);
     587        11698 :               DECL_ARGUMENTS (decl) = NULL;
     588        11698 :               DECL_RESULT (decl) = NULL;
     589        11698 :               DECL_INITIAL (decl) = error_mark_node;
     590              :             }
     591              :         }
     592       376085 :       if (gimple_has_body_p (decl) || (node && node->thunk))
     593              :         {
     594       120993 :           tree t;
     595              : 
     596              :           /* If DECL has a gimple body, then the context for its
     597              :              arguments must be DECL.  Otherwise, it doesn't really
     598              :              matter, as we will not be emitting any code for DECL.  In
     599              :              general, there may be other instances of DECL created by
     600              :              the front end and since PARM_DECLs are generally shared,
     601              :              their DECL_CONTEXT changes as the replicas of DECL are
     602              :              created.  The only time where DECL_CONTEXT is important
     603              :              is for the FUNCTION_DECLs that have a gimple body (since
     604              :              the PARM_DECL will be used in the function's body).  */
     605       466674 :           for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t))
     606       345681 :             DECL_CONTEXT (t) = decl;
     607       120993 :           if (!DECL_FUNCTION_SPECIFIC_TARGET (decl))
     608       120979 :             DECL_FUNCTION_SPECIFIC_TARGET (decl)
     609       120979 :               = target_option_default_node;
     610       120993 :           if (!DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl))
     611       117252 :             DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl)
     612       117252 :               = optimization_default_node;
     613              :         }
     614              : 
     615              :       /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
     616              :          At this point, it is not needed anymore.  */
     617       376085 :       DECL_SAVED_TREE (decl) = NULL_TREE;
     618              : 
     619              :       /* Clear the abstract origin if it refers to a method.
     620              :          Otherwise dwarf2out.cc will ICE as we splice functions out of
     621              :          TYPE_FIELDS and thus the origin will not be output
     622              :          correctly.  */
     623       376085 :       if (DECL_ABSTRACT_ORIGIN (decl)
     624        16685 :           && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))
     625       392770 :           && RECORD_OR_UNION_TYPE_P
     626              :           (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))))
     627        12605 :         DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
     628              : 
     629       376085 :       DECL_VINDEX (decl) = NULL_TREE;
     630              :     }
     631              :   else if (VAR_P (decl))
     632              :     {
     633              :       /* See comment above why we set the flag for functions.  */
     634       802719 :       if (TREE_PUBLIC (decl))
     635       236019 :         TREE_ADDRESSABLE (decl) = true;
     636       802719 :       if ((DECL_EXTERNAL (decl)
     637         4710 :            && (!TREE_STATIC (decl) || !TREE_READONLY (decl)))
     638       805139 :           || (decl_function_context (decl) && !TREE_STATIC (decl)))
     639       541850 :         DECL_INITIAL (decl) = NULL_TREE;
     640              :     }
     641              :   else if (TREE_CODE (decl) == TYPE_DECL)
     642              :     {
     643       155629 :       DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
     644       155629 :       DECL_VISIBILITY_SPECIFIED (decl) = 0;
     645       155629 :       TREE_PUBLIC (decl) = 0;
     646       155629 :       TREE_PRIVATE (decl) = 0;
     647       155629 :       DECL_ARTIFICIAL (decl) = 0;
     648       155629 :       TYPE_DECL_SUPPRESS_DEBUG (decl) = 0;
     649       155629 :       DECL_INITIAL (decl) = NULL_TREE;
     650       155629 :       DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
     651       155629 :       DECL_MODE (decl) = VOIDmode;
     652       155629 :       SET_DECL_ALIGN (decl, 0);
     653              :       /* TREE_TYPE is cleared at WPA time in free_odr_warning_data.  */
     654              :     }
     655              :   else if (TREE_CODE (decl) == FIELD_DECL)
     656              :     {
     657       104345 :       TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
     658       104345 :       DECL_INITIAL (decl) = NULL_TREE;
     659              :     }
     660              :   else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL
     661        21696 :            && DECL_INITIAL (decl)
     662        17977 :            && TREE_CODE (DECL_INITIAL (decl)) == BLOCK)
     663              :     {
     664              :       /* Strip builtins from the translation-unit BLOCK.  We still have targets
     665              :          without builtin_decl_explicit support and also builtins are shared
     666              :          nodes and thus we can't use TREE_CHAIN in multiple lists.  */
     667        17977 :       tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl));
     668        17977 :       while (*nextp)
     669              :         {
     670            0 :           tree var = *nextp;
     671            0 :           if (TREE_CODE (var) == FUNCTION_DECL
     672            0 :               && fndecl_built_in_p (var))
     673            0 :             *nextp = TREE_CHAIN (var);
     674              :           else
     675            0 :             nextp = &TREE_CHAIN (var);
     676              :         }
     677              :     }
     678              :   /* We need to keep field decls associated with their trees. Otherwise tree
     679              :      merging may merge some fields and keep others disjoint which in turn will
     680              :      not do well with TREE_CHAIN pointers linking them.
     681              : 
     682              :      Also do not drop containing types for virtual methods and tables because
     683              :      these are needed by devirtualization.
     684              :      C++ destructors are special because C++ frontends sometimes produces
     685              :      virtual destructor as an alias of non-virtual destructor.  In
     686              :      devirutalization code we always walk through aliases and we need
     687              :      context to be preserved too.  See PR89335  */
     688      2020757 :   if (TREE_CODE (decl) != FIELD_DECL
     689      2020757 :       && ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
     690      1178804 :           || (!DECL_VIRTUAL_P (decl)
     691      1171378 :               && (TREE_CODE (decl) != FUNCTION_DECL
     692       371394 :                   || !DECL_CXX_DESTRUCTOR_P (decl)))))
     693      1902244 :     DECL_CONTEXT (decl) = fld_decl_context (DECL_CONTEXT (decl));
     694      2020757 : }
     695              : 
     696              : 
     697              : /* Operand callback helper for free_lang_data_in_node.  *TP is the
     698              :    subtree operand being considered.  */
     699              : 
     700              : static tree
     701      9680120 : find_decls_types_r (tree *tp, int *ws, void *data)
     702              : {
     703      9680120 :   tree t = *tp;
     704      9680120 :   class free_lang_data_d *fld = (class free_lang_data_d *) data;
     705              : 
     706      9680120 :   if (TREE_CODE (t) == TREE_LIST)
     707              :     return NULL_TREE;
     708              : 
     709              :   /* Language specific nodes will be removed, so there is no need
     710              :      to gather anything under them.  */
     711      9023065 :   if (is_lang_specific (t))
     712              :     {
     713           14 :       *ws = 0;
     714           14 :       return NULL_TREE;
     715              :     }
     716              : 
     717      9023051 :   if (DECL_P (t))
     718              :     {
     719              :       /* Note that walk_tree does not traverse every possible field in
     720              :          decls, so we have to do our own traversals here.  */
     721      2020757 :       add_tree_to_fld_list (t, fld);
     722              : 
     723      2020757 :       fld_worklist_push (DECL_NAME (t), fld);
     724      2020757 :       fld_worklist_push (DECL_CONTEXT (t), fld);
     725      2020757 :       fld_worklist_push (DECL_SIZE (t), fld);
     726      2020757 :       fld_worklist_push (DECL_SIZE_UNIT (t), fld);
     727              : 
     728              :       /* We are going to remove everything under DECL_INITIAL for
     729              :          TYPE_DECLs.  No point walking them.  */
     730      2020757 :       if (TREE_CODE (t) != TYPE_DECL)
     731      1865128 :         fld_worklist_push (DECL_INITIAL (t), fld);
     732              : 
     733              :       /* Remove C++ annotations, those aren't needed for LTO and contain
     734              :          trees we sometimes can't stream.  */
     735      2020757 :       DECL_ATTRIBUTES (t)
     736      2020757 :         = remove_attribute ("annotation ", DECL_ATTRIBUTES (t));
     737      2020757 :       fld_worklist_push (DECL_ATTRIBUTES (t), fld);
     738      2020757 :       fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld);
     739              : 
     740      2020757 :       if (TREE_CODE (t) == FUNCTION_DECL)
     741              :         {
     742       766172 :           for (tree arg = DECL_ARGUMENTS (t); arg; arg = DECL_CHAIN (arg))
     743       390087 :             fld_worklist_push (arg, fld);
     744       376085 :           fld_worklist_push (DECL_RESULT (t), fld);
     745              :         }
     746      1644672 :       else if (TREE_CODE (t) == FIELD_DECL)
     747              :         {
     748       104345 :           fld_worklist_push (DECL_FIELD_OFFSET (t), fld);
     749       104345 :           fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld);
     750       104345 :           fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld);
     751       104345 :           fld_worklist_push (DECL_FCONTEXT (t), fld);
     752              :         }
     753              : 
     754      2020757 :       if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
     755      2020757 :           && DECL_HAS_VALUE_EXPR_P (t))
     756         6385 :         fld_worklist_push (DECL_VALUE_EXPR (t), fld);
     757              : 
     758      2020757 :       *ws = 0;
     759              :     }
     760      7002294 :   else if (TYPE_P (t))
     761              :     {
     762              :       /* Note that walk_tree does not traverse every possible field in
     763              :          types, so we have to do our own traversals here.  */
     764       828838 :       add_tree_to_fld_list (t, fld);
     765              : 
     766       828838 :       if (!RECORD_OR_UNION_TYPE_P (t))
     767       758920 :         fld_worklist_push (TYPE_CACHED_VALUES (t), fld);
     768       828838 :       fld_worklist_push (TYPE_SIZE (t), fld);
     769       828838 :       fld_worklist_push (TYPE_SIZE_UNIT (t), fld);
     770              :       /* Remove C++ annotations, those aren't needed for LTO and contain
     771              :          trees we sometimes can't stream.  */
     772       828838 :       TYPE_ATTRIBUTES (t)
     773       828838 :         = remove_attribute ("annotation ", TYPE_ATTRIBUTES (t));
     774       828838 :       fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
     775       828838 :       fld_worklist_push (TYPE_POINTER_TO (t), fld);
     776       828838 :       fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
     777       828838 :       fld_worklist_push (TYPE_NAME (t), fld);
     778              :       /* While we do not stream TYPE_POINTER_TO and TYPE_REFERENCE_TO
     779              :          lists, we may look types up in these lists and use them while
     780              :          optimizing the function body.  Thus we need to free lang data
     781              :          in them.  */
     782       828838 :       if (TREE_CODE (t) == POINTER_TYPE)
     783       345171 :         fld_worklist_push (TYPE_NEXT_PTR_TO (t), fld);
     784       828838 :       if (TREE_CODE (t) == REFERENCE_TYPE)
     785        35340 :         fld_worklist_push (TYPE_NEXT_REF_TO (t), fld);
     786       828838 :       if (!POINTER_TYPE_P (t))
     787       448327 :         fld_worklist_push (TYPE_MIN_VALUE_RAW (t), fld);
     788              :       /* TYPE_MAX_VALUE_RAW is TYPE_BINFO for record types.  */
     789       828838 :       if (!RECORD_OR_UNION_TYPE_P (t))
     790       758920 :         fld_worklist_push (TYPE_MAX_VALUE_RAW (t), fld);
     791       828838 :       fld_worklist_push (TYPE_MAIN_VARIANT (t), fld);
     792              :       /* Do not walk TYPE_NEXT_VARIANT.  We do not stream it and thus
     793              :          do not and want not to reach unused variants this way.  */
     794       828838 :       if (TYPE_CONTEXT (t))
     795              :         {
     796        22945 :           tree ctx = TYPE_CONTEXT (t);
     797              :           /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
     798              :              So push that instead.  */
     799        22945 :           while (ctx && TREE_CODE (ctx) == BLOCK)
     800            0 :             ctx = BLOCK_SUPERCONTEXT (ctx);
     801        22945 :           fld_worklist_push (ctx, fld);
     802              :         }
     803       828838 :       fld_worklist_push (TYPE_CANONICAL (t), fld);
     804              : 
     805       828838 :       if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t))
     806              :         {
     807              :           unsigned i;
     808              :           tree tem;
     809        30948 :           FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t)), i, tem)
     810         6633 :             fld_worklist_push (TREE_TYPE (tem), fld);
     811        24315 :           fld_worklist_push (BINFO_TYPE (TYPE_BINFO (t)), fld);
     812        24315 :           fld_worklist_push (BINFO_VTABLE (TYPE_BINFO (t)), fld);
     813              :         }
     814       828838 :       if (RECORD_OR_UNION_TYPE_P (t))
     815              :         {
     816        69918 :           tree tem;
     817              :           /* Push all TYPE_FIELDS - there can be interleaving interesting
     818              :              and non-interesting things.  */
     819        69918 :           tem = TYPE_FIELDS (t);
     820       631844 :           while (tem)
     821              :             {
     822       561926 :               if (TREE_CODE (tem) == FIELD_DECL)
     823       137764 :                 fld_worklist_push (tem, fld);
     824       561926 :               tem = TREE_CHAIN (tem);
     825              :             }
     826              :         }
     827       828838 :       if (FUNC_OR_METHOD_TYPE_P (t))
     828       162480 :         fld_worklist_push (TYPE_METHOD_BASETYPE (t), fld);
     829              : 
     830       828838 :       fld_worklist_push (TYPE_STUB_DECL (t), fld);
     831       828838 :       *ws = 0;
     832              :     }
     833      6173456 :   else if (TREE_CODE (t) == BLOCK)
     834              :     {
     835      1031166 :       for (tree *tem = &BLOCK_VARS (t); *tem; )
     836              :         {
     837       834198 :           if (TREE_CODE (*tem) != LABEL_DECL
     838       834198 :               && (TREE_CODE (*tem) != VAR_DECL
     839       378194 :                   || !auto_var_in_fn_p (*tem, DECL_CONTEXT (*tem))))
     840              :             {
     841       474036 :               gcc_assert (TREE_CODE (*tem) != RESULT_DECL
     842              :                           && TREE_CODE (*tem) != PARM_DECL);
     843       474036 :               *tem = TREE_CHAIN (*tem);
     844              :             }
     845              :           else
     846              :             {
     847       360162 :               fld_worklist_push (*tem, fld);
     848       360162 :               tem = &TREE_CHAIN (*tem);
     849              :             }
     850              :         }
     851       242038 :       for (tree tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem))
     852        45070 :         fld_worklist_push (tem, fld);
     853       196968 :       fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld);
     854              :     }
     855              :   /* walk_tree does not visit ce->index which can be a FIELD_DECL, pulling
     856              :      in otherwise unused structure fields so handle CTORs explicitly.  */
     857      5976488 :   else if (TREE_CODE (t) == CONSTRUCTOR)
     858              :     {
     859              :       unsigned HOST_WIDE_INT idx;
     860              :       constructor_elt *ce;
     861       857949 :       for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce); idx++)
     862              :         {
     863       578909 :           if (ce->index)
     864       454849 :             fld_worklist_push (ce->index, fld);
     865       578909 :           fld_worklist_push (ce->value, fld);
     866              :         }
     867       279040 :       *ws = 0;
     868              :     }
     869              : 
     870      9023051 :   if (TREE_CODE (t) != IDENTIFIER_NODE
     871      7611730 :       && CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPED))
     872      7414762 :     fld_worklist_push (TREE_TYPE (t), fld);
     873              : 
     874              :   return NULL_TREE;
     875              : }
     876              : 
     877              : 
     878              : /* Find decls and types in T.  */
     879              : 
     880              : static void
     881      8244021 : find_decls_types (tree t, class free_lang_data_d *fld)
     882              : {
     883     19112273 :   while (1)
     884              :     {
     885     13678147 :       if (!fld->pset.contains (t))
     886      9464539 :         walk_tree (&t, find_decls_types_r, fld, &fld->pset);
     887     13678147 :       if (fld->worklist.is_empty ())
     888              :         break;
     889      5434126 :       t = fld->worklist.pop ();
     890              :     }
     891      8244021 : }
     892              : 
     893              : /* Translate all the types in LIST with the corresponding runtime
     894              :    types.  */
     895              : 
     896              : static tree
     897          579 : get_eh_types_for_runtime (tree list)
     898              : {
     899          579 :   tree head, prev;
     900              : 
     901          579 :   if (list == NULL_TREE)
     902              :     return NULL_TREE;
     903              : 
     904          204 :   head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
     905          204 :   prev = head;
     906          204 :   list = TREE_CHAIN (list);
     907          204 :   while (list)
     908              :     {
     909            0 :       tree n = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
     910            0 :       TREE_CHAIN (prev) = n;
     911            0 :       prev = TREE_CHAIN (prev);
     912            0 :       list = TREE_CHAIN (list);
     913              :     }
     914              : 
     915              :   return head;
     916              : }
     917              : 
     918              : 
     919              : /* Find decls and types referenced in EH region R and store them in
     920              :    FLD->DECLS and FLD->TYPES.  */
     921              : 
     922              : static void
     923        38077 : find_decls_types_in_eh_region (eh_region r, class free_lang_data_d *fld)
     924              : {
     925        38077 :   switch (r->type)
     926              :     {
     927              :     case ERT_CLEANUP:
     928              :       break;
     929              : 
     930          592 :     case ERT_TRY:
     931          592 :       {
     932          592 :         eh_catch c;
     933              : 
     934              :         /* The types referenced in each catch must first be changed to the
     935              :            EH types used at runtime.  This removes references to FE types
     936              :            in the region.  */
     937         1004 :         for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
     938              :           {
     939          412 :             c->type_list = get_eh_types_for_runtime (c->type_list);
     940          412 :             walk_tree (&c->type_list, find_decls_types_r, fld, &fld->pset);
     941              :           }
     942              :       }
     943              :       break;
     944              : 
     945          167 :     case ERT_ALLOWED_EXCEPTIONS:
     946          167 :       r->u.allowed.type_list
     947          167 :         = get_eh_types_for_runtime (r->u.allowed.type_list);
     948          167 :       walk_tree (&r->u.allowed.type_list, find_decls_types_r, fld, &fld->pset);
     949          167 :       break;
     950              : 
     951        14287 :     case ERT_MUST_NOT_THROW:
     952        14287 :       walk_tree (&r->u.must_not_throw.failure_decl,
     953              :                  find_decls_types_r, fld, &fld->pset);
     954        14287 :       break;
     955              :     }
     956        38077 : }
     957              : 
     958              : 
     959              : /* Find decls and types referenced in cgraph node N and store them in
     960              :    FLD->DECLS and FLD->TYPES.  Unlike pass_referenced_vars, this will
     961              :    look for *every* kind of DECL and TYPE node reachable from N,
     962              :    including those embedded inside types and decls (i.e,, TYPE_DECLs,
     963              :    NAMESPACE_DECLs, etc).  */
     964              : 
     965              : static void
     966       364387 : find_decls_types_in_node (struct cgraph_node *n, class free_lang_data_d *fld)
     967              : {
     968       364387 :   basic_block bb;
     969       364387 :   struct function *fn;
     970       364387 :   unsigned ix;
     971       364387 :   tree t;
     972              : 
     973       364387 :   find_decls_types (n->decl, fld);
     974              : 
     975       364387 :   if (!gimple_has_body_p (n->decl))
     976       364387 :     return;
     977              : 
     978       120823 :   gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
     979              : 
     980       120823 :   fn = DECL_STRUCT_FUNCTION (n->decl);
     981              : 
     982              :   /* Traverse locals. */
     983       770368 :   FOR_EACH_LOCAL_DECL (fn, ix, t)
     984       559998 :     find_decls_types (t, fld);
     985              : 
     986              :   /* Traverse EH regions in FN.  */
     987       120823 :   {
     988       120823 :     eh_region r;
     989       158900 :     FOR_ALL_EH_REGION_FN (r, fn)
     990        38077 :       find_decls_types_in_eh_region (r, fld);
     991              :   }
     992              : 
     993              :   /* Traverse every statement in FN.  */
     994       874011 :   FOR_EACH_BB_FN (bb, fn)
     995              :     {
     996       753188 :       gphi_iterator psi;
     997       753188 :       gimple_stmt_iterator si;
     998       753188 :       unsigned i;
     999              : 
    1000       753354 :       for (psi = gsi_start_phis (bb); !gsi_end_p (psi); gsi_next (&psi))
    1001              :         {
    1002          166 :           gphi *phi = psi.phi ();
    1003              : 
    1004          491 :           for (i = 0; i < gimple_phi_num_args (phi); i++)
    1005              :             {
    1006          325 :               tree *arg_p = gimple_phi_arg_def_ptr (phi, i);
    1007          325 :               find_decls_types (*arg_p, fld);
    1008              :             }
    1009              :         }
    1010              : 
    1011      3758150 :       for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
    1012              :         {
    1013      2251774 :           gimple *stmt = gsi_stmt (si);
    1014              : 
    1015      2251774 :           if (is_gimple_call (stmt))
    1016       521284 :             find_decls_types (gimple_call_fntype (stmt), fld);
    1017              : 
    1018      8770600 :           for (i = 0; i < gimple_num_ops (stmt); i++)
    1019              :             {
    1020      6518826 :               tree arg = gimple_op (stmt, i);
    1021      6518826 :               find_decls_types (arg, fld);
    1022              :               /* find_decls_types doesn't walk TREE_PURPOSE of TREE_LISTs,
    1023              :                  which we need for asm stmts.  */
    1024      6518826 :               if (arg
    1025      4878314 :                   && TREE_CODE (arg) == TREE_LIST
    1026        19185 :                   && TREE_PURPOSE (arg)
    1027      6536693 :                   && gimple_code (stmt) == GIMPLE_ASM)
    1028        17867 :                 find_decls_types (TREE_PURPOSE (arg), fld);
    1029              :             }
    1030              :         }
    1031              :     }
    1032              : }
    1033              : 
    1034              : 
    1035              : /* Find decls and types referenced in varpool node N and store them in
    1036              :    FLD->DECLS and FLD->TYPES.  Unlike pass_referenced_vars, this will
    1037              :    look for *every* kind of DECL and TYPE node reachable from N,
    1038              :    including those embedded inside types and decls (i.e,, TYPE_DECLs,
    1039              :    NAMESPACE_DECLs, etc).  */
    1040              : 
    1041              : static void
    1042       261250 : find_decls_types_in_var (varpool_node *v, class free_lang_data_d *fld)
    1043              : {
    1044            0 :   find_decls_types (v->decl, fld);
    1045            0 : }
    1046              : 
    1047              : /* Find decls and types referenced in asm node N and store them in
    1048              :    FLD->DECLS and FLD->TYPES.
    1049              :    Asm strings are represented as a C/C++/etc. strings. If there is
    1050              :    no other string, we would delete/prune/unify the type and cause
    1051              :    issues in verify_type(tree).
    1052              :    Likely we could just add the string type, but we scan the whole
    1053              :    tree to be sure.  */
    1054              : static void
    1055           84 : find_decls_types_in_asm (asm_node *v, class free_lang_data_d *fld)
    1056              : {
    1057            0 :   find_decls_types (v->asm_str, fld);
    1058            0 : }
    1059              : 
    1060              : /* Free language specific information for every operand and expression
    1061              :    in every node of the call graph.  This process operates in three stages:
    1062              : 
    1063              :    1- Every callgraph node and varpool node is traversed looking for
    1064              :    decls and types embedded in them.  This is a more exhaustive
    1065              :    search than that done by find_referenced_vars, because it will
    1066              :    also collect individual fields, decls embedded in types, etc.
    1067              : 
    1068              :    2- All the decls found are sent to free_lang_data_in_decl.
    1069              : 
    1070              :    3- All the types found are sent to free_lang_data_in_type.
    1071              : 
    1072              :    The ordering between decls and types is important because
    1073              :    free_lang_data_in_decl sets assembler names, which includes
    1074              :    mangling.  So types cannot be freed up until assembler names have
    1075              :    been set up.  */
    1076              : 
    1077              : static void
    1078        22979 : free_lang_data_in_cgraph (class free_lang_data_d *fld)
    1079              : {
    1080        22979 :   struct cgraph_node *n;
    1081        22979 :   varpool_node *v;
    1082        22979 :   tree t;
    1083        22979 :   unsigned i;
    1084        22979 :   alias_pair *p;
    1085              : 
    1086              :   /* Find decls and types in the body of every function in the callgraph.  */
    1087       387366 :   FOR_EACH_FUNCTION (n)
    1088       364387 :     find_decls_types_in_node (n, fld);
    1089              : 
    1090        22979 :   FOR_EACH_VEC_SAFE_ELT (alias_pairs, i, p)
    1091            0 :     find_decls_types (p->decl, fld);
    1092              : 
    1093              :   /* Find decls and types in every varpool symbol.  */
    1094       284229 :   FOR_EACH_VARIABLE (v)
    1095       261250 :     find_decls_types_in_var (v, fld);
    1096              : 
    1097              :   /* Find the decls and types in every asm node.
    1098              :      Should only be a string type.  */
    1099        23063 :   for (asm_node* anode = symtab->first_asm_symbol (); anode;
    1100           84 :        anode = safe_as_a<asm_node*> (anode->next))
    1101           84 :     find_decls_types_in_asm (anode, fld);
    1102              : 
    1103              :   /* Set the assembler name on every decl found.  We need to do this
    1104              :      now because free_lang_data_in_decl will invalidate data needed
    1105              :      for mangling.  This breaks mangling on interdependent decls.  */
    1106      2043736 :   FOR_EACH_VEC_ELT (fld->decls, i, t)
    1107      2020757 :     assign_assembler_name_if_needed (t);
    1108              : 
    1109              :   /* Traverse every decl found freeing its language data.  */
    1110      2043736 :   FOR_EACH_VEC_ELT (fld->decls, i, t)
    1111      2020757 :     free_lang_data_in_decl (t, fld);
    1112              : 
    1113              :   /* Traverse every type found freeing its language data.  */
    1114       891725 :   FOR_EACH_VEC_ELT (fld->types, i, t)
    1115       868746 :     free_lang_data_in_type (t, fld);
    1116        22979 : }
    1117              : 
    1118              : 
    1119              : /* Free resources that are used by FE but are not needed once they are done. */
    1120              : 
    1121              : static unsigned
    1122       232107 : free_lang_data (void)
    1123              : {
    1124       232107 :   unsigned i;
    1125       232107 :   class free_lang_data_d fld;
    1126              : 
    1127              :   /* If we are the LTO frontend we have freed lang-specific data already.  */
    1128       232107 :   if (in_lto_p
    1129       232107 :       || (!flag_generate_lto && !flag_generate_offload))
    1130              :     {
    1131              :       /* Rebuild type inheritance graph even when not doing LTO to get
    1132              :          consistent profile data.  */
    1133       209128 :       rebuild_type_inheritance_graph ();
    1134       209128 :       return 0;
    1135              :     }
    1136              : 
    1137        22979 :   fld_incomplete_types = new hash_map<tree, tree>;
    1138        22979 :   fld_simplified_types = new hash_map<tree, tree>;
    1139              : 
    1140              :   /* Provide a dummy TRANSLATION_UNIT_DECL if the FE failed to provide one.  */
    1141        22979 :   if (vec_safe_is_empty (all_translation_units))
    1142         1055 :     build_translation_unit_decl (NULL_TREE);
    1143              : 
    1144              :   /* Allocate and assign alias sets to the standard integer types
    1145              :      while the slots are still in the way the frontends generated them.  */
    1146       459580 :   for (i = 0; i < itk_none; ++i)
    1147       436601 :     if (integer_types[i])
    1148       298725 :       TYPE_ALIAS_SET (integer_types[i]) = get_alias_set (integer_types[i]);
    1149              : 
    1150              :   /* Traverse the IL resetting language specific information for
    1151              :      operands, expressions, etc.  */
    1152        22979 :   free_lang_data_in_cgraph (&fld);
    1153              : 
    1154              :   /* Create gimple variants for common types.  */
    1155       160853 :   for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
    1156       137874 :     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
    1157              : 
    1158              :   /* Reset some langhooks.  Do not reset types_compatible_p, it may
    1159              :      still be used indirectly via the get_alias_set langhook.  */
    1160        22979 :   lang_hooks.dwarf_name = lhd_dwarf_name;
    1161        22979 :   lang_hooks.decl_printable_name = gimple_decl_printable_name;
    1162        22979 :   lang_hooks.gimplify_expr = lhd_gimplify_expr;
    1163        22979 :   lang_hooks.overwrite_decl_assembler_name = lhd_overwrite_decl_assembler_name;
    1164        22979 :   lang_hooks.print_xnode = lhd_print_tree_nothing;
    1165        22979 :   lang_hooks.print_decl = lhd_print_tree_nothing;
    1166        22979 :   lang_hooks.print_type = lhd_print_tree_nothing;
    1167        22979 :   lang_hooks.print_identifier = lhd_print_tree_nothing;
    1168              : 
    1169        22979 :   lang_hooks.tree_inlining.var_mod_type_p = hook_bool_tree_tree_false;
    1170              : 
    1171        22979 :   if (flag_checking)
    1172              :     {
    1173              :       int i;
    1174              :       tree t;
    1175              : 
    1176       891665 :       FOR_EACH_VEC_ELT (fld.types, i, t)
    1177       868692 :         verify_type (t);
    1178              :     }
    1179              : 
    1180              :   /* We do not want the default decl_assembler_name implementation,
    1181              :      rather if we have fixed everything we want a wrapper around it
    1182              :      asserting that all non-local symbols already got their assembler
    1183              :      name and only produce assembler names for local symbols.  Or rather
    1184              :      make sure we never call decl_assembler_name on local symbols and
    1185              :      devise a separate, middle-end private scheme for it.  */
    1186              : 
    1187              :   /* Reset diagnostic machinery.  */
    1188        22979 :   tree_diagnostics_defaults (global_dc);
    1189              : 
    1190        22979 :   rebuild_type_inheritance_graph ();
    1191              : 
    1192        45958 :   delete fld_incomplete_types;
    1193        45958 :   delete fld_simplified_types;
    1194              : 
    1195              :   return 0;
    1196       232107 : }
    1197              : 
    1198              : const pass_data pass_data_ipa_free_lang_data =
    1199              :   {
    1200              :    SIMPLE_IPA_PASS, /* type */
    1201              :    "*free_lang_data", /* name */
    1202              :    OPTGROUP_NONE, /* optinfo_flags */
    1203              :    TV_IPA_FREE_LANG_DATA, /* tv_id */
    1204              :    0, /* properties_required */
    1205              :    0, /* properties_provided */
    1206              :    0, /* properties_destroyed */
    1207              :    0, /* todo_flags_start */
    1208              :    0, /* todo_flags_finish */
    1209              :   };
    1210              : 
    1211              : class pass_ipa_free_lang_data : public simple_ipa_opt_pass
    1212              : {
    1213              : public:
    1214       287872 :   pass_ipa_free_lang_data (gcc::context *ctxt)
    1215       575744 :     : simple_ipa_opt_pass (pass_data_ipa_free_lang_data, ctxt)
    1216              :   {}
    1217              : 
    1218              :   /* opt_pass methods: */
    1219       232107 :   unsigned int execute (function *) final override { return free_lang_data (); }
    1220              : 
    1221              : }; // class pass_ipa_free_lang_data
    1222              : 
    1223              : } // anon namespace
    1224              : 
    1225              : simple_ipa_opt_pass *
    1226       287872 : make_pass_ipa_free_lang_data (gcc::context *ctxt)
    1227              : {
    1228       287872 :   return new pass_ipa_free_lang_data (ctxt);
    1229              : }
        

Generated by: LCOV version 2.4-beta

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