From 1aec2ecce4085a664f489e7a3585d993a9939a1d Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 18 Mar 2015 15:16:59 +0100 Subject: [PATCH] re PR ipa/65432 (Invalid read of size 1: ipa_icf::sem_item_optimizer::merge_classes(unsigned int) (ipa-icf.c:2958)) Fix PR ipa/65432 PR ipa/65432 * cgraph.c (cgraph_node::get_create): Remove unnecessary xstrdup_for_dump wrapper. * ipa-icf.c (sem_item::dump): Use symtab_node::name instead of sem_item::name. (sem_function::equals): Wrap symtab_node::name and symtab_node::asm_name with xstrdup_for_dump. (sem_variable::equals): Likewise. (sem_item_optimizer::read_section): Use symtab_node::name instead of sem_item::name. (sem_item_optimizer::parse_funcs_and_vars): Likewise. (sem_item_optimizer::merge_classes): Wrap symtab_node::name and symtab_node::asm_name with xstrdup_for_dump. (congruence_class::dump): Use symtab_node::name instead of sem_item::name. * ipa-icf.h (symtab_node::name): Remove. (symtab_node::asm_name): Likewise. From-SVN: r221491 --- gcc/ChangeLog | 20 ++++++++++++++++++++ gcc/cgraph.c | 5 ++--- gcc/ipa-icf.c | 35 +++++++++++++++++++++++------------ gcc/ipa-icf.h | 12 ------------ 4 files changed, 45 insertions(+), 27 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0e9955bcdc4..7325636dd25 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,23 @@ +2015-03-18 Martin Liska + + PR ipa/65432 + * cgraph.c (cgraph_node::get_create): Remove unnecessary + xstrdup_for_dump wrapper. + * ipa-icf.c (sem_item::dump): Use symtab_node::name instead of + sem_item::name. + (sem_function::equals): Wrap symtab_node::name and symtab_node::asm_name + with xstrdup_for_dump. + (sem_variable::equals): Likewise. + (sem_item_optimizer::read_section): Use symtab_node::name instead of + sem_item::name. + (sem_item_optimizer::parse_funcs_and_vars): Likewise. + (sem_item_optimizer::merge_classes): Wrap symtab_node::name and + symtab_node::asm_name with xstrdup_for_dump. + (congruence_class::dump): Use symtab_node::name instead of + sem_item::name. + * ipa-icf.h (symtab_node::name): Remove. + (symtab_node::asm_name): Likewise. + 2015-03-18 Jakub Jelinek PR tree-optimization/65450 diff --git a/gcc/cgraph.c b/gcc/cgraph.c index ede58bf5aaf..e2958c4a508 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -553,12 +553,11 @@ cgraph_node::get_create (tree decl) if (dump_file) fprintf (dump_file, "Introduced new external node " "(%s/%i) and turned into root of the clone tree.\n", - xstrdup_for_dump (node->name ()), node->order); + node->name (), node->order); } else if (dump_file) fprintf (dump_file, "Introduced new external node " - "(%s/%i).\n", xstrdup_for_dump (node->name ()), - node->order); + "(%s/%i).\n", node->name (), node->order); return node; } diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index 25b83062d3f..f68d23cf4dc 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -239,12 +239,12 @@ sem_item::dump (void) if (dump_file) { fprintf (dump_file, "[%s] %s (%u) (tree:%p)\n", type == FUNC ? "func" : "var", - name(), node->order, (void *) node->decl); + node->name(), node->order, (void *) node->decl); fprintf (dump_file, " hash: %u\n", get_hash ()); fprintf (dump_file, " references: "); for (unsigned i = 0; i < refs.length (); i++) - fprintf (dump_file, "%s%s ", refs[i]->name (), + fprintf (dump_file, "%s%s ", refs[i]->node->name (), i < refs.length() - 1 ? "," : ""); fprintf (dump_file, "\n"); @@ -575,8 +575,13 @@ sem_function::equals (sem_item *item, if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "Equals called for:%s:%s (%u:%u) (%s:%s) with result: %s\n\n", - name(), item->name (), node->order, item->node->order, asm_name (), - item->asm_name (), eq ? "true" : "false"); + xstrdup_for_dump (node->name()), + xstrdup_for_dump (item->node->name ()), + node->order, + item->node->order, + xstrdup_for_dump (node->asm_name ()), + xstrdup_for_dump (item->node->asm_name ()), + eq ? "true" : "false"); return eq; } @@ -1522,8 +1527,11 @@ sem_variable::equals (sem_item *item, if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "Equals called for vars:%s:%s (%u:%u) (%s:%s) with result: %s\n\n", - name(), item->name (), node->order, item->node->order, asm_name (), - item->asm_name (), ret ? "true" : "false"); + xstrdup_for_dump (node->name()), + xstrdup_for_dump (item->node->name ()), + node->order, item->node->order, + xstrdup_for_dump (node->asm_name ()), + xstrdup_for_dump (item->node->asm_name ()), ret ? "true" : "false"); return ret; } @@ -1995,8 +2003,8 @@ sem_item_optimizer::read_section (lto_file_decl_data *file_data, gcc_assert (node->definition); if (dump_file) - fprintf (dump_file, "Symbol added:%s (tree: %p, uid:%u)\n", node->asm_name (), - (void *) node->decl, node->order); + fprintf (dump_file, "Symbol added:%s (tree: %p, uid:%u)\n", + node->asm_name (), (void *) node->decl, node->order); if (is_a (node)) { @@ -2259,7 +2267,7 @@ sem_item_optimizer::parse_funcs_and_vars (void) m_symtab_node_map.put (cnode, f); if (dump_file) - fprintf (dump_file, "Parsed function:%s\n", f->asm_name ()); + fprintf (dump_file, "Parsed function:%s\n", f->node->asm_name ()); if (dump_file && (dump_flags & TDF_DETAILS)) f->dump_to_file (dump_file); @@ -2955,9 +2963,11 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count) if (dump_file) { fprintf (dump_file, "Semantic equality hit:%s->%s\n", - source->name (), alias->name ()); + xstrdup_for_dump (source->node->name ()), + xstrdup_for_dump (alias->node->name ())); fprintf (dump_file, "Assembler symbol names:%s->%s\n", - source->asm_name (), alias->asm_name ()); + xstrdup_for_dump (source->node->asm_name ()), + xstrdup_for_dump (alias->node->asm_name ())); } if (lookup_attribute ("no_icf", DECL_ATTRIBUTES (alias->decl))) @@ -2993,7 +3003,8 @@ congruence_class::dump (FILE *file, unsigned int indent) const FPUTS_SPACES (file, indent + 2, ""); for (unsigned i = 0; i < members.length (); i++) - fprintf (file, "%s(%p/%u) ", members[i]->asm_name (), (void *) members[i]->decl, + fprintf (file, "%s(%p/%u) ", members[i]->node->asm_name (), + (void *) members[i]->decl, members[i]->node->order); fprintf (file, "\n"); diff --git a/gcc/ipa-icf.h b/gcc/ipa-icf.h index c51bb4a4299..8245b5445cc 100644 --- a/gcc/ipa-icf.h +++ b/gcc/ipa-icf.h @@ -171,18 +171,6 @@ public: /* Add reference to a semantic TARGET. */ void add_reference (sem_item *target); - /* Gets symbol name of the item. */ - const char *name (void) - { - return node->name (); - } - - /* Gets assembler name of the item. */ - const char *asm_name (void) - { - return node->asm_name (); - } - /* Fast equality function based on knowledge known in WPA. */ virtual bool equals_wpa (sem_item *item, hash_map &ignored_nodes) = 0; -- 2.30.2