cgraph*.c and ipa-*.c use xstrdup on strings when dumping them via
fprintf, leaking all of the duplicated buffers.

Is/was there a reason for doing this?

Taking them out fixes these leaks (seen when dumping is enabled):

12 bytes in 1 blocks are definitely lost in loss record 11 of 148
at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x5DED3E7: xmalloc (xmalloc.c:147)
by 0x5DED4D9: xstrdup (xstrdup.c:34)
by 0x5126326: ipa_print_node_jump_functions(_IO_FILE*, cgraph_node*) 
(ipa-prop.c:397)
by 0x512657F: ipa_print_all_jump_functions(_IO_FILE*) (ipa-prop.c:443)
by 0x5CE4471: ipcp_driver() (ipa-cp.c:4216)
by 0x5CE46D8: (anonymous namespace)::pass_ipa_cp::execute(function*) 
(ipa-cp.c:4315)
by 0x525BF51: execute_one_pass(opt_pass*) (passes.c:2311)
by 0x525CE68: execute_ipa_pass_list(opt_pass*) (passes.c:2708)
by 0x4E5263C: ipa_passes() (cgraphunit.c:2099)
by 0x4E5298C: symbol_table::compile() (cgraphunit.c:2187)
by 0x4E52D22: symbol_table::finalize_compilation_unit() (cgraphunit.c:2340)

12 bytes in 1 blocks are definitely lost in loss record 12 of 148
at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x5DED3E7: xmalloc (xmalloc.c:147)
by 0x5DED4D9: xstrdup (xstrdup.c:34)
by 0x5CF155A: report_inline_failed_reason(cgraph_edge*) (ipa-inline.c:253)
by 0x5CF1C35: can_inline_edge_p(cgraph_edge*, bool, bool) (ipa-inline.c:394)
by 0x5CF4DFC: inline_small_functions() (ipa-inline.c:1651)
by 0x5CF6785: ipa_inline() (ipa-inline.c:2188)
by 0x5CF7358: (anonymous namespace)::pass_ipa_inline::execute(function*) 
(ipa-inline.c:2557)
by 0x525BF51: execute_one_pass(opt_pass*) (passes.c:2311)
by 0x525CE68: execute_ipa_pass_list(opt_pass*) (passes.c:2708)
by 0x4E5263C: ipa_passes() (cgraphunit.c:2099)
by 0x4E5298C: symbol_table::compile() (cgraphunit.c:2187)

16 bytes in 1 blocks are definitely lost in loss record 16 of 148
at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x5DED3E7: xmalloc (xmalloc.c:147)
by 0x5DED4D9: xstrdup (xstrdup.c:34)
by 0x5126308: ipa_print_node_jump_functions(_IO_FILE*, cgraph_node*) 
(ipa-prop.c:397)
by 0x512657F: ipa_print_all_jump_functions(_IO_FILE*) (ipa-prop.c:443)
by 0x5CE4471: ipcp_driver() (ipa-cp.c:4216)
by 0x5CE46D8: (anonymous namespace)::pass_ipa_cp::execute(function*) 
(ipa-cp.c:4315)
by 0x525BF51: execute_one_pass(opt_pass*) (passes.c:2311)
by 0x525CE68: execute_ipa_pass_list(opt_pass*) (passes.c:2708)
by 0x4E5263C: ipa_passes() (cgraphunit.c:2099)
by 0x4E5298C: symbol_table::compile() (cgraphunit.c:2187)
by 0x4E52D22: symbol_table::finalize_compilation_unit() (cgraphunit.c:2340)

16 bytes in 1 blocks are definitely lost in loss record 17 of 148
at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x5DED3E7: xmalloc (xmalloc.c:147)
by 0x5DED4D9: xstrdup (xstrdup.c:34)
by 0x5CF1533: report_inline_failed_reason(cgraph_edge*) (ipa-inline.c:253)
by 0x5CF1C35: can_inline_edge_p(cgraph_edge*, bool, bool) (ipa-inline.c:394)
by 0x5CF4DFC: inline_small_functions() (ipa-inline.c:1651)
by 0x5CF6785: ipa_inline() (ipa-inline.c:2188)
by 0x5CF7358: (anonymous namespace)::pass_ipa_inline::execute(function*) 
(ipa-inline.c:2557)
by 0x525BF51: execute_one_pass(opt_pass*) (passes.c:2311)
by 0x525CE68: execute_ipa_pass_list(opt_pass*) (passes.c:2708)
by 0x4E5263C: ipa_passes() (cgraphunit.c:2099)
by 0x4E5298C: symbol_table::compile() (cgraphunit.c:2187)

