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"
24 #include "diagnostic-core.h"
29 #include "basic-block.h"
32 #include "hard-reg-set.h"
34 #include "fold-const.h"
35 #include "internal-fn.h"
37 #include "lto-streamer.h"
38 #include "ipa-utils.h"
39 #include "alloc-pool.h"
40 #include "symbol-summary.h"
42 #include "ipa-inline.h"
44 #include "print-tree.h"
46 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
47 all edges and removing the old node. */
50 lto_cgraph_replace_node (struct cgraph_node
*node
,
51 struct cgraph_node
*prevailing_node
)
53 struct cgraph_edge
*e
, *next
;
56 if (symtab
->dump_file
)
58 fprintf (symtab
->dump_file
, "Replacing cgraph node %s/%i by %s/%i"
60 node
->name (), node
->order
,
61 prevailing_node
->name (),
62 prevailing_node
->order
,
63 IDENTIFIER_POINTER ((*targetm
.asm_out
.mangle_assembler_name
)
64 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->decl
)))));
67 /* Merge node flags. */
68 if (node
->force_output
)
69 prevailing_node
->mark_force_output ();
70 if (node
->forced_by_abi
)
71 prevailing_node
->forced_by_abi
= true;
72 if (node
->address_taken
)
74 gcc_assert (!prevailing_node
->global
.inlined_to
);
75 prevailing_node
->mark_address_taken ();
77 if (node
->definition
&& prevailing_node
->definition
)
78 prevailing_node
->merged
= true;
80 /* Redirect all incoming edges. */
82 = types_compatible_p (TREE_TYPE (TREE_TYPE (prevailing_node
->decl
)),
83 TREE_TYPE (TREE_TYPE (node
->decl
)));
84 for (e
= node
->callers
; e
; e
= next
)
86 next
= e
->next_caller
;
87 e
->redirect_callee (prevailing_node
);
88 /* If there is a mismatch between the supposed callee return type and
89 the real one do not attempt to inline this function.
90 ??? We really need a way to match function signatures for ABI
91 compatibility and perform related promotions at inlining time. */
93 e
->call_stmt_cannot_inline_p
= 1;
95 /* Redirect incomming references. */
96 prevailing_node
->clone_referring (node
);
98 /* Fix instrumentation references. */
99 if (node
->instrumented_version
)
101 gcc_assert (node
->instrumentation_clone
102 == prevailing_node
->instrumentation_clone
);
103 node
->instrumented_version
->instrumented_version
= prevailing_node
;
104 if (!prevailing_node
->instrumented_version
)
105 prevailing_node
->instrumented_version
= node
->instrumented_version
;
106 /* Need to reset node->instrumented_version to NULL,
107 otherwise node removal code would reset
108 node->instrumented_version->instrumented_version. */
109 node
->instrumented_version
= NULL
;
112 ipa_merge_profiles (prevailing_node
, node
);
113 lto_free_function_in_decl_state_for_node (node
);
115 if (node
->decl
!= prevailing_node
->decl
)
116 node
->release_body ();
118 /* Finally remove the replaced node. */
122 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
123 all edges and removing the old node. */
126 lto_varpool_replace_node (varpool_node
*vnode
,
127 varpool_node
*prevailing_node
)
129 gcc_assert (!vnode
->definition
|| prevailing_node
->definition
);
130 gcc_assert (!vnode
->analyzed
|| prevailing_node
->analyzed
);
132 prevailing_node
->clone_referring (vnode
);
133 if (vnode
->force_output
)
134 prevailing_node
->force_output
= true;
135 if (vnode
->forced_by_abi
)
136 prevailing_node
->forced_by_abi
= true;
138 /* Be sure we can garbage collect the initializer. */
139 if (DECL_INITIAL (vnode
->decl
)
140 && vnode
->decl
!= prevailing_node
->decl
)
141 DECL_INITIAL (vnode
->decl
) = error_mark_node
;
143 /* Check and report ODR violations on virtual tables. */
144 if (DECL_VIRTUAL_P (vnode
->decl
) || DECL_VIRTUAL_P (prevailing_node
->decl
))
145 compare_virtual_tables (prevailing_node
, vnode
);
147 if (vnode
->tls_model
!= prevailing_node
->tls_model
)
151 /* Non-TLS and TLS never mix together. Also emulated model is not
152 compatible with anything else. */
153 if (prevailing_node
->tls_model
== TLS_MODEL_NONE
154 || prevailing_node
->tls_model
== TLS_MODEL_EMULATED
155 || vnode
->tls_model
== TLS_MODEL_NONE
156 || vnode
->tls_model
== TLS_MODEL_EMULATED
)
158 /* Linked is silently supporting transitions
159 GD -> IE, GD -> LE, LD -> LE, IE -> LE, LD -> IE.
160 Do the same transitions and error out on others. */
161 else if ((prevailing_node
->tls_model
== TLS_MODEL_REAL
162 || prevailing_node
->tls_model
== TLS_MODEL_LOCAL_DYNAMIC
)
163 && (vnode
->tls_model
== TLS_MODEL_INITIAL_EXEC
164 || vnode
->tls_model
== TLS_MODEL_LOCAL_EXEC
))
165 prevailing_node
->tls_model
= vnode
->tls_model
;
166 else if ((vnode
->tls_model
== TLS_MODEL_REAL
167 || vnode
->tls_model
== TLS_MODEL_LOCAL_DYNAMIC
)
168 && (prevailing_node
->tls_model
== TLS_MODEL_INITIAL_EXEC
169 || prevailing_node
->tls_model
== TLS_MODEL_LOCAL_EXEC
))
171 else if (prevailing_node
->tls_model
== TLS_MODEL_INITIAL_EXEC
172 && vnode
->tls_model
== TLS_MODEL_LOCAL_EXEC
)
173 prevailing_node
->tls_model
= vnode
->tls_model
;
174 else if (vnode
->tls_model
== TLS_MODEL_INITIAL_EXEC
175 && prevailing_node
->tls_model
== TLS_MODEL_LOCAL_EXEC
)
181 error_at (DECL_SOURCE_LOCATION (vnode
->decl
),
182 "%qD is defined with tls model %s", vnode
->decl
, tls_model_names
[vnode
->tls_model
]);
183 inform (DECL_SOURCE_LOCATION (prevailing_node
->decl
),
184 "previously defined here as %s",
185 tls_model_names
[prevailing_node
->tls_model
]);
188 /* Finally remove the replaced node. */
192 /* Return non-zero if we want to output waring about T1 and T2.
193 Return value is a bitmask of reasons of violation:
194 Bit 0 indicates that types are not compatible of memory layout.
195 Bot 1 indicates that types are not compatible because of C++ ODR rule. */
198 warn_type_compatibility_p (tree prevailing_type
, tree type
)
201 /* C++ provide a robust way to check for type compatibility via the ODR
203 if (odr_or_derived_type_p (prevailing_type
) && odr_or_derived_type_p (type
)
204 && !odr_types_equivalent_p (prevailing_type
, type
))
207 /* Function types needs special care, because types_compatible_p never
208 thinks prototype is compatible to non-prototype. */
209 if ((TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
210 && TREE_CODE (type
) == TREE_CODE (prevailing_type
))
212 lev
|= warn_type_compatibility_p (TREE_TYPE (prevailing_type
),
214 if (TREE_CODE (type
) == METHOD_TYPE
)
215 lev
|= warn_type_compatibility_p (TYPE_METHOD_BASETYPE (prevailing_type
),
216 TYPE_METHOD_BASETYPE (type
));
217 if (prototype_p (prevailing_type
) && prototype_p (type
)
218 && TYPE_ARG_TYPES (prevailing_type
) != TYPE_ARG_TYPES (type
))
221 for (parm1
= TYPE_ARG_TYPES (prevailing_type
),
222 parm2
= TYPE_ARG_TYPES (type
);
224 parm1
= TREE_CHAIN (prevailing_type
),
225 parm2
= TREE_CHAIN (type
))
226 lev
|= warn_type_compatibility_p (TREE_VALUE (parm1
),
231 if (comp_type_attributes (prevailing_type
, type
) == 0)
235 /* Sharing a global symbol is a strong hint that two types are
236 compatible. We could use this information to complete
237 incomplete pointed-to types more aggressively here, ignoring
238 mismatches in both field and tag names. It's difficult though
239 to guarantee that this does not have side-effects on merging
240 more compatible types from other translation units though. */
242 /* We can tolerate differences in type qualification, the
243 qualification of the prevailing definition will prevail.
244 ??? In principle we might want to only warn for structurally
245 incompatible types here, but unless we have protective measures
246 for TBAA in place that would hide useful information. */
247 prevailing_type
= TYPE_MAIN_VARIANT (prevailing_type
);
248 type
= TYPE_MAIN_VARIANT (type
);
250 if (!types_compatible_p (prevailing_type
, type
))
252 if (TREE_CODE (prevailing_type
) == FUNCTION_TYPE
253 || TREE_CODE (type
) == METHOD_TYPE
)
255 if (COMPLETE_TYPE_P (type
) && COMPLETE_TYPE_P (prevailing_type
))
258 /* If type is incomplete then avoid warnings in the cases
259 that TBAA handles just fine. */
261 if (TREE_CODE (prevailing_type
) != TREE_CODE (type
))
264 if (TREE_CODE (prevailing_type
) == ARRAY_TYPE
)
266 tree tem1
= TREE_TYPE (prevailing_type
);
267 tree tem2
= TREE_TYPE (type
);
268 while (TREE_CODE (tem1
) == ARRAY_TYPE
269 && TREE_CODE (tem2
) == ARRAY_TYPE
)
271 tem1
= TREE_TYPE (tem1
);
272 tem2
= TREE_TYPE (tem2
);
275 if (TREE_CODE (tem1
) != TREE_CODE (tem2
))
278 if (!types_compatible_p (tem1
, tem2
))
282 /* Fallthru. Compatible enough. */
285 /* ??? We might want to emit a warning here if type qualification
286 differences were spotted. Do not do this unconditionally though. */
291 /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
292 Return false if the symbols are not fully compatible and a diagnostic
293 should be emitted. */
296 lto_symtab_merge (symtab_node
*prevailing
, symtab_node
*entry
)
298 tree prevailing_decl
= prevailing
->decl
;
299 tree decl
= entry
->decl
;
301 if (prevailing_decl
== decl
)
304 /* Merge decl state in both directions, we may still end up using
306 TREE_ADDRESSABLE (prevailing_decl
) |= TREE_ADDRESSABLE (decl
);
307 TREE_ADDRESSABLE (decl
) |= TREE_ADDRESSABLE (prevailing_decl
);
309 /* The linker may ask us to combine two incompatible symbols.
310 Detect this case and notify the caller of required diagnostics. */
312 if (TREE_CODE (decl
) == FUNCTION_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 /* Likewise builtins are their own prevailing decl. This preserves
801 non-builtin vs. builtin uses from compile-time. */
802 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
805 /* Ensure DECL_ASSEMBLER_NAME will not set assembler name. */
806 gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl
));
808 /* Walk through the list of candidates and return the one we merged to. */
809 ret
= symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl
));