public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4274] analyzer: eliminate region_model::on_ fns for sockets
@ 2022-11-24  1:46 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2022-11-24  1:46 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5d2908b7bf93051af0ea2be3323d17630f0e3f37

commit r13-4274-g5d2908b7bf93051af0ea2be3323d17630f0e3f37
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Wed Nov 23 20:43:32 2022 -0500

    analyzer: eliminate region_model::on_ fns for sockets
    
    This mostly mechanical patch eliminates a confusing extra layer of
    redundant calls in the handling of socket-related functions.
    
    gcc/analyzer/ChangeLog:
            * region-model.h (region_model::on_socket): Delete decl.
            (region_model::on_bind): Likewise.
            (region_model::on_listen): Likewise.
            (region_model::on_accept): Likewise.
            (region_model::on_connect): Likewise.
            * sm-fd.cc (kf_socket::outcome_of_socket::update_model): Move body
            of region_model::on_socket into here, ...
            (region_model::on_socket): ...eliminating this function.
            (kf_bind::outcome_of_bind::update_model): Likewise for on_bind...
            (region_model::on_bind): ...eliminating this function.
            (kf_listen::outcome_of_listen::update_model): Likewise fo
            on_listen...
            (region_model::on_listen): ...eliminating this function.
            (kf_accept::outcome_of_accept::update_model): Likewise fo
            on_accept...
            (region_model::on_accept): ...eliminating this function.
            (kf_connect::outcome_of_connect::update_model): Likewise fo
            on_connect...
            (region_model::on_connect): ...eliminating this function.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/region-model.h |   5 --
 gcc/analyzer/sm-fd.cc       | 144 +++++++++++++++-----------------------------
 2 files changed, 49 insertions(+), 100 deletions(-)

diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h
index 8e4616c28de..4413f5542d9 100644
--- a/gcc/analyzer/region-model.h
+++ b/gcc/analyzer/region-model.h
@@ -515,11 +515,6 @@ class region_model
 
   /* Implemented in sm-fd.cc  */
   void mark_as_valid_fd (const svalue *sval, region_model_context *ctxt);
-  bool on_socket (const call_details &cd, bool successful);
-  bool on_bind (const call_details &cd, bool successful);
-  bool on_listen (const call_details &cd, bool successful);
-  bool on_accept (const call_details &cd, bool successful);
-  bool on_connect (const call_details &cd, bool successful);
 
   /* Implemented in sm-malloc.cc  */
   void on_realloc_with_move (const call_details &cd,
diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc
index af59aef401d..8f8ec851bab 100644
--- a/gcc/analyzer/sm-fd.cc
+++ b/gcc/analyzer/sm-fd.cc
@@ -2270,7 +2270,16 @@ public:
 		       region_model_context *ctxt) const final override
     {
       const call_details cd (get_call_details (model, ctxt));
-      return cd.get_model ()->on_socket (cd, m_success);
+      sm_state_map *smap;
+      const fd_state_machine *fd_sm;
+      std::unique_ptr<sm_context> sm_ctxt;
+      if (!get_fd_state (ctxt, &smap, &fd_sm, NULL, &sm_ctxt))
+	return true;
+      const extrinsic_state *ext_state = ctxt->get_ext_state ();
+      if (!ext_state)
+	return true;
+
+      return fd_sm->on_socket (cd, m_success, sm_ctxt.get (), *ext_state);
     }
   };
 
@@ -2290,24 +2299,6 @@ public:
   }
 };
 
-/* Specialcase hook for handling "socket", for use by
-   kf_socket::outcome_of_socket::update_model.  */
-
-bool
-region_model::on_socket (const call_details &cd, bool successful)
-{
-  sm_state_map *smap;
-  const fd_state_machine *fd_sm;
-  std::unique_ptr<sm_context> sm_ctxt;
-  if (!get_fd_state (cd.get_ctxt (), &smap, &fd_sm, NULL, &sm_ctxt))
-    return true;
-  const extrinsic_state *ext_state = cd.get_ctxt ()->get_ext_state ();
-  if (!ext_state)
-    return true;
-
-  return fd_sm->on_socket (cd, successful, sm_ctxt.get (), *ext_state);
-}
-
 /* Handle calls to "bind".
    See e.g. https://man7.org/linux/man-pages/man3/bind.3p.html  */
 
@@ -2326,7 +2317,15 @@ public:
 		       region_model_context *ctxt) const final override
     {
       const call_details cd (get_call_details (model, ctxt));
-      return cd.get_model ()->on_bind (cd, m_success);
+      sm_state_map *smap;
+      const fd_state_machine *fd_sm;
+      std::unique_ptr<sm_context> sm_ctxt;
+      if (!get_fd_state (ctxt, &smap, &fd_sm, NULL, &sm_ctxt))
+	return true;
+      const extrinsic_state *ext_state = ctxt->get_ext_state ();
+      if (!ext_state)
+	return true;
+      return fd_sm->on_bind (cd, m_success, sm_ctxt.get (), *ext_state);
     }
   };
 
@@ -2346,24 +2345,6 @@ public:
   }
 };
 
-/* Specialcase hook for handling "bind", for use by
-   kf_bind::outcome_of_bind::update_model.  */
-
-bool
-region_model::on_bind (const call_details &cd, bool successful)
-{
-  sm_state_map *smap;
-  const fd_state_machine *fd_sm;
-  std::unique_ptr<sm_context> sm_ctxt;
-  if (!get_fd_state (cd.get_ctxt (), &smap, &fd_sm, NULL, &sm_ctxt))
-    return true;
-  const extrinsic_state *ext_state = cd.get_ctxt ()->get_ext_state ();
-  if (!ext_state)
-    return true;
-
-  return fd_sm->on_bind (cd, successful, sm_ctxt.get (), *ext_state);
-}
-
 /* Handle calls to "listen".
    See e.g. https://man7.org/linux/man-pages/man3/listen.3p.html  */
 