gcc/ChangeLog:
        PR jit/63854
        * cgraph.c (cgraph_node::get_create): Remove xstrdup from within
        fprintf dumping call.
        (cgraph_edge::make_speculative): Likewise.
        (cgraph_edge::resolve_speculation): Likewise.
        (cgraph_edge::redirect_call_stmt_to_callee): Likewise.
        (cgraph_node::dump): Likewise.
        * cgraphclones.c (symbol_table::materialize_all_clones): Likewise.
        * ipa-cp.c (perhaps_add_new_callers): Likewise.
        * ipa-inline.c (report_inline_failed_reason): Likewise.
        (want_early_inline_function_p): Likewise.
        (edge_badness): Likewise.
        (update_edge_key): Likewise.
        (flatten_function): Likewise.
        (inline_always_inline_functions): Likewise.
        (early_inline_small_functions): Likewise.
        * ipa-profile.c (ipa_profile): Likewise.
        * ipa-prop.c (ipa_print_node_jump_functions): Likewise.
        (ipa_make_edge_direct_to_target): Likewise.
        (remove_described_reference): Likewise.
        (propagate_controlled_uses): Likewise.
        * ipa-utils.c (ipa_merge_profiles): Likewise.
---
 gcc/cgraph.c       | 32 ++++++++++++++++----------------
 gcc/cgraphclones.c |  4 ++--
 gcc/ipa-cp.c       |  4 ++--
 gcc/ipa-inline.c   | 44 ++++++++++++++++++++++----------------------
 gcc/ipa-profile.c  |  4 ++--
 gcc/ipa-prop.c     | 34 +++++++++++++++++-----------------
 gcc/ipa-utils.c    |  4 ++--
 7 files changed, 63 insertions(+), 63 deletions(-)

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 5323468..b79a3aa 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -537,11 +537,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 (node->name ()), node->order);
+                node->name (), node->order);
     }
   else if (dump_file)
     fprintf (dump_file, "Introduced new external node "
-            "(%s/%i).\n", xstrdup (node->name ()),
+            "(%s/%i).\n", node->name (),
             node->order);
   return node;
 }
@@ -1070,8 +1070,8 @@ cgraph_edge::make_speculative (cgraph_node *n2, gcov_type 
direct_count,
     {
       fprintf (dump_file, "Indirect call -> speculative call"
               " %s/%i => %s/%i\n",
-              xstrdup (n->name ()), n->order,
-              xstrdup (n2->name ()), n2->order);
+              n->name (), n->order,
+              n2->name (), n2->order);
     }
   speculative = true;
   e2 = n->create_edge (n2, call_stmt, direct_count, direct_frequency);
@@ -1190,16 +1190,16 @@ cgraph_edge::resolve_speculation (tree callee_decl)
            {
              fprintf (dump_file, "Speculative indirect call %s/%i => %s/%i has 
"
                       "turned out to have contradicting known target ",
-                      xstrdup (edge->caller->name ()), edge->caller->order,
-                      xstrdup (e2->callee->name ()), e2->callee->order);
+                      edge->caller->name (), edge->caller->order,
+                      e2->callee->name (), e2->callee->order);
              print_generic_expr (dump_file, callee_decl, 0);
              fprintf (dump_file, "\n");
            }
          else
            {
              fprintf (dump_file, "Removing speculative call %s/%i => %s/%i\n",
-                      xstrdup (edge->caller->name ()), edge->caller->order,
-                      xstrdup (e2->callee->name ()), e2->callee->order);
+                      edge->caller->name (), edge->caller->order,
+                      e2->callee->name (), e2->callee->order);
            }
        }
     }
