public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4248] analyzer: fix ICE on 'bind(INT_CST, ...)' [PR107783]
@ 2022-11-22 22:32 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2022-11-22 22:32 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:64fb291c5839e1a82afb62743172b4eab1267399
commit r13-4248-g64fb291c5839e1a82afb62743172b4eab1267399
Author: David Malcolm <dmalcolm@redhat.com>
Date: Tue Nov 22 17:29:21 2022 -0500
analyzer: fix ICE on 'bind(INT_CST, ...)' [PR107783]
This was crashing inside fd_phase_mismatch's ctor with assertion
failure when the state was "fd-constant".
Fix the ICE by not complaining about constants passed to these APIs.
gcc/analyzer/ChangeLog:
PR analyzer/107783
* sm-fd.cc (fd_state_machine::check_for_new_socket_fd): Don't
complain when old state is "fd-constant".
(fd_state_machine::on_listen): Likewise.
(fd_state_machine::on_accept): Likewise.
gcc/testsuite/ChangeLog:
PR analyzer/107783
* gcc.dg/analyzer/fd-accept.c (test_accept_on_constant): New.
* gcc.dg/analyzer/fd-bind.c (test_bind_on_constant): New.
* gcc.dg/analyzer/fd-connect.c (test_connect_on_constant): New.
* gcc.dg/analyzer/fd-listen.c (test_listen_on_connected_socket):
Fix typo.
(test_listen_on_constant): New.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diff:
---
gcc/analyzer/sm-fd.cc | 9 ++++++---
gcc/testsuite/gcc.dg/analyzer/fd-accept.c | 5 +++++
gcc/testsuite/gcc.dg/analyzer/fd-bind.c | 5 +++++
gcc/testsuite/gcc.dg/analyzer/fd-connect.c | 5 +++++
gcc/testsuite/gcc.dg/analyzer/fd-listen.c | 7 ++++++-
5 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc
index 3e500575428..f7779be7d26 100644
--- a/gcc/analyzer/sm-fd.cc
+++ b/gcc/analyzer/sm-fd.cc
@@ -1798,7 +1798,8 @@ fd_state_machine::check_for_new_socket_fd (const call_details &cd,
|| old_state == m_new_datagram_socket
|| old_state == m_new_unknown_socket
|| old_state == m_start
- || old_state == m_stop))
+ || old_state == m_stop
+ || old_state == m_constant_fd))
{
/* Complain about "bind" or "connect" in wrong phase. */
tree diag_arg = sm_ctxt->get_diagnostic_tree (fd_sval);
@@ -1900,6 +1901,7 @@ fd_state_machine::on_listen (const call_details &cd,
if (!check_for_socket_fd (cd, successful, sm_ctxt, fd_sval, node, old_state))
return false;
if (!(old_state == m_start
+ || old_state == m_constant_fd
|| old_state == m_stop
|| old_state == m_bound_stream_socket
|| old_state == m_bound_unknown_socket
@@ -2015,8 +2017,9 @@ fd_state_machine::on_accept (const call_details &cd,
if (!check_for_socket_fd (cd, successful, sm_ctxt, fd_sval, node, old_state))
return false;
- if (old_state == m_start)
- /* If we were in the start state, assume we had the expected state. */
+ if (old_state == m_start || old_state == m_constant_fd)
+ /* If we were in the start state (or a constant), assume we had the
+ expected state. */
sm_ctxt->set_next_state (cd.get_call_stmt (), fd_sval,
m_listening_stream_socket);
else if (old_state == m_stop)
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-accept.c b/gcc/testsuite/gcc.dg/analyzer/fd-accept.c
index 5426063f31d..1b25012624b 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-accept.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-accept.c
@@ -69,3 +69,8 @@ int test_accept_on_accept (int fd_a)
return fd_b;
}
+
+int test_accept_on_constant ()
+{
+ return accept (0, NULL, 0);
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-bind.c b/gcc/testsuite/gcc.dg/analyzer/fd-bind.c
index c34803f1380..d027b1a6b51 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-bind.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-bind.c
@@ -74,3 +74,8 @@ void test_bind_after_accept (int fd, const char *sockname)
close (afd);
}
+
+int test_bind_on_constant ()
+{
+ return bind (0, NULL, 0);
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-connect.c b/gcc/testsuite/gcc.dg/analyzer/fd-connect.c
index 7bf687e2570..ad837c93f4b 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-connect.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-connect.c
@@ -46,3 +46,8 @@ void test_connect_after_bind (const char *sockname,
close (fd);
}
+
+int test_connect_on_constant ()
+{
+ return connect (0, NULL, 0);
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-listen.c b/gcc/testsuite/gcc.dg/analyzer/fd-listen.c
index becf4690293..a241113e3f0 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-listen.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-listen.c
@@ -54,7 +54,7 @@ void test_listen_on_new_datagram_socket (void)
close (fd);
}
-void test_listed_on_connected_socket (int fd)
+void test_listen_on_connected_socket (int fd)
{
int afd = accept (fd, NULL, 0);
if (afd == -1)
@@ -63,3 +63,8 @@ void test_listed_on_connected_socket (int fd)
/* { dg-message "'listen' expects a bound stream socket file descriptor but 'afd' is connected" "final event" { target *-*-* } .-1 } */
close (afd);
}
+
+int test_listen_on_constant ()
+{
+ return listen (0, 10);
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-22 22:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 22:32 [gcc r13-4248] analyzer: fix ICE on 'bind(INT_CST, ...)' [PR107783] 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).