From b9b5fc0c2175b34131d9fd0805b1b307f754f4f0 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 15 Sep 2020 14:25:52 -0400 Subject: [PATCH] analyzer: add program_point::get_next Avoid some future copy-and-paste by introducing a function. gcc/analyzer/ChangeLog: * engine.cc (exploded_graph::process_node) : Simplify by using program_point::get_next. * program-point.cc (program_point::get_next): New. * program-point.h (program_point::get_next): New decl. --- gcc/analyzer/engine.cc | 24 ++++-------------------- gcc/analyzer/program-point.cc | 29 +++++++++++++++++++++++++++++ gcc/analyzer/program-point.h | 2 ++ 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 8f5c5143ca5..5903b19b774 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -2458,26 +2458,10 @@ exploded_graph::process_node (exploded_node *node) &ctxt); } - if (point.get_supernode ()->m_stmts.length () > 0) - { - program_point next_point - = program_point::before_stmt (point.get_supernode (), 0, - point.get_call_string ()); - exploded_node *next - = get_or_create_node (next_point, next_state, node); - if (next) - add_edge (node, next, NULL); - } - else - { - program_point next_point - = program_point::after_supernode (point.get_supernode (), - point.get_call_string ()); - exploded_node *next = get_or_create_node (next_point, next_state, - node); - if (next) - add_edge (node, next, NULL); - } + program_point next_point (point.get_next ()); + exploded_node *next = get_or_create_node (next_point, next_state, node); + if (next) + add_edge (node, next, NULL); } break; case PK_BEFORE_STMT: diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-point.cc index 2c0a4c42bf5..ef19e6e38e5 100644 --- a/gcc/analyzer/program-point.cc +++ b/gcc/analyzer/program-point.cc @@ -529,6 +529,35 @@ function_point::next_stmt () } } +/* For those program points for which there is a uniquely-defined + successor, return it. */ + +program_point +program_point::get_next () const +{ + switch (m_function_point.get_kind ()) + { + default: + gcc_unreachable (); + case PK_ORIGIN: + case PK_AFTER_SUPERNODE: + gcc_unreachable (); /* Not uniquely defined. */ + case PK_BEFORE_SUPERNODE: + if (get_supernode ()->m_stmts.length () > 0) + return before_stmt (get_supernode (), 0, get_call_string ()); + else + return after_supernode (get_supernode (), get_call_string ()); + case PK_BEFORE_STMT: + { + unsigned next_idx = get_stmt_idx (); + if (next_idx < get_supernode ()->m_stmts.length ()) + return before_stmt (get_supernode (), next_idx, get_call_string ()); + else + return after_supernode (get_supernode (), get_call_string ()); + } + } +} + #if CHECKING_P namespace selftest { diff --git a/gcc/analyzer/program-point.h b/gcc/analyzer/program-point.h index cb11478468d..97fd0a5e9de 100644 --- a/gcc/analyzer/program-point.h +++ b/gcc/analyzer/program-point.h @@ -294,6 +294,8 @@ public: /* For before_stmt, go to next stmt. */ void next_stmt () { m_function_point.next_stmt (); } + program_point get_next () const; + private: function_point m_function_point; call_string m_call_string; -- 2.30.2