[pushed 2/2] analyzer: use label_text for superedge::get_description

David Malcolm dmalcolm@redhat.com
Thu Jul 7 20:00:55 GMT 2022


No functional change intended.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Lightly tested with valgrind.

Pushed to trunk as r13-1564-g52f538fa4a13d5.

gcc/analyzer/ChangeLog:
	* checker-path.cc (start_cfg_edge_event::get_desc): Update for
	superedge::get_description returning a label_text.
	* engine.cc (feasibility_state::maybe_update_for_edge): Likewise.
	* supergraph.cc (superedge::dump): Likewise.
	(superedge::get_description): Convert return type from char * to
	label_text.
	* supergraph.h (superedge::get_description): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/analyzer/checker-path.cc |  3 +--
 gcc/analyzer/engine.cc       |  5 ++---
 gcc/analyzer/supergraph.cc   | 13 +++++--------
 gcc/analyzer/supergraph.h    |  2 +-
 4 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc
index 959ffdd853c..211cf3e0333 100644
--- a/gcc/analyzer/checker-path.cc
+++ b/gcc/analyzer/checker-path.cc
@@ -594,8 +594,7 @@ label_text
 start_cfg_edge_event::get_desc (bool can_colorize) const
 {
   bool user_facing = !flag_analyzer_verbose_edges;
-  label_text edge_desc
-    = label_text::take (m_sedge->get_description (user_facing));
+  label_text edge_desc (m_sedge->get_description (user_facing));
   if (user_facing)
     {
       if (edge_desc.m_buffer && strlen (edge_desc.m_buffer) > 0)
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 0674c8ba3b6..888123f2b95 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -4586,12 +4586,11 @@ feasibility_state::maybe_update_for_edge (logger *logger,
     {
       if (logger)
 	{
-	  char *desc = sedge->get_description (false);
+	  label_text desc (sedge->get_description (false));
 	  logger->log ("  sedge: SN:%i -> SN:%i %s",
 		       sedge->m_src->m_index,
 		       sedge->m_dest->m_index,
-		       desc);
-	  free (desc);
+		       desc.m_buffer);
 	}
 
       const gimple *last_stmt = src_point.get_supernode ()->get_last_stmt ();
diff --git a/gcc/analyzer/supergraph.cc b/gcc/analyzer/supergraph.cc
index f023c533a09..52b4852404d 100644
--- a/gcc/analyzer/supergraph.cc
+++ b/gcc/analyzer/supergraph.cc
@@ -854,13 +854,12 @@ void
 superedge::dump (pretty_printer *pp) const
 {
   pp_printf (pp, "edge: SN: %i -> SN: %i", m_src->m_index, m_dest->m_index);
-  char *desc = get_description (false);
-  if (strlen (desc) > 0)
+  label_text desc (get_description (false));
+  if (strlen (desc.m_buffer) > 0)
     {
       pp_space (pp);
-      pp_string (pp, desc);
+      pp_string (pp, desc.m_buffer);
     }
-  free (desc);
 }
 
 /* Dump this superedge to stderr.  */
@@ -998,17 +997,15 @@ superedge::get_any_callgraph_edge () const
 /* Build a description of this superedge (e.g. "true" for the true
    edge of a conditional, or "case 42:" for a switch case).
 
-   The caller is responsible for freeing the result.
-
    If USER_FACING is false, the result also contains any underlying
    CFG edge flags. e.g. " (flags FALLTHRU | DFS_BACK)".  */
 
-char *
+label_text
 superedge::get_description (bool user_facing) const
 {
   pretty_printer pp;
   dump_label_to_pp (&pp, user_facing);
-  return xstrdup (pp_formatted_text (&pp));
+  return label_text::take (xstrdup (pp_formatted_text (&pp)));
 }
 
 /* Implementation of superedge::dump_label_to_pp for non-switch CFG
diff --git a/gcc/analyzer/supergraph.h b/gcc/analyzer/supergraph.h
index 42c6df57435..e9a5be27d88 100644
--- a/gcc/analyzer/supergraph.h
+++ b/gcc/analyzer/supergraph.h
@@ -331,7 +331,7 @@ class superedge : public dedge<supergraph_traits>
   ::edge get_any_cfg_edge () const;
   cgraph_edge *get_any_callgraph_edge () const;
 
-  char *get_description (bool user_facing) const;
+  label_text get_description (bool user_facing) const;
 
  protected:
   superedge (supernode *src, supernode *dest, enum edge_kind kind)
-- 
2.26.3



More information about the Gcc-patches mailing list