Update copyright years.
[gcc.git] / gcc / lto / lto-symtab.c
1 /* LTO symbol table.
2 Copyright (C) 2009-2015 Free Software Foundation, Inc.
3 Contributed by CodeSourcery, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "diagnostic-core.h"
25 #include "tree.h"
26 #include "predict.h"
27 #include "vec.h"
28 #include "hashtab.h"
29 #include "hash-set.h"
30 #include "machmode.h"
31 #include "tm.h"
32 #include "hard-reg-set.h"
33 #include "input.h"
34 #include "function.h"
35 #include "basic-block.h"
36 #include "tree-ssa-alias.h"
37 #include "internal-fn.h"
38 #include "gimple-expr.h"
39 #include "is-a.h"
40 #include "gimple.h"
41 #include "plugin-api.h"
42 #include "hash-map.h"
43 #include "ipa-ref.h"
44 #include "cgraph.h"
45 #include "lto-streamer.h"
46 #include "ipa-utils.h"
47 #include "alloc-pool.h"
48 #include "symbol-summary.h"
49 #include "ipa-prop.h"
50 #include "ipa-inline.h"
51 #include "builtins.h"
52
53 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
54 all edges and removing the old node. */
55
56 static void
57 lto_cgraph_replace_node (struct cgraph_node *node,
58 struct cgraph_node *prevailing_node)
59 {
60 struct cgraph_edge *e, *next;
61 bool compatible_p;
62
63 if (symtab->dump_file)
64 {
65 fprintf (symtab->dump_file, "Replacing cgraph node %s/%i by %s/%i"
66 " for symbol %s\n",
67 node->name (), node->order,
68 prevailing_node->name (),
69 prevailing_node->order,
70 IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name)
71 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)))));
72 }
73
74 /* Merge node flags. */
75 if (node->force_output)
76 prevailing_node->mark_force_output ();
77 if (node->forced_by_abi)
78 prevailing_node->forced_by_abi = true;
79 if (node->address_taken)
80 {
81 gcc_assert (!prevailing_node->global.inlined_to);
82 prevailing_node->mark_address_taken ();
83 }
84
85 /* Redirect all incoming edges. */
86 compatible_p
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)
90 {
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. */
97 if (!compatible_p)
98 e->call_stmt_cannot_inline_p = 1;
99 }
100 /* Redirect incomming references. */
101 prevailing_node->clone_referring (node);
102
103 /* Fix instrumentation references. */
104 if (node->instrumented_version)
105 {
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;
115 }
116
117 ipa_merge_profiles (prevailing_node, node);
118 lto_free_function_in_decl_state_for_node (node);
119
120 if (node->decl != prevailing_node->decl)
121 node->release_body ();
122
123 /* Finally remove the replaced node. */
124 node->remove ();
125 }
126
127 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
128 all edges and removing the old node. */
129
130 static void
131 lto_varpool_replace_node (varpool_node *vnode,
132 varpool_node *prevailing_node)
133 {
134 gcc_assert (!vnode->definition || prevailing_node->definition);
135 gcc_assert (!vnode->analyzed || prevailing_node->analyzed);
136
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;
142
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;
147
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);
151
152 if (vnode->tls_model != prevailing_node->tls_model)
153 {
154 error_at (DECL_SOURCE_LOCATION (vnode->decl),
155 "%qD is defined as %s", vnode->decl, tls_model_names [vnode->tls_model]);
156 inform (DECL_SOURCE_LOCATION (prevailing_node->decl),
157 "previously defined here as %s",
158 tls_model_names [prevailing_node->tls_model]);
159 }
160 /* Finally remove the replaced node. */
161 vnode->remove ();
162 }
163
164 /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
165 Return false if the symbols are not fully compatible and a diagnostic
166 should be emitted. */
167
168 static bool
169 lto_symtab_merge (symtab_node *prevailing, symtab_node *entry)
170 {
171 tree prevailing_decl = prevailing->decl;
172 tree decl = entry->decl;
173 tree prevailing_type, type;
174
175 if (prevailing_decl == decl)
176 return true;
177
178 /* Merge decl state in both directions, we may still end up using
179 the new decl. */
180 TREE_ADDRESSABLE (prevailing_decl) |= TREE_ADDRESSABLE (decl);
181 TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (prevailing_decl);
182
183 /* The linker may ask us to combine two incompatible symbols.
184 Detect this case and notify the caller of required diagnostics. */
185
186 if (TREE_CODE (decl) == FUNCTION_DECL)
187 {
188 if (!types_compatible_p (TREE_TYPE (prevailing_decl),
189 TREE_TYPE (decl)))
190 /* If we don't have a merged type yet...sigh. The linker
191 wouldn't complain if the types were mismatched, so we
192 probably shouldn't either. Just use the type from
193 whichever decl appears to be associated with the
194 definition. If for some odd reason neither decl is, the
195 older one wins. */
196 (void) 0;
197
198 return true;
199 }
200
201 /* Now we exclusively deal with VAR_DECLs. */
202
203 /* Sharing a global symbol is a strong hint that two types are
204 compatible. We could use this information to complete
205 incomplete pointed-to types more aggressively here, ignoring
206 mismatches in both field and tag names. It's difficult though
207 to guarantee that this does not have side-effects on merging
208 more compatible types from other translation units though. */
209
210 /* We can tolerate differences in type qualification, the
211 qualification of the prevailing definition will prevail.
212 ??? In principle we might want to only warn for structurally
213 incompatible types here, but unless we have protective measures
214 for TBAA in place that would hide useful information. */
215 prevailing_type = TYPE_MAIN_VARIANT (TREE_TYPE (prevailing_decl));
216 type = TYPE_MAIN_VARIANT (TREE_TYPE (decl));
217
218 if (!types_compatible_p (prevailing_type, type))
219 {
220 if (COMPLETE_TYPE_P (type))
221 return false;
222
223 /* If type is incomplete then avoid warnings in the cases
224 that TBAA handles just fine. */
225
226 if (TREE_CODE (prevailing_type) != TREE_CODE (type))
227 return false;
228
229 if (TREE_CODE (prevailing_type) == ARRAY_TYPE)
230 {
231 tree tem1 = TREE_TYPE (prevailing_type);
232 tree tem2 = TREE_TYPE (type);
233 while (TREE_CODE (tem1) == ARRAY_TYPE
234 && TREE_CODE (tem2) == ARRAY_TYPE)
235 {
236 tem1 = TREE_TYPE (tem1);
237 tem2 = TREE_TYPE (tem2);
238 }
239
240 if (TREE_CODE (tem1) != TREE_CODE (tem2))
241 return false;
242
243 if (!types_compatible_p (tem1, tem2))
244 return false;
245 }
246
247 /* Fallthru. Compatible enough. */
248 }
249
250 /* ??? We might want to emit a warning here if type qualification
251 differences were spotted. Do not do this unconditionally though. */
252
253 /* There is no point in comparing too many details of the decls here.
254 The type compatibility checks or the completing of types has properly
255 dealt with most issues. */
256
257 /* The following should all not invoke fatal errors as in non-LTO
258 mode the linker wouldn't complain either. Just emit warnings. */
259
260 /* Report a warning if user-specified alignments do not match. */
261 if ((DECL_USER_ALIGN (prevailing_decl) && DECL_USER_ALIGN (decl))
262 && DECL_ALIGN (prevailing_decl) < DECL_ALIGN (decl))
263 return false;
264
265 return true;
266 }
267
268 /* Return true if the symtab entry E can be replaced by another symtab
269 entry. */
270
271 static bool
272 lto_symtab_resolve_replaceable_p (symtab_node *e)
273 {
274 if (DECL_EXTERNAL (e->decl)
275 || DECL_COMDAT (e->decl)
276 || DECL_ONE_ONLY (e->decl)
277 || DECL_WEAK (e->decl))
278 return true;
279
280 if (TREE_CODE (e->decl) == VAR_DECL)
281 return (DECL_COMMON (e->decl)
282 || (!flag_no_common && !DECL_INITIAL (e->decl)));
283
284 return false;
285 }
286
287 /* Return true, if the symbol E should be resolved by lto-symtab.
288 Those are all external symbols and all real symbols that are not static (we
289 handle renaming of static later in partitioning). */
290
291 static bool
292 lto_symtab_symbol_p (symtab_node *e)
293 {
294 if (!TREE_PUBLIC (e->decl) && !DECL_EXTERNAL (e->decl))
295 return false;
296 return e->real_symbol_p ();
297 }
298
299 /* Return true if the symtab entry E can be the prevailing one. */
300
301 static bool
302 lto_symtab_resolve_can_prevail_p (symtab_node *e)
303 {
304 if (!lto_symtab_symbol_p (e))
305 return false;
306
307 /* The C++ frontend ends up neither setting TREE_STATIC nor
308 DECL_EXTERNAL on virtual methods but only TREE_PUBLIC.
309 So do not reject !TREE_STATIC here but only DECL_EXTERNAL. */
310 if (DECL_EXTERNAL (e->decl))
311 return false;
312
313 return e->definition;
314 }
315
316 /* Resolve the symbol with the candidates in the chain *SLOT and store
317 their resolutions. */
318
319 static symtab_node *
320 lto_symtab_resolve_symbols (symtab_node *first)
321 {
322 symtab_node *e;
323 symtab_node *prevailing = NULL;
324
325 /* Always set e->node so that edges are updated to reflect decl merging. */
326 for (e = first; e; e = e->next_sharing_asm_name)
327 if (lto_symtab_symbol_p (e)
328 && (e->resolution == LDPR_PREVAILING_DEF_IRONLY
329 || e->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
330 || e->resolution == LDPR_PREVAILING_DEF))
331 {
332 prevailing = e;
333 break;
334 }
335
336 /* If the chain is already resolved there is nothing else to do. */
337 if (prevailing)
338 {
339 /* Assert it's the only one. */
340 for (e = prevailing->next_sharing_asm_name; e; e = e->next_sharing_asm_name)
341 if (lto_symtab_symbol_p (e)
342 && (e->resolution == LDPR_PREVAILING_DEF_IRONLY
343 || e->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
344 || e->resolution == LDPR_PREVAILING_DEF))
345 fatal_error ("multiple prevailing defs for %qE",
346 DECL_NAME (prevailing->decl));
347 return prevailing;
348 }
349
350 /* Find the single non-replaceable prevailing symbol and
351 diagnose ODR violations. */
352 for (e = first; e; e = e->next_sharing_asm_name)
353 {
354 if (!lto_symtab_resolve_can_prevail_p (e))
355 continue;
356
357 /* If we have a non-replaceable definition it prevails. */
358 if (!lto_symtab_resolve_replaceable_p (e))
359 {
360 if (prevailing)
361 {
362 error_at (DECL_SOURCE_LOCATION (e->decl),
363 "%qD has already been defined", e->decl);
364 inform (DECL_SOURCE_LOCATION (prevailing->decl),
365 "previously defined here");
366 }
367 prevailing = e;
368 }
369 }
370 if (prevailing)
371 return prevailing;
372
373 /* Do a second round choosing one from the replaceable prevailing decls. */
374 for (e = first; e; e = e->next_sharing_asm_name)
375 {
376 if (!lto_symtab_resolve_can_prevail_p (e))
377 continue;
378
379 /* Choose the first function that can prevail as prevailing. */
380 if (TREE_CODE (e->decl) == FUNCTION_DECL)
381 {
382 prevailing = e;
383 break;
384 }
385
386 /* From variables that can prevail choose the largest one. */
387 if (!prevailing
388 || tree_int_cst_lt (DECL_SIZE (prevailing->decl),
389 DECL_SIZE (e->decl))
390 /* When variables are equivalent try to chose one that has useful
391 DECL_INITIAL. This makes sense for keyed vtables that are
392 DECL_EXTERNAL but initialized. In units that do not need them
393 we replace the initializer by error_mark_node to conserve
394 memory.
395
396 We know that the vtable is keyed outside the LTO unit - otherwise
397 the keyed instance would prevail. We still can preserve useful
398 info in the initializer. */
399 || (DECL_SIZE (prevailing->decl) == DECL_SIZE (e->decl)
400 && (DECL_INITIAL (e->decl)
401 && DECL_INITIAL (e->decl) != error_mark_node)
402 && (!DECL_INITIAL (prevailing->decl)
403 || DECL_INITIAL (prevailing->decl) == error_mark_node)))
404 prevailing = e;
405 }
406
407 return prevailing;
408 }
409
410 /* Merge all decls in the symbol table chain to the prevailing decl and
411 issue diagnostics about type mismatches. If DIAGNOSED_P is true
412 do not issue further diagnostics.*/
413
414 static void
415 lto_symtab_merge_decls_2 (symtab_node *first, bool diagnosed_p)
416 {
417 symtab_node *prevailing;
418 symtab_node *e;
419 vec<tree> mismatches = vNULL;
420 unsigned i;
421 tree decl;
422
423 /* Nothing to do for a single entry. */
424 prevailing = first;
425 if (!prevailing->next_sharing_asm_name)
426 return;
427
428 /* Try to merge each entry with the prevailing one. */
429 for (e = prevailing->next_sharing_asm_name;
430 e; e = e->next_sharing_asm_name)
431 if (TREE_PUBLIC (e->decl))
432 {
433 if (!lto_symtab_merge (prevailing, e)
434 && !diagnosed_p)
435 mismatches.safe_push (e->decl);
436 }
437 if (mismatches.is_empty ())
438 return;
439
440 /* Diagnose all mismatched re-declarations. */
441 FOR_EACH_VEC_ELT (mismatches, i, decl)
442 {
443 if (!types_compatible_p (TREE_TYPE (prevailing->decl),
444 TREE_TYPE (decl)))
445 diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
446 "type of %qD does not match original "
447 "declaration", decl);
448
449 else if ((DECL_USER_ALIGN (prevailing->decl)
450 && DECL_USER_ALIGN (decl))
451 && DECL_ALIGN (prevailing->decl) < DECL_ALIGN (decl))
452 {
453 diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
454 "alignment of %qD is bigger than "
455 "original declaration", decl);
456 }
457 }
458 if (diagnosed_p)
459 inform (DECL_SOURCE_LOCATION (prevailing->decl),
460 "previously declared here");
461
462 mismatches.release ();
463 }
464
465 /* Helper to process the decl chain for the symbol table entry *SLOT. */
466
467 static void
468 lto_symtab_merge_decls_1 (symtab_node *first)
469 {
470 symtab_node *e;
471 symtab_node *prevailing;
472 bool diagnosed_p = false;
473
474 if (symtab->dump_file)
475 {
476 fprintf (symtab->dump_file, "Merging nodes for %s. Candidates:\n",
477 first->asm_name ());
478 for (e = first; e; e = e->next_sharing_asm_name)
479 if (TREE_PUBLIC (e->decl))
480 e->dump (symtab->dump_file);
481 }
482
483 /* Compute the symbol resolutions. This is a no-op when using the
484 linker plugin and resolution was decided by the linker. */
485 prevailing = lto_symtab_resolve_symbols (first);
486
487 /* If there's not a prevailing symbol yet it's an external reference.
488 Happens a lot during ltrans. Choose the first symbol with a
489 cgraph or a varpool node. */
490 if (!prevailing)
491 {
492 for (prevailing = first;
493 prevailing; prevailing = prevailing->next_sharing_asm_name)
494 if (lto_symtab_symbol_p (prevailing))
495 break;
496 if (!prevailing)
497 return;
498 /* For variables chose with a priority variant with vnode
499 attached (i.e. from unit where external declaration of
500 variable is actually used).
501 When there are multiple variants, chose one with size.
502 This is needed for C++ typeinfos, for example in
503 lto/20081204-1 there are typeifos in both units, just
504 one of them do have size. */
505 if (TREE_CODE (prevailing->decl) == VAR_DECL)
506 {
507 for (e = prevailing->next_sharing_asm_name;
508 e; e = e->next_sharing_asm_name)
509 if (!COMPLETE_TYPE_P (TREE_TYPE (prevailing->decl))
510 && COMPLETE_TYPE_P (TREE_TYPE (e->decl))
511 && lto_symtab_symbol_p (e))
512 prevailing = e;
513 }
514 /* For variables prefer the non-builtin if one is available. */
515 else if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
516 {
517 for (e = first; e; e = e->next_sharing_asm_name)
518 if (TREE_CODE (e->decl) == FUNCTION_DECL
519 && !DECL_BUILT_IN (e->decl)
520 && lto_symtab_symbol_p (e))
521 {
522 prevailing = e;
523 break;
524 }
525 }
526 }
527
528 symtab->symtab_prevail_in_asm_name_hash (prevailing);
529
530 /* Diagnose mismatched objects. */
531 for (e = prevailing->next_sharing_asm_name;
532 e; e = e->next_sharing_asm_name)
533 {
534 if (TREE_CODE (prevailing->decl)
535 == TREE_CODE (e->decl))
536 continue;
537 if (!lto_symtab_symbol_p (e))
538 continue;
539
540 switch (TREE_CODE (prevailing->decl))
541 {
542 case VAR_DECL:
543 gcc_assert (TREE_CODE (e->decl) == FUNCTION_DECL);
544 error_at (DECL_SOURCE_LOCATION (e->decl),
545 "variable %qD redeclared as function",
546 prevailing->decl);
547 break;
548
549 case FUNCTION_DECL:
550 gcc_assert (TREE_CODE (e->decl) == VAR_DECL);
551 error_at (DECL_SOURCE_LOCATION (e->decl),
552 "function %qD redeclared as variable",
553 prevailing->decl);
554 break;
555
556 default:
557 gcc_unreachable ();
558 }
559
560 diagnosed_p = true;
561 }
562 if (diagnosed_p)
563 inform (DECL_SOURCE_LOCATION (prevailing->decl),
564 "previously declared here");
565
566 /* Merge the chain to the single prevailing decl and diagnose
567 mismatches. */
568 lto_symtab_merge_decls_2 (prevailing, diagnosed_p);
569
570 if (symtab->dump_file)
571 {
572 fprintf (symtab->dump_file, "After resolution:\n");
573 for (e = prevailing; e; e = e->next_sharing_asm_name)
574 e->dump (symtab->dump_file);
575 }
576 }
577
578 /* Resolve and merge all symbol table chains to a prevailing decl. */
579
580 void
581 lto_symtab_merge_decls (void)
582 {
583 symtab_node *node;
584
585 /* Populate assembler name hash. */
586 symtab->symtab_initialize_asm_name_hash ();
587
588 FOR_EACH_SYMBOL (node)
589 if (!node->previous_sharing_asm_name
590 && node->next_sharing_asm_name)
591 lto_symtab_merge_decls_1 (node);
592 }
593
594 /* Helper to process the decl chain for the symbol table entry *SLOT. */
595
596 static void
597 lto_symtab_merge_symbols_1 (symtab_node *prevailing)
598 {
599 symtab_node *e;
600 symtab_node *next;
601
602 /* Replace the cgraph node of each entry with the prevailing one. */
603 for (e = prevailing->next_sharing_asm_name; e;
604 e = next)
605 {
606 next = e->next_sharing_asm_name;
607
608 if (!lto_symtab_symbol_p (e))
609 continue;
610 cgraph_node *ce = dyn_cast <cgraph_node *> (e);
611 if (ce && !DECL_BUILT_IN (e->decl))
612 lto_cgraph_replace_node (ce, dyn_cast<cgraph_node *> (prevailing));
613 if (varpool_node *ve = dyn_cast <varpool_node *> (e))
614 lto_varpool_replace_node (ve, dyn_cast<varpool_node *> (prevailing));
615 }
616
617 return;
618 }
619
620 /* Merge cgraph nodes according to the symbol merging done by
621 lto_symtab_merge_decls. */
622
623 void
624 lto_symtab_merge_symbols (void)
625 {
626 symtab_node *node;
627
628 if (!flag_ltrans)
629 {
630 symtab->symtab_initialize_asm_name_hash ();
631
632 /* Do the actual merging.
633 At this point we invalidate hash translating decls into symtab nodes
634 because after removing one of duplicate decls the hash is not correcly
635 updated to the ohter dupliate. */
636 FOR_EACH_SYMBOL (node)
637 if (lto_symtab_symbol_p (node)
638 && node->next_sharing_asm_name
639 && !node->previous_sharing_asm_name)
640 lto_symtab_merge_symbols_1 (node);
641
642 /* Resolve weakref aliases whose target are now in the compilation unit.
643 also re-populate the hash translating decls into symtab nodes*/
644 FOR_EACH_SYMBOL (node)
645 {
646 cgraph_node *cnode, *cnode2;
647 varpool_node *vnode;
648 symtab_node *node2;
649
650 if (!node->analyzed && node->alias_target)
651 {
652 symtab_node *tgt = symtab_node::get_for_asmname (node->alias_target);
653 gcc_assert (node->weakref);
654 if (tgt)
655 node->resolve_alias (tgt);
656 }
657 node->aux = NULL;
658
659 if (!(cnode = dyn_cast <cgraph_node *> (node))
660 || !cnode->clone_of
661 || cnode->clone_of->decl != cnode->decl)
662 {
663 /* Builtins are not merged via decl merging. It is however
664 possible that tree merging unified the declaration. We
665 do not want duplicate entries in symbol table. */
666 if (cnode && DECL_BUILT_IN (node->decl)
667 && (cnode2 = cgraph_node::get (node->decl))
668 && cnode2 != cnode)
669 lto_cgraph_replace_node (cnode2, cnode);
670
671 /* The user defined assembler variables are also not unified by their
672 symbol name (since it is irrelevant), but we need to unify symbol
673 nodes if tree merging occured. */
674 if ((vnode = dyn_cast <varpool_node *> (node))
675 && DECL_HARD_REGISTER (vnode->decl)
676 && (node2 = symtab_node::get (vnode->decl))
677 && node2 != node)
678 lto_varpool_replace_node (dyn_cast <varpool_node *> (node2),
679 vnode);
680
681
682 /* Abstract functions may have duplicated cgraph nodes attached;
683 remove them. */
684 else if (cnode && DECL_ABSTRACT_P (cnode->decl)
685 && (cnode2 = cgraph_node::get (node->decl))
686 && cnode2 != cnode)
687 cnode2->remove ();
688
689 node->decl->decl_with_vis.symtab_node = node;
690 }
691 }
692 }
693 }
694
695 /* Given the decl DECL, return the prevailing decl with the same name. */
696
697 tree
698 lto_symtab_prevailing_decl (tree decl)
699 {
700 symtab_node *ret;
701
702 /* Builtins and local symbols are their own prevailing decl. */
703 if ((!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl)) || is_builtin_fn (decl))
704 return decl;
705
706 /* DECL_ABSTRACT_Ps are their own prevailing decl. */
707 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT_P (decl))
708 return decl;
709
710 /* Likewise builtins are their own prevailing decl. This preserves
711 non-builtin vs. builtin uses from compile-time. */
712 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
713 return decl;
714
715 /* Ensure DECL_ASSEMBLER_NAME will not set assembler name. */
716 gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
717
718 /* Walk through the list of candidates and return the one we merged to. */
719 ret = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
720 if (!ret)
721 return decl;
722
723 return ret->decl;
724 }