LCOV - code coverage report
Current view: top level - gcc/lto - lto-symtab.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 80.4 % 516 415
Test Date: 2026-02-28 14:20:25 Functions: 100.0 % 15 15
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* LTO symbol table.
       2              :    Copyright (C) 2009-2026 Free Software Foundation, Inc.
       3              :    Contributed by CodeSourcery, Inc.
       4              : 
       5              : This file is part of GCC.
       6              : 
       7              : GCC is free software; you can redistribute it and/or modify it under
       8              : the terms of the GNU General Public License as published by the Free
       9              : Software Foundation; either version 3, or (at your option) any later
      10              : version.
      11              : 
      12              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15              : 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              : #include "config.h"
      22              : #include "system.h"
      23              : #include "coretypes.h"
      24              : #include "target.h"
      25              : #include "function.h"
      26              : #include "basic-block.h"
      27              : #include "tree.h"
      28              : #include "gimple.h"
      29              : #include "cgraph.h"
      30              : #include "lto-streamer.h"
      31              : #include "ipa-utils.h"
      32              : #include "builtins.h"
      33              : #include "alias.h"
      34              : #include "lto.h"
      35              : #include "lto-symtab.h"
      36              : #include "stringpool.h"
      37              : #include "attribs.h"
      38              : 
      39              : /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
      40              :    all edges and removing the old node.  */
      41              : 
      42              : static void
      43         1939 : lto_cgraph_replace_node (struct cgraph_node *node,
      44              :                          struct cgraph_node *prevailing_node)
      45              : {
      46         1939 :   struct cgraph_edge *e, *next;
      47         1939 :   bool compatible_p;
      48              : 
      49         1939 :   if (dump_file)
      50              :     {
      51            0 :       fprintf (dump_file, "Replacing cgraph node %s by %s"
      52              :                " for symbol %s\n",
      53              :                node->dump_name (),
      54              :                prevailing_node->dump_name (),
      55            0 :                IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name)
      56              :                  (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)))));
      57              :     }
      58              : 
      59              :   /* Merge node flags.  */
      60         1939 :   if (node->force_output)
      61            0 :     prevailing_node->mark_force_output ();
      62         1939 :   if (node->forced_by_abi)
      63            0 :     prevailing_node->forced_by_abi = true;
      64         1939 :   prevailing_node->ref_by_asm |= node->ref_by_asm;
      65         1939 :   prevailing_node->must_remain_in_tu_name |= node->must_remain_in_tu_name;
      66         1939 :   prevailing_node->must_remain_in_tu_body |= node->must_remain_in_tu_body;
      67              : 
      68         1939 :   if (node->address_taken)
      69              :     {
      70          144 :       gcc_assert (!prevailing_node->inlined_to);
      71          144 :       prevailing_node->mark_address_taken ();
      72              :     }
      73           82 :   if (node->definition && prevailing_node->definition
      74         2021 :       && DECL_COMDAT (node->decl) && DECL_COMDAT (prevailing_node->decl))
      75           77 :     prevailing_node->merged_comdat = true;
      76         1857 :   else if ((node->definition || node->body_removed)
      77            5 :            && DECL_DECLARED_INLINE_P (node->decl)
      78            3 :            && DECL_EXTERNAL (node->decl)
      79         1865 :            && prevailing_node->definition)
      80            3 :     prevailing_node->merged_extern_inline = true;
      81         1939 :   prevailing_node->merged_comdat |= node->merged_comdat;
      82         1939 :   prevailing_node->merged_extern_inline |= node->merged_extern_inline;
      83              : 
      84              :   /* Redirect all incoming edges.  */
      85         1939 :   compatible_p
      86         1939 :     = types_compatible_p (TREE_TYPE (TREE_TYPE (prevailing_node->decl)),
      87         1939 :                           TREE_TYPE (TREE_TYPE (node->decl)));
      88         7219 :   for (e = node->callers; e; e = next)
      89              :     {
      90         5280 :       next = e->next_caller;
      91         5280 :       e->redirect_callee (prevailing_node);
      92              :       /* If there is a mismatch between the supposed callee return type and
      93              :          the real one do not attempt to inline this function.
      94              :          ???  We really need a way to match function signatures for ABI
      95              :          compatibility and perform related promotions at inlining time.  */
      96         5280 :       if (!compatible_p)
      97              :         {
      98            1 :           e->inline_failed = CIF_LTO_MISMATCHED_DECLARATIONS;
      99            1 :           e->call_stmt_cannot_inline_p = 1;
     100              :         }
     101              :     }
     102              :   /* Redirect incomming references.  */
     103         1939 :   prevailing_node->clone_referring (node);
     104         1939 :   lto_free_function_in_decl_state_for_node (node);
     105              : 
     106         1939 :   if (node->decl != prevailing_node->decl)
     107         1137 :     node->release_body ();
     108              : 
     109              :   /* Finally remove the replaced node.  */
     110         1939 :   node->remove ();
     111         1939 : }
     112              : 
     113              : /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
     114              :    all edges and removing the old node.  */
     115              : 
     116              : static void
     117          739 : lto_varpool_replace_node (varpool_node *vnode,
     118              :                           varpool_node *prevailing_node)
     119              : {
     120          739 :   gcc_assert (!vnode->definition || prevailing_node->definition);
     121          739 :   gcc_assert (!vnode->analyzed || prevailing_node->analyzed);
     122              : 
     123          739 :   prevailing_node->clone_referring (vnode);
     124          739 :   if (vnode->force_output)
     125           11 :     prevailing_node->force_output = true;
     126          739 :   if (vnode->forced_by_abi)
     127            3 :     prevailing_node->forced_by_abi = true;
     128          739 :   prevailing_node->ref_by_asm |= vnode->ref_by_asm;
     129          739 :   prevailing_node->must_remain_in_tu_name |= vnode->must_remain_in_tu_name;
     130          739 :   prevailing_node->must_remain_in_tu_body |= vnode->must_remain_in_tu_body;
     131              : 
     132              :   /* Be sure we can garbage collect the initializer.  */
     133          739 :   if (DECL_INITIAL (vnode->decl)
     134          739 :       && vnode->decl != prevailing_node->decl)
     135           29 :     DECL_INITIAL (vnode->decl) = error_mark_node;
     136              : 
     137              :   /* Check and report ODR violations on virtual tables.  */
     138          739 :   if (DECL_VIRTUAL_P (vnode->decl) || DECL_VIRTUAL_P (prevailing_node->decl))
     139           63 :     compare_virtual_tables (prevailing_node, vnode);
     140              : 
     141          739 :   if (vnode->tls_model != prevailing_node->tls_model)
     142              :     {
     143            0 :       bool error = false;
     144              : 
     145              :       /* Non-TLS and TLS never mix together.  Also emulated model is not
     146              :          compatible with anything else.  */
     147            0 :       if (prevailing_node->tls_model == TLS_MODEL_NONE
     148            0 :           || prevailing_node->tls_model == TLS_MODEL_EMULATED
     149            0 :           || vnode->tls_model == TLS_MODEL_NONE
     150            0 :           || vnode->tls_model == TLS_MODEL_EMULATED)
     151              :         error = true;
     152              :       /* Linked is silently supporting transitions
     153              :          GD -> IE, GD -> LE, LD -> LE, IE -> LE, LD -> IE.
     154              :          Do the same transitions and error out on others.  */
     155            0 :       else if ((prevailing_node->tls_model == TLS_MODEL_REAL
     156            0 :                 || prevailing_node->tls_model == TLS_MODEL_LOCAL_DYNAMIC)
     157            0 :                && (vnode->tls_model == TLS_MODEL_INITIAL_EXEC
     158            0 :                    || vnode->tls_model == TLS_MODEL_LOCAL_EXEC))
     159            0 :         prevailing_node->tls_model = vnode->tls_model;
     160            0 :       else if ((vnode->tls_model == TLS_MODEL_REAL
     161            0 :                 || vnode->tls_model == TLS_MODEL_LOCAL_DYNAMIC)
     162            0 :                && (prevailing_node->tls_model == TLS_MODEL_INITIAL_EXEC
     163            0 :                    || prevailing_node->tls_model == TLS_MODEL_LOCAL_EXEC))
     164              :         ;
     165            0 :       else if (prevailing_node->tls_model == TLS_MODEL_INITIAL_EXEC
     166            0 :                && vnode->tls_model == TLS_MODEL_LOCAL_EXEC)
     167            0 :         prevailing_node->tls_model = vnode->tls_model;
     168            0 :       else if (vnode->tls_model == TLS_MODEL_INITIAL_EXEC
     169            0 :                && prevailing_node->tls_model == TLS_MODEL_LOCAL_EXEC)
     170              :         ;
     171              :       else
     172              :         error = true;
     173            0 :       if (error)
     174              :         {
     175            0 :           error_at (DECL_SOURCE_LOCATION (vnode->decl),
     176            0 :                     "%qD is defined with tls model %s", vnode->decl, tls_model_names [vnode->tls_model]);
     177            0 :           inform (DECL_SOURCE_LOCATION (prevailing_node->decl),
     178              :                   "previously defined here as %s",
     179            0 :                   tls_model_names [prevailing_node->tls_model]);
     180              :         }
     181              :     }
     182              :   /* Finally remove the replaced node.  */
     183          739 :   vnode->remove ();
     184          739 : }
     185              : 
     186              : /* Return non-zero if we want to output waring about T1 and T2.
     187              :    Return value is a bitmask of reasons of violation:
     188              :    Bit 0 indicates that types are not compatible.
     189              :    Bit 1 indicates that types are not compatible because of C++ ODR rule.
     190              :    If COMMON_OR_EXTERN is true, do not warn on size mismatches of arrays.
     191              :    Bit 2 indicates that types are not ODR compatible
     192              : 
     193              :    The interoperability rules are language specific.  At present we do only
     194              :    full checking for C++ ODR rule and for other languages we do basic check
     195              :    that data structures are of same size and TBAA compatible.  Our TBAA
     196              :    implementation should be coarse enough so all valid type transitions
     197              :    across different languages are allowed.
     198              : 
     199              :    In partiucular we thus allow almost arbitrary type changes with
     200              :    -fno-strict-aliasing which may be tough of as a feature rather than bug
     201              :    as it allows to implement dodgy tricks in the language runtimes.
     202              : 
     203              :    Naturally this code can be strenghtened significantly if we could track
     204              :    down the language of origin.  */
     205              : 
     206              : static int
     207         2524 : warn_type_compatibility_p (tree prevailing_type, tree type,
     208              :                            bool common_or_extern)
     209              : {
     210         2524 :   int lev = 0;
     211         2524 :   bool odr_p = odr_or_derived_type_p (prevailing_type)
     212         2524 :                && odr_or_derived_type_p (type);
     213              : 
     214         2524 :   if (prevailing_type == type)
     215              :     return 0;
     216              : 
     217              :   /* C++ provide a robust way to check for type compatibility via the ODR
     218              :      rule.  */
     219          858 :   if (odr_p && !odr_types_equivalent_p (prevailing_type, type))
     220              :     lev |= 2;
     221              : 
     222              :   /* Function types needs special care, because types_compatible_p never
     223              :      thinks prototype is compatible to non-prototype.  */
     224          858 :   if (FUNC_OR_METHOD_TYPE_P (type))
     225              :     {
     226          268 :       if (TREE_CODE (type) != TREE_CODE (prevailing_type))
     227            0 :         lev |= 1;
     228          268 :       lev |= warn_type_compatibility_p (TREE_TYPE (prevailing_type),
     229          268 :                                         TREE_TYPE (type), false);
     230          268 :       if (TREE_CODE (type) == METHOD_TYPE
     231           84 :           && TREE_CODE (prevailing_type) == METHOD_TYPE)
     232           84 :         lev |= warn_type_compatibility_p (TYPE_METHOD_BASETYPE (prevailing_type),
     233           84 :                                           TYPE_METHOD_BASETYPE (type), false);
     234          535 :       if (prototype_p (prevailing_type) && prototype_p (type)
     235          528 :           && TYPE_ARG_TYPES (prevailing_type) != TYPE_ARG_TYPES (type))
     236              :         {
     237           77 :           tree parm1, parm2;
     238           77 :           for (parm1 = TYPE_ARG_TYPES (prevailing_type),
     239           77 :                parm2 = TYPE_ARG_TYPES (type);
     240          539 :                parm1 && parm2;
     241          924 :                parm1 = TREE_CHAIN (parm1),
     242          462 :                parm2 = TREE_CHAIN (parm2))
     243          924 :             lev |= warn_type_compatibility_p (TREE_VALUE (parm1),
     244          462 :                                               TREE_VALUE (parm2), false);
     245           77 :           if (parm1 || parm2)
     246           24 :             lev |= odr_p ? 3 : 1;
     247              :         }
     248          268 :       if (comp_type_attributes (prevailing_type, type) == 0)
     249            0 :         lev |= 1;
     250          268 :       return lev;
     251              :     }
     252              : 
     253              :   /* Get complete type.  */
     254          590 :   prevailing_type = TYPE_MAIN_VARIANT (prevailing_type);
     255          590 :   type = TYPE_MAIN_VARIANT (type);
     256              : 
     257              :   /* We cannot use types_compatible_p because we permit some changes
     258              :      across types.  For example unsigned size_t and "signed size_t" may be
     259              :      compatible when merging C and Fortran types.  */
     260          590 :   if (COMPLETE_TYPE_P (prevailing_type)
     261          571 :       && COMPLETE_TYPE_P (type)
     262              :       /* While global declarations are never variadic, we can recurse here
     263              :          for function parameter types.  */
     264          505 :       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
     265          505 :       && TREE_CODE (TYPE_SIZE (prevailing_type)) == INTEGER_CST
     266         1095 :       && !tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (prevailing_type)))
     267              :     {
     268              :        /* As a special case do not warn about merging
     269              :           int a[];
     270              :           and
     271              :           int a[]={1,2,3};
     272              :           here the first declaration is COMMON or EXTERN
     273              :           and sizeof(a) == sizeof (int).  */
     274           53 :        if (!common_or_extern
     275           34 :            || TREE_CODE (type) != ARRAY_TYPE
     276           59 :            || TYPE_SIZE (type) != TYPE_SIZE (TREE_TYPE (type)))
     277           47 :        lev |= 1;
     278              :     }
     279              : 
     280              :   /* Verify TBAA compatibility.  Take care of alias set 0 and the fact that
     281              :      we make ptr_type_node to TBAA compatible with every other type.  */
     282          590 :   if (type_with_alias_set_p (type) && type_with_alias_set_p (prevailing_type))
     283              :     {
     284          565 :       alias_set_type set1 = get_alias_set (type);
     285          565 :       alias_set_type set2 = get_alias_set (prevailing_type);
     286              : 
     287          565 :       if (set1 && set2 && set1 != set2)
     288              :         {
     289              :            tree t1 = type, t2 = prevailing_type;
     290              : 
     291              :           /* Alias sets of arrays with aliased components are the same as alias
     292              :              sets of the inner types.  */
     293          225 :           while (TREE_CODE (t1) == ARRAY_TYPE
     294            6 :                  && !TYPE_NONALIASED_COMPONENT (t1)
     295            6 :                  && TREE_CODE (t2) == ARRAY_TYPE
     296          231 :                  && !TYPE_NONALIASED_COMPONENT (t2))
     297              :             {
     298            6 :               t1 = TREE_TYPE (t1);
     299            6 :               t2 = TREE_TYPE (t2);
     300              :             }
     301          179 :           if ((!POINTER_TYPE_P (t1) || !POINTER_TYPE_P (t2))
     302          396 :               || (set1 != TYPE_ALIAS_SET (ptr_type_node)
     303          171 :                   && set2 != TYPE_ALIAS_SET (ptr_type_node)))
     304          198 :             lev |= 5;
     305              :         }
     306              :     }
     307              : 
     308              :   return lev;
     309              : }
     310              : 
     311              : /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
     312              :    Return false if the symbols are not fully compatible and a diagnostic
     313              :    should be emitted.  */
     314              : 
     315              : static bool
     316         1671 : lto_symtab_merge (symtab_node *prevailing, symtab_node *entry)
     317              : {
     318         1671 :   tree prevailing_decl = prevailing->decl;
     319         1671 :   tree decl = entry->decl;
     320              : 
     321         1671 :   if (prevailing_decl == decl)
     322              :     return true;
     323              : 
     324         1671 :   if (TREE_CODE (decl) != TREE_CODE (prevailing_decl))
     325              :     return false;
     326              : 
     327              :   /* Merge decl state in both directions, we may still end up using
     328              :      the new decl.  */
     329         1671 :   TREE_ADDRESSABLE (prevailing_decl) |= TREE_ADDRESSABLE (decl);
     330         1671 :   TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (prevailing_decl);
     331              : 
     332              :   /* The linker may ask us to combine two incompatible symbols.
     333              :      Detect this case and notify the caller of required diagnostics.  */
     334              : 
     335         1671 :   if (TREE_CODE (decl) == FUNCTION_DECL)
     336              :     {
     337              :       /* Merge decl state in both directions, we may still end up using
     338              :          the new decl.  */
     339         1126 :       DECL_POSSIBLY_INLINED (prevailing_decl) |= DECL_POSSIBLY_INLINED (decl);
     340         1126 :       DECL_POSSIBLY_INLINED (decl) |= DECL_POSSIBLY_INLINED (prevailing_decl);
     341              : 
     342         1126 :       if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl),
     343         1126 :                                      TREE_TYPE (decl),
     344         1126 :                                      DECL_COMMON (decl)
     345         1126 :                                      || DECL_EXTERNAL (decl)))
     346              :         return false;
     347              : 
     348              :       return true;
     349              :     }
     350              : 
     351          545 :   if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl),
     352          545 :                                  TREE_TYPE (decl),
     353          545 :                                  DECL_COMMON (decl) || DECL_EXTERNAL (decl)))
     354              :     return false;
     355              : 
     356              :   /* There is no point in comparing too many details of the decls here.
     357              :      The type compatibility checks or the completing of types has properly
     358              :      dealt with most issues.  */
     359              : 
     360              :   /* The following should all not invoke fatal errors as in non-LTO
     361              :      mode the linker wouldn't complain either.  Just emit warnings.  */
     362              : 
     363              :   /* Report a warning if user-specified alignments do not match.  */
     364          591 :   if ((DECL_USER_ALIGN (prevailing_decl) && DECL_USER_ALIGN (decl))
     365          547 :       && DECL_ALIGN (prevailing_decl) < DECL_ALIGN (decl))
     366              :     return false;
     367              : 
     368          974 :   if (DECL_SIZE (decl) && DECL_SIZE (prevailing_decl)
     369          974 :       && !tree_int_cst_equal (DECL_SIZE (decl), DECL_SIZE (prevailing_decl)))
     370              :       {
     371           20 :         if (!DECL_COMMON (decl) && !DECL_EXTERNAL (decl))
     372              :           return false;
     373              : 
     374           20 :         tree type = TREE_TYPE (decl);
     375              : 
     376              :         /* For record type, check for array at the end of the structure.  */
     377           20 :         if (TREE_CODE (type) == RECORD_TYPE)
     378              :           {
     379           14 :             tree field = TYPE_FIELDS (type);
     380           30 :             while (DECL_CHAIN (field) != NULL_TREE)
     381           16 :               field = DECL_CHAIN (field);
     382              : 
     383           14 :             return TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE;
     384              :           }
     385              :       /* As a special case do not warn about merging
     386              :          int a[];
     387              :          and
     388              :          int a[]={1,2,3};
     389              :          here the first declaration is COMMON
     390              :          and sizeof(a) == sizeof (int).  */
     391            6 :         else if (TREE_CODE (type) != ARRAY_TYPE
     392            6 :                  || (TYPE_SIZE (type) != TYPE_SIZE (TREE_TYPE (type))))
     393              :           return false;
     394              :       }
     395              : 
     396              :   return true;
     397              : }
     398              : 
     399              : /* Return true if the symtab entry E can be replaced by another symtab
     400              :    entry.  */
     401              : 
     402              : static bool
     403          667 : lto_symtab_resolve_replaceable_p (symtab_node *e)
     404              : {
     405          667 :   if (DECL_EXTERNAL (e->decl)
     406          667 :       || DECL_COMDAT (e->decl)
     407          595 :       || DECL_ONE_ONLY (e->decl)
     408         1262 :       || DECL_WEAK (e->decl))
     409           75 :     return true;
     410              : 
     411          592 :   if (VAR_P (e->decl))
     412          183 :     return (DECL_COMMON (e->decl)
     413          183 :             || (!flag_no_common && !DECL_INITIAL (e->decl)));
     414              : 
     415              :   return false;
     416              : }
     417              : 
     418              : /* Return true, if the symbol E should be resolved by lto-symtab.
     419              :    Those are all external symbols and all real symbols that are not static (we
     420              :    handle renaming of static later in partitioning).  */
     421              : 
     422              : static bool
     423       169816 : lto_symtab_symbol_p (symtab_node *e)
     424              : {
     425       169816 :   if (!TREE_PUBLIC (e->decl) && !DECL_EXTERNAL (e->decl))
     426              :     return false;
     427       137574 :   return e->real_symbol_p ();
     428              : }
     429              : 
     430              : /* Return true if the symtab entry E can be the prevailing one.  */
     431              : 
     432              : static bool
     433         4447 : lto_symtab_resolve_can_prevail_p (symtab_node *e)
     434              : {
     435         4447 :   if (!lto_symtab_symbol_p (e))
     436              :     return false;
     437              : 
     438              :   /* The C++ frontend ends up neither setting TREE_STATIC nor
     439              :      DECL_EXTERNAL on virtual methods but only TREE_PUBLIC.
     440              :      So do not reject !TREE_STATIC here but only DECL_EXTERNAL.  */
     441         4073 :   if (DECL_EXTERNAL (e->decl))
     442              :     return false;
     443              : 
     444          736 :   return e->definition;
     445              : }
     446              : 
     447              : /* Resolve the symbol with the candidates in the chain *SLOT and store
     448              :    their resolutions.  */
     449              : 
     450              : static symtab_node *
     451         2168 : lto_symtab_resolve_symbols (symtab_node *first)
     452              : {
     453         2168 :   symtab_node *e;
     454         2168 :   symtab_node *prevailing = NULL;
     455              : 
     456              :   /* Always set e->node so that edges are updated to reflect decl merging. */
     457         5601 :   for (e = first; e; e = e->next_sharing_asm_name)
     458         4490 :     if (lto_symtab_symbol_p (e)
     459         4490 :         && (e->resolution == LDPR_PREVAILING_DEF_IRONLY
     460              :             || e->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
     461              :             || e->resolution == LDPR_PREVAILING_DEF))
     462              :       {
     463              :         prevailing = e;
     464              :         break;
     465              :       }
     466              : 
     467              :   /* If the chain is already resolved there is nothing else to do.  */
     468         2168 :   if (prevailing)
     469              :     {
     470              :       /* Assert it's the only one.
     471              :          GCC should silence multiple PREVAILING_DEF_IRONLY defs error
     472              :          on COMMON symbols since it isn't error.
     473              :          See: https://sourceware.org/bugzilla/show_bug.cgi?id=23079.  */
     474         1533 :       for (e = prevailing->next_sharing_asm_name; e; e = e->next_sharing_asm_name)
     475          476 :         if (lto_symtab_symbol_p (e)
     476          464 :             && !DECL_COMMON (prevailing->decl)
     477          454 :             && !DECL_COMMON (e->decl)
     478          922 :             && (e->resolution == LDPR_PREVAILING_DEF_IRONLY
     479              :                 || e->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
     480              :                 || e->resolution == LDPR_PREVAILING_DEF))
     481            0 :           fatal_error (input_location, "multiple prevailing defs for %qE",
     482            0 :                        DECL_NAME (prevailing->decl));
     483              :       return prevailing;
     484              :     }
     485              : 
     486              :   /* Find the single non-replaceable prevailing symbol and
     487              :      diagnose ODR violations.  */
     488         3932 :   for (e = first; e; e = e->next_sharing_asm_name)
     489              :     {
     490         2821 :       if (!lto_symtab_resolve_can_prevail_p (e))
     491         2154 :         continue;
     492              : 
     493              :       /* If we have a non-replaceable definition it prevails.  */
     494          667 :       if (!lto_symtab_resolve_replaceable_p (e))
     495              :         {
     496          579 :           if (prevailing)
     497              :             {
     498            0 :               error_at (DECL_SOURCE_LOCATION (e->decl),
     499              :                         "%qD has already been defined", e->decl);
     500            0 :               inform (DECL_SOURCE_LOCATION (prevailing->decl),
     501              :                       "previously defined here");
     502              :             }
     503              :           prevailing = e;
     504              :         }
     505              :     }
     506         1111 :   if (prevailing)
     507              :     return prevailing;
     508              : 
     509              :   /* Do a second round choosing one from the replaceable prevailing decls.  */
     510         2138 :   for (e = first; e; e = e->next_sharing_asm_name)
     511              :     {
     512         1626 :       if (!lto_symtab_resolve_can_prevail_p (e))
     513         1557 :         continue;
     514              : 
     515              :       /* Choose the first function that can prevail as prevailing.  */
     516           69 :       if (TREE_CODE (e->decl) == FUNCTION_DECL)
     517              :         {
     518              :           prevailing = e;
     519              :           break;
     520              :         }
     521              : 
     522              :       /* From variables that can prevail choose the largest one.  */
     523           49 :       if (!prevailing
     524           18 :           || tree_int_cst_lt (DECL_SIZE (prevailing->decl),
     525           18 :                               DECL_SIZE (e->decl))
     526              :           /* When variables are equivalent try to chose one that has useful
     527              :              DECL_INITIAL.  This makes sense for keyed vtables that are
     528              :              DECL_EXTERNAL but initialized.  In units that do not need them
     529              :              we replace the initializer by error_mark_node to conserve
     530              :              memory.
     531              : 
     532              :              We know that the vtable is keyed outside the LTO unit - otherwise
     533              :              the keyed instance would prevail.  We still can preserve useful
     534              :              info in the initializer.  */
     535           65 :           || (DECL_SIZE (prevailing->decl) == DECL_SIZE (e->decl)
     536           12 :               && (DECL_INITIAL (e->decl)
     537           12 :                   && DECL_INITIAL (e->decl) != error_mark_node)
     538            4 :               && (!DECL_INITIAL (prevailing->decl)
     539            4 :                   || DECL_INITIAL (prevailing->decl) == error_mark_node)))
     540              :         prevailing = e;
     541              :     }
     542              : 
     543              :   return prevailing;
     544              : }
     545              : 
     546              : /* Decide if it is OK to merge DECL into PREVAILING.
     547              :    Because we wrap most of uses of declarations in MEM_REF, we can tolerate
     548              :    some differences but other code may inspect directly the DECL.  */
     549              : 
     550              : static bool
     551         1671 : lto_symtab_merge_p (tree prevailing, tree decl)
     552              : {
     553         1671 :   if (TREE_CODE (prevailing) != TREE_CODE (decl))
     554              :     {
     555            0 :       if (dump_file)
     556            0 :         fprintf (dump_file, "Not merging decls; "
     557              :                  "TREE_CODE mismatch\n");
     558            0 :       return false;
     559              :     }
     560         1671 :   gcc_checking_assert (TREE_CHAIN (prevailing) == TREE_CHAIN (decl));
     561              : 
     562         1671 :   if (TREE_CODE (prevailing) == FUNCTION_DECL)
     563              :     {
     564         1126 :       if (fndecl_built_in_p (prevailing) != fndecl_built_in_p (decl))
     565              :         {
     566            2 :           if (dump_file)
     567            0 :             fprintf (dump_file, "Not merging decls; "
     568              :                      "DECL_BUILT_IN mismatch\n");
     569            2 :           return false;
     570              :         }
     571         1124 :       if (fndecl_built_in_p (prevailing)
     572         1124 :           && (DECL_BUILT_IN_CLASS (prevailing) != DECL_BUILT_IN_CLASS (decl)
     573          239 :               || (DECL_UNCHECKED_FUNCTION_CODE (prevailing)
     574          239 :                   != DECL_UNCHECKED_FUNCTION_CODE (decl))))
     575              :         {
     576            0 :           if (dump_file)
     577            0 :             fprintf (dump_file, "Not merging decls; "
     578              :                      "DECL_BUILT_IN_CLASS or CODE mismatch\n");
     579            0 :           return false;
     580              :         }
     581              :     }
     582              : 
     583         1669 :   if (DECL_ATTRIBUTES (prevailing) != DECL_ATTRIBUTES (decl))
     584              :     {
     585          230 :       tree prev_attr = lookup_attribute ("error", DECL_ATTRIBUTES (prevailing));
     586          230 :       tree attr = lookup_attribute ("error", DECL_ATTRIBUTES (decl));
     587          230 :       if ((prev_attr == NULL) != (attr == NULL)
     588          230 :           || (prev_attr && !attribute_value_equal (prev_attr, attr)))
     589              :         {
     590            0 :           if (dump_file)
     591            0 :             fprintf (dump_file, "Not merging decls; "
     592              :                      "error attribute mismatch\n");
     593            0 :           return false;
     594              :         }
     595              : 
     596          230 :       prev_attr = lookup_attribute ("warning", DECL_ATTRIBUTES (prevailing));
     597          230 :       attr = lookup_attribute ("warning", DECL_ATTRIBUTES (decl));
     598          230 :       if ((prev_attr == NULL) != (attr == NULL)
     599          230 :           || (prev_attr && !attribute_value_equal (prev_attr, attr)))
     600              :         {
     601            1 :           if (dump_file)
     602            0 :             fprintf (dump_file, "Not merging decls; "
     603              :                      "warning attribute mismatch\n");
     604            1 :           return false;
     605              :         }
     606              : 
     607          229 :       prev_attr = lookup_attribute ("noreturn", DECL_ATTRIBUTES (prevailing));
     608          229 :       attr = lookup_attribute ("noreturn", DECL_ATTRIBUTES (decl));
     609          229 :       if ((prev_attr == NULL) != (attr == NULL))
     610              :         {
     611            9 :           if (dump_file)
     612            0 :             fprintf (dump_file, "Not merging decls; "
     613              :                      "noreturn attribute mismatch\n");
     614            9 :           return false;
     615              :         }
     616              :     }
     617              :   return true;
     618              : }
     619              : 
     620              : /* Merge all decls in the symbol table chain to the prevailing decl and
     621              :    issue diagnostics about type mismatches.  If DIAGNOSED_P is true
     622              :    do not issue further diagnostics.*/
     623              : 
     624              : static void
     625         2076 : lto_symtab_merge_decls_2 (symtab_node *first, bool diagnosed_p)
     626              : {
     627         2076 :   symtab_node *prevailing;
     628         2076 :   symtab_node *e;
     629         2076 :   vec<tree> mismatches = vNULL;
     630         2076 :   unsigned i;
     631         2076 :   tree decl;
     632         2076 :   bool tbaa_p = false;
     633              : 
     634              :   /* Nothing to do for a single entry.  */
     635         2076 :   prevailing = first;
     636         2076 :   if (!prevailing->next_sharing_asm_name)
     637         2037 :     return;
     638              : 
     639              :   /* Try to merge each entry with the prevailing one.  */
     640              :   symtab_node *last_prevailing = prevailing, *next;
     641         4782 :   for (e = prevailing->next_sharing_asm_name; e; e = next)
     642              :     {
     643         2706 :       next = e->next_sharing_asm_name;
     644              : 
     645              :       /* Skip non-LTO symbols and symbols whose declaration we already
     646              :          visited.  */
     647         2706 :       if (lto_symtab_prevailing_decl (e->decl) != e->decl
     648         2668 :           || !lto_symtab_symbol_p (e)
     649         5357 :           || e->decl == prevailing->decl)
     650         1035 :         continue;
     651              : 
     652         1671 :       if (!lto_symtab_merge (prevailing, e)
     653           48 :           && !diagnosed_p
     654         1719 :           && !DECL_ARTIFICIAL (e->decl))
     655           39 :         mismatches.safe_push (e->decl);
     656              : 
     657              :       symtab_node *this_prevailing;
     658            0 :       for (this_prevailing = prevailing; ;
     659            0 :            this_prevailing = this_prevailing->next_sharing_asm_name)
     660              :         {
     661         1671 :           if (this_prevailing->decl != e->decl
     662         1671 :               && lto_symtab_merge_p (this_prevailing->decl, e->decl))
     663              :             break;
     664           12 :           if (this_prevailing == last_prevailing)
     665              :             {
     666              :               this_prevailing = NULL;
     667              :               break;
     668              :             }
     669              :         }
     670              : 
     671         1671 :       if (this_prevailing)
     672         1659 :         lto_symtab_prevail_decl (this_prevailing->decl, e->decl);
     673              :       /* Maintain LRU list: relink the new prevaililng symbol
     674              :          just after previaling node in the chain and update last_prevailing.
     675              :          Since the number of possible declarations of a given symbol is
     676              :          small, this should be faster than building a hash.  */
     677           12 :       else if (e == prevailing->next_sharing_asm_name)
     678              :         last_prevailing = e;
     679              :       else
     680              :         {
     681            0 :           if (e->next_sharing_asm_name)
     682            0 :             e->next_sharing_asm_name->previous_sharing_asm_name
     683            0 :               = e->previous_sharing_asm_name;
     684            0 :           e->previous_sharing_asm_name->next_sharing_asm_name
     685            0 :             = e->next_sharing_asm_name;
     686            0 :           e->previous_sharing_asm_name = prevailing;
     687            0 :           e->next_sharing_asm_name = prevailing->next_sharing_asm_name;
     688            0 :           prevailing->next_sharing_asm_name->previous_sharing_asm_name = e;
     689            0 :           prevailing->next_sharing_asm_name = e;
     690            0 :           if (last_prevailing == prevailing)
     691            0 :             last_prevailing = e;
     692              :         }
     693              :     }
     694         2076 :   if (mismatches.is_empty ())
     695              :     return;
     696              : 
     697              :   /* Diagnose all mismatched re-declarations.  */
     698           78 :   FOR_EACH_VEC_ELT (mismatches, i, decl)
     699              :     {
     700              :       /* Do not diagnose two built-in declarations, there is no useful
     701              :          location in that case.  It also happens for AVR if two built-ins
     702              :          use the same asm name because their libgcc assembler code is the
     703              :          same, see PR78562.  */
     704           39 :       if (DECL_IS_UNDECLARED_BUILTIN (prevailing->decl)
     705           39 :           && DECL_IS_UNDECLARED_BUILTIN (decl))
     706            0 :         continue;
     707              : 
     708           39 :       int level = warn_type_compatibility_p (TREE_TYPE (prevailing->decl),
     709           39 :                                              TREE_TYPE (decl),
     710           39 :                                              DECL_COMDAT (decl));
     711           39 :       if (level)
     712              :         {
     713           39 :           bool diag = false;
     714           39 :           if (level & 2)
     715              :             {
     716              :               /* Silence warning for method and variables which belong
     717              :                  to types which already have ODR violation reported.  Complaining
     718              :                  once is enough.  */
     719            6 :               if (TREE_CODE (decl) != FUNCTION_DECL
     720            0 :                   || TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE
     721            0 :                   || !TYPE_METHOD_BASETYPE (TREE_TYPE (decl))
     722            0 :                   || !odr_type_p (TYPE_METHOD_BASETYPE (TREE_TYPE (decl)))
     723            6 :                   || !odr_type_violation_reported_p
     724            0 :                         (TYPE_METHOD_BASETYPE (TREE_TYPE (decl))))
     725            6 :                 diag = warning_at (DECL_SOURCE_LOCATION (decl),
     726            6 :                                    OPT_Wodr,
     727              :                                    "%qD violates the C++ One Definition Rule",
     728              :                                    decl);
     729              :             }
     730           39 :           if (!diag && (level & 1))
     731           33 :             diag = warning_at (DECL_SOURCE_LOCATION (decl),
     732           33 :                                OPT_Wlto_type_mismatch,
     733              :                                "type of %qD does not match original "
     734              :                                "declaration", decl);
     735           33 :           if (diag)
     736              :             {
     737           13 :               warn_types_mismatch (TREE_TYPE (prevailing->decl),
     738           13 :                                    TREE_TYPE (decl),
     739           13 :                                    DECL_SOURCE_LOCATION (prevailing->decl),
     740           13 :                                    DECL_SOURCE_LOCATION (decl));
     741           13 :               if ((level & 4)
     742           13 :                   && !TREE_READONLY (prevailing->decl))
     743              :                 tbaa_p = true;
     744              :             }
     745           39 :           diagnosed_p |= diag;
     746              :         }
     747            0 :       else if ((DECL_USER_ALIGN (prevailing->decl)
     748            0 :                 && DECL_USER_ALIGN (decl))
     749            0 :                && DECL_ALIGN (prevailing->decl) < DECL_ALIGN (decl))
     750              :         {
     751            0 :           diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl),
     752            0 :                                      OPT_Wlto_type_mismatch,
     753              :                                      "alignment of %qD is bigger than "
     754              :                                      "original declaration", decl);
     755              :         }
     756              :       else
     757            0 :         diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl),
     758            0 :                                    OPT_Wlto_type_mismatch,
     759              :                                    "size of %qD differ from the size of "
     760              :                                    "original declaration", decl);
     761              :     }
     762           39 :   if (diagnosed_p)
     763           13 :     inform (DECL_SOURCE_LOCATION (prevailing->decl),
     764              :             "%qD was previously declared here", prevailing->decl);
     765           39 :   if (tbaa_p)
     766           13 :     inform (DECL_SOURCE_LOCATION (prevailing->decl),
     767              :             "code may be misoptimized unless "
     768              :             "%<-fno-strict-aliasing%> is used");
     769              : 
     770           39 :   mismatches.release ();
     771              : }
     772              : 
     773              : /* Helper to process the decl chain for the symbol table entry *SLOT.  */
     774              : 
     775              : static void
     776         2168 : lto_symtab_merge_decls_1 (symtab_node *first)
     777              : {
     778         2168 :   symtab_node *e;
     779         2168 :   symtab_node *prevailing;
     780         2168 :   bool diagnosed_p = false;
     781              : 
     782         2168 :   if (dump_file)
     783              :     {
     784            0 :       fprintf (dump_file, "Merging nodes for %s. Candidates:\n",
     785              :                first->asm_name ());
     786            0 :       for (e = first; e; e = e->next_sharing_asm_name)
     787            0 :         if (TREE_PUBLIC (e->decl))
     788            0 :           e->dump (dump_file);
     789              :     }
     790              : 
     791              :   /* Compute the symbol resolutions.  This is a no-op when using the
     792              :      linker plugin and resolution was decided by the linker.  */
     793         2168 :   prevailing = lto_symtab_resolve_symbols (first);
     794              : 
     795              :   /* If there's not a prevailing symbol yet it's an external reference.
     796              :      Happens a lot during ltrans.  Choose the first symbol with a
     797              :      cgraph or a varpool node.  */
     798         2168 :   if (!prevailing)
     799              :     {
     800          185 :       for (prevailing = first;
     801          666 :            prevailing; prevailing = prevailing->next_sharing_asm_name)
     802          574 :         if (lto_symtab_symbol_p (prevailing))
     803              :           break;
     804          481 :       if (!prevailing)
     805              :         return;
     806              :       /* For variables chose with a priority variant with vnode
     807              :          attached (i.e. from unit where external declaration of
     808              :          variable is actually used).
     809              :          When there are multiple variants, chose one with size.
     810              :          This is needed for C++ typeinfos, for example in
     811              :          lto/20081204-1 there are typeifos in both units, just
     812              :          one of them do have size.  */
     813          389 :       if (VAR_P (prevailing->decl))
     814              :         {
     815           80 :           for (e = prevailing->next_sharing_asm_name;
     816          214 :                e; e = e->next_sharing_asm_name)
     817          134 :             if (!COMPLETE_TYPE_P (TREE_TYPE (prevailing->decl))
     818           23 :                 && COMPLETE_TYPE_P (TREE_TYPE (e->decl))
     819          134 :                 && lto_symtab_symbol_p (e))
     820              :               prevailing = e;
     821              :         }
     822              :       /* For functions prefer the non-builtin if one is available.  */
     823          309 :       else if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
     824              :         {
     825          685 :           for (e = first; e; e = e->next_sharing_asm_name)
     826          499 :             if (TREE_CODE (e->decl) == FUNCTION_DECL
     827          499 :                 && !fndecl_built_in_p (e->decl)
     828          622 :                 && lto_symtab_symbol_p (e))
     829              :               {
     830              :                 prevailing = e;
     831              :                 break;
     832              :               }
     833              :         }
     834              :     }
     835              : 
     836         2076 :   symtab->symtab_prevail_in_asm_name_hash (prevailing);
     837              : 
     838              :   /* Diagnose mismatched objects.  */
     839         2076 :   for (e = prevailing->next_sharing_asm_name;
     840         4782 :        e; e = e->next_sharing_asm_name)
     841              :     {
     842         5412 :       if (TREE_CODE (prevailing->decl)
     843         2706 :           == TREE_CODE (e->decl))
     844         2706 :         continue;
     845            0 :       if (!lto_symtab_symbol_p (e))
     846            0 :         continue;
     847              : 
     848            0 :       switch (TREE_CODE (prevailing->decl))
     849              :         {
     850            0 :         case VAR_DECL:
     851            0 :           gcc_assert (TREE_CODE (e->decl) == FUNCTION_DECL);
     852            0 :           error_at (DECL_SOURCE_LOCATION (e->decl),
     853              :                     "variable %qD redeclared as function",
     854              :                     prevailing->decl);
     855            0 :           break;
     856              : 
     857            0 :         case FUNCTION_DECL:
     858            0 :           gcc_assert (VAR_P (e->decl));
     859            0 :           error_at (DECL_SOURCE_LOCATION (e->decl),
     860              :                     "function %qD redeclared as variable",
     861              :                     prevailing->decl);
     862            0 :           break;
     863              : 
     864            0 :         default:
     865            0 :           gcc_unreachable ();
     866              :         }
     867              : 
     868              :       diagnosed_p = true;
     869              :     }
     870         2076 :   if (diagnosed_p)
     871            0 :       inform (DECL_SOURCE_LOCATION (prevailing->decl),
     872              :               "previously declared here");
     873              : 
     874              :   /* Merge the chain to the single prevailing decl and diagnose
     875              :      mismatches.  */
     876         2076 :   lto_symtab_merge_decls_2 (prevailing, diagnosed_p);
     877              : 
     878         2076 :   if (dump_file)
     879              :     {
     880            0 :       fprintf (dump_file, "After resolution:\n");
     881            0 :       for (e = prevailing; e; e = e->next_sharing_asm_name)
     882            0 :         e->dump (dump_file);
     883              :     }
     884              : }
     885              : 
     886              : /* Resolve and merge all symbol table chains to a prevailing decl.  */
     887              : 
     888              : void
     889        12202 : lto_symtab_merge_decls (void)
     890              : {
     891        12202 :   symtab_node *node;
     892              : 
     893        12202 :   gcc_assert (!dump_file);
     894        12202 :   dump_file = dump_begin (decl_merge_dump_id, NULL);
     895              : 
     896              :   /* Populate assembler name hash.   */
     897        12202 :   symtab->symtab_initialize_asm_name_hash ();
     898              : 
     899       169660 :   FOR_EACH_SYMBOL (node)
     900       157458 :     if (!node->previous_sharing_asm_name
     901       154660 :         && node->next_sharing_asm_name)
     902         2168 :       lto_symtab_merge_decls_1 (node);
     903              : 
     904        12202 :   if (dump_file)
     905            0 :     dump_end (decl_merge_dump_id, dump_file);
     906        12202 :   dump_file = NULL;
     907        12202 : }
     908              : 
     909              : /* Helper to process the decl chain for the symbol table entry *SLOT.  */
     910              : 
     911              : static void
     912         2076 : lto_symtab_merge_symbols_1 (symtab_node *prevailing)
     913              : {
     914         2076 :   symtab_node *e;
     915         2076 :   symtab_node *next;
     916              : 
     917         2076 :   prevailing->decl->decl_with_vis.symtab_node = prevailing;
     918              : 
     919              :   /* Replace the cgraph node of each entry with the prevailing one.  */
     920         2076 :   for (e = prevailing->next_sharing_asm_name; e;
     921              :        e = next)
     922              :     {
     923         2706 :       next = e->next_sharing_asm_name;
     924         2706 :       cgraph_node *ce = dyn_cast <cgraph_node *> (e);
     925              : 
     926           20 :       if ((!TREE_PUBLIC (e->decl) && !DECL_EXTERNAL (e->decl))
     927         2709 :           || (ce != NULL && ce->inlined_to))
     928           17 :         continue;
     929         2689 :       symtab_node *to = symtab_node::get (lto_symtab_prevailing_decl (e->decl));
     930              : 
     931              :       /* No matter how we are going to deal with resolution, we will ultimately
     932              :          use prevailing definition.  */
     933         2689 :       if (ce)
     934         1951 :         ipa_merge_profiles (dyn_cast<cgraph_node *> (prevailing),
     935              :                               dyn_cast<cgraph_node *> (e));
     936              : 
     937              :       /* If we decided to replace the node by TO, do it.  */
     938         2689 :       if (e != to)
     939              :         {
     940         2677 :           if (ce)
     941         3878 :             lto_cgraph_replace_node (ce, dyn_cast<cgraph_node *> (to));
     942         5520 :           else if (varpool_node *ve = dyn_cast <varpool_node *> (e))
     943         1476 :             lto_varpool_replace_node (ve, dyn_cast<varpool_node *> (to));
     944              :         }
     945              :       /* Watch out for duplicated symbols for a given declaration.  */
     946           12 :       else if (!e->transparent_alias
     947           12 :                || !e->definition || e->get_alias_target () != to)
     948              :         {
     949              :           /* We got a new declaration we do not want to merge.  In this case
     950              :              get rid of the existing definition and create a transparent
     951              :              alias.  */
     952           12 :           if (ce)
     953              :             {
     954           12 :               lto_free_function_in_decl_state_for_node (ce);
     955           12 :               if (!ce->weakref)
     956           12 :                 ce->release_body ();
     957           12 :               ce->reset ();
     958           12 :               symtab->call_cgraph_removal_hooks (ce);
     959              :             }
     960              :           else
     961              :             {
     962            0 :               DECL_INITIAL (e->decl) = error_mark_node;
     963            0 :               lto_free_function_in_decl_state_for_node (e);
     964            0 :               symtab->call_varpool_removal_hooks (dyn_cast<varpool_node *> (e));
     965              :             }
     966           12 :           e->remove_all_references ();
     967           12 :           e->analyzed = e->body_removed = false;
     968           12 :           e->resolve_alias (prevailing, true);
     969           12 :           gcc_assert (e != prevailing);
     970              :         }
     971              :     }
     972              : 
     973         2076 :   return;
     974              : }
     975              : 
     976              : /* Merge cgraph nodes according to the symbol merging done by
     977              :    lto_symtab_merge_decls.  */
     978              : 
     979              : void
     980        12202 : lto_symtab_merge_symbols (void)
     981              : {
     982        12202 :   symtab_node *node;
     983              : 
     984        12202 :   if (!flag_ltrans)
     985              :     {
     986        12202 :       symtab->symtab_initialize_asm_name_hash ();
     987              : 
     988              :       /* Do the actual merging.
     989              :          At this point we invalidate hash translating decls into symtab nodes
     990              :          because after removing one of duplicate decls the hash is not correcly
     991              :          updated to the other duplicate.  */
     992       169240 :       FOR_EACH_SYMBOL (node)
     993       157038 :         if (lto_symtab_symbol_p (node)
     994       125573 :             && node->next_sharing_asm_name
     995       159708 :             && !node->previous_sharing_asm_name)
     996         2076 :           lto_symtab_merge_symbols_1 (node);
     997              : 
     998              :       /* Resolve weakref aliases whose target are now in the compilation unit.
     999              :          also re-populate the hash translating decls into symtab nodes*/
    1000       167582 :       FOR_EACH_SYMBOL (node)
    1001              :         {
    1002       155380 :           cgraph_node *cnode, *cnode2;
    1003       155380 :           varpool_node *vnode;
    1004       155380 :           symtab_node *node2;
    1005              : 
    1006       155380 :           if (!node->analyzed && node->alias_target)
    1007              :             {
    1008           20 :               symtab_node *tgt = symtab_node::get_for_asmname (node->alias_target);
    1009           20 :               gcc_assert (node->weakref);
    1010           20 :               if (tgt)
    1011           12 :                 node->resolve_alias (tgt, true);
    1012              :             }
    1013              :           /* If the symbol was preempted outside IR, see if we want to get rid
    1014              :              of the definition.  */
    1015       155380 :           if (node->analyzed
    1016       131183 :               && !DECL_EXTERNAL (node->decl)
    1017       286498 :               && (node->resolution == LDPR_PREEMPTED_REG
    1018       131109 :                   || node->resolution == LDPR_RESOLVED_IR
    1019       131109 :                   || node->resolution == LDPR_RESOLVED_EXEC
    1020       131108 :                   || node->resolution == LDPR_RESOLVED_DYN))
    1021              :             {
    1022              :               /* If alias to local symbol was preempted by external definition,
    1023              :                  we know it is not pointing to the local symbol.  Remove it.  */
    1024           10 :               if (node->alias
    1025            4 :                   && !node->weakref
    1026            4 :                   && !node->transparent_alias
    1027           14 :                   && node->get_alias_target ()->binds_to_current_def_p ())
    1028              :                 {
    1029            4 :                   node->alias = false;
    1030            4 :                   node->remove_all_references ();
    1031            4 :                   node->definition = false;
    1032            4 :                   node->analyzed = false;
    1033            4 :                   node->cpp_implicit_alias = false;
    1034              :                 }
    1035            6 :               else if (!node->alias
    1036            6 :                        && node->definition
    1037           12 :                        && node->get_availability () <= AVAIL_INTERPOSABLE)
    1038              :                 {
    1039            3 :                   if ((cnode = dyn_cast <cgraph_node *> (node)) != NULL)
    1040            2 :                     cnode->reset ();
    1041              :                   else
    1042              :                     {
    1043            1 :                       node->analyzed = node->definition = false;
    1044            1 :                       node->remove_all_references ();
    1045              :                     }
    1046            3 :                   node->body_removed = true;
    1047              :                 }
    1048           10 :               DECL_EXTERNAL (node->decl) = 1;
    1049              :             }
    1050              : 
    1051       155380 :           if (!(cnode = dyn_cast <cgraph_node *> (node))
    1052       110071 :               || !cnode->clone_of
    1053            0 :               || cnode->clone_of->decl != cnode->decl)
    1054              :             {
    1055              :               /* Builtins are not merged via decl merging.  It is however
    1056              :                  possible that tree merging unified the declaration.  We
    1057              :                  do not want duplicate entries in symbol table.  */
    1058       110071 :               if (cnode && fndecl_built_in_p (node->decl)
    1059        18134 :                   && (cnode2 = cgraph_node::get (node->decl))
    1060       173514 :                   && cnode2 != cnode)
    1061            0 :                 lto_cgraph_replace_node (cnode2, cnode);
    1062              : 
    1063              :               /* The user defined assembler variables are also not unified by their
    1064              :                  symbol name (since it is irrelevant), but we need to unify symbol
    1065              :                  nodes if tree merging occurred.  */
    1066       155380 :               if ((vnode = dyn_cast <varpool_node *> (node))
    1067        45309 :                   && DECL_HARD_REGISTER (vnode->decl)
    1068            6 :                   && (node2 = symtab_node::get (vnode->decl))
    1069            6 :                   && node2 != node)
    1070            1 :                 lto_varpool_replace_node (dyn_cast <varpool_node *> (node2),
    1071              :                                           vnode);
    1072              : 
    1073              : 
    1074              :               /* Abstract functions may have duplicated cgraph nodes attached;
    1075              :                  remove them.  */
    1076       110071 :               else if (cnode && DECL_ABSTRACT_P (cnode->decl)
    1077            0 :                        && (cnode2 = cgraph_node::get (node->decl))
    1078       155379 :                        && cnode2 != cnode)
    1079            0 :                 cnode2->remove ();
    1080              : 
    1081       155380 :               node->decl->decl_with_vis.symtab_node = node;
    1082              :             }
    1083              :         }
    1084              :     }
    1085        12202 : }
    1086              : 
    1087              : /* Virtual tables may matter for code generation even if they are not
    1088              :    directly referenced by the code because they may be used for
    1089              :    devirtualization.
    1090              :    For this reason it is important to merge even virtual tables that have no
    1091              :    associated symbol table entries.  Without doing so we lose optimization
    1092              :    oppurtunities by losing track of the vtable constructor.
    1093              :    FIXME: we probably ought to introduce explicit symbol table entries for
    1094              :    those before streaming.  */
    1095              : 
    1096              : tree
    1097         1002 : lto_symtab_prevailing_virtual_decl (tree decl)
    1098              : {
    1099         1002 :   if (DECL_ABSTRACT_P (decl))
    1100              :     return decl;
    1101              : 
    1102          655 :   if (type_in_anonymous_namespace_p (DECL_CONTEXT (decl)))
    1103              :     /* There can't be any other declarations.  */
    1104              :     return decl;
    1105              : 
    1106          654 :   gcc_checking_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
    1107              : 
    1108          654 :   symtab_node *n = symtab_node::get_for_asmname
    1109          654 :                      (DECL_ASSEMBLER_NAME (decl));
    1110         1308 :   while (n && ((!DECL_EXTERNAL (n->decl) && !TREE_PUBLIC (n->decl))
    1111           54 :                || !DECL_VIRTUAL_P (n->decl)))
    1112            0 :     n = n->next_sharing_asm_name;
    1113          654 :   if (n)
    1114              :     {
    1115              :       /* Merge decl state in both directions, we may still end up using
    1116              :          the other decl.  */
    1117           54 :       TREE_ADDRESSABLE (n->decl) |= TREE_ADDRESSABLE (decl);
    1118           54 :       TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (n->decl);
    1119              : 
    1120           54 :       if (TREE_CODE (decl) == FUNCTION_DECL)
    1121              :         {
    1122              :           /* Merge decl state in both directions, we may still end up using
    1123              :              the other decl.  */
    1124           26 :           DECL_POSSIBLY_INLINED (n->decl) |= DECL_POSSIBLY_INLINED (decl);
    1125           26 :           DECL_POSSIBLY_INLINED (decl) |= DECL_POSSIBLY_INLINED (n->decl);
    1126              :         }
    1127           54 :       lto_symtab_prevail_decl (n->decl, decl);
    1128           54 :       decl = n->decl;
    1129              :     }
    1130              :   else
    1131          600 :     symtab_node::get_create (decl);
    1132              : 
    1133              :   return decl;
    1134              : }
        

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.