From 595718cdb0264379c182782a003f3297c467c7a9 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 1 Apr 2026 18:15:25 -0400 Subject: [PATCH 34/98] FIXME: more on dataflow events: use std::vector in exploded_path --- gcc/analyzer/common.h | 1 + gcc/analyzer/diagnostic-manager.cc | 6 +++--- gcc/analyzer/engine.cc | 16 +++++++--------- gcc/analyzer/exploded-path.cc | 21 ++++++++++++++------- gcc/analyzer/exploded-path.h | 15 ++++++--------- gcc/analyzer/feasible-graph.cc | 4 ++-- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/gcc/analyzer/common.h b/gcc/analyzer/common.h index a5e81bd2d31a..b20adb26fe77 100644 --- a/gcc/analyzer/common.h +++ b/gcc/analyzer/common.h @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see #define GCC_ANALYZER_COMMON_H #include "config.h" +#define INCLUDE_ALGORITHM #define INCLUDE_LIST #define INCLUDE_MAP #define INCLUDE_SET diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index 33517581fdaf..d50d656b687c 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -1656,7 +1656,7 @@ diagnostic_manager::annotate_exploded_path (const path_builder &pb, interesting_t interest; pb.get_pending_diagnostic ()->mark_interesting_stuff (&interest); - gcc_assert (epath.m_elements.length () > 0); + gcc_assert (epath.m_elements.size () > 0); eedge_annotation curr_annotation; @@ -1664,7 +1664,7 @@ diagnostic_manager::annotate_exploded_path (const path_builder &pb, curr_annotation.m_region_holding_value = interest.m_read_regions[0]; // Walk epath backwards, propagating annotation information - for (int idx = epath.m_elements.length () - 1; idx > 0; --idx) + for (int idx = epath.m_elements.size () - 1; idx >= 0; --idx) { exploded_path::element_t &iter_element = epath.m_elements[idx]; if (logger) @@ -1758,7 +1758,7 @@ diagnostic_manager::build_emission_path (const path_builder &pb, } /* Walk EPATH, adding events as appropriate. */ - for (unsigned i = 0; i < epath.m_elements.length (); i++) + for (unsigned i = 0; i < epath.m_elements.size (); ++i) { const exploded_edge *eedge = epath.m_elements[i].m_eedge; gcc_assert (eedge); diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 181798973e04..3f9e89532909 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -308,7 +308,7 @@ public: after the SSA name was set? (if any). */ for (unsigned idx = idx_of_def_stmt + 1; - idx < epath.m_elements.length (); + idx < epath.m_elements.size (); ++idx) { const exploded_edge *eedge = epath.m_elements[idx].m_eedge; @@ -352,11 +352,10 @@ public: retval = gimple_return_retval (return_stmt); log_scope sentinel (logger, "walking backward along epath"); - int idx; - exploded_path::element_t *element; - FOR_EACH_VEC_ELT_REVERSE (epath.m_elements, idx, element) + for (int idx = epath.m_elements.size (); idx >= 0; --idx) { - const exploded_edge *eedge = element->m_eedge; + const exploded_path::element_t &element = epath.m_elements[idx]; + const exploded_edge *eedge = element.m_eedge; if (logger) { logger->log ("eedge[%i]: EN %i -> EN %i", @@ -404,11 +403,10 @@ private: { LOG_SCOPE (logger); - int idx; - exploded_path::element_t *element; - FOR_EACH_VEC_ELT_REVERSE (epath.m_elements, idx, element) + for (int idx = epath.m_elements.size (); idx >= 0; --idx) { - const exploded_edge *eedge = element->m_eedge; + const exploded_path::element_t &element = epath.m_elements[idx]; + const exploded_edge *eedge = element.m_eedge; if (eedge->m_src->get_stack_depth () != eedge->m_dest->get_stack_depth ()) { diff --git a/gcc/analyzer/exploded-path.cc b/gcc/analyzer/exploded-path.cc index 44d4a2b8cf26..71c204d39225 100644 --- a/gcc/analyzer/exploded-path.cc +++ b/gcc/analyzer/exploded-path.cc @@ -47,6 +47,7 @@ eedge_annotation::dump () const /* Copy ctor. */ +#if 0 exploded_path::exploded_path (const exploded_path &other) : m_elements (other.m_elements.length ()) { @@ -55,6 +56,7 @@ exploded_path::exploded_path (const exploded_path &other) FOR_EACH_VEC_ELT (other.m_elements, i, element) m_elements.quick_push (*element); } +#endif /* Look for the last use of SEARCH_STMT within this path. If found write the edge's index to *OUT_IDX and return true, otherwise @@ -64,10 +66,9 @@ bool exploded_path::find_stmt_backwards (const gimple *search_stmt, int *out_idx) const { - int i; - element_t *element; - FOR_EACH_VEC_ELT_REVERSE (m_elements, i, element) + for (int i = m_elements.size () - 1; i >= 0; --i) { + const element_t *element = &m_elements[i]; const exploded_edge *eedge = element->m_eedge; if (search_stmt->code == GIMPLE_PHI) { @@ -100,8 +101,8 @@ exploded_path::find_stmt_backwards (const gimple *search_stmt, exploded_node * exploded_path::get_final_enode () const { - gcc_assert (m_elements.length () > 0); - return m_elements[m_elements.length () - 1].m_eedge->m_dest; + gcc_assert (m_elements.size () > 0); + return m_elements.back ().m_eedge->m_dest; } /* Check state along this path, returning true if it is feasible. @@ -119,7 +120,7 @@ exploded_path::feasible_p (logger *logger, eg->get_supergraph ()); /* Traverse the path, updating this state. */ - for (unsigned edge_idx = 0; edge_idx < m_elements.length (); edge_idx++) + for (unsigned edge_idx = 0; edge_idx < m_elements.size (); ++edge_idx) { const exploded_edge *eedge = m_elements[edge_idx].m_eedge; if (logger) @@ -160,7 +161,7 @@ void exploded_path::dump_to_pp (pretty_printer *pp, const extrinsic_state *ext_state) const { - for (unsigned i = 0; i < m_elements.length (); i++) + for (unsigned i = 0; i < m_elements.size (); ++i) { const element_t &element = m_elements[i]; const exploded_edge *eedge = element.m_eedge; @@ -210,6 +211,12 @@ exploded_path::dump_to_file (const char *filename, fclose (fp); } +void +exploded_path::reverse () +{ + std::reverse (m_elements.begin (), m_elements.end ()); +} + } // namespace ana #endif /* #if ENABLE_ANALYZER */ diff --git a/gcc/analyzer/exploded-path.h b/gcc/analyzer/exploded-path.h index 157998e52edd..cfa7513b2554 100644 --- a/gcc/analyzer/exploded-path.h +++ b/gcc/analyzer/exploded-path.h @@ -42,10 +42,10 @@ public: eedge_annotation m_annotation_at_dst; }; - exploded_path () : m_elements () {} - exploded_path (const exploded_path &other); + exploded_path () = default; + exploded_path (const exploded_path &other) = default; - unsigned length () const { return m_elements.length (); } + unsigned length () const { return m_elements.size (); } bool find_stmt_backwards (const gimple *search_stmt, int *out_idx) const; @@ -65,16 +65,13 @@ public: void append_edge (const exploded_edge *edge) { - m_elements.safe_push (edge); + m_elements.push_back (edge); } void - reverse () - { - m_elements.reverse (); - } + reverse (); - auto_vec m_elements; + std::vector m_elements; }; /* Finding the shortest exploded_path within an exploded_graph. */ diff --git a/gcc/analyzer/feasible-graph.cc b/gcc/analyzer/feasible-graph.cc index e6513cd4e2a5..37ba84d012c7 100644 --- a/gcc/analyzer/feasible-graph.cc +++ b/gcc/analyzer/feasible-graph.cc @@ -187,12 +187,12 @@ feasible_graph::make_epath (feasible_node *fnode) const gcc_assert (fnode->m_preds.length () == 1); feasible_edge *pred_fedge = static_cast (fnode->m_preds[0]); - epath->m_elements.safe_push (pred_fedge->get_inner_edge ()); + epath->m_elements.push_back (pred_fedge->get_inner_edge ()); fnode = static_cast (pred_fedge->m_src); } /* Now reverse it. */ - epath->m_elements.reverse (); + epath->reverse (); return epath; } -- 2.49.0