@@ -1319,9 +1319,9 @@ cgraph_edge::redirect_call_stmt_to_callee (void)
          if (dump_file)
            fprintf (dump_file, "Not expanding speculative call of %s/%i -> 
%s/%i\n"
                     "Type mismatch.\n",
-                    xstrdup (e->caller->name ()),
+                    e->caller->name (),
                     e->caller->order,
-                    xstrdup (e->callee->name ()),
+                    e->callee->name (),
                     e->callee->order);
          e = e->resolve_speculation ();
          /* We are producing the final function body and will throw away the
@@ -1338,9 +1338,9 @@ cgraph_edge::redirect_call_stmt_to_callee (void)
            fprintf (dump_file,
                     "Expanding speculative call of %s/%i -> %s/%i count:"
                     "%"PRId64"\n",
-                    xstrdup (e->caller->name ()),
+                    e->caller->name (),
                     e->caller->order,
-                    xstrdup (e->callee->name ()),
+                    e->callee->name (),
                     e->callee->order,
                     (int64_t)e->count);
          gcc_assert (e2->speculative);
@@ -1415,8 +1415,8 @@ cgraph_edge::redirect_call_stmt_to_callee (void)
   if (symtab->dump_file)
     {
       fprintf (symtab->dump_file, "updating call of %s/%i -> %s/%i: ",
-              xstrdup (e->caller->name ()), e->caller->order,
-              xstrdup (e->callee->name ()), e->callee->order);
+              e->caller->name (), e->caller->order,
+              e->callee->name (), e->callee->order);
       print_gimple_stmt (symtab->dump_file, e->call_stmt, 0, dump_flags);
       if (e->callee->clone.combined_args_to_skip)
        {
@@ -1965,9 +1965,9 @@ cgraph_node::dump (FILE *f)
 
   if (global.inlined_to)
     fprintf (f, "  Function %s/%i is inline copy in %s/%i\n",
-            xstrdup (name ()),
+            name (),
             order,
-            xstrdup (global.inlined_to->name ()),
+            global.inlined_to->name (),
             global.inlined_to->order);
   if (clone_of)
     fprintf (f, "  Clone of %s/%i\n",
diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
index 086dd92..a40ed4b 100644
--- a/gcc/cgraphclones.c
+++ b/gcc/cgraphclones.c
@@ -1074,8 +1074,8 @@ symbol_table::materialize_all_clones (void)
                  if (symtab->dump_file)
                    {
                      fprintf (symtab->dump_file, "cloning %s to %s\n",
-                              xstrdup (node->clone_of->name ()),
-                              xstrdup (node->name ()));
+                              node->clone_of->name (),
+                              node->name ());
                      if (node->clone.tree_map)
                        {
                          unsigned int i;
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index f97912b..11b886b 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -3791,9 +3791,9 @@ perhaps_add_new_callers (cgraph_node *node, 
ipcp_value<valtype> *val)
                  if (dump_file)
                    fprintf (dump_file, " - adding an extra caller %s/%i"
                             " of %s/%i\n",
-                            xstrdup (cs->caller->name ()),
+                            cs->caller->name (),
                             cs->caller->order,
-                            xstrdup (val->spec_node->name ()),
+                            val->spec_node->name (),
                             val->spec_node->order);
 
                  cs->redirect_callee (val->spec_node);
diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c
index 72c0715..a0779a1 100644
--- a/gcc/ipa-inline.c
+++ b/gcc/ipa-inline.c
@@ -248,8 +248,8 @@ report_inline_failed_reason (struct cgraph_edge *e)
   if (dump_file)
     {
       fprintf (dump_file, "  not inlinable: %s/%i -> %s/%i, %s\n",
-              xstrdup (e->caller->name ()), e->caller->order,
-              xstrdup (e->callee->name ()), e->callee->order,
+              e->caller->name (), e->caller->order,
+              e->callee->name (), e->callee->order,
               cgraph_inline_failed_string (e->inline_failed));
     }
 }
@@ -480,9 +480,9 @@ want_early_inline_function_p (struct cgraph_edge *e)
          if (dump_file)
            fprintf (dump_file, "  will not early inline: %s/%i->%s/%i, "
                     "call is cold and code would grow by %i\n",
-                    xstrdup (e->caller->name ()),
+                    e->caller->name (),
                     e->caller->order,
-                    xstrdup (callee->name ()), callee->order,
+                    callee->name (), callee->order,
                     growth);
          want_inline = false;
        }
@@ -491,9 +491,9 @@ want_early_inline_function_p (struct cgraph_edge *e)
          if (dump_file)
            fprintf (dump_file, "  will not early inline: %s/%i->%s/%i, "
                     "growth %i exceeds --param early-inlining-insns\n",
-                    xstrdup (e->caller->name ()),
+                    e->caller->name (),
                     e->caller->order,
-                    xstrdup (callee->name ()), callee->order,
+                    callee->name (), callee->order,
                     growth);
          want_inline = false;
        }
@@ -504,9 +504,9 @@ want_early_inline_function_p (struct cgraph_edge *e)
            fprintf (dump_file, "  will not early inline: %s/%i->%s/%i, "
                     "growth %i exceeds --param early-inlining-insns "
                     "divided by number of calls\n",
-                    xstrdup (e->caller->name ()),
+                    e->caller->name (),
                     e->caller->order,
-                    xstrdup (callee->name ()), callee->order,
+                    callee->name (), callee->order,
                     growth);
          want_inline = false;
        }
@@ -925,9 +925,9 @@ edge_badness (struct cgraph_edge *edge, bool dump)
   if (dump)
     {
       fprintf (dump_file, "    Badness calculation for %s/%i -> %s/%i\n",
-              xstrdup (edge->caller->name ()),
+              edge->caller->name (),
               edge->caller->order,
-              xstrdup (callee->name ()),
+              callee->name (),
               edge->callee->order);
       fprintf (dump_file, "      size growth %i, time %i ",
               growth,
@@ -1093,9 +1093,9 @@ update_edge_key (edge_heap_t *heap, struct cgraph_edge 
*edge)
            {
              fprintf (dump_file,
                       "  decreasing badness %s/%i -> %s/%i, %i to %i\n",
-                      xstrdup (edge->caller->name ()),
+                      edge->caller->name (),
                       edge->caller->order,
-                      xstrdup (edge->callee->name ()),
+                      edge->callee->name (),
                       edge->callee->order,
                       (int)n->get_key (),
                       badness);
@@ -1110,9 +1110,9 @@ update_edge_key (edge_heap_t *heap, struct cgraph_edge 
*edge)
         {
           fprintf (dump_file,
                    "  enqueuing call %s/%i -> %s/%i, badness %i\n",
-                   xstrdup (edge->caller->name ()),
+                   edge->caller->name (),
                    edge->caller->order,
-                   xstrdup (edge->callee->name ()),
+                   edge->callee->name (),
                    edge->callee->order,
                    badness);
         }
@@ -1891,8 +1891,8 @@ flatten_function (struct cgraph_node *node, bool early)
          if (dump_file)
            fprintf (dump_file,
                     "Not inlining %s into %s to avoid cycle.\n",
-                    xstrdup (callee->name ()),
-                    xstrdup (e->caller->name ()));
+                    callee->name (),
+                    e->caller->name ());
          e->inline_failed = CIF_RECURSIVE_INLINING;
          continue;
        }
@@ -1932,8 +1932,8 @@ flatten_function (struct cgraph_node *node, bool early)
          recursing through the original node if the node was cloned.  */
       if (dump_file)
        fprintf (dump_file, " Inlining %s into %s.\n",
-                xstrdup (callee->name ()),
-                xstrdup (e->caller->name ()));
+                callee->name (),
+                e->caller->name ());
       orig_callee = callee;
       inline_call (e, true, NULL, NULL, false);
       if (e->callee != orig_callee)
