2 Copyright (C) 2009-2015 Free Software Foundation, Inc.
3 Contributed by CodeSourcery, Inc.
5 This file is part of GCC.
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
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
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/>. */
23 #include "coretypes.h"
26 #include "basic-block.h"
30 #include "lto-streamer.h"
31 #include "ipa-utils.h"
34 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
35 all edges and removing the old node. */
38 lto_cgraph_replace_node (struct cgraph_node
*node
,
39 struct cgraph_node
*prevailing_node
)
41 struct cgraph_edge
*e
, *next
;
44 if (symtab
->dump_file
)
46 fprintf (symtab
->dump_file
, "Replacing cgraph node %s/%i by %s/%i"
48 node
->name (), node
->order
,
49 prevailing_node
->name (),
50 prevailing_node
->order
,
51 IDENTIFIER_POINTER ((*targetm
.asm_out
.mangle_assembler_name
)
52 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->decl
)))));
55 /* Merge node flags. */
56 if (node
->force_output
)
57 prevailing_node
->mark_force_output ();
58 if (node
->forced_by_abi
)
59 prevailing_node
->forced_by_abi
= true;
60 if (node
->address_taken
)
62 gcc_assert (!prevailing_node
->global
.inlined_to
);
63 prevailing_node
->mark_address_taken ();
65 if (node
->definition
&& prevailing_node
->definition
)
66 prevailing_node
->merged
= true;
68 /* Redirect all incoming edges. */
70 = types_compatible_p (TREE_TYPE (TREE_TYPE (prevailing_node
->decl
)),
71 TREE_TYPE (TREE_TYPE (node
->decl
)));
72 for (e
= node
->callers
; e
; e
= next
)
74 next
= e
->next_caller
;
75 e
->redirect_callee (prevailing_node
);
76 /* If there is a mismatch between the supposed callee return type and
77 the real one do not attempt to inline this function.
78 ??? We really need a way to match function signatures for ABI
79 compatibility and perform related promotions at inlining time. */
81 e
->call_stmt_cannot_inline_p
= 1;
83 /* Redirect incomming references. */
84 prevailing_node
->clone_referring (node
);
86 /* Fix instrumentation references. */
87 if (node
->instrumented_version
)
89 gcc_assert (node
->instrumentation_clone
90 == prevailing_node
->instrumentation_clone
);
91 node
->instrumented_version
->instrumented_version
= prevailing_node
;
92 if (!prevailing_node
->instrumented_version
)
93 prevailing_node
->instrumented_version
= node
->instrumented_version
;
94 /* Need to reset node->instrumented_version to NULL,
95 otherwise node removal code would reset
96 node->instrumented_version->instrumented_version. */
97 node
->instrumented_version
= NULL
;
100 ipa_merge_profiles (prevailing_node
, node
);
101 lto_free_function_in_decl_state_for_node (node
);
103 if (node
->decl
!= prevailing_node
->decl
)
104 node
->release_body ();
106 /* Finally remove the replaced node. */
110 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
111 all edges and removing the old node. */
114 lto_varpool_replace_node (varpool_node
*vnode
,
115 varpool_node
*prevailing_node
)
117 gcc_assert (!vnode
->definition
|| prevailing_node
->definition
);
118 gcc_assert (!vnode
->analyzed
|| prevailing_node
->analyzed
);
120 prevailing_node
->clone_referring (vnode
);
121 if (vnode
->force_output
)
122 prevailing_node
->force_output
= true;
123 if (vnode
->forced_by_abi
)
124 prevailing_node
->forced_by_abi
= true;
126 /* Be sure we can garbage collect the initializer. */
127 if (DECL_INITIAL (vnode
->decl
)
128 && vnode
->decl
!= prevailing_node
->decl
)
129 DECL_INITIAL (vnode
->decl
) = error_mark_node
;
131 /* Check and report ODR violations on virtual tables. */
132 if (DECL_VIRTUAL_P (vnode
->decl
) || DECL_VIRTUAL_P (prevailing_node
->decl
))
133 compare_virtual_tables (prevailing_node
, vnode
);
135 if (vnode
->tls_model
!= prevailing_node
->tls_model
)
139 /* Non-TLS and TLS never mix together. Also emulated model is not
140 compatible with anything else. */
141 if (prevailing_node
->tls_model
== TLS_MODEL_NONE
142 || prevailing_node
->tls_model
== TLS_MODEL_EMULATED
143 || vnode
->tls_model
== TLS_MODEL_NONE
144 || vnode
->tls_model
== TLS_MODEL_EMULATED
)
146 /* Linked is silently supporting transitions
147 GD -> IE, GD -> LE, LD -> LE, IE -> LE, LD -> IE.
148 Do the same transitions and error out on others. */
149 else if ((prevailing_node
->tls_model
== TLS_MODEL_REAL
150 || prevailing_node
->tls_model
== TLS_MODEL_LOCAL_DYNAMIC
)
151 && (vnode
->tls_model
== TLS_MODEL_INITIAL_EXEC
152 || vnode
->tls_model
== TLS_MODEL_LOCAL_EXEC
))
153 prevailing_node
->tls_model
= vnode
->tls_model
;
154 else if ((vnode
->tls_model
== TLS_MODEL_REAL
155 || vnode
->tls_model
== TLS_MODEL_LOCAL_DYNAMIC
)
156 && (prevailing_node
->tls_model
== TLS_MODEL_INITIAL_EXEC
157 || prevailing_node
->tls_model
== TLS_MODEL_LOCAL_EXEC
))
159 else if (prevailing_node
->tls_model
== TLS_MODEL_INITIAL_EXEC
160 && vnode
->tls_model
== TLS_MODEL_LOCAL_EXEC
)
161 prevailing_node
->tls_model
= vnode
->tls_model
;
162 else if (vnode
->tls_model
== TLS_MODEL_INITIAL_EXEC
163 && prevailing_node
->tls_model
== TLS_MODEL_LOCAL_EXEC
)
169 error_at (DECL_SOURCE_LOCATION (vnode
->decl
),
170 "%qD is defined with tls model %s", vnode
->decl
, tls_model_names
[vnode
->tls_model
]);
171 inform (DECL_SOURCE_LOCATION (prevailing_node
->decl
),
172 "previously defined here as %s",
173 tls_model_names
[prevailing_node
->tls_model
]);
176 /* Finally remove the replaced node. */
180 /* Return non-zero if we want to output waring about T1 and T2.
181 Return value is a bitmask of reasons of violation:
182 Bit 0 indicates that types are not compatible of memory layout.
183 Bit 1 indicates that types are not compatible because of C++ ODR rule. */
186 warn_type_compatibility_p (tree prevailing_type
, tree type
)
190 /* Get complete type.
191 ??? We might want to emit a warning here if type qualification
192 differences were spotted. Do not do this unconditionally though. */
193 type
= TYPE_MAIN_VARIANT (type
);
194 prevailing_type
= TYPE_MAIN_VARIANT (prevailing_type
);
195 if (prevailing_type
== type
)
198 bool odr_p
= odr_or_derived_type_p (prevailing_type
)
199 && odr_or_derived_type_p (type
);
200 /* C++ provide a robust way to check for type compatibility via the ODR
202 if (odr_p
&& !odr_types_equivalent_p (prevailing_type
, type
))
205 /* Function types needs special care, because types_compatible_p never
206 thinks prototype is compatible to non-prototype. */
207 if ((TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
208 && TREE_CODE (type
) == TREE_CODE (prevailing_type
))
210 lev
|= warn_type_compatibility_p (TREE_TYPE (prevailing_type
),
212 if (TREE_CODE (type
) == METHOD_TYPE
)
213 lev
|= warn_type_compatibility_p (TYPE_METHOD_BASETYPE (prevailing_type
),
214 TYPE_METHOD_BASETYPE (type
));
215 if (prototype_p (prevailing_type
) && prototype_p (type
)
216 && TYPE_ARG_TYPES (prevailing_type
) != TYPE_ARG_TYPES (type
))
219 for (parm1
= TYPE_ARG_TYPES (prevailing_type
),
220 parm2
= TYPE_ARG_TYPES (type
);
222 parm1
= TREE_CHAIN (parm1
),
223 parm2
= TREE_CHAIN (parm2
))
224 lev
|= warn_type_compatibility_p (TREE_VALUE (parm1
),
229 if (comp_type_attributes (prevailing_type
, type
) == 0)
233 /* Sharing a global symbol is a strong hint that two types are
234 compatible. We could use this information to complete
235 incomplete pointed-to types more aggressively here, ignoring
236 mismatches in both field and tag names. It's difficult though
237 to guarantee that this does not have side-effects on merging
238 more compatible types from other translation units though. */
240 /* We can tolerate differences in type qualification, the
241 qualification of the prevailing definition will prevail.
242 ??? In principle we might want to only warn for structurally
243 incompatible types here, but unless we have protective measures
244 for TBAA in place that would hide useful information. */
245 prevailing_type
= TYPE_MAIN_VARIANT (prevailing_type
);
246 type
= TYPE_MAIN_VARIANT (type
);
248 if (!types_compatible_p (prevailing_type
, type
))
250 if (TREE_CODE (prevailing_type
) == FUNCTION_TYPE
251 || TREE_CODE (type
) == METHOD_TYPE
)
253 if (COMPLETE_TYPE_P (type
) && COMPLETE_TYPE_P (prevailing_type
))
256 /* If type is incomplete then avoid warnings in the cases
257 that TBAA handles just fine. */
259 if (TREE_CODE (prevailing_type
) != TREE_CODE (type
))
262 if (TREE_CODE (prevailing_type
) == ARRAY_TYPE
)
264 tree tem1
= TREE_TYPE (prevailing_type
);
265 tree tem2
= TREE_TYPE (type
);
266 while (TREE_CODE (tem1
) == ARRAY_TYPE
267 && TREE_CODE (tem2
) == ARRAY_TYPE
)
269 tem1
= TREE_TYPE (tem1
);
270 tem2
= TREE_TYPE (tem2
);
273 if (TREE_CODE (tem1
) != TREE_CODE (tem2
))
276 if (!types_compatible_p (tem1
, tem2
))
280 /* Fallthru. Compatible enough. */
286 /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
287 Return false if the symbols are not fully compatible and a diagnostic
288 should be emitted. */
291 lto_symtab_merge (symtab_node
*prevailing
, symtab_node
*entry
)
293 tree prevailing_decl
= prevailing
->decl
;
294 tree decl
= entry
->decl
;
296 if (prevailing_decl
== decl
)
299 /* Merge decl state in both directions, we may still end up using
301 TREE_ADDRESSABLE (prevailing_decl
) |= TREE_ADDRESSABLE (decl
);
302 TREE_ADDRESSABLE (decl
) |= TREE_ADDRESSABLE (prevailing_decl
);
304 /* The linker may ask us to combine two incompatible symbols.
305 Detect this case and notify the caller of required diagnostics. */
307 if (TREE_CODE (decl
) == FUNCTION_DECL
)
309 /* Merge decl state in both directions, we may still end up using
311 DECL_POSSIBLY_INLINED (prevailing_decl
) |= DECL_POSSIBLY_INLINED (decl
);
312 DECL_POSSIBLY_INLINED (decl
) |= DECL_POSSIBLY_INLINED (prevailing_decl
);
314 if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl
),
321 if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl
),
325 /* There is no point in comparing too many details of the decls here.
326 The type compatibility checks or the completing of types has properly
327 dealt with most issues. */
329 /* The following should all not invoke fatal errors as in non-LTO
330 mode the linker wouldn't complain either. Just emit warnings. */
332 /* Report a warning if user-specified alignments do not match. */
333 if ((DECL_USER_ALIGN (prevailing_decl
) && DECL_USER_ALIGN (decl
))
334 && DECL_ALIGN (prevailing_decl
) < DECL_ALIGN (decl
))
340 /* Return true if the symtab entry E can be replaced by another symtab
344 lto_symtab_resolve_replaceable_p (symtab_node
*e
)
346 if (DECL_EXTERNAL (e
->decl
)
347 || DECL_COMDAT (e
->decl
)
348 || DECL_ONE_ONLY (e
->decl
)
349 || DECL_WEAK (e
->decl
))
352 if (TREE_CODE (e
->decl
) == VAR_DECL
)
353 return (DECL_COMMON (e
->decl
)
354 || (!flag_no_common
&& !DECL_INITIAL (e
->decl
)));
359 /* Return true, if the symbol E should be resolved by lto-symtab.
360 Those are all external symbols and all real symbols that are not static (we
361 handle renaming of static later in partitioning). */
364 lto_symtab_symbol_p (symtab_node
*e
)
366 if (!TREE_PUBLIC (e
->decl
) && !DECL_EXTERNAL (e
->decl
))
368 return e
->real_symbol_p ();
371 /* Return true if the symtab entry E can be the prevailing one. */
374 lto_symtab_resolve_can_prevail_p (symtab_node
*e
)
376 if (!lto_symtab_symbol_p (e
))
379 /* The C++ frontend ends up neither setting TREE_STATIC nor
380 DECL_EXTERNAL on virtual methods but only TREE_PUBLIC.
381 So do not reject !TREE_STATIC here but only DECL_EXTERNAL. */
382 if (DECL_EXTERNAL (e
->decl
))
385 return e
->definition
;
388 /* Resolve the symbol with the candidates in the chain *SLOT and store
389 their resolutions. */
392 lto_symtab_resolve_symbols (symtab_node
*first
)
395 symtab_node
*prevailing
= NULL
;
397 /* Always set e->node so that edges are updated to reflect decl merging. */
398 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
399 if (lto_symtab_symbol_p (e
)
400 && (e
->resolution
== LDPR_PREVAILING_DEF_IRONLY
401 || e
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
402 || e
->resolution
== LDPR_PREVAILING_DEF
))
408 /* If the chain is already resolved there is nothing else to do. */
411 /* Assert it's the only one. */
412 for (e
= prevailing
->next_sharing_asm_name
; e
; e
= e
->next_sharing_asm_name
)
413 if (lto_symtab_symbol_p (e
)
414 && (e
->resolution
== LDPR_PREVAILING_DEF_IRONLY
415 || e
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
416 || e
->resolution
== LDPR_PREVAILING_DEF
))
417 fatal_error (input_location
, "multiple prevailing defs for %qE",
418 DECL_NAME (prevailing
->decl
));
422 /* Find the single non-replaceable prevailing symbol and
423 diagnose ODR violations. */
424 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
426 if (!lto_symtab_resolve_can_prevail_p (e
))
429 /* If we have a non-replaceable definition it prevails. */
430 if (!lto_symtab_resolve_replaceable_p (e
))
434 error_at (DECL_SOURCE_LOCATION (e
->decl
),
435 "%qD has already been defined", e
->decl
);
436 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
437 "previously defined here");
445 /* Do a second round choosing one from the replaceable prevailing decls. */
446 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
448 if (!lto_symtab_resolve_can_prevail_p (e
))
451 /* Choose the first function that can prevail as prevailing. */
452 if (TREE_CODE (e
->decl
) == FUNCTION_DECL
)
458 /* From variables that can prevail choose the largest one. */
460 || tree_int_cst_lt (DECL_SIZE (prevailing
->decl
),
462 /* When variables are equivalent try to chose one that has useful
463 DECL_INITIAL. This makes sense for keyed vtables that are
464 DECL_EXTERNAL but initialized. In units that do not need them
465 we replace the initializer by error_mark_node to conserve
468 We know that the vtable is keyed outside the LTO unit - otherwise
469 the keyed instance would prevail. We still can preserve useful
470 info in the initializer. */
471 || (DECL_SIZE (prevailing
->decl
) == DECL_SIZE (e
->decl
)
472 && (DECL_INITIAL (e
->decl
)
473 && DECL_INITIAL (e
->decl
) != error_mark_node
)
474 && (!DECL_INITIAL (prevailing
->decl
)
475 || DECL_INITIAL (prevailing
->decl
) == error_mark_node
)))
482 /* Merge all decls in the symbol table chain to the prevailing decl and
483 issue diagnostics about type mismatches. If DIAGNOSED_P is true
484 do not issue further diagnostics.*/
487 lto_symtab_merge_decls_2 (symtab_node
*first
, bool diagnosed_p
)
489 symtab_node
*prevailing
;
491 vec
<tree
> mismatches
= vNULL
;
495 /* Nothing to do for a single entry. */
497 if (!prevailing
->next_sharing_asm_name
)
500 /* Try to merge each entry with the prevailing one. */
501 for (e
= prevailing
->next_sharing_asm_name
;
502 e
; e
= e
->next_sharing_asm_name
)
503 if (TREE_PUBLIC (e
->decl
))
505 if (!lto_symtab_merge (prevailing
, e
)
507 && !DECL_ARTIFICIAL (e
->decl
))
508 mismatches
.safe_push (e
->decl
);
510 if (mismatches
.is_empty ())
513 /* Diagnose all mismatched re-declarations. */
514 FOR_EACH_VEC_ELT (mismatches
, i
, decl
)
516 int level
= warn_type_compatibility_p (TREE_TYPE (prevailing
->decl
),
522 diag
= warning_at (DECL_SOURCE_LOCATION (decl
),
524 "%qD violates the C++ One Definition Rule ",
526 if (!diag
&& (level
& 1))
527 diag
= warning_at (DECL_SOURCE_LOCATION (decl
),
528 OPT_Wlto_type_mismatch
,
529 "type of %qD does not match original "
530 "declaration", decl
);
532 warn_types_mismatch (TREE_TYPE (prevailing
->decl
),
534 DECL_SOURCE_LOCATION (prevailing
->decl
),
535 DECL_SOURCE_LOCATION (decl
));
538 else if ((DECL_USER_ALIGN (prevailing
->decl
)
539 && DECL_USER_ALIGN (decl
))
540 && DECL_ALIGN (prevailing
->decl
) < DECL_ALIGN (decl
))
542 diagnosed_p
|= warning_at (DECL_SOURCE_LOCATION (decl
),
543 OPT_Wlto_type_mismatch
,
544 "alignment of %qD is bigger than "
545 "original declaration", decl
);
549 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
550 "%qD was previously declared here", prevailing
->decl
);
552 mismatches
.release ();
555 /* Helper to process the decl chain for the symbol table entry *SLOT. */
558 lto_symtab_merge_decls_1 (symtab_node
*first
)
561 symtab_node
*prevailing
;
562 bool diagnosed_p
= false;
564 if (symtab
->dump_file
)
566 fprintf (symtab
->dump_file
, "Merging nodes for %s. Candidates:\n",
568 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
569 if (TREE_PUBLIC (e
->decl
))
570 e
->dump (symtab
->dump_file
);
573 /* Compute the symbol resolutions. This is a no-op when using the
574 linker plugin and resolution was decided by the linker. */
575 prevailing
= lto_symtab_resolve_symbols (first
);
577 /* If there's not a prevailing symbol yet it's an external reference.
578 Happens a lot during ltrans. Choose the first symbol with a
579 cgraph or a varpool node. */
582 for (prevailing
= first
;
583 prevailing
; prevailing
= prevailing
->next_sharing_asm_name
)
584 if (lto_symtab_symbol_p (prevailing
))
588 /* For variables chose with a priority variant with vnode
589 attached (i.e. from unit where external declaration of
590 variable is actually used).
591 When there are multiple variants, chose one with size.
592 This is needed for C++ typeinfos, for example in
593 lto/20081204-1 there are typeifos in both units, just
594 one of them do have size. */
595 if (TREE_CODE (prevailing
->decl
) == VAR_DECL
)
597 for (e
= prevailing
->next_sharing_asm_name
;
598 e
; e
= e
->next_sharing_asm_name
)
599 if (!COMPLETE_TYPE_P (TREE_TYPE (prevailing
->decl
))
600 && COMPLETE_TYPE_P (TREE_TYPE (e
->decl
))
601 && lto_symtab_symbol_p (e
))
604 /* For variables prefer the non-builtin if one is available. */
605 else if (TREE_CODE (prevailing
->decl
) == FUNCTION_DECL
)
607 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
608 if (TREE_CODE (e
->decl
) == FUNCTION_DECL
609 && !DECL_BUILT_IN (e
->decl
)
610 && lto_symtab_symbol_p (e
))
618 symtab
->symtab_prevail_in_asm_name_hash (prevailing
);
620 /* Diagnose mismatched objects. */
621 for (e
= prevailing
->next_sharing_asm_name
;
622 e
; e
= e
->next_sharing_asm_name
)
624 if (TREE_CODE (prevailing
->decl
)
625 == TREE_CODE (e
->decl
))
627 if (!lto_symtab_symbol_p (e
))
630 switch (TREE_CODE (prevailing
->decl
))
633 gcc_assert (TREE_CODE (e
->decl
) == FUNCTION_DECL
);
634 error_at (DECL_SOURCE_LOCATION (e
->decl
),
635 "variable %qD redeclared as function",
640 gcc_assert (TREE_CODE (e
->decl
) == VAR_DECL
);
641 error_at (DECL_SOURCE_LOCATION (e
->decl
),
642 "function %qD redeclared as variable",
653 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
654 "previously declared here");
656 /* Merge the chain to the single prevailing decl and diagnose
658 lto_symtab_merge_decls_2 (prevailing
, diagnosed_p
);
660 if (symtab
->dump_file
)
662 fprintf (symtab
->dump_file
, "After resolution:\n");
663 for (e
= prevailing
; e
; e
= e
->next_sharing_asm_name
)
664 e
->dump (symtab
->dump_file
);
668 /* Resolve and merge all symbol table chains to a prevailing decl. */
671 lto_symtab_merge_decls (void)
675 /* Populate assembler name hash. */
676 symtab
->symtab_initialize_asm_name_hash ();
678 FOR_EACH_SYMBOL (node
)
679 if (!node
->previous_sharing_asm_name
680 && node
->next_sharing_asm_name
)
681 lto_symtab_merge_decls_1 (node
);
684 /* Helper to process the decl chain for the symbol table entry *SLOT. */
687 lto_symtab_merge_symbols_1 (symtab_node
*prevailing
)
692 /* Replace the cgraph node of each entry with the prevailing one. */
693 for (e
= prevailing
->next_sharing_asm_name
; e
;
696 next
= e
->next_sharing_asm_name
;
698 if (!lto_symtab_symbol_p (e
))
700 cgraph_node
*ce
= dyn_cast
<cgraph_node
*> (e
);
701 if (ce
&& !DECL_BUILT_IN (e
->decl
))
702 lto_cgraph_replace_node (ce
, dyn_cast
<cgraph_node
*> (prevailing
));
703 if (varpool_node
*ve
= dyn_cast
<varpool_node
*> (e
))
704 lto_varpool_replace_node (ve
, dyn_cast
<varpool_node
*> (prevailing
));
710 /* Merge cgraph nodes according to the symbol merging done by
711 lto_symtab_merge_decls. */
714 lto_symtab_merge_symbols (void)
720 symtab
->symtab_initialize_asm_name_hash ();
722 /* Do the actual merging.
723 At this point we invalidate hash translating decls into symtab nodes
724 because after removing one of duplicate decls the hash is not correcly
725 updated to the ohter dupliate. */
726 FOR_EACH_SYMBOL (node
)
727 if (lto_symtab_symbol_p (node
)
728 && node
->next_sharing_asm_name
729 && !node
->previous_sharing_asm_name
)
730 lto_symtab_merge_symbols_1 (node
);
732 /* Resolve weakref aliases whose target are now in the compilation unit.
733 also re-populate the hash translating decls into symtab nodes*/
734 FOR_EACH_SYMBOL (node
)
736 cgraph_node
*cnode
, *cnode2
;
740 if (!node
->analyzed
&& node
->alias_target
)
742 symtab_node
*tgt
= symtab_node::get_for_asmname (node
->alias_target
);
743 gcc_assert (node
->weakref
);
745 node
->resolve_alias (tgt
);
749 if (!(cnode
= dyn_cast
<cgraph_node
*> (node
))
751 || cnode
->clone_of
->decl
!= cnode
->decl
)
753 /* Builtins are not merged via decl merging. It is however
754 possible that tree merging unified the declaration. We
755 do not want duplicate entries in symbol table. */
756 if (cnode
&& DECL_BUILT_IN (node
->decl
)
757 && (cnode2
= cgraph_node::get (node
->decl
))
759 lto_cgraph_replace_node (cnode2
, cnode
);
761 /* The user defined assembler variables are also not unified by their
762 symbol name (since it is irrelevant), but we need to unify symbol
763 nodes if tree merging occured. */
764 if ((vnode
= dyn_cast
<varpool_node
*> (node
))
765 && DECL_HARD_REGISTER (vnode
->decl
)
766 && (node2
= symtab_node::get (vnode
->decl
))
768 lto_varpool_replace_node (dyn_cast
<varpool_node
*> (node2
),
772 /* Abstract functions may have duplicated cgraph nodes attached;
774 else if (cnode
&& DECL_ABSTRACT_P (cnode
->decl
)
775 && (cnode2
= cgraph_node::get (node
->decl
))
779 node
->decl
->decl_with_vis
.symtab_node
= node
;
785 /* Given the decl DECL, return the prevailing decl with the same name. */
788 lto_symtab_prevailing_decl (tree decl
)
792 /* Builtins and local symbols are their own prevailing decl. */
793 if ((!TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
)) || is_builtin_fn (decl
))
796 /* DECL_ABSTRACT_Ps are their own prevailing decl. */
797 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_ABSTRACT_P (decl
))
800 /* When decl did not participate in symbol resolution leave it alone.
801 This can happen when we streamed the decl as abstract origin
802 from the block tree of inlining a partially inlined function.
803 If all, the split function and the original function end up
804 optimized away early we do not put the abstract origin into the
805 ltrans boundary and we'll end up ICEing in
806 dwarf2out.c:gen_inlined_subroutine_die because we eventually
807 replace a decl with DECL_POSSIBLY_INLINED set with one without. */
808 if (TREE_CODE (decl
) == FUNCTION_DECL
809 && ! cgraph_node::get (decl
))
812 /* Ensure DECL_ASSEMBLER_NAME will not set assembler name. */
813 gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl
));
815 /* Walk through the list of candidates and return the one we merged to. */
816 ret
= symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl
));
820 /* Do not replace a non-builtin with a builtin. */
821 if (is_builtin_fn (ret
->decl
))