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 "fold-const.h"
32 #include "hard-reg-set.h"
34 #include "basic-block.h"
35 #include "tree-ssa-alias.h"
36 #include "internal-fn.h"
37 #include "gimple-expr.h"
39 #include "plugin-api.h"
42 #include "lto-streamer.h"
43 #include "ipa-utils.h"
44 #include "alloc-pool.h"
45 #include "symbol-summary.h"
47 #include "ipa-inline.h"
49 #include "print-tree.h"
51 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
52 all edges and removing the old node. */
55 lto_cgraph_replace_node (struct cgraph_node
*node
,
56 struct cgraph_node
*prevailing_node
)
58 struct cgraph_edge
*e
, *next
;
61 if (symtab
->dump_file
)
63 fprintf (symtab
->dump_file
, "Replacing cgraph node %s/%i by %s/%i"
65 node
->name (), node
->order
,
66 prevailing_node
->name (),
67 prevailing_node
->order
,
68 IDENTIFIER_POINTER ((*targetm
.asm_out
.mangle_assembler_name
)
69 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->decl
)))));
72 /* Merge node flags. */
73 if (node
->force_output
)
74 prevailing_node
->mark_force_output ();
75 if (node
->forced_by_abi
)
76 prevailing_node
->forced_by_abi
= true;
77 if (node
->address_taken
)
79 gcc_assert (!prevailing_node
->global
.inlined_to
);
80 prevailing_node
->mark_address_taken ();
82 if (node
->definition
&& prevailing_node
->definition
)
83 prevailing_node
->merged
= true;
85 /* Redirect all incoming edges. */
87 = types_compatible_p (TREE_TYPE (TREE_TYPE (prevailing_node
->decl
)),
88 TREE_TYPE (TREE_TYPE (node
->decl
)));
89 for (e
= node
->callers
; e
; e
= next
)
91 next
= e
->next_caller
;
92 e
->redirect_callee (prevailing_node
);
93 /* If there is a mismatch between the supposed callee return type and
94 the real one do not attempt to inline this function.
95 ??? We really need a way to match function signatures for ABI
96 compatibility and perform related promotions at inlining time. */
98 e
->call_stmt_cannot_inline_p
= 1;
100 /* Redirect incomming references. */
101 prevailing_node
->clone_referring (node
);
103 /* Fix instrumentation references. */
104 if (node
->instrumented_version
)
106 gcc_assert (node
->instrumentation_clone
107 == prevailing_node
->instrumentation_clone
);
108 node
->instrumented_version
->instrumented_version
= prevailing_node
;
109 if (!prevailing_node
->instrumented_version
)
110 prevailing_node
->instrumented_version
= node
->instrumented_version
;
111 /* Need to reset node->instrumented_version to NULL,
112 otherwise node removal code would reset
113 node->instrumented_version->instrumented_version. */
114 node
->instrumented_version
= NULL
;
117 ipa_merge_profiles (prevailing_node
, node
);
118 lto_free_function_in_decl_state_for_node (node
);
120 if (node
->decl
!= prevailing_node
->decl
)
121 node
->release_body ();
123 /* Finally remove the replaced node. */
127 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
128 all edges and removing the old node. */
131 lto_varpool_replace_node (varpool_node
*vnode
,
132 varpool_node
*prevailing_node
)
134 gcc_assert (!vnode
->definition
|| prevailing_node
->definition
);
135 gcc_assert (!vnode
->analyzed
|| prevailing_node
->analyzed
);
137 prevailing_node
->clone_referring (vnode
);
138 if (vnode
->force_output
)
139 prevailing_node
->force_output
= true;
140 if (vnode
->forced_by_abi
)
141 prevailing_node
->forced_by_abi
= true;
143 /* Be sure we can garbage collect the initializer. */
144 if (DECL_INITIAL (vnode
->decl
)
145 && vnode
->decl
!= prevailing_node
->decl
)
146 DECL_INITIAL (vnode
->decl
) = error_mark_node
;
148 /* Check and report ODR violations on virtual tables. */
149 if (DECL_VIRTUAL_P (vnode
->decl
) || DECL_VIRTUAL_P (prevailing_node
->decl
))
150 compare_virtual_tables (prevailing_node
, vnode
);
152 if (vnode
->tls_model
!= prevailing_node
->tls_model
)
156 /* Non-TLS and TLS never mix together. Also emulated model is not
157 compatible with anything else. */
158 if (prevailing_node
->tls_model
== TLS_MODEL_NONE
159 || prevailing_node
->tls_model
== TLS_MODEL_EMULATED
160 || vnode
->tls_model
== TLS_MODEL_NONE
161 || vnode
->tls_model
== TLS_MODEL_EMULATED
)
163 /* Linked is silently supporting transitions
164 GD -> IE, GD -> LE, LD -> LE, IE -> LE, LD -> IE.
165 Do the same transitions and error out on others. */
166 else if ((prevailing_node
->tls_model
== TLS_MODEL_REAL
167 || prevailing_node
->tls_model
== TLS_MODEL_LOCAL_DYNAMIC
)
168 && (vnode
->tls_model
== TLS_MODEL_INITIAL_EXEC
169 || vnode
->tls_model
== TLS_MODEL_LOCAL_EXEC
))
170 prevailing_node
->tls_model
= vnode
->tls_model
;
171 else if ((vnode
->tls_model
== TLS_MODEL_REAL
172 || vnode
->tls_model
== TLS_MODEL_LOCAL_DYNAMIC
)
173 && (prevailing_node
->tls_model
== TLS_MODEL_INITIAL_EXEC
174 || prevailing_node
->tls_model
== TLS_MODEL_LOCAL_EXEC
))
176 else if (prevailing_node
->tls_model
== TLS_MODEL_INITIAL_EXEC
177 && vnode
->tls_model
== TLS_MODEL_LOCAL_EXEC
)
178 prevailing_node
->tls_model
= vnode
->tls_model
;
179 else if (vnode
->tls_model
== TLS_MODEL_INITIAL_EXEC
180 && prevailing_node
->tls_model
== TLS_MODEL_LOCAL_EXEC
)
186 error_at (DECL_SOURCE_LOCATION (vnode
->decl
),
187 "%qD is defined with tls model %s", vnode
->decl
, tls_model_names
[vnode
->tls_model
]);
188 inform (DECL_SOURCE_LOCATION (prevailing_node
->decl
),
189 "previously defined here as %s",
190 tls_model_names
[prevailing_node
->tls_model
]);
193 /* Finally remove the replaced node. */
197 /* Return non-zero if we want to output waring about T1 and T2.
198 Return value is a bitmask of reasons of violation:
199 Bit 0 indicates that types are not compatible of memory layout.
200 Bot 1 indicates that types are not compatible because of C++ ODR rule. */
203 warn_type_compatibility_p (tree prevailing_type
, tree type
)
206 /* C++ provide a robust way to check for type compatibility via the ODR
208 if (odr_or_derived_type_p (prevailing_type
) && odr_or_derived_type_p (type
)
209 && !odr_types_equivalent_p (prevailing_type
, type
))
212 /* Function types needs special care, because types_compatible_p never
213 thinks prototype is compatible to non-prototype. */
214 if ((TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
215 && TREE_CODE (type
) == TREE_CODE (prevailing_type
))
217 lev
|= warn_type_compatibility_p (TREE_TYPE (prevailing_type
),
219 if (TREE_CODE (type
) == METHOD_TYPE
)
220 lev
|= warn_type_compatibility_p (TYPE_METHOD_BASETYPE (prevailing_type
),
221 TYPE_METHOD_BASETYPE (type
));
222 if (prototype_p (prevailing_type
) && prototype_p (type
)
223 && TYPE_ARG_TYPES (prevailing_type
) != TYPE_ARG_TYPES (type
))
226 for (parm1
= TYPE_ARG_TYPES (prevailing_type
),
227 parm2
= TYPE_ARG_TYPES (type
);
229 parm1
= TREE_CHAIN (prevailing_type
),
230 parm2
= TREE_CHAIN (type
))
231 lev
|= warn_type_compatibility_p (TREE_VALUE (parm1
),
236 if (comp_type_attributes (prevailing_type
, type
) == 0)
240 /* Sharing a global symbol is a strong hint that two types are
241 compatible. We could use this information to complete
242 incomplete pointed-to types more aggressively here, ignoring
243 mismatches in both field and tag names. It's difficult though
244 to guarantee that this does not have side-effects on merging
245 more compatible types from other translation units though. */
247 /* We can tolerate differences in type qualification, the
248 qualification of the prevailing definition will prevail.
249 ??? In principle we might want to only warn for structurally
250 incompatible types here, but unless we have protective measures
251 for TBAA in place that would hide useful information. */
252 prevailing_type
= TYPE_MAIN_VARIANT (prevailing_type
);
253 type
= TYPE_MAIN_VARIANT (type
);
255 if (!types_compatible_p (prevailing_type
, type
))
257 if (TREE_CODE (prevailing_type
) == FUNCTION_TYPE
258 || TREE_CODE (type
) == METHOD_TYPE
)
260 if (COMPLETE_TYPE_P (type
) && COMPLETE_TYPE_P (prevailing_type
))
263 /* If type is incomplete then avoid warnings in the cases
264 that TBAA handles just fine. */
266 if (TREE_CODE (prevailing_type
) != TREE_CODE (type
))
269 if (TREE_CODE (prevailing_type
) == ARRAY_TYPE
)
271 tree tem1
= TREE_TYPE (prevailing_type
);
272 tree tem2
= TREE_TYPE (type
);
273 while (TREE_CODE (tem1
) == ARRAY_TYPE
274 && TREE_CODE (tem2
) == ARRAY_TYPE
)
276 tem1
= TREE_TYPE (tem1
);
277 tem2
= TREE_TYPE (tem2
);
280 if (TREE_CODE (tem1
) != TREE_CODE (tem2
))
283 if (!types_compatible_p (tem1
, tem2
))
287 /* Fallthru. Compatible enough. */
290 /* ??? We might want to emit a warning here if type qualification
291 differences were spotted. Do not do this unconditionally though. */
296 /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
297 Return false if the symbols are not fully compatible and a diagnostic
298 should be emitted. */
301 lto_symtab_merge (symtab_node
*prevailing
, symtab_node
*entry
)
303 tree prevailing_decl
= prevailing
->decl
;
304 tree decl
= entry
->decl
;
306 if (prevailing_decl
== decl
)
309 /* Merge decl state in both directions, we may still end up using
311 TREE_ADDRESSABLE (prevailing_decl
) |= TREE_ADDRESSABLE (decl
);
312 TREE_ADDRESSABLE (decl
) |= TREE_ADDRESSABLE (prevailing_decl
);
314 /* The linker may ask us to combine two incompatible symbols.
315 Detect this case and notify the caller of required diagnostics. */
317 if (TREE_CODE (decl
) == FUNCTION_DECL
)
319 if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl
),
326 if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl
),
330 /* There is no point in comparing too many details of the decls here.
331 The type compatibility checks or the completing of types has properly
332 dealt with most issues. */
334 /* The following should all not invoke fatal errors as in non-LTO
335 mode the linker wouldn't complain either. Just emit warnings. */
337 /* Report a warning if user-specified alignments do not match. */
338 if ((DECL_USER_ALIGN (prevailing_decl
) && DECL_USER_ALIGN (decl
))
339 && DECL_ALIGN (prevailing_decl
) < DECL_ALIGN (decl
))
345 /* Return true if the symtab entry E can be replaced by another symtab
349 lto_symtab_resolve_replaceable_p (symtab_node
*e
)
351 if (DECL_EXTERNAL (e
->decl
)
352 || DECL_COMDAT (e
->decl
)
353 || DECL_ONE_ONLY (e
->decl
)
354 || DECL_WEAK (e
->decl
))
357 if (TREE_CODE (e
->decl
) == VAR_DECL
)
358 return (DECL_COMMON (e
->decl
)
359 || (!flag_no_common
&& !DECL_INITIAL (e
->decl
)));
364 /* Return true, if the symbol E should be resolved by lto-symtab.
365 Those are all external symbols and all real symbols that are not static (we
366 handle renaming of static later in partitioning). */
369 lto_symtab_symbol_p (symtab_node
*e
)
371 if (!TREE_PUBLIC (e
->decl
) && !DECL_EXTERNAL (e
->decl
))
373 return e
->real_symbol_p ();
376 /* Return true if the symtab entry E can be the prevailing one. */
379 lto_symtab_resolve_can_prevail_p (symtab_node
*e
)
381 if (!lto_symtab_symbol_p (e
))
384 /* The C++ frontend ends up neither setting TREE_STATIC nor
385 DECL_EXTERNAL on virtual methods but only TREE_PUBLIC.
386 So do not reject !TREE_STATIC here but only DECL_EXTERNAL. */
387 if (DECL_EXTERNAL (e
->decl
))
390 return e
->definition
;
393 /* Resolve the symbol with the candidates in the chain *SLOT and store
394 their resolutions. */
397 lto_symtab_resolve_symbols (symtab_node
*first
)
400 symtab_node
*prevailing
= NULL
;
402 /* Always set e->node so that edges are updated to reflect decl merging. */
403 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
404 if (lto_symtab_symbol_p (e
)
405 && (e
->resolution
== LDPR_PREVAILING_DEF_IRONLY
406 || e
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
407 || e
->resolution
== LDPR_PREVAILING_DEF
))
413 /* If the chain is already resolved there is nothing else to do. */
416 /* Assert it's the only one. */
417 for (e
= prevailing
->next_sharing_asm_name
; e
; e
= e
->next_sharing_asm_name
)
418 if (lto_symtab_symbol_p (e
)
419 && (e
->resolution
== LDPR_PREVAILING_DEF_IRONLY
420 || e
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
421 || e
->resolution
== LDPR_PREVAILING_DEF
))
422 fatal_error (input_location
, "multiple prevailing defs for %qE",
423 DECL_NAME (prevailing
->decl
));
427 /* Find the single non-replaceable prevailing symbol and
428 diagnose ODR violations. */
429 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
431 if (!lto_symtab_resolve_can_prevail_p (e
))
434 /* If we have a non-replaceable definition it prevails. */
435 if (!lto_symtab_resolve_replaceable_p (e
))
439 error_at (DECL_SOURCE_LOCATION (e
->decl
),
440 "%qD has already been defined", e
->decl
);
441 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
442 "previously defined here");
450 /* Do a second round choosing one from the replaceable prevailing decls. */
451 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
453 if (!lto_symtab_resolve_can_prevail_p (e
))
456 /* Choose the first function that can prevail as prevailing. */
457 if (TREE_CODE (e
->decl
) == FUNCTION_DECL
)
463 /* From variables that can prevail choose the largest one. */
465 || tree_int_cst_lt (DECL_SIZE (prevailing
->decl
),
467 /* When variables are equivalent try to chose one that has useful
468 DECL_INITIAL. This makes sense for keyed vtables that are
469 DECL_EXTERNAL but initialized. In units that do not need them
470 we replace the initializer by error_mark_node to conserve
473 We know that the vtable is keyed outside the LTO unit - otherwise
474 the keyed instance would prevail. We still can preserve useful
475 info in the initializer. */
476 || (DECL_SIZE (prevailing
->decl
) == DECL_SIZE (e
->decl
)
477 && (DECL_INITIAL (e
->decl
)
478 && DECL_INITIAL (e
->decl
) != error_mark_node
)
479 && (!DECL_INITIAL (prevailing
->decl
)
480 || DECL_INITIAL (prevailing
->decl
) == error_mark_node
)))
487 /* Merge all decls in the symbol table chain to the prevailing decl and
488 issue diagnostics about type mismatches. If DIAGNOSED_P is true
489 do not issue further diagnostics.*/
492 lto_symtab_merge_decls_2 (symtab_node
*first
, bool diagnosed_p
)
494 symtab_node
*prevailing
;
496 vec
<tree
> mismatches
= vNULL
;
500 /* Nothing to do for a single entry. */
502 if (!prevailing
->next_sharing_asm_name
)
505 /* Try to merge each entry with the prevailing one. */
506 for (e
= prevailing
->next_sharing_asm_name
;
507 e
; e
= e
->next_sharing_asm_name
)
508 if (TREE_PUBLIC (e
->decl
))
510 if (!lto_symtab_merge (prevailing
, e
)
512 && !DECL_ARTIFICIAL (e
->decl
))
513 mismatches
.safe_push (e
->decl
);
515 if (mismatches
.is_empty ())
518 /* Diagnose all mismatched re-declarations. */
519 FOR_EACH_VEC_ELT (mismatches
, i
, decl
)
521 int level
= warn_type_compatibility_p (TREE_TYPE (prevailing
->decl
),
527 diag
= warning_at (DECL_SOURCE_LOCATION (decl
),
529 "%qD violates the C++ One Definition Rule ",
531 if (!diag
&& (level
& 1))
532 diag
= warning_at (DECL_SOURCE_LOCATION (decl
),
533 OPT_Wlto_type_mismatch
,
534 "type of %qD does not match original "
535 "declaration", decl
);
537 warn_types_mismatch (TREE_TYPE (prevailing
->decl
),
539 DECL_SOURCE_LOCATION (prevailing
->decl
),
540 DECL_SOURCE_LOCATION (decl
));
543 else if ((DECL_USER_ALIGN (prevailing
->decl
)
544 && DECL_USER_ALIGN (decl
))
545 && DECL_ALIGN (prevailing
->decl
) < DECL_ALIGN (decl
))
547 diagnosed_p
|= warning_at (DECL_SOURCE_LOCATION (decl
),
548 OPT_Wlto_type_mismatch
,
549 "alignment of %qD is bigger than "
550 "original declaration", decl
);
554 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
555 "%qD was previously declared here", prevailing
->decl
);
557 mismatches
.release ();
560 /* Helper to process the decl chain for the symbol table entry *SLOT. */
563 lto_symtab_merge_decls_1 (symtab_node
*first
)
566 symtab_node
*prevailing
;
567 bool diagnosed_p
= false;
569 if (symtab
->dump_file
)
571 fprintf (symtab
->dump_file
, "Merging nodes for %s. Candidates:\n",
573 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
574 if (TREE_PUBLIC (e
->decl
))
575 e
->dump (symtab
->dump_file
);
578 /* Compute the symbol resolutions. This is a no-op when using the
579 linker plugin and resolution was decided by the linker. */
580 prevailing
= lto_symtab_resolve_symbols (first
);
582 /* If there's not a prevailing symbol yet it's an external reference.
583 Happens a lot during ltrans. Choose the first symbol with a
584 cgraph or a varpool node. */
587 for (prevailing
= first
;
588 prevailing
; prevailing
= prevailing
->next_sharing_asm_name
)
589 if (lto_symtab_symbol_p (prevailing
))
593 /* For variables chose with a priority variant with vnode
594 attached (i.e. from unit where external declaration of
595 variable is actually used).
596 When there are multiple variants, chose one with size.
597 This is needed for C++ typeinfos, for example in
598 lto/20081204-1 there are typeifos in both units, just
599 one of them do have size. */
600 if (TREE_CODE (prevailing
->decl
) == VAR_DECL
)
602 for (e
= prevailing
->next_sharing_asm_name
;
603 e
; e
= e
->next_sharing_asm_name
)
604 if (!COMPLETE_TYPE_P (TREE_TYPE (prevailing
->decl
))
605 && COMPLETE_TYPE_P (TREE_TYPE (e
->decl
))
606 && lto_symtab_symbol_p (e
))
609 /* For variables prefer the non-builtin if one is available. */
610 else if (TREE_CODE (prevailing
->decl
) == FUNCTION_DECL
)
612 for (e
= first
; e
; e
= e
->next_sharing_asm_name
)
613 if (TREE_CODE (e
->decl
) == FUNCTION_DECL
614 && !DECL_BUILT_IN (e
->decl
)
615 && lto_symtab_symbol_p (e
))
623 symtab
->symtab_prevail_in_asm_name_hash (prevailing
);
625 /* Diagnose mismatched objects. */
626 for (e
= prevailing
->next_sharing_asm_name
;
627 e
; e
= e
->next_sharing_asm_name
)
629 if (TREE_CODE (prevailing
->decl
)
630 == TREE_CODE (e
->decl
))
632 if (!lto_symtab_symbol_p (e
))
635 switch (TREE_CODE (prevailing
->decl
))
638 gcc_assert (TREE_CODE (e
->decl
) == FUNCTION_DECL
);
639 error_at (DECL_SOURCE_LOCATION (e
->decl
),
640 "variable %qD redeclared as function",
645 gcc_assert (TREE_CODE (e
->decl
) == VAR_DECL
);
646 error_at (DECL_SOURCE_LOCATION (e
->decl
),
647 "function %qD redeclared as variable",
658 inform (DECL_SOURCE_LOCATION (prevailing
->decl
),
659 "previously declared here");
661 /* Merge the chain to the single prevailing decl and diagnose
663 lto_symtab_merge_decls_2 (prevailing
, diagnosed_p
);
665 if (symtab
->dump_file
)
667 fprintf (symtab
->dump_file
, "After resolution:\n");
668 for (e
= prevailing
; e
; e
= e
->next_sharing_asm_name
)
669 e
->dump (symtab
->dump_file
);
673 /* Resolve and merge all symbol table chains to a prevailing decl. */
676 lto_symtab_merge_decls (void)
680 /* Populate assembler name hash. */
681 symtab
->symtab_initialize_asm_name_hash ();
683 FOR_EACH_SYMBOL (node
)
684 if (!node
->previous_sharing_asm_name
685 && node
->next_sharing_asm_name
)
686 lto_symtab_merge_decls_1 (node
);
689 /* Helper to process the decl chain for the symbol table entry *SLOT. */
692 lto_symtab_merge_symbols_1 (symtab_node
*prevailing
)
697 /* Replace the cgraph node of each entry with the prevailing one. */
698 for (e
= prevailing
->next_sharing_asm_name
; e
;
701 next
= e
->next_sharing_asm_name
;
703 if (!lto_symtab_symbol_p (e
))
705 cgraph_node
*ce
= dyn_cast
<cgraph_node
*> (e
);
706 if (ce
&& !DECL_BUILT_IN (e
->decl
))
707 lto_cgraph_replace_node (ce
, dyn_cast
<cgraph_node
*> (prevailing
));
708 if (varpool_node
*ve
= dyn_cast
<varpool_node
*> (e
))
709 lto_varpool_replace_node (ve
, dyn_cast
<varpool_node
*> (prevailing
));
715 /* Merge cgraph nodes according to the symbol merging done by
716 lto_symtab_merge_decls. */
719 lto_symtab_merge_symbols (void)
725 symtab
->symtab_initialize_asm_name_hash ();
727 /* Do the actual merging.
728 At this point we invalidate hash translating decls into symtab nodes
729 because after removing one of duplicate decls the hash is not correcly
730 updated to the ohter dupliate. */
731 FOR_EACH_SYMBOL (node
)
732 if (lto_symtab_symbol_p (node
)
733 && node
->next_sharing_asm_name
734 && !node
->previous_sharing_asm_name
)
735 lto_symtab_merge_symbols_1 (node
);
737 /* Resolve weakref aliases whose target are now in the compilation unit.
738 also re-populate the hash translating decls into symtab nodes*/
739 FOR_EACH_SYMBOL (node
)
741 cgraph_node
*cnode
, *cnode2
;
745 if (!node
->analyzed
&& node
->alias_target
)
747 symtab_node
*tgt
= symtab_node::get_for_asmname (node
->alias_target
);
748 gcc_assert (node
->weakref
);
750 node
->resolve_alias (tgt
);
754 if (!(cnode
= dyn_cast
<cgraph_node
*> (node
))
756 || cnode
->clone_of
->decl
!= cnode
->decl
)
758 /* Builtins are not merged via decl merging. It is however
759 possible that tree merging unified the declaration. We
760 do not want duplicate entries in symbol table. */
761 if (cnode
&& DECL_BUILT_IN (node
->decl
)
762 && (cnode2
= cgraph_node::get (node
->decl
))
764 lto_cgraph_replace_node (cnode2
, cnode
);
766 /* The user defined assembler variables are also not unified by their
767 symbol name (since it is irrelevant), but we need to unify symbol
768 nodes if tree merging occured. */
769 if ((vnode
= dyn_cast
<varpool_node
*> (node
))
770 && DECL_HARD_REGISTER (vnode
->decl
)
771 && (node2
= symtab_node::get (vnode
->decl
))
773 lto_varpool_replace_node (dyn_cast
<varpool_node
*> (node2
),
777 /* Abstract functions may have duplicated cgraph nodes attached;
779 else if (cnode
&& DECL_ABSTRACT_P (cnode
->decl
)
780 && (cnode2
= cgraph_node::get (node
->decl
))
784 node
->decl
->decl_with_vis
.symtab_node
= node
;
790 /* Given the decl DECL, return the prevailing decl with the same name. */
793 lto_symtab_prevailing_decl (tree decl
)
797 /* Builtins and local symbols are their own prevailing decl. */
798 if ((!TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
)) || is_builtin_fn (decl
))
801 /* DECL_ABSTRACT_Ps are their own prevailing decl. */
802 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_ABSTRACT_P (decl
))
805 /* Likewise builtins are their own prevailing decl. This preserves
806 non-builtin vs. builtin uses from compile-time. */
807 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
810 /* Ensure DECL_ASSEMBLER_NAME will not set assembler name. */
811 gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl
));
813 /* Walk through the list of candidates and return the one we merged to. */
814 ret
= symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl
));