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"
28 #include "double-int.h"
36 #include "fold-const.h"
39 #include "hard-reg-set.h"
42 #include "basic-block.h"
43 #include "tree-ssa-alias.h"
44 #include "internal-fn.h"
45 #include "gimple-expr.h"
48 #include "plugin-api.h"
52 #include "lto-streamer.h"
53 #include "ipa-utils.h"
54 #include "alloc-pool.h"
55 #include "symbol-summary.h"
57 #include "ipa-inline.h"
59 #include "print-tree.h"
61 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
62 all edges and removing the old node. */
65 lto_cgraph_replace_node (struct cgraph_node
*node
,
66 struct cgraph_node
*prevailing_node
)
68 struct cgraph_edge
*e
, *next
;
71 if (symtab
->dump_file
)
73 fprintf (symtab
->dump_file
, "Replacing cgraph node %s/%i by %s/%i"
75 node
->name (), node
->order
,
76 prevailing_node
->name (),
77 prevailing_node
->order
,
78 IDENTIFIER_POINTER ((*targetm
.asm_out
.mangle_assembler_name
)
79 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->decl
)))));
82 /* Merge node flags. */
83 if (node
->force_output
)
84 prevailing_node
->mark_force_output ();
85 if (node
->forced_by_abi
)
86 prevailing_node
->forced_by_abi
= true;
87 if (node
->address_taken
)
89 gcc_assert (!prevailing_node
->global
.inlined_to
);
90 prevailing_node
->mark_address_taken ();
92 if (node
->definition
&& prevailing_node
->definition
)
93 prevailing_node
->merged
= true;
95 /* Redirect all incoming edges. */
97 = types_compatible_p (TREE_TYPE (TREE_TYPE (prevailing_node
->decl
)),
98 TREE_TYPE (TREE_TYPE (node
->decl
)));
99 for (e
= node
->callers
; e
; e
= next
)
101 next
= e
->next_caller
;
102 e
->redirect_callee (prevailing_node
);
103 /* If there is a mismatch between the supposed callee return type and
104 the real one do not attempt to inline this function.
105 ??? We really need a way to match function signatures for ABI
106 compatibility and perform related promotions at inlining time. */
108 e
->call_stmt_cannot_inline_p
= 1;
110 /* Redirect incomming references. */
111 prevailing_node
->clone_referring (node
);
113 /* Fix instrumentation references. */
114 if (node
->instrumented_version
)
116 gcc_assert (node
->instrumentation_clone
117 == prevailing_node
->instrumentation_clone
);
118 node
->instrumented_version
->instrumented_version
= prevailing_node
;
119 if (!prevailing_node
->instrumented_version
)
120 prevailing_node
->instrumented_version
= node
->instrumented_version
;
121 /* Need to reset node->instrumented_version to NULL,
122 otherwise node removal code would reset
123 node->instrumented_version->instrumented_version. */
124 node
->instrumented_version
= NULL
;
127 ipa_merge_profiles (prevailing_node
, node
);
128 lto_free_function_in_decl_state_for_node (node
);
130 if (node
->decl
!= prevailing_node
->decl
)
131 node
->release_body ();
133 /* Finally remove the replaced node. */
137 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
138 all edges and removing the old node. */
141 lto_varpool_replace_node (varpool_node
*vnode
,
142 varpool_node
*prevailing_node
)
144 gcc_assert (!vnode
->definition
|| prevailing_node
->definition
);
145 gcc_assert (!vnode
->analyzed
|| prevailing_node
->analyzed
);
147 prevailing_node
->clone_referring (vnode
);
148 if (vnode
->force_output
)
149 prevailing_node
->force_output
= true;
150 if (vnode
->forced_by_abi
)
151 prevailing_node
->forced_by_abi
= true;
153 /* Be sure we can garbage collect the initializer. */
154 if (DECL_INITIAL (vnode
->decl
)
155 && vnode
->decl
!= prevailing_node
->decl
)
156 DECL_INITIAL (vnode
->decl
) = error_mark_node
;
158 /* Check and report ODR violations on virtual tables. */
159 if (DECL_VIRTUAL_P (vnode
->decl
) || DECL_VIRTUAL_P (prevailing_node
->decl
))
160 compare_virtual_tables (prevailing_node
, vnode
);
162 if (vnode
->tls_model
!= prevailing_node
->tls_model
)
166 /* Non-TLS and TLS never mix together. Also emulated model is not
167 compatible with anything else. */
168 if (prevailing_node
->tls_model
== TLS_MODEL_NONE
169 || prevailing_node
->tls_model
== TLS_MODEL_EMULATED
170 || vnode
->tls_model
== TLS_MODEL_NONE
171 || vnode
->tls_model
== TLS_MODEL_EMULATED
)
173 /* Linked is silently supporting transitions
174 GD -> IE, GD -> LE, LD -> LE, IE -> LE, LD -> IE.
175 Do the same transitions and error out on others. */
176 else if ((prevailing_node
->tls_model
== TLS_MODEL_REAL
177 || prevailing_node
->tls_model
== TLS_MODEL_LOCAL_DYNAMIC
)
178 && (vnode
->tls_model
== TLS_MODEL_INITIAL_EXEC
179 || vnode
->tls_model
== TLS_MODEL_LOCAL_EXEC
))
180 prevailing_node
->tls_model
= vnode
->tls_model
;
181 else if ((vnode
->tls_model
== TLS_MODEL_REAL
182 || vnode
->tls_model
== TLS_MODEL_LOCAL_DYNAMIC
)
183 && (prevailing_node
->tls_model
== TLS_MODEL_INITIAL_EXEC
184 || prevailing_node
->tls_model
== TLS_MODEL_LOCAL_EXEC
))
186 else if (prevailing_node
->tls_model
== TLS_MODEL_INITIAL_EXEC
187 && vnode
->tls_model
== TLS_MODEL_LOCAL_EXEC
)
188 prevailing_node
->tls_model
= vnode
->tls_model
;
189 else if (vnode
->tls_model
== TLS_MODEL_INITIAL_EXEC
190 && prevailing_node
->tls_model
== TLS_MODEL_LOCAL_EXEC
)
196 error_at (DECL_SOURCE_LOCATION (vnode
->decl
),
197 "%qD is defined with tls model %s", vnode
->decl
, tls_model_names
[vnode
->tls_model
]);
198 inform (DECL_SOURCE_LOCATION (prevailing_node
->decl
),
199 "previously defined here as %s",
200 tls_model_names
[prevailing_node
->tls_model
]);
203 /* Finally remove the replaced node. */
207 /* Return non-zero if we want to output waring about T1 and T2.
208 Return value is a bitmask of reasons of violation:
209 Bit 0 indicates that types are not compatible of memory layout.
210 Bot 1 indicates that types are not compatible because of C++ ODR rule. */
213 warn_type_compatibility_p (tree prevailing_type
, tree type
)
216 /* C++ provide a robust way to check for type compatibility via the ODR
218 if (odr_or_derived_type_p (prevailing_type
) && odr_type_p (type
)
219 && !odr_types_equivalent_p (prevailing_type
, type
))
222 /* Function types needs special care, because types_compatible_p never
223 thinks prototype is compatible to non-prototype. */
224 if ((TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
225 && TREE_CODE (type
) == TREE_CODE (prevailing_type
))
227 lev
|= warn_type_compatibility_p (TREE_TYPE (prevailing_type
),
229 if (TREE_CODE (type
) == METHOD_TYPE
)
230 lev
|= warn_type_compatibility_p (TYPE_METHOD_BASETYPE (prevailing_type
),
231 TYPE_METHOD_BASETYPE (type
));
232 if (prototype_p (prevailing_type
) && prototype_p (type
)
233 && TYPE_ARG_TYPES (prevailing_type
) != TYPE_ARG_TYPES (type
))
236 for (parm1
= TYPE_ARG_TYPES (prevailing_type
),
237 parm2
= TYPE_ARG_TYPES (type
);
239 parm1
= TREE_CHAIN (prevailing_type
),
240 parm2
= TREE_CHAIN (type
))
241 lev
|= warn_type_compatibility_p (TREE_VALUE (parm1
),
246 if (comp_type_attributes (prevailing_type
, type
) == 0)
250 /* Sharing a global symbol is a strong hint that two types are
251 compatible. We could use this information to complete
252 incomplete pointed-to types more aggressively here, ignoring
253 mismatches in both field and tag names. It's difficult though
254 to guarantee that this does not have side-effects on merging
255 more compatible types from other translation units though. */
257 /* We can tolerate differences in type qualification, the
258 qualification of the prevailing definition will prevail.
259 ??? In principle we might want to only warn for structurally
260 incompatible types here, but unless we have protective measures
261 for TBAA in place that would hide useful information. */
262 prevailing_type
= TYPE_MAIN_VARIANT (prevailing_type
);
263 type
= TYPE_MAIN_VARIANT (type
);
265 if (!types_compatible_p (prevailing_type
, type
))
267 if (TREE_CODE (prevailing_type
) == FUNCTION_TYPE
268 || TREE_CODE (type
) == METHOD_TYPE
)
270 if (COMPLETE_TYPE_P (type
) && COMPLETE_TYPE_P (prevailing_type
))
273 /* If type is incomplete then avoid warnings in the cases
274 that TBAA handles just fine. */
276 if (TREE_CODE (prevailing_type
) != TREE_CODE (type
))
279 if (TREE_CODE (prevailing_type
) == ARRAY_TYPE
)
281 tree tem1
= TREE_TYPE (prevailing_type
);
282 tree tem2
= TREE_TYPE (type
);
283 while (TREE_CODE (tem1
) == ARRAY_TYPE
284 && TREE_CODE (tem2
) == ARRAY_TYPE
)
286 tem1
= TREE_TYPE (tem1
);
287 tem2
= TREE_TYPE (tem2
);
290 if (TREE_CODE (tem1
) != TREE_CODE (tem2
))
293 if (!types_compatible_p (tem1
, tem2
))
297 /* Fallthru. Compatible enough. */
300 /* ??? We might want to emit a warning here if type qualification
301 differences were spotted. Do not do this unconditionally though. */
306 /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
307 Return false if the symbols are not fully compatible and a diagnostic
308 should be emitted. */
311 lto_symtab_merge (symtab_node
*prevailing
, symtab_node
*entry
)
313 tree prevailing_decl
= prevailing
->decl
;
314 tree decl
= entry
->decl
;
316 if (prevailing_decl
== decl
)
319 /* Merge decl state in both directions, we may still end up using
321 TREE_ADDRESSABLE (prevailing_decl
) |= TREE_ADDRESSABLE (decl
);
322 TREE_ADDRESSABLE (decl
) |= TREE_ADDRESSABLE (prevailing_decl
);
324 /* The linker may ask us to combine two incompatible symbols.
325 Detect this case and notify the caller of required diagnostics. */
327 if (TREE_CODE (decl
) == FUNCTION_DECL
)
329 if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl
),
336 if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl
),
340 /* There is no point in comparing too many details of the decls here.
341 The type compatibility checks or the completing of types has properly
342 dealt with most issues. */
344 /* The following should all not invoke fatal errors as in non-LTO
345 mode the linker wouldn't complain either. Just emit warnings. */
347 /* Report a warning if user-specified alignments do not match. */
348 if ((DECL_USER_ALIGN (prevailing_decl
) && DECL_USER_ALIGN (decl
))
349 && DECL_ALIGN (prevailing_decl
) < DECL_ALIGN (decl
))
355 /* Return true if the symtab entry E can be replaced by another symtab
359 lto_symtab_resolve_replaceable_p (symtab_node
*e
)
361 if (DECL_EXTERNAL (e
->decl
)
362 || DECL_COMDAT (e
->decl
)
363 || DECL_ONE_ONLY (e
->decl
)
364 || DECL_WEAK (e
->decl
))
367 if (TREE_CODE (e
->decl
) == VAR_DECL
)
368 return (DECL_COMMON (e
->decl
)
369 || (!flag_no_common
&& !DECL_INITIAL (e
->decl
)));
374 /* Return true, if the symbol E should be resolved by lto-symtab.
375 Those are all external symbols and all real symbols that are not static (we
376 handle renaming of static later in partitioning). */
379 lto_symtab_symbol_p (symtab_node
*e
)
381 if (!TREE_PUBLIC (e
->decl
) && !DECL_EXTERNAL (e
->decl
))
383 return e
->real_symbol_p ();
386 /* Return true if the symtab entry E can be the prevailing one. */
389 lto_symtab_resolve_can_prevail_p (symtab_node
*e
)
391 if (!lto_symtab_symbol_p (e
))
394 /* The C++ frontend ends up neither setting TREE_STATIC nor
395 DECL_EXTERNAL on virtual methods but only TREE_PUBLIC.
396 So do not reject !TREE_STATIC here but only DECL_EXTERNAL. */
397 if (DECL_EXTERNAL (e
->decl
))
400 return e
->definition
;
403 /* Resolve the symbol with the candidates in the chain *SLOT and store
404 their resolutions. */
407 lto_symtab_resolve_symbols (symtab_node
*first
)
410 symtab_node
*prevailing
= NULL
;
412 /* Always set e->node so that edges are updated to reflect decl merging. */
413 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
414 if (lto_symtab_symbol_p (e
)
415 && (e
->resolution
== LDPR_PREVAILING_DEF_IRONLY
416 || e
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
417 || e
->resolution
== LDPR_PREVAILING_DEF
))
423 /* If the chain is already resolved there is nothing else to do. */
426 /* Assert it's the only one. */
427 for (e
= prevailing
->next_sharing_asm_name
; e
; e
= e
->next_sharing_asm_name
)
428 if (lto_symtab_symbol_p (e
)
429 && (e
->resolution
== LDPR_PREVAILING_DEF_IRONLY
430 || e
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
431 || e
->resolution
== LDPR_PREVAILING_DEF
))
432 fatal_error (input_location
, "multiple prevailing defs for %qE",
433 DECL_NAME (prevailing
->decl
));
437 /* Find the single non-replaceable prevailing symbol and
438 diagnose ODR violations. */
439 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
441 if (!lto_symtab_resolve_can_prevail_p (e
))
444 /* If we have a non-replaceable definition it prevails. */
445 if (!lto_symtab_resolve_replaceable_p (e
))
449 error_at (DECL_SOURCE_LOCATION (e
->decl
),
450 "%qD has already been defined", e
->decl
);
451 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
452 "previously defined here");
460 /* Do a second round choosing one from the replaceable prevailing decls. */
461 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
463 if (!lto_symtab_resolve_can_prevail_p (e
))
466 /* Choose the first function that can prevail as prevailing. */
467 if (TREE_CODE (e
->decl
) == FUNCTION_DECL
)
473 /* From variables that can prevail choose the largest one. */
475 || tree_int_cst_lt (DECL_SIZE (prevailing
->decl
),
477 /* When variables are equivalent try to chose one that has useful
478 DECL_INITIAL. This makes sense for keyed vtables that are
479 DECL_EXTERNAL but initialized. In units that do not need them
480 we replace the initializer by error_mark_node to conserve
483 We know that the vtable is keyed outside the LTO unit - otherwise
484 the keyed instance would prevail. We still can preserve useful
485 info in the initializer. */
486 || (DECL_SIZE (prevailing
->decl
) == DECL_SIZE (e
->decl
)
487 && (DECL_INITIAL (e
->decl
)
488 && DECL_INITIAL (e
->decl
) != error_mark_node
)
489 && (!DECL_INITIAL (prevailing
->decl
)
490 || DECL_INITIAL (prevailing
->decl
) == error_mark_node
)))
497 /* Merge all decls in the symbol table chain to the prevailing decl and
498 issue diagnostics about type mismatches. If DIAGNOSED_P is true
499 do not issue further diagnostics.*/
502 lto_symtab_merge_decls_2 (symtab_node
*first
, bool diagnosed_p
)
504 symtab_node
*prevailing
;
506 vec
<tree
> mismatches
= vNULL
;
510 /* Nothing to do for a single entry. */
512 if (!prevailing
->next_sharing_asm_name
)
515 /* Try to merge each entry with the prevailing one. */
516 for (e
= prevailing
->next_sharing_asm_name
;
517 e
; e
= e
->next_sharing_asm_name
)
518 if (TREE_PUBLIC (e
->decl
))
520 if (!lto_symtab_merge (prevailing
, e
)
522 && !DECL_ARTIFICIAL (e
->decl
))
523 mismatches
.safe_push (e
->decl
);
525 if (mismatches
.is_empty ())
528 /* Diagnose all mismatched re-declarations. */
529 FOR_EACH_VEC_ELT (mismatches
, i
, decl
)
531 int level
= warn_type_compatibility_p (TREE_TYPE (prevailing
->decl
),
537 diag
= warning_at (DECL_SOURCE_LOCATION (decl
),
539 "%qD violates the C++ One Definition Rule ",
541 if (!diag
&& (level
& 1))
542 diag
= warning_at (DECL_SOURCE_LOCATION (decl
),
543 OPT_Wlto_type_mismatch
,
544 "type of %qD does not match original "
545 "declaration", decl
);
547 warn_types_mismatch (TREE_TYPE (prevailing
->decl
),
551 else if ((DECL_USER_ALIGN (prevailing
->decl
)
552 && DECL_USER_ALIGN (decl
))
553 && DECL_ALIGN (prevailing
->decl
) < DECL_ALIGN (decl
))
555 diagnosed_p
|= warning_at (DECL_SOURCE_LOCATION (decl
),
556 OPT_Wlto_type_mismatch
,
557 "alignment of %qD is bigger than "
558 "original declaration", decl
);
562 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
563 "%qD was previously declared here", prevailing
->decl
);
565 mismatches
.release ();
568 /* Helper to process the decl chain for the symbol table entry *SLOT. */
571 lto_symtab_merge_decls_1 (symtab_node
*first
)
574 symtab_node
*prevailing
;
575 bool diagnosed_p
= false;
577 if (symtab
->dump_file
)
579 fprintf (symtab
->dump_file
, "Merging nodes for %s. Candidates:\n",
581 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
582 if (TREE_PUBLIC (e
->decl
))
583 e
->dump (symtab
->dump_file
);
586 /* Compute the symbol resolutions. This is a no-op when using the
587 linker plugin and resolution was decided by the linker. */
588 prevailing
= lto_symtab_resolve_symbols (first
);
590 /* If there's not a prevailing symbol yet it's an external reference.
591 Happens a lot during ltrans. Choose the first symbol with a
592 cgraph or a varpool node. */
595 for (prevailing
= first
;
596 prevailing
; prevailing
= prevailing
->next_sharing_asm_name
)
597 if (lto_symtab_symbol_p (prevailing
))
601 /* For variables chose with a priority variant with vnode
602 attached (i.e. from unit where external declaration of
603 variable is actually used).
604 When there are multiple variants, chose one with size.
605 This is needed for C++ typeinfos, for example in
606 lto/20081204-1 there are typeifos in both units, just
607 one of them do have size. */
608 if (TREE_CODE (prevailing
->decl
) == VAR_DECL
)
610 for (e
= prevailing
->next_sharing_asm_name
;
611 e
; e
= e
->next_sharing_asm_name
)
612 if (!COMPLETE_TYPE_P (TREE_TYPE (prevailing
->decl
))
613 && COMPLETE_TYPE_P (TREE_TYPE (e
->decl
))
614 && lto_symtab_symbol_p (e
))
617 /* For variables prefer the non-builtin if one is available. */
618 else if (TREE_CODE (prevailing
->decl
) == FUNCTION_DECL
)
620 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
621 if (TREE_CODE (e
->decl
) == FUNCTION_DECL
622 && !DECL_BUILT_IN (e
->decl
)
623 && lto_symtab_symbol_p (e
))
631 symtab
->symtab_prevail_in_asm_name_hash (prevailing
);
633 /* Diagnose mismatched objects. */
634 for (e
= prevailing
->next_sharing_asm_name
;
635 e
; e
= e
->next_sharing_asm_name
)
637 if (TREE_CODE (prevailing
->decl
)
638 == TREE_CODE (e
->decl
))
640 if (!lto_symtab_symbol_p (e
))
643 switch (TREE_CODE (prevailing
->decl
))
646 gcc_assert (TREE_CODE (e
->decl
) == FUNCTION_DECL
);
647 error_at (DECL_SOURCE_LOCATION (e
->decl
),
648 "variable %qD redeclared as function",
653 gcc_assert (TREE_CODE (e
->decl
) == VAR_DECL
);
654 error_at (DECL_SOURCE_LOCATION (e
->decl
),
655 "function %qD redeclared as variable",
666 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
667 "previously declared here");
669 /* Merge the chain to the single prevailing decl and diagnose
671 lto_symtab_merge_decls_2 (prevailing
, diagnosed_p
);
673 if (symtab
->dump_file
)
675 fprintf (symtab
->dump_file
, "After resolution:\n");
676 for (e
= prevailing
; e
; e
= e
->next_sharing_asm_name
)
677 e
->dump (symtab
->dump_file
);
681 /* Resolve and merge all symbol table chains to a prevailing decl. */
684 lto_symtab_merge_decls (void)
688 /* Populate assembler name hash. */
689 symtab
->symtab_initialize_asm_name_hash ();
691 FOR_EACH_SYMBOL (node
)
692 if (!node
->previous_sharing_asm_name
693 && node
->next_sharing_asm_name
)
694 lto_symtab_merge_decls_1 (node
);
697 /* Helper to process the decl chain for the symbol table entry *SLOT. */
700 lto_symtab_merge_symbols_1 (symtab_node
*prevailing
)
705 /* Replace the cgraph node of each entry with the prevailing one. */
706 for (e
= prevailing
->next_sharing_asm_name
; e
;
709 next
= e
->next_sharing_asm_name
;
711 if (!lto_symtab_symbol_p (e
))
713 cgraph_node
*ce
= dyn_cast
<cgraph_node
*> (e
);
714 if (ce
&& !DECL_BUILT_IN (e
->decl
))
715 lto_cgraph_replace_node (ce
, dyn_cast
<cgraph_node
*> (prevailing
));
716 if (varpool_node
*ve
= dyn_cast
<varpool_node
*> (e
))
717 lto_varpool_replace_node (ve
, dyn_cast
<varpool_node
*> (prevailing
));
723 /* Merge cgraph nodes according to the symbol merging done by
724 lto_symtab_merge_decls. */
727 lto_symtab_merge_symbols (void)
733 symtab
->symtab_initialize_asm_name_hash ();
735 /* Do the actual merging.
736 At this point we invalidate hash translating decls into symtab nodes
737 because after removing one of duplicate decls the hash is not correcly
738 updated to the ohter dupliate. */
739 FOR_EACH_SYMBOL (node
)
740 if (lto_symtab_symbol_p (node
)
741 && node
->next_sharing_asm_name
742 && !node
->previous_sharing_asm_name
)
743 lto_symtab_merge_symbols_1 (node
);
745 /* Resolve weakref aliases whose target are now in the compilation unit.
746 also re-populate the hash translating decls into symtab nodes*/
747 FOR_EACH_SYMBOL (node
)
749 cgraph_node
*cnode
, *cnode2
;
753 if (!node
->analyzed
&& node
->alias_target
)
755 symtab_node
*tgt
= symtab_node::get_for_asmname (node
->alias_target
);
756 gcc_assert (node
->weakref
);
758 node
->resolve_alias (tgt
);
762 if (!(cnode
= dyn_cast
<cgraph_node
*> (node
))
764 || cnode
->clone_of
->decl
!= cnode
->decl
)
766 /* Builtins are not merged via decl merging. It is however
767 possible that tree merging unified the declaration. We
768 do not want duplicate entries in symbol table. */
769 if (cnode
&& DECL_BUILT_IN (node
->decl
)
770 && (cnode2
= cgraph_node::get (node
->decl
))
772 lto_cgraph_replace_node (cnode2
, cnode
);
774 /* The user defined assembler variables are also not unified by their
775 symbol name (since it is irrelevant), but we need to unify symbol
776 nodes if tree merging occured. */
777 if ((vnode
= dyn_cast
<varpool_node
*> (node
))
778 && DECL_HARD_REGISTER (vnode
->decl
)
779 && (node2
= symtab_node::get (vnode
->decl
))
781 lto_varpool_replace_node (dyn_cast
<varpool_node
*> (node2
),
785 /* Abstract functions may have duplicated cgraph nodes attached;
787 else if (cnode
&& DECL_ABSTRACT_P (cnode
->decl
)
788 && (cnode2
= cgraph_node::get (node
->decl
))
792 node
->decl
->decl_with_vis
.symtab_node
= node
;
798 /* Given the decl DECL, return the prevailing decl with the same name. */
801 lto_symtab_prevailing_decl (tree decl
)
805 /* Builtins and local symbols are their own prevailing decl. */
806 if ((!TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
)) || is_builtin_fn (decl
))
809 /* DECL_ABSTRACT_Ps are their own prevailing decl. */
810 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_ABSTRACT_P (decl
))
813 /* Likewise builtins are their own prevailing decl. This preserves
814 non-builtin vs. builtin uses from compile-time. */
815 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
818 /* Ensure DECL_ASSEMBLER_NAME will not set assembler name. */
819 gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl
));
821 /* Walk through the list of candidates and return the one we merged to. */
822 ret
= symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl
));