2 Copyright (C) 2012-2015 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
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"
29 #include "double-int.h"
36 #include "fold-const.h"
37 #include "print-tree.h"
40 #include "hard-reg-set.h"
45 #include "basic-block.h"
46 #include "tree-ssa-alias.h"
47 #include "internal-fn.h"
48 #include "gimple-expr.h"
51 #include "tree-inline.h"
52 #include "langhooks.h"
54 #include "plugin-api.h"
57 #include "diagnostic.h"
59 #include "lto-streamer.h"
61 #include "ipa-utils.h"
64 static const char *ipa_ref_use_name[] = {"read","write","addr","alias","chkp"};
66 const char * const ld_plugin_symbol_resolution_names[]=
71 "prevailing_def_ironly",
77 "prevailing_def_ironly_exp"
80 /* Hash asmnames ignoring the user specified marks. */
83 symbol_table::decl_assembler_name_hash (const_tree asmname)
85 if (IDENTIFIER_POINTER (asmname)[0] == '*')
87 const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
88 size_t ulp_len = strlen (user_label_prefix);
92 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
95 return htab_hash_string (decl_str);
98 return htab_hash_string (IDENTIFIER_POINTER (asmname));
102 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
105 symbol_table::decl_assembler_name_equal (tree decl, const_tree asmname)
107 tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
108 const char *decl_str;
109 const char *asmname_str;
112 if (decl_asmname == asmname)
115 decl_str = IDENTIFIER_POINTER (decl_asmname);
116 asmname_str = IDENTIFIER_POINTER (asmname);
119 /* If the target assembler name was set by the user, things are trickier.
120 We have a leading '*' to begin with. After that, it's arguable what
121 is the correct thing to do with -fleading-underscore. Arguably, we've
122 historically been doing the wrong thing in assemble_alias by always
123 printing the leading underscore. Since we're not changing that, make
124 sure user_label_prefix follows the '*' before matching. */
125 if (decl_str[0] == '*')
127 size_t ulp_len = strlen (user_label_prefix);
133 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
134 decl_str += ulp_len, test=true;
138 if (asmname_str[0] == '*')
140 size_t ulp_len = strlen (user_label_prefix);
146 else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0)
147 asmname_str += ulp_len, test=true;
154 return strcmp (decl_str, asmname_str) == 0;
158 /* Returns nonzero if P1 and P2 are equal. */
160 /* Insert NODE to assembler name hash. */
163 symbol_table::insert_to_assembler_name_hash (symtab_node *node,
166 if (is_a <varpool_node *> (node) && DECL_HARD_REGISTER (node->decl))
168 gcc_checking_assert (!node->previous_sharing_asm_name
169 && !node->next_sharing_asm_name);
170 if (assembler_name_hash)
174 tree decl = node->decl;
176 tree name = DECL_ASSEMBLER_NAME (node->decl);
178 /* C++ FE can produce decls without associated assembler name and insert
179 them to symtab to hold section or TLS information. */
183 hashval_t hash = decl_assembler_name_hash (name);
184 aslot = assembler_name_hash->find_slot_with_hash (name, hash, INSERT);
185 gcc_assert (*aslot != node);
186 node->next_sharing_asm_name = (symtab_node *)*aslot;
188 (*aslot)->previous_sharing_asm_name = node;
191 /* Update also possible inline clones sharing a decl. */
192 cnode = dyn_cast <cgraph_node *> (node);
193 if (cnode && cnode->clones && with_clones)
194 for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
195 if (cnode->decl == decl)
196 insert_to_assembler_name_hash (cnode, true);
201 /* Remove NODE from assembler name hash. */
204 symbol_table::unlink_from_assembler_name_hash (symtab_node *node,
207 if (assembler_name_hash)
210 tree decl = node->decl;
212 if (node->next_sharing_asm_name)
213 node->next_sharing_asm_name->previous_sharing_asm_name
214 = node->previous_sharing_asm_name;
215 if (node->previous_sharing_asm_name)
217 node->previous_sharing_asm_name->next_sharing_asm_name
218 = node->next_sharing_asm_name;
222 tree name = DECL_ASSEMBLER_NAME (node->decl);
228 hashval_t hash = decl_assembler_name_hash (name);
229 slot = assembler_name_hash->find_slot_with_hash (name, hash,
231 gcc_assert (*slot == node);
232 if (!node->next_sharing_asm_name)
233 assembler_name_hash->clear_slot (slot);
235 *slot = node->next_sharing_asm_name;
237 node->next_sharing_asm_name = NULL;
238 node->previous_sharing_asm_name = NULL;
240 /* Update also possible inline clones sharing a decl. */
241 cnode = dyn_cast <cgraph_node *> (node);
242 if (cnode && cnode->clones && with_clones)
243 for (cnode = cnode->clones; cnode; cnode = cnode->next_sibling_clone)
244 if (cnode->decl == decl)
245 unlink_from_assembler_name_hash (cnode, true);
249 /* Arrange node to be first in its entry of assembler_name_hash. */
252 symbol_table::symtab_prevail_in_asm_name_hash (symtab_node *node)
254 unlink_from_assembler_name_hash (node, false);
255 insert_to_assembler_name_hash (node, false);
258 /* Initalize asm name hash unless. */
261 symbol_table::symtab_initialize_asm_name_hash (void)
264 if (!assembler_name_hash)
266 assembler_name_hash = hash_table<asmname_hasher>::create_ggc (10);
267 FOR_EACH_SYMBOL (node)
268 insert_to_assembler_name_hash (node, false);
272 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
275 symbol_table::change_decl_assembler_name (tree decl, tree name)
277 symtab_node *node = NULL;
279 /* We can have user ASM names on things, like global register variables, that
280 are not in the symbol table. */
281 if ((TREE_CODE (decl) == VAR_DECL
282 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
283 || TREE_CODE (decl) == FUNCTION_DECL)
284 node = symtab_node::get (decl);
285 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
287 SET_DECL_ASSEMBLER_NAME (decl, name);
289 insert_to_assembler_name_hash (node, true);
293 if (name == DECL_ASSEMBLER_NAME (decl))
296 tree alias = (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (decl))
297 ? TREE_CHAIN (DECL_ASSEMBLER_NAME (decl))
300 unlink_from_assembler_name_hash (node, true);
301 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
302 && DECL_RTL_SET_P (decl))
303 warning (0, "%D renamed after being referenced in assembly", decl);
305 SET_DECL_ASSEMBLER_NAME (decl, name);
308 IDENTIFIER_TRANSPARENT_ALIAS (name) = 1;
309 TREE_CHAIN (name) = alias;
312 insert_to_assembler_name_hash (node, true);
316 /* Return true when RESOLUTION indicate that linker will use
317 the symbol from non-LTO object files. */
320 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution)
322 return (resolution == LDPR_PREVAILING_DEF
323 || resolution == LDPR_PREEMPTED_REG
324 || resolution == LDPR_RESOLVED_EXEC
325 || resolution == LDPR_RESOLVED_DYN);
328 /* Hash sections by their names. */
331 section_name_hasher::hash (section_hash_entry *n)
333 return htab_hash_string (n->name);
336 /* Return true if section P1 name equals to P2. */
339 section_name_hasher::equal (section_hash_entry *n1, const char *name)
341 return n1->name == name || !strcmp (n1->name, name);
344 /* Add node into symbol table. This function is not used directly, but via
345 cgraph/varpool node creation routines. */
348 symtab_node::register_symbol (void)
350 symtab->register_symbol (this);
352 if (!decl->decl_with_vis.symtab_node)
353 decl->decl_with_vis.symtab_node = this;
357 /* Be sure to do this last; C++ FE might create new nodes via
358 DECL_ASSEMBLER_NAME langhook! */
359 symtab->insert_to_assembler_name_hash (this, false);
362 /* Remove NODE from same comdat group. */
365 symtab_node::remove_from_same_comdat_group (void)
367 if (same_comdat_group)
370 for (prev = same_comdat_group;
371 prev->same_comdat_group != this;
372 prev = prev->same_comdat_group)
374 if (same_comdat_group == prev)
375 prev->same_comdat_group = NULL;
377 prev->same_comdat_group = same_comdat_group;
378 same_comdat_group = NULL;
379 set_comdat_group (NULL);
383 /* Remove node from symbol table. This function is not used directly, but via
384 cgraph/varpool node removal routines. */
387 symtab_node::unregister (void)
389 remove_all_references ();
390 remove_all_referring ();
392 /* Remove reference to section. */
393 set_section_for_node (NULL);
395 remove_from_same_comdat_group ();
397 symtab->unregister (this);
399 /* During LTO symtab merging we temporarily corrupt decl to symtab node
401 gcc_assert (decl->decl_with_vis.symtab_node || in_lto_p);
402 if (decl->decl_with_vis.symtab_node == this)
404 symtab_node *replacement_node = NULL;
405 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
406 replacement_node = cnode->find_replacement ();
407 decl->decl_with_vis.symtab_node = replacement_node;
409 if (!is_a <varpool_node *> (this) || !DECL_HARD_REGISTER (decl))
410 symtab->unlink_from_assembler_name_hash (this, false);
411 if (in_init_priority_hash)
412 symtab->init_priority_hash->remove (this);
416 /* Remove symbol from symbol table. */
419 symtab_node::remove (void)
421 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
423 else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
427 /* Add NEW_ to the same comdat group that OLD is in. */
430 symtab_node::add_to_same_comdat_group (symtab_node *old_node)
432 gcc_assert (old_node->get_comdat_group ());
433 gcc_assert (!same_comdat_group);
434 gcc_assert (this != old_node);
436 set_comdat_group (old_node->get_comdat_group ());
437 same_comdat_group = old_node;
438 if (!old_node->same_comdat_group)
439 old_node->same_comdat_group = this;
443 for (n = old_node->same_comdat_group;
444 n->same_comdat_group != old_node;
445 n = n->same_comdat_group)
447 n->same_comdat_group = this;
451 /* Dissolve the same_comdat_group list in which NODE resides. */
454 symtab_node::dissolve_same_comdat_group_list (void)
456 symtab_node *n = this;
459 if (!same_comdat_group)
463 next = n->same_comdat_group;
464 n->same_comdat_group = NULL;
465 /* Clear comdat_group for comdat locals, since
466 make_decl_local doesn't. */
467 if (!TREE_PUBLIC (n->decl))
468 n->set_comdat_group (NULL);
474 /* Return printable assembler name of NODE.
475 This function is used only for debugging. When assembler name
476 is unknown go with identifier name. */
479 symtab_node::asm_name () const
481 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
482 return lang_hooks.decl_printable_name (decl, 2);
483 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
486 /* Return printable identifier name. */
489 symtab_node::name () const
491 return lang_hooks.decl_printable_name (decl, 2);
494 /* Return ipa reference from this symtab_node to
495 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
499 symtab_node::create_reference (symtab_node *referred_node,
500 enum ipa_ref_use use_type)
502 return create_reference (referred_node, use_type, NULL);
506 /* Return ipa reference from this symtab_node to
507 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
508 of the use and STMT the statement (if it exists). */
511 symtab_node::create_reference (symtab_node *referred_node,
512 enum ipa_ref_use use_type, gimple stmt)
514 ipa_ref *ref = NULL, *ref2 = NULL;
515 ipa_ref_list *list, *list2;
516 ipa_ref_t *old_references;
518 gcc_checking_assert (!stmt || is_a <cgraph_node *> (this));
519 gcc_checking_assert (use_type != IPA_REF_ALIAS || !stmt);
522 old_references = vec_safe_address (list->references);
523 vec_safe_grow (list->references, vec_safe_length (list->references) + 1);
524 ref = &list->references->last ();
526 list2 = &referred_node->ref_list;
528 /* IPA_REF_ALIAS is always inserted at the beginning of the list. */
529 if(use_type == IPA_REF_ALIAS)
531 list2->referring.safe_insert (0, ref);
532 ref->referred_index = 0;
534 for (unsigned int i = 1; i < list2->referring.length (); i++)
535 list2->referring[i]->referred_index = i;
539 list2->referring.safe_push (ref);
540 ref->referred_index = list2->referring.length () - 1;
543 ref->referring = this;
544 ref->referred = referred_node;
546 ref->lto_stmt_uid = 0;
548 ref->speculative = 0;
550 /* If vector was moved in memory, update pointers. */
551 if (old_references != list->references->address ())
554 for (i = 0; iterate_reference(i, ref2); i++)
555 ref2->referred_ref_list ()->referring[ref2->referred_index] = ref2;
560 /* If VAL is a reference to a function or a variable, add a reference from
561 this symtab_node to the corresponding symbol table node. USE_TYPE specify
562 type of the use and STMT the statement (if it exists). Return the new
563 reference or NULL if none was created. */
566 symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
570 if (TREE_CODE (val) != ADDR_EXPR)
572 val = get_base_var (val);
573 if (val && (TREE_CODE (val) == FUNCTION_DECL
574 || TREE_CODE (val) == VAR_DECL))
576 symtab_node *referred = symtab_node::get (val);
577 gcc_checking_assert (referred);
578 return create_reference (referred, use_type, stmt);
583 /* Clone all references from symtab NODE to this symtab_node. */
586 symtab_node::clone_references (symtab_node *node)
588 ipa_ref *ref = NULL, *ref2 = NULL;
590 for (i = 0; node->iterate_reference (i, ref); i++)
592 bool speculative = ref->speculative;
593 unsigned int stmt_uid = ref->lto_stmt_uid;
595 ref2 = create_reference (ref->referred, ref->use, ref->stmt);
596 ref2->speculative = speculative;
597 ref2->lto_stmt_uid = stmt_uid;
601 /* Clone all referring from symtab NODE to this symtab_node. */
604 symtab_node::clone_referring (symtab_node *node)
606 ipa_ref *ref = NULL, *ref2 = NULL;
608 for (i = 0; node->iterate_referring(i, ref); i++)
610 bool speculative = ref->speculative;
611 unsigned int stmt_uid = ref->lto_stmt_uid;
613 ref2 = ref->referring->create_reference (this, ref->use, ref->stmt);
614 ref2->speculative = speculative;
615 ref2->lto_stmt_uid = stmt_uid;
619 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
622 symtab_node::clone_reference (ipa_ref *ref, gimple stmt)
624 bool speculative = ref->speculative;
625 unsigned int stmt_uid = ref->lto_stmt_uid;
628 ref2 = create_reference (ref->referred, ref->use, stmt);
629 ref2->speculative = speculative;
630 ref2->lto_stmt_uid = stmt_uid;
634 /* Find the structure describing a reference to REFERRED_NODE
635 and associated with statement STMT. */
638 symtab_node::find_reference (symtab_node *referred_node,
639 gimple stmt, unsigned int lto_stmt_uid)
644 for (i = 0; iterate_reference (i, r); i++)
645 if (r->referred == referred_node
647 && ((stmt && r->stmt == stmt)
648 || (lto_stmt_uid && r->lto_stmt_uid == lto_stmt_uid)
649 || (!stmt && !lto_stmt_uid && !r->stmt && !r->lto_stmt_uid)))
654 /* Remove all references that are associated with statement STMT. */
657 symtab_node::remove_stmt_references (gimple stmt)
662 while (iterate_reference (i, r))
664 r->remove_reference ();
669 /* Remove all stmt references in non-speculative references.
670 Those are not maintained during inlining & clonning.
671 The exception are speculative references that are updated along
672 with callgraph edges associated with them. */
675 symtab_node::clear_stmts_in_references (void)
680 for (i = 0; iterate_reference (i, r); i++)
688 /* Remove all references in ref list. */
691 symtab_node::remove_all_references (void)
693 while (vec_safe_length (ref_list.references))
694 ref_list.references->last ().remove_reference ();
695 vec_free (ref_list.references);
698 /* Remove all referring items in ref list. */
701 symtab_node::remove_all_referring (void)
703 while (ref_list.referring.length ())
704 ref_list.referring.last ()->remove_reference ();
705 ref_list.referring.release ();
708 /* Dump references in ref list to FILE. */
711 symtab_node::dump_references (FILE *file)
715 for (i = 0; iterate_reference (i, ref); i++)
717 fprintf (file, "%s/%i (%s)",
718 ref->referred->asm_name (),
719 ref->referred->order,
720 ipa_ref_use_name [ref->use]);
721 if (ref->speculative)
722 fprintf (file, " (speculative)");
724 fprintf (file, "\n");
727 /* Dump referring in list to FILE. */
730 symtab_node::dump_referring (FILE *file)
734 for (i = 0; iterate_referring(i, ref); i++)
736 fprintf (file, "%s/%i (%s)",
737 ref->referring->asm_name (),
738 ref->referring->order,
739 ipa_ref_use_name [ref->use]);
740 if (ref->speculative)
741 fprintf (file, " (speculative)");
743 fprintf (file, "\n");
746 /* Return true if list contains an alias. */
748 symtab_node::has_aliases_p (void)
753 for (i = 0; iterate_referring (i, ref); i++)
754 if (ref->use == IPA_REF_ALIAS)
759 /* Iterates I-th reference in the list, REF is also set. */
762 symtab_node::iterate_reference (unsigned i, ipa_ref *&ref)
764 vec_safe_iterate (ref_list.references, i, &ref);
769 /* Iterates I-th referring item in the list, REF is also set. */
772 symtab_node::iterate_referring (unsigned i, ipa_ref *&ref)
774 ref_list.referring.iterate (i, &ref);
779 /* Iterates I-th referring alias item in the list, REF is also set. */
782 symtab_node::iterate_direct_aliases (unsigned i, ipa_ref *&ref)
784 ref_list.referring.iterate (i, &ref);
786 if (ref && ref->use != IPA_REF_ALIAS)
792 static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
794 /* Dump base fields of symtab nodes to F. Not to be used directly. */
797 symtab_node::dump_base (FILE *f)
799 static const char * const visibility_types[] = {
800 "default", "protected", "hidden", "internal"
803 fprintf (f, "%s/%i (%s)", asm_name (), order, name ());
804 dump_addr (f, " @", (void *)this);
805 fprintf (f, "\n Type: %s", symtab_type_names[type]);
808 fprintf (f, " definition");
810 fprintf (f, " analyzed");
812 fprintf (f, " alias");
814 fprintf (f, " weakref");
815 if (cpp_implicit_alias)
816 fprintf (f, " cpp_implicit_alias");
818 fprintf (f, " target:%s",
819 DECL_P (alias_target)
820 ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
822 : IDENTIFIER_POINTER (alias_target));
824 fprintf (f, "\n Body removed by symtab_remove_unreachable_nodes");
825 fprintf (f, "\n Visibility:");
826 if (in_other_partition)
827 fprintf (f, " in_other_partition");
828 if (used_from_other_partition)
829 fprintf (f, " used_from_other_partition");
831 fprintf (f, " force_output");
833 fprintf (f, " forced_by_abi");
834 if (externally_visible)
835 fprintf (f, " externally_visible");
837 fprintf (f, " no_reorder");
838 if (resolution != LDPR_UNKNOWN)
840 ld_plugin_symbol_resolution_names[(int)resolution]);
841 if (TREE_ASM_WRITTEN (decl))
842 fprintf (f, " asm_written");
843 if (DECL_EXTERNAL (decl))
844 fprintf (f, " external");
845 if (TREE_PUBLIC (decl))
846 fprintf (f, " public");
847 if (DECL_COMMON (decl))
848 fprintf (f, " common");
849 if (DECL_WEAK (decl))
850 fprintf (f, " weak");
851 if (DECL_DLLIMPORT_P (decl))
852 fprintf (f, " dll_import");
853 if (DECL_COMDAT (decl))
854 fprintf (f, " comdat");
855 if (get_comdat_group ())
856 fprintf (f, " comdat_group:%s",
857 IDENTIFIER_POINTER (get_comdat_group_id ()));
858 if (DECL_ONE_ONLY (decl))
859 fprintf (f, " one_only");
861 fprintf (f, " section:%s",
863 if (implicit_section)
864 fprintf (f," (implicit_section)");
865 if (DECL_VISIBILITY_SPECIFIED (decl))
866 fprintf (f, " visibility_specified");
867 if (DECL_VISIBILITY (decl))
868 fprintf (f, " visibility:%s",
869 visibility_types [DECL_VISIBILITY (decl)]);
870 if (DECL_VIRTUAL_P (decl))
871 fprintf (f, " virtual");
872 if (DECL_ARTIFICIAL (decl))
873 fprintf (f, " artificial");
874 if (TREE_CODE (decl) == FUNCTION_DECL)
876 if (DECL_STATIC_CONSTRUCTOR (decl))
877 fprintf (f, " constructor");
878 if (DECL_STATIC_DESTRUCTOR (decl))
879 fprintf (f, " destructor");
883 if (same_comdat_group)
884 fprintf (f, " Same comdat group as: %s/%i\n",
885 same_comdat_group->asm_name (),
886 same_comdat_group->order);
887 if (next_sharing_asm_name)
888 fprintf (f, " next sharing asm name: %i\n",
889 next_sharing_asm_name->order);
890 if (previous_sharing_asm_name)
891 fprintf (f, " previous sharing asm name: %i\n",
892 previous_sharing_asm_name->order);
895 fprintf (f, " Address is taken.\n");
898 fprintf (f, " Aux:");
899 dump_addr (f, " @", (void *)aux);
902 fprintf (f, " References: ");
904 fprintf (f, " Referring: ");
907 fprintf (f, " Read from file: %s\n",
908 lto_file_data->file_name);
911 /* Dump symtab node to F. */
914 symtab_node::dump (FILE *f)
916 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (this))
918 else if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
922 /* Dump symbol table to F. */
925 symtab_node::dump_table (FILE *f)
928 fprintf (f, "Symbol table:\n\n");
929 FOR_EACH_SYMBOL (node)
934 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
935 Return NULL if there's no such node. */
938 symtab_node::get_for_asmname (const_tree asmname)
942 symtab->symtab_initialize_asm_name_hash ();
943 hashval_t hash = symtab->decl_assembler_name_hash (asmname);
945 = symtab->assembler_name_hash->find_slot_with_hash (asmname, hash,
956 /* Dump symtab node NODE to stderr. */
959 symtab_node::debug (void)
964 /* Verify common part of symtab nodes. */
967 symtab_node::verify_base (void)
969 bool error_found = false;
970 symtab_node *hashed_node;
972 if (is_a <cgraph_node *> (this))
974 if (TREE_CODE (decl) != FUNCTION_DECL)
976 error ("function symbol is not function");
980 else if (is_a <varpool_node *> (this))
982 if (TREE_CODE (decl) != VAR_DECL)
984 error ("variable symbol is not variable");
990 error ("node has unknown type");
994 if (symtab->state != LTO_STREAMING)
996 hashed_node = symtab_node::get (decl);
999 error ("node not found node->decl->decl_with_vis.symtab_node");
1002 if (hashed_node != this
1003 && (!is_a <cgraph_node *> (this)
1004 || !dyn_cast <cgraph_node *> (this)->clone_of
1005 || dyn_cast <cgraph_node *> (this)->clone_of->decl != decl))
1007 error ("node differs from node->decl->decl_with_vis.symtab_node");
1011 if (symtab->assembler_name_hash)
1013 hashed_node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
1014 if (hashed_node && hashed_node->previous_sharing_asm_name)
1016 error ("assembler name hash list corrupted");
1021 if (hashed_node == this)
1023 hashed_node = hashed_node->next_sharing_asm_name;
1026 && !(is_a <varpool_node *> (this)
1027 || DECL_HARD_REGISTER (decl)))
1029 error ("node not found in symtab assembler name hash");
1033 if (previous_sharing_asm_name
1034 && previous_sharing_asm_name->next_sharing_asm_name != this)
1036 error ("double linked list of assembler names corrupted");
1039 if (analyzed && !definition)
1041 error ("node is analyzed byt it is not a definition");
1044 if (cpp_implicit_alias && !alias)
1046 error ("node is alias but not implicit alias");
1049 if (alias && !definition && !weakref)
1051 error ("node is alias but not definition");
1054 if (weakref && !alias)
1056 error ("node is weakref but not an alias");
1059 if (same_comdat_group)
1061 symtab_node *n = same_comdat_group;
1063 if (!n->get_comdat_group ())
1065 error ("node is in same_comdat_group list but has no comdat_group");
1068 if (n->get_comdat_group () != get_comdat_group ())
1070 error ("same_comdat_group list across different groups");
1073 if (n->type != type)
1075 error ("mixing different types of symbol in same comdat groups is not supported");
1080 error ("node is alone in a comdat group");
1085 if (!n->same_comdat_group)
1087 error ("same_comdat_group is not a circular list");
1091 n = n->same_comdat_group;
1094 if (comdat_local_p ())
1096 ipa_ref *ref = NULL;
1098 for (int i = 0; iterate_referring (i, ref); ++i)
1100 if (!in_same_comdat_group_p (ref->referring))
1102 error ("comdat-local symbol referred to by %s outside its "
1104 identifier_to_locale (ref->referring->name()));
1110 if (implicit_section && !get_section ())
1112 error ("implicit_section flag is set but section isn't");
1115 if (get_section () && get_comdat_group ()
1116 && !implicit_section
1117 && !lookup_attribute ("section", DECL_ATTRIBUTES (decl)))
1119 error ("Both section and comdat group is set");
1122 /* TODO: Add string table for sections, so we do not keep holding duplicated
1124 if (alias && definition
1125 && get_section () != get_alias_target ()->get_section ()
1127 || !get_alias_target ()->get_section ()
1128 || strcmp (get_section(),
1129 get_alias_target ()->get_section ())))
1131 error ("Alias and target's section differs");
1132 get_alias_target ()->dump (stderr);
1135 if (alias && definition
1136 && get_comdat_group () != get_alias_target ()->get_comdat_group ())
1138 error ("Alias and target's comdat groups differs");
1139 get_alias_target ()->dump (stderr);
1146 /* Verify consistency of NODE. */
1149 symtab_node::verify (void)
1154 timevar_push (TV_CGRAPH_VERIFY);
1155 if (cgraph_node *node = dyn_cast <cgraph_node *> (this))
1156 node->verify_node ();
1161 internal_error ("symtab_node::verify failed");
1163 timevar_pop (TV_CGRAPH_VERIFY);
1166 /* Verify symbol table for internal consistency. */
1169 symtab_node::verify_symtab_nodes (void)
1172 hash_map<tree, symtab_node *> comdat_head_map (251);
1174 FOR_EACH_SYMBOL (node)
1177 if (node->get_comdat_group ())
1179 symtab_node **entry, *s;
1182 entry = &comdat_head_map.get_or_insert (node->get_comdat_group (),
1187 for (s = (*entry)->same_comdat_group; s != NULL && s != node; s = s->same_comdat_group)
1188 if (!s || s == *entry)
1190 error ("Two symbols with same comdat_group are not linked by the same_comdat_group list.");
1193 internal_error ("symtab_node::verify failed");
1199 /* Return true when NODE is known to be used from other (non-LTO)
1200 object file. Known only when doing LTO via linker plugin. */
1203 symtab_node::used_from_object_file_p_worker (symtab_node *node)
1205 if (!TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl))
1207 if (resolution_used_from_other_file_p (node->resolution))
1213 /* Return true when symtab_node is known to be used from other (non-LTO)
1214 object file. Known only when doing LTO via linker plugin. */
1217 symtab_node::used_from_object_file_p (void)
1219 return symtab_node::used_from_object_file_p_worker (this);
1222 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
1223 but other code such as notice_global_symbol generates rtl. */
1226 symtab_node::make_decl_local (void)
1230 /* Avoid clearing comdat_groups on comdat-local decls. */
1231 if (TREE_PUBLIC (decl) == 0)
1234 if (TREE_CODE (decl) == VAR_DECL)
1235 DECL_COMMON (decl) = 0;
1236 else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
1238 DECL_COMDAT (decl) = 0;
1239 DECL_WEAK (decl) = 0;
1240 DECL_EXTERNAL (decl) = 0;
1241 DECL_VISIBILITY_SPECIFIED (decl) = 0;
1242 DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
1243 TREE_PUBLIC (decl) = 0;
1244 if (!DECL_RTL_SET_P (decl))
1247 /* Update rtl flags. */
1248 make_decl_rtl (decl);
1250 rtl = DECL_RTL (decl);
1254 symbol = XEXP (rtl, 0);
1255 if (GET_CODE (symbol) != SYMBOL_REF)
1258 SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
1261 /* Walk the alias chain to return the symbol NODE is alias of.
1262 If NODE is not an alias, return NODE.
1263 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1266 symtab_node::ultimate_alias_target (enum availability *availability)
1268 bool weakref_p = false;
1273 *availability = get_availability ();
1277 /* To determine visibility of the target, we follow ELF semantic of aliases.
1278 Here alias is an alternative assembler name of a given definition. Its
1279 availability prevails the availability of its target (i.e. static alias of
1280 weak definition is available.
1282 Weakref is a different animal (and not part of ELF per se). It is just
1283 alternative name of a given symbol used within one complation unit
1284 and is translated prior hitting the object file. It inherits the
1285 visibility of its target (i.e. weakref of non-overwritable definition
1286 is non-overwritable, while weakref of weak definition is weak).
1288 If we ever get into supporting targets with different semantics, a target
1289 hook will be needed here. */
1293 weakref_p = weakref;
1295 *availability = get_availability ();
1297 *availability = AVAIL_LOCAL;
1300 symtab_node *node = this;
1303 if (node->alias && node->analyzed)
1304 node = node->get_alias_target ();
1309 else if (node->analyzed)
1313 enum availability a = node->get_availability ();
1314 if (a < *availability)
1319 *availability = AVAIL_NOT_AVAILABLE;
1322 if (node && availability && weakref_p)
1324 enum availability a = node->get_availability ();
1325 if (a < *availability)
1327 weakref_p = node->weakref;
1331 *availability = AVAIL_NOT_AVAILABLE;
1335 /* C++ FE sometimes change linkage flags after producing same body aliases.
1337 FIXME: C++ produce implicit aliases for virtual functions and vtables that
1338 are obviously equivalent. The way it is doing so is however somewhat
1339 kludgy and interferes with the visibility code. As a result we need to
1340 copy the visibility from the target to get things right. */
1343 symtab_node::fixup_same_cpp_alias_visibility (symtab_node *target)
1345 if (is_a <cgraph_node *> (this))
1347 DECL_DECLARED_INLINE_P (decl)
1348 = DECL_DECLARED_INLINE_P (target->decl);
1349 DECL_DISREGARD_INLINE_LIMITS (decl)
1350 = DECL_DISREGARD_INLINE_LIMITS (target->decl);
1352 /* FIXME: It is not really clear why those flags should not be copied for
1356 DECL_WEAK (decl) = DECL_WEAK (target->decl);
1357 DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
1358 DECL_VISIBILITY (decl) = DECL_VISIBILITY (target->decl);
1360 DECL_VIRTUAL_P (decl) = DECL_VIRTUAL_P (target->decl);
1361 if (TREE_PUBLIC (decl))
1365 DECL_EXTERNAL (decl) = DECL_EXTERNAL (target->decl);
1366 DECL_COMDAT (decl) = DECL_COMDAT (target->decl);
1367 group = target->get_comdat_group ();
1368 set_comdat_group (group);
1369 if (group && !same_comdat_group)
1370 add_to_same_comdat_group (target);
1372 externally_visible = target->externally_visible;
1375 /* Set section, do not recurse into aliases.
1376 When one wants to change section of symbol and its aliases,
1380 symtab_node::set_section_for_node (const char *section)
1382 const char *current = get_section ();
1383 section_hash_entry **slot;
1385 if (current == section
1386 || (current && section
1387 && !strcmp (current, section)))
1392 x_section->ref_count--;
1393 if (!x_section->ref_count)
1395 hashval_t hash = htab_hash_string (x_section->name);
1396 slot = symtab->section_hash->find_slot_with_hash (x_section->name,
1398 ggc_free (x_section);
1399 symtab->section_hash->clear_slot (slot);
1405 implicit_section = false;
1408 if (!symtab->section_hash)
1409 symtab->section_hash = hash_table<section_name_hasher>::create_ggc (10);
1410 slot = symtab->section_hash->find_slot_with_hash (section,
1411 htab_hash_string (section),
1414 x_section = (section_hash_entry *)*slot;
1417 int len = strlen (section);
1418 *slot = x_section = ggc_cleared_alloc<section_hash_entry> ();
1419 x_section->name = ggc_vec_alloc<char> (len + 1);
1420 memcpy (x_section->name, section, len + 1);
1422 x_section->ref_count++;
1425 /* Worker for set_section. */
1428 symtab_node::set_section (symtab_node *n, void *s)
1430 n->set_section_for_node ((char *)s);
1434 /* Set section of symbol and its aliases. */
1437 symtab_node::set_section (const char *section)
1439 gcc_assert (!this->alias);
1440 call_for_symbol_and_aliases
1441 (symtab_node::set_section, const_cast<char *>(section), true);
1444 /* Return the initialization priority. */
1447 symtab_node::get_init_priority ()
1449 if (!this->in_init_priority_hash)
1450 return DEFAULT_INIT_PRIORITY;
1452 symbol_priority_map *h = symtab->init_priority_hash->get (this);
1453 return h ? h->init : DEFAULT_INIT_PRIORITY;
1456 /* Return availability of NODE. */
1457 enum availability symtab_node::get_availability (void)
1459 if (is_a <cgraph_node *> (this))
1460 return dyn_cast <cgraph_node *> (this)->get_availability ();
1462 return dyn_cast <varpool_node *> (this)->get_availability ();;
1466 /* Return the finalization priority. */
1469 cgraph_node::get_fini_priority ()
1471 if (!this->in_init_priority_hash)
1472 return DEFAULT_INIT_PRIORITY;
1473 symbol_priority_map *h = symtab->init_priority_hash->get (this);
1474 return h ? h->fini : DEFAULT_INIT_PRIORITY;
1477 /* Return the initialization and finalization priority information for
1478 DECL. If there is no previous priority information, a freshly
1479 allocated structure is returned. */
1481 symbol_priority_map *
1482 symtab_node::priority_info (void)
1484 if (!symtab->init_priority_hash)
1485 symtab->init_priority_hash = hash_map<symtab_node *, symbol_priority_map>::create_ggc (13);
1488 symbol_priority_map *h
1489 = &symtab->init_priority_hash->get_or_insert (this, &existed);
1492 h->init = DEFAULT_INIT_PRIORITY;
1493 h->fini = DEFAULT_INIT_PRIORITY;
1494 in_init_priority_hash = true;
1500 /* Set initialization priority to PRIORITY. */
1503 symtab_node::set_init_priority (priority_type priority)
1505 symbol_priority_map *h;
1507 if (is_a <cgraph_node *> (this))
1508 gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl));
1510 if (priority == DEFAULT_INIT_PRIORITY)
1512 gcc_assert (get_init_priority() == priority);
1515 h = priority_info ();
1519 /* Set fialization priority to PRIORITY. */
1522 cgraph_node::set_fini_priority (priority_type priority)
1524 symbol_priority_map *h;
1526 gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl));
1528 if (priority == DEFAULT_INIT_PRIORITY)
1530 gcc_assert (get_fini_priority() == priority);
1533 h = priority_info ();
1537 /* Worker for symtab_resolve_alias. */
1540 symtab_node::set_implicit_section (symtab_node *n,
1541 void *data ATTRIBUTE_UNUSED)
1543 n->implicit_section = true;
1547 /* Add reference recording that symtab node is alias of TARGET.
1548 The function can fail in the case of aliasing cycles; in this case
1549 it returns false. */
1552 symtab_node::resolve_alias (symtab_node *target)
1556 gcc_assert (!analyzed && !vec_safe_length (ref_list.references));
1558 /* Never let cycles to creep into the symbol table alias references;
1559 those will make alias walkers to be infinite. */
1560 for (n = target; n && n->alias;
1561 n = n->analyzed ? n->get_alias_target () : NULL)
1564 if (is_a <cgraph_node *> (this))
1565 error ("function %q+D part of alias cycle", decl);
1566 else if (is_a <varpool_node *> (this))
1567 error ("variable %q+D part of alias cycle", decl);
1574 /* "analyze" the node - i.e. mark the reference. */
1578 create_reference (target, IPA_REF_ALIAS, NULL);
1580 /* Add alias into the comdat group of its target unless it is already there. */
1581 if (same_comdat_group)
1582 remove_from_same_comdat_group ();
1583 set_comdat_group (NULL);
1584 if (target->get_comdat_group ())
1585 add_to_same_comdat_group (target);
1587 if ((get_section () != target->get_section ()
1588 || target->get_comdat_group ()) && get_section () && !implicit_section)
1590 error ("section of alias %q+D must match section of its target", decl);
1592 call_for_symbol_and_aliases (symtab_node::set_section,
1593 const_cast<char *>(target->get_section ()), true);
1594 if (target->implicit_section)
1595 call_for_symbol_and_aliases (set_implicit_section, NULL, true);
1597 /* Alias targets become redundant after alias is resolved into an reference.
1598 We do not want to keep it around or we would have to mind updating them
1599 when renaming symbols. */
1600 alias_target = NULL;
1602 if (cpp_implicit_alias && symtab->state >= CONSTRUCTION)
1603 fixup_same_cpp_alias_visibility (target);
1605 /* If alias has address taken, so does the target. */
1607 target->ultimate_alias_target ()->address_taken = true;
1611 /* Call calback on symtab node and aliases associated to this node.
1612 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1616 symtab_node::call_for_symbol_and_aliases (bool (*callback) (symtab_node *,
1618 void *data, bool include_overwritable)
1623 if (callback (this, data))
1625 for (i = 0; iterate_referring (i, ref); i++)
1626 if (ref->use == IPA_REF_ALIAS)
1628 symtab_node *alias = ref->referring;
1629 if (include_overwritable
1630 || alias->get_availability () > AVAIL_INTERPOSABLE)
1631 if (alias->call_for_symbol_and_aliases (callback, data,
1632 include_overwritable))
1638 /* Worker searching noninterposable alias. */
1641 symtab_node::noninterposable_alias (symtab_node *node, void *data)
1643 if (decl_binds_to_current_def_p (node->decl))
1645 symtab_node *fn = node->ultimate_alias_target ();
1647 /* Ensure that the alias is well formed this may not be the case
1648 of user defined aliases and currently it is not always the case
1649 of C++ same body aliases (that is a bug). */
1650 if (TREE_TYPE (node->decl) != TREE_TYPE (fn->decl)
1651 || DECL_CONTEXT (node->decl) != DECL_CONTEXT (fn->decl)
1652 || (TREE_CODE (node->decl) == FUNCTION_DECL
1653 && flags_from_decl_or_type (node->decl)
1654 != flags_from_decl_or_type (fn->decl))
1655 || DECL_ATTRIBUTES (node->decl) != DECL_ATTRIBUTES (fn->decl))
1658 *(symtab_node **)data = node;
1664 /* If node can not be overwriten by static or dynamic linker to point to
1665 different definition, return NODE. Otherwise look for alias with such
1666 property and if none exists, introduce new one. */
1669 symtab_node::noninterposable_alias (void)
1672 symtab_node *new_node = NULL;
1674 /* First try to look up existing alias or base object
1675 (if that is already non-overwritable). */
1676 symtab_node *node = ultimate_alias_target ();
1677 gcc_assert (!node->alias && !node->weakref);
1678 node->call_for_symbol_and_aliases (symtab_node::noninterposable_alias,
1679 (void *)&new_node, true);
1682 #ifndef ASM_OUTPUT_DEF
1683 /* If aliases aren't supported by the assembler, fail. */
1687 /* Otherwise create a new one. */
1688 new_decl = copy_node (node->decl);
1689 DECL_NAME (new_decl) = clone_function_name (node->decl, "localalias");
1690 if (TREE_CODE (new_decl) == FUNCTION_DECL)
1691 DECL_STRUCT_FUNCTION (new_decl) = NULL;
1692 DECL_INITIAL (new_decl) = NULL;
1693 SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
1694 SET_DECL_RTL (new_decl, NULL);
1696 /* Update the properties. */
1697 DECL_EXTERNAL (new_decl) = 0;
1698 TREE_PUBLIC (new_decl) = 0;
1699 DECL_COMDAT (new_decl) = 0;
1700 DECL_WEAK (new_decl) = 0;
1702 /* Since the aliases can be added to vtables, keep DECL_VIRTUAL flag. */
1703 DECL_VIRTUAL_P (new_decl) = DECL_VIRTUAL_P (node->decl);
1704 if (TREE_CODE (new_decl) == FUNCTION_DECL)
1706 DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
1707 DECL_STATIC_DESTRUCTOR (new_decl) = 0;
1708 new_node = cgraph_node::create_alias (new_decl, node->decl);
1712 TREE_READONLY (new_decl) = TREE_READONLY (node->decl);
1713 DECL_INITIAL (new_decl) = error_mark_node;
1714 new_node = varpool_node::create_alias (new_decl, node->decl);
1716 new_node->resolve_alias (node);
1717 gcc_assert (decl_binds_to_current_def_p (new_decl)
1718 && targetm.binds_local_p (new_decl));
1722 /* Return true if symtab node and TARGET represents
1723 semantically equivalent symbols. */
1726 symtab_node::semantically_equivalent_p (symtab_node *target)
1728 enum availability avail;
1732 /* Equivalent functions are equivalent. */
1733 if (decl == target->decl)
1736 /* If symbol is not overwritable by different implementation,
1737 walk to the base object it defines. */
1738 ba = ultimate_alias_target (&avail);
1739 if (avail >= AVAIL_AVAILABLE)
1746 bb = target->ultimate_alias_target (&avail);
1747 if (avail >= AVAIL_AVAILABLE)
1757 /* Classify symbol symtab node for partitioning. */
1759 enum symbol_partitioning_class
1760 symtab_node::get_partitioning_class (void)
1762 /* Inline clones are always duplicated.
1763 This include external delcarations. */
1764 cgraph_node *cnode = dyn_cast <cgraph_node *> (this);
1766 if (DECL_ABSTRACT_P (decl))
1767 return SYMBOL_EXTERNAL;
1769 if (cnode && cnode->global.inlined_to)
1770 return SYMBOL_DUPLICATE;
1772 /* Weakref aliases are always duplicated. */
1774 return SYMBOL_DUPLICATE;
1776 /* External declarations are external. */
1777 if (DECL_EXTERNAL (decl))
1778 return SYMBOL_EXTERNAL;
1780 if (varpool_node *vnode = dyn_cast <varpool_node *> (this))
1782 if (alias && definition && !ultimate_alias_target ()->definition)
1783 return SYMBOL_EXTERNAL;
1784 /* Constant pool references use local symbol names that can not
1785 be promoted global. We should never put into a constant pool
1786 objects that can not be duplicated across partitions. */
1787 if (DECL_IN_CONSTANT_POOL (decl))
1788 return SYMBOL_DUPLICATE;
1789 gcc_checking_assert (vnode->definition);
1791 /* Functions that are cloned may stay in callgraph even if they are unused.
1792 Handle them as external; compute_ltrans_boundary take care to make
1793 proper things to happen (i.e. to make them appear in the boundary but
1794 with body streamed, so clone can me materialized). */
1795 else if (!dyn_cast <cgraph_node *> (this)->function_symbol ()->definition)
1796 return SYMBOL_EXTERNAL;
1798 /* Linker discardable symbols are duplicated to every use unless they are
1800 if (DECL_ONE_ONLY (decl)
1803 && !used_from_object_file_p ())
1804 return SYMBOL_DUPLICATE;
1806 return SYMBOL_PARTITION;
1809 /* Return true when symbol is known to be non-zero. */
1812 symtab_node::nonzero_address ()
1814 /* Weakrefs may be NULL when their target is not defined. */
1815 if (alias && weakref)
1819 symtab_node *target = ultimate_alias_target ();
1821 if (target->alias && target->weakref)
1823 /* We can not recurse to target::nonzero. It is possible that the
1824 target is used only via the alias.
1825 We may walk references and look for strong use, but we do not know
1826 if this strong use will survive to final binary, so be
1828 ??? Maybe we could do the lookup during late optimization that
1829 could be useful to eliminate the NULL pointer checks in LTO
1831 if (target->definition && !DECL_EXTERNAL (target->decl))
1833 if (target->resolution != LDPR_UNKNOWN
1834 && target->resolution != LDPR_UNDEF
1835 && flag_delete_null_pointer_checks)
1843 /* With !flag_delete_null_pointer_checks we assume that symbols may
1844 bind to NULL. This is on by default on embedded targets only.
1846 Otherwise all non-WEAK symbols must be defined and thus non-NULL or
1847 linking fails. Important case of WEAK we want to do well are comdats.
1848 Those are handled by later check for definition.
1850 When parsing, beware the cases when WEAK attribute is added later. */
1851 if (!DECL_WEAK (decl)
1852 && flag_delete_null_pointer_checks)
1854 refuse_visibility_changes = true;
1858 /* If target is defined and not extern, we know it will be output and thus
1859 it will bind to non-NULL.
1860 Play safe for flag_delete_null_pointer_checks where weak definition maye
1861 be re-defined by NULL. */
1862 if (definition && !DECL_EXTERNAL (decl)
1863 && (flag_delete_null_pointer_checks || !DECL_WEAK (decl)))
1865 if (!DECL_WEAK (decl))
1866 refuse_visibility_changes = true;
1870 /* As the last resort, check the resolution info. */
1871 if (resolution != LDPR_UNKNOWN
1872 && resolution != LDPR_UNDEF
1873 && flag_delete_null_pointer_checks)
1878 /* Return 0 if symbol is known to have different address than S2,
1879 Return 1 if symbol is known to have same address as S2,
1880 return 2 otherwise. */
1882 symtab_node::equal_address_to (symtab_node *s2)
1884 enum availability avail1, avail2;
1886 /* A Shortcut: equivalent symbols are always equivalent. */
1890 /* For non-interposable aliases, lookup and compare their actual definitions.
1891 Also check if the symbol needs to bind to given definition. */
1892 symtab_node *rs1 = ultimate_alias_target (&avail1);
1893 symtab_node *rs2 = s2->ultimate_alias_target (&avail2);
1894 bool binds_local1 = rs1->analyzed && decl_binds_to_current_def_p (this->decl);
1895 bool binds_local2 = rs2->analyzed && decl_binds_to_current_def_p (s2->decl);
1896 bool really_binds_local1 = binds_local1;
1897 bool really_binds_local2 = binds_local2;
1899 /* Addresses of vtables and virtual functions can not be used by user
1900 code and are used only within speculation. In this case we may make
1901 symbol equivalent to its alias even if interposition may break this
1902 rule. Doing so will allow us to turn speculative inlining into
1903 non-speculative more agressively. */
1904 if (DECL_VIRTUAL_P (this->decl) && avail1 >= AVAIL_AVAILABLE)
1905 binds_local1 = true;
1906 if (DECL_VIRTUAL_P (s2->decl) && avail2 >= AVAIL_AVAILABLE)
1907 binds_local2 = true;
1909 /* If both definitions are available we know that even if they are bound
1910 to other unit they must be defined same way and therefore we can use
1911 equivalence test. */
1912 if (rs1 != rs2 && avail1 >= AVAIL_AVAILABLE && avail2 >= AVAIL_AVAILABLE)
1913 binds_local1 = binds_local2 = true;
1915 if ((binds_local1 ? rs1 : this)
1916 == (binds_local2 ? rs2 : s2))
1918 /* We made use of the fact that alias is not weak. */
1919 if (binds_local1 && rs1 != this)
1920 refuse_visibility_changes = true;
1921 if (binds_local2 && rs2 != s2)
1922 s2->refuse_visibility_changes = true;
1926 /* If both symbols may resolve to NULL, we can not really prove them different. */
1927 if (!nonzero_address () && !s2->nonzero_address ())
1930 /* Except for NULL, functions and variables never overlap. */
1931 if (TREE_CODE (decl) != TREE_CODE (s2->decl))
1934 /* If one of the symbols is unresolved alias, punt. */
1935 if (rs1->alias || rs2->alias)
1938 /* If we have a non-interposale definition of at least one of the symbols
1939 and the other symbol is different, we know other unit can not interpose
1940 it to the first symbol; all aliases of the definition needs to be
1941 present in the current unit. */
1942 if (((really_binds_local1 || really_binds_local2)
1943 /* If we have both definitions and they are different, we know they
1944 will be different even in units they binds to. */
1945 || (binds_local1 && binds_local2))
1948 /* We make use of the fact that one symbol is not alias of the other
1949 and that the definition is non-interposable. */
1950 refuse_visibility_changes = true;
1951 s2->refuse_visibility_changes = true;
1952 rs1->refuse_visibility_changes = true;
1953 rs2->refuse_visibility_changes = true;
1957 /* TODO: Alias oracle basically assume that addresses of global variables
1958 are different unless they are declared as alias of one to another.
1959 We probably should be consistent and use this fact here, too, and update
1960 alias oracle to use this predicate. */