public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-4220] analyzer: fix ICE on 'bind' with non-pointer arg [P107783]
Date: Tue, 22 Nov 2022 00:10:13 +0000 (GMT)	[thread overview]
Message-ID: <20221122001013.91033384F48B@sourceware.org> (raw)

https://gcc.gnu.org/g:12a4785c9120beeef42f1bded52cc2674e206f57

commit r13-4220-g12a4785c9120beeef42f1bded52cc2674e206f57
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Mon Nov 21 19:08:17 2022 -0500

    analyzer: fix ICE on 'bind' with non-pointer arg [P107783]
    
    gcc/analyzer/ChangeLog:
            PR analyzer/107783
            * region-model-impl-calls.cc (kf_accept::matches_call_types_p):
            Require that args 1 and 2 be pointers.
            (kf_bind::matches_call_types_p): Require that arg 1 be a pointer.
            * region-model.h (call_details::arg_is_pointer_p): New
    
    gcc/testsuite/ChangeLog:
            PR analyzer/107783
            * gcc.dg/analyzer/fd-bind-pr107783.c: New test.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/region-model-impl-calls.cc          | 6 ++++--
 gcc/analyzer/region-model.h                      | 4 ++++
 gcc/testsuite/gcc.dg/analyzer/fd-bind-pr107783.c | 5 +++++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/analyzer/region-model-impl-calls.cc b/gcc/analyzer/region-model-impl-calls.cc
index a71eb3de98f..8a44c97eec9 100644
--- a/gcc/analyzer/region-model-impl-calls.cc
+++ b/gcc/analyzer/region-model-impl-calls.cc
@@ -595,7 +595,9 @@ class kf_accept : public known_function
 
   bool matches_call_types_p (const call_details &cd) const final override
   {
-    return cd.num_args () == 3;
+    return (cd.num_args () == 3
+	    && cd.arg_is_pointer_p (1)
+	    && cd.arg_is_pointer_p (2));
   }
 
   void impl_call_post (const call_details &cd) const final override
@@ -633,7 +635,7 @@ public:
 
   bool matches_call_types_p (const call_details &cd) const final override
   {
-    return cd.num_args () == 3;
+    return (cd.num_args () == 3 && cd.arg_is_pointer_p (1));
   }
 
   void impl_call_post (const call_details &cd) const final override
diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h
index c828d739482..244780eb4f4 100644
--- a/gcc/analyzer/region-model.h
+++ b/gcc/analyzer/region-model.h
@@ -256,6 +256,10 @@ public:
   bool maybe_set_lhs (const svalue *result) const;
 
   unsigned num_args () const;
+  bool arg_is_pointer_p (unsigned idx) const
+  {
+    return POINTER_TYPE_P (get_arg_type (idx));
+  }
 
   const gcall *get_call_stmt () const { return m_call; }
   location_t get_location () const;
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-bind-pr107783.c b/gcc/testsuite/gcc.dg/analyzer/fd-bind-pr107783.c
new file mode 100644
index 00000000000..36304179b43
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-bind-pr107783.c
@@ -0,0 +1,5 @@
+int
+foo (void)
+{
+  return bind (0, 0, 0); /* { dg-warning "implicit declaration of function 'bind'" } */
+}

                 reply	other threads:[~2022-11-22  0:10 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=20221122001013.91033384F48B@sourceware.org \
    --to=dmalcolm@gcc.gnu.org \
    --cc=gcc-cvs@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).