From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [committed] analyzer: simplify sm_state_map lookup
Date: Mon, 24 Oct 2022 16:53:12 -0400 [thread overview]
Message-ID: <20221024205312.1760173-1-dmalcolm@redhat.com> (raw)
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r13-3467-g53881c47e4b357.
gcc/analyzer/ChangeLog:
* engine.cc (impl_region_model_context::get_malloc_map): Replace
with...
(impl_region_model_context::get_state_map_by_name): ...this.
(impl_region_model_context::get_fd_map): Delete.
(impl_region_model_context::get_taint_map): Delete.
* exploded-graph.h (impl_region_model_context::get_fd_map):
Delete.
(impl_region_model_context::get_malloc_map): Delete.
(impl_region_model_context::get_taint_map): Delete.
(impl_region_model_context::get_state_map_by_name): New.
* region-model.h (region_model_context::get_state_map_by_name):
New vfunc.
(region_model_context::get_fd_map): Convert from vfunc to
function.
(region_model_context::get_malloc_map): Likewise.
(region_model_context::get_taint_map): Likewise.
(noop_region_model_context::get_state_map_by_name): New.
(noop_region_model_context::get_fd_map): Delete.
(noop_region_model_context::get_malloc_map): Delete.
(noop_region_model_context::get_taint_map): Delete.
(region_model_context_decorator::get_state_map_by_name): New.
(region_model_context_decorator::get_fd_map): Delete.
(region_model_context_decorator::get_malloc_map): Delete.
(region_model_context_decorator::get_taint_map): Delete.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
gcc/analyzer/engine.cc | 47 ++++----------------
gcc/analyzer/exploded-graph.h | 13 ++----
gcc/analyzer/region-model.h | 80 +++++++++++++++--------------------
3 files changed, 48 insertions(+), 92 deletions(-)
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index a664a99eb78..52978dd0d37 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -214,50 +214,21 @@ impl_region_model_context::terminate_path ()
}
bool
-impl_region_model_context::get_malloc_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx)
-{
- unsigned malloc_sm_idx;
- if (!m_ext_state.get_sm_idx_by_name ("malloc", &malloc_sm_idx))
- return false;
-
- *out_smap = m_new_state->m_checker_states[malloc_sm_idx];
- *out_sm = &m_ext_state.get_sm (malloc_sm_idx);
- *out_sm_idx = malloc_sm_idx;
- return true;
-}
-
-bool
-impl_region_model_context::get_fd_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx)
-{
- unsigned fd_sm_idx;
- if (!m_ext_state.get_sm_idx_by_name ("file-descriptor", &fd_sm_idx))
- return false;
-
- *out_smap = m_new_state->m_checker_states[fd_sm_idx];
- *out_sm = &m_ext_state.get_sm (fd_sm_idx);
- *out_sm_idx = fd_sm_idx;
- return true;
-}
-
-bool
-impl_region_model_context::get_taint_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx)
+impl_region_model_context::get_state_map_by_name (const char *name,
+ sm_state_map **out_smap,
+ const state_machine **out_sm,
+ unsigned *out_sm_idx)
{
if (!m_new_state)
return false;
- unsigned taint_sm_idx;
- if (!m_ext_state.get_sm_idx_by_name ("taint", &taint_sm_idx))
+ unsigned sm_idx;
+ if (!m_ext_state.get_sm_idx_by_name (name, &sm_idx))
return false;
- *out_smap = m_new_state->m_checker_states[taint_sm_idx];
- *out_sm = &m_ext_state.get_sm (taint_sm_idx);
- *out_sm_idx = taint_sm_idx;
+ *out_smap = m_new_state->m_checker_states[sm_idx];
+ *out_sm = &m_ext_state.get_sm (sm_idx);
+ *out_sm_idx = sm_idx;
return true;
}
diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h
index ad278e277dc..5996252f1fb 100644
--- a/gcc/analyzer/exploded-graph.h
+++ b/gcc/analyzer/exploded-graph.h
@@ -96,15 +96,10 @@ class impl_region_model_context : public region_model_context
{
return &m_ext_state;
}
- bool get_fd_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx) final override;
- bool get_malloc_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx) final override;
- bool get_taint_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx) final override;
+ bool get_state_map_by_name (const char *name,
+ sm_state_map **out_smap,
+ const state_machine **out_sm,
+ unsigned *out_sm_idx) override;
const gimple *get_stmt () const override { return m_stmt; }
diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h
index d849e0d774b..19e8043daa4 100644
--- a/gcc/analyzer/region-model.h
+++ b/gcc/analyzer/region-model.h
@@ -737,19 +737,33 @@ class region_model_context
virtual const extrinsic_state *get_ext_state () const = 0;
- /* Hook for clients to access the "fd" state machine in
+ /* Hook for clients to access the a specific state machine in
any underlying program_state. */
- virtual bool get_fd_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx) = 0;
- /* Likewise for the "malloc" state machine. */
- virtual bool get_malloc_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx) = 0;
- /* Likewise for the "taint" state machine. */
- virtual bool get_taint_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx) = 0;
+ virtual bool get_state_map_by_name (const char *name,
+ sm_state_map **out_smap,
+ const state_machine **out_sm,
+ unsigned *out_sm_idx) = 0;
+
+ /* Precanned ways for clients to access specific state machines. */
+ bool get_fd_map (sm_state_map **out_smap,
+ const state_machine **out_sm,
+ unsigned *out_sm_idx)
+ {
+ return get_state_map_by_name ("file-descriptor", out_smap, out_sm,
+ out_sm_idx);
+ }
+ bool get_malloc_map (sm_state_map **out_smap,
+ const state_machine **out_sm,
+ unsigned *out_sm_idx)
+ {
+ return get_state_map_by_name ("malloc", out_smap, out_sm, out_sm_idx);
+ }
+ bool get_taint_map (sm_state_map **out_smap,
+ const state_machine **out_sm,
+ unsigned *out_sm_idx)
+ {
+ return get_state_map_by_name ("taint", out_smap, out_sm, out_sm_idx);
+ }
/* Get the current statement, if any. */
virtual const gimple *get_stmt () const = 0;
@@ -796,21 +810,10 @@ public:
const extrinsic_state *get_ext_state () const override { return NULL; }
- bool get_fd_map (sm_state_map **,
- const state_machine **,
- unsigned *) override
- {
- return false;
- }
- bool get_malloc_map (sm_state_map **,
- const state_machine **,
- unsigned *) override
- {
- return false;
- }
- bool get_taint_map (sm_state_map **,
- const state_machine **,
- unsigned *) override
+ bool get_state_map_by_name (const char *,
+ sm_state_map **,
+ const state_machine **,
+ unsigned *) override
{
return false;
}
@@ -929,25 +932,12 @@ class region_model_context_decorator : public region_model_context
return m_inner->get_ext_state ();
}
- bool get_fd_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx) override
- {
- return m_inner->get_fd_map (out_smap, out_sm, out_sm_idx);
- }
-
- bool get_malloc_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx) override
- {
- return m_inner->get_malloc_map (out_smap, out_sm, out_sm_idx);
- }
-
- bool get_taint_map (sm_state_map **out_smap,
- const state_machine **out_sm,
- unsigned *out_sm_idx) override
+ bool get_state_map_by_name (const char *name,
+ sm_state_map **out_smap,
+ const state_machine **out_sm,
+ unsigned *out_sm_idx) override
{
- return m_inner->get_taint_map (out_smap, out_sm, out_sm_idx);
+ return m_inner->get_state_map_by_name (name, out_smap, out_sm, out_sm_idx);
}
const gimple *get_stmt () const override
--
2.26.3
reply other threads:[~2022-10-24 20:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221024205312.1760173-1-dmalcolm@redhat.com \
--to=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).