@@ -2310,8 +2310,8 @@ inline_always_inline_functions (struct cgraph_node *node)
 
       if (dump_file)
        fprintf (dump_file, "  Inlining %s into %s (always_inline).\n",
-                xstrdup (e->callee->name ()),
-                xstrdup (e->caller->name ()));
+                e->callee->name (),
+                e->caller->name ());
       inline_call (e, true, NULL, NULL, false);
       inlined = true;
     }
@@ -2362,8 +2362,8 @@ early_inline_small_functions (struct cgraph_node *node)
 
       if (dump_file)
        fprintf (dump_file, " Inlining %s into %s.\n",
-                xstrdup (callee->name ()),
-                xstrdup (e->caller->name ()));
+                callee->name (),
+                e->caller->name ());
       inline_call (e, true, NULL, NULL, true);
       inlined = true;
     }
diff --git a/gcc/ipa-profile.c b/gcc/ipa-profile.c
index 340d033..d8a4371 100644
--- a/gcc/ipa-profile.c
+++ b/gcc/ipa-profile.c
@@ -607,8 +607,8 @@ ipa_profile (void)
                    {
                      fprintf (dump_file, "Indirect call -> direct call from"
                               " other module %s/%i => %s/%i, prob %3.2f\n",
-                              xstrdup (n->name ()), n->order,
-                              xstrdup (n2->name ()), n2->order,
+                              n->name (), n->order,
+                              n2->name (), n2->order,
                               e->indirect_info->common_target_probability
                               / (float)REG_BR_PROB_BASE);
                    }
diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
index be1921a..68f6fa6 100644
--- a/gcc/ipa-prop.c
+++ b/gcc/ipa-prop.c
@@ -392,8 +392,8 @@ ipa_print_node_jump_functions (FILE *f, struct cgraph_node 
*node)
        continue;
 
       fprintf (f, "    callsite  %s/%i -> %s/%i : \n",
-              xstrdup (node->name ()), node->order,
-              xstrdup (cs->callee->name ()),
+              node->name (), node->order,
+              cs->callee->name (),
               cs->callee->order);
       ipa_print_node_jump_functions_for_edge (f, cs);
     }