@@ -2381,7 +2362,16 @@ class kf_listen : public known_function
 		       region_model_context *ctxt) const final override
     {
       const call_details cd (get_call_details (model, ctxt));
-      return cd.get_model ()->on_listen (cd, m_success);
+      sm_state_map *smap;
+      const fd_state_machine *fd_sm;
+      std::unique_ptr<sm_context> sm_ctxt;
+      if (!get_fd_state (ctxt, &smap, &fd_sm, NULL, &sm_ctxt))
+	return true;
+      const extrinsic_state *ext_state = ctxt->get_ext_state ();
+      if (!ext_state)
+	return true;
+
+      return fd_sm->on_listen (cd, m_success, sm_ctxt.get (), *ext_state);
     }
   };
 
@@ -2401,24 +2391,6 @@ class kf_listen : public known_function
   }
 };
 
-/* Specialcase hook for handling "listen", for use by
-   kf_listen::outcome_of_listen::update_model.  */
-
-bool
-region_model::on_listen (const call_details &cd, bool successful)
-{
-  sm_state_map *smap;
-  const fd_state_machine *fd_sm;
-  std::unique_ptr<sm_context> sm_ctxt;
-  if (!get_fd_state (cd.get_ctxt (), &smap, &fd_sm, NULL, &sm_ctxt))
-    return true;
-  const extrinsic_state *ext_state = cd.get_ctxt ()->get_ext_state ();
-  if (!ext_state)
-    return true;
-
-  return fd_sm->on_listen (cd, successful, sm_ctxt.get (), *ext_state);
-}
-
 /* Handle calls to "accept".
    See e.g. https://man7.org/linux/man-pages/man3/accept.3p.html  */
 
@@ -2436,7 +2408,16 @@ class kf_accept : public known_function
 		       region_model_context *ctxt) const final override
     {
       const call_details cd (get_call_details (model, ctxt));
-      return cd.get_model ()->on_accept (cd, m_success);
+      sm_state_map *smap;
+      const fd_state_machine *fd_sm;
+      std::unique_ptr<sm_context> sm_ctxt;
+      if (!get_fd_state (ctxt, &smap, &fd_sm, NULL, &sm_ctxt))
+	return true;
+      const extrinsic_state *ext_state = ctxt->get_ext_state ();
+      if (!ext_state)
+	return true;
+
+      return fd_sm->on_accept (cd, m_success, sm_ctxt.get (), *ext_state);
     }
   };
 
@@ -2458,24 +2439,6 @@ class kf_accept : public known_function
   }
 };
 
-/* Specialcase hook for handling "accept", for use by
-   kf_accept::outcome_of_accept::update_model.  */
-
-bool
-region_model::on_accept (const call_details &cd, bool successful)
-{
-  sm_state_map *smap;
-  const fd_state_machine *fd_sm;
-  std::unique_ptr<sm_context> sm_ctxt;
-  if (!get_fd_state (cd.get_ctxt (), &smap, &fd_sm, NULL, &sm_ctxt))
-    return true;
-  const extrinsic_state *ext_state = cd.get_ctxt ()->get_ext_state ();
-  if (!ext_state)
-    return true;
-
-  return fd_sm->on_accept (cd, successful, sm_ctxt.get (), *ext_state);
-}
-
 /* Handle calls to "connect".
    See e.g. https://man7.org/linux/man-pages/man3/connect.3p.html  */
 
@@ -2494,7 +2457,16 @@ public:
 		       region_model_context *ctxt) const final override
     {
       const call_details cd (get_call_details (model, ctxt));
-      return cd.get_model ()->on_connect (cd, m_success);
+      sm_state_map *smap;
+      const fd_state_machine *fd_sm;
+      std::unique_ptr<sm_context> sm_ctxt;
+      if (!get_fd_state (ctxt, &smap, &fd_sm, NULL, &sm_ctxt))
+	return true;
+      const extrinsic_state *ext_state = ctxt->get_ext_state ();
+      if (!ext_state)
+	return true;
+
+      return fd_sm->on_connect (cd, m_success, sm_ctxt.get (), *ext_state);
     }
   };
 
@@ -2515,24 +2487,6 @@ public:
   }
 };
 
-/* Specialcase hook for handling "connect", for use by
-   kf_connect::outcome_of_connect::update_model.  */
-
-bool
-region_model::on_connect (const call_details &cd, bool successful)
-{
-  sm_state_map *smap;
-  const fd_state_machine *fd_sm;
-  std::unique_ptr<sm_context> sm_ctxt;
-  if (!get_fd_state (cd.get_ctxt (), &smap, &fd_sm, NULL, &sm_ctxt))
-    return true;
-  const extrinsic_state *ext_state = cd.get_ctxt ()->get_ext_state ();
-  if (!ext_state)
-    return true;
-
-  return fd_sm->on_connect (cd, successful, sm_ctxt.get (), *ext_state);
-}
-
 /* Handler for calls to "pipe" and "pipe2".
    See e.g. https://www.man7.org/linux/man-pages/man2/pipe.2.html  */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-24  1:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-24  1:46 [gcc r13-4274] analyzer: eliminate region_model::on_ fns for sockets David Malcolm

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).