@@ -2620,9 +2620,9 @@ ipa_make_edge_direct_to_target (struct cgraph_edge *ie, 
tree target,
          if (dump_file)
            fprintf (dump_file, "ipa-prop: Discovered call to a known target "
                     "(%s/%i -> %s/%i) but can not refer to it. Giving up.\n",
-                    xstrdup (ie->caller->name ()),
+                    ie->caller->name (),
                     ie->caller->order,
-                    xstrdup (ie->callee->name ()),
+                    ie->callee->name (),
                     ie->callee->order);
          return NULL;
        }
@@ -2641,11 +2641,11 @@ ipa_make_edge_direct_to_target (struct cgraph_edge *ie, 
tree target,
          if (dump_file)
            fprintf (dump_file, "ipa-prop: Discovered call to a speculative 
target "
                     "(%s/%i -> %s/%i) but the call is already speculated to 
%s/%i. Giving up.\n",
-                    xstrdup (ie->caller->name ()),
+                    ie->caller->name (),
                     ie->caller->order,
-                    xstrdup (callee->name ()),
+                    callee->name (),
                     callee->order,
-                    xstrdup (e2->callee->name ()),
+                    e2->callee->name (),
                     e2->callee->order);
        }
       else
@@ -2653,9 +2653,9 @@ ipa_make_edge_direct_to_target (struct cgraph_edge *ie, 
tree target,
          if (dump_file)
            fprintf (dump_file, "ipa-prop: Discovered call to a speculative 
target "
                     "(%s/%i -> %s/%i) this agree with previous speculation.\n",
-                    xstrdup (ie->caller->name ()),
+                    ie->caller->name (),
                     ie->caller->order,
-                    xstrdup (callee->name ()),
+                    callee->name (),
                     callee->order);
        }
       return NULL;
@@ -2676,9 +2676,9 @@ ipa_make_edge_direct_to_target (struct cgraph_edge *ie, 
tree target,
               "(%s/%i -> %s/%i), for stmt ",
               ie->indirect_info->polymorphic ? "a virtual" : "an indirect",
               speculative ? "speculative" : "known",
-              xstrdup (ie->caller->name ()),
+              ie->caller->name (),
               ie->caller->order,
-              xstrdup (callee->name ()),
+              callee->name (),
               callee->order);
       if (ie->call_stmt)
        print_gimple_stmt (dump_file, ie->call_stmt, 2, TDF_SLIM);
@@ -2762,8 +2762,8 @@ remove_described_reference (symtab_node *symbol, struct 
ipa_cst_ref_desc *rdesc)
   to_del->remove_reference ();
   if (dump_file)
     fprintf (dump_file, "ipa-prop: Removed a reference from %s/%i to %s.\n",
-            xstrdup (origin->caller->name ()),
-            origin->caller->order, xstrdup (symbol->name ()));
+            origin->caller->name (),
+            origin->caller->order, symbol->name ());
   return true;
 }
 
@@ -3177,9 +3177,9 @@ propagate_controlled_uses (struct cgraph_edge *cs)
                  if (dump_file)
                    fprintf (dump_file, "ipa-prop: Removing cloning-created "
                             "reference from %s/%i to %s/%i.\n",
-                            xstrdup (new_root->name ()),
+                            new_root->name (),
                             new_root->order,
-                            xstrdup (n->name ()), n->order);
+                            n->name (), n->order);
                  ref->remove_reference ();
                }
            }
@@ -3218,9 +3218,9 @@ propagate_controlled_uses (struct cgraph_edge *cs)
                            fprintf (dump_file, "ipa-prop: Removing "
                                     "cloning-created reference "
                                     "from %s/%i to %s/%i.\n",
-                                    xstrdup (clone->name ()),
+                                    clone->name (),
                                     clone->order,
-                                    xstrdup (n->name ()),
+                                    n->name (),
                                     n->order);
                          ref->remove_reference ();
                        }
diff --git a/gcc/ipa-utils.c b/gcc/ipa-utils.c
index 7613205..c0b855a 100644
--- a/gcc/ipa-utils.c
+++ b/gcc/ipa-utils.c
@@ -427,8 +427,8 @@ ipa_merge_profiles (struct cgraph_node *dst,
   if (symtab->dump_file)
     {
       fprintf (symtab->dump_file, "Merging profiles of %s/%i to %s/%i\n",
-              xstrdup (src->name ()), src->order,
-              xstrdup (dst->name ()), dst->order);
+              src->name (), src->order,
+              dst->name (), dst->order);
     }
   dst->count += src->count;
 
-- 
1.8.5.3

Reply via email to