From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id CCD5F385841A for ; Tue, 22 Nov 2022 22:37:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CCD5F385841A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669156624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sBGVhQiFXNZTQTZ8FBWPtrcCU+mRWBtE3bRJMHU946E=; b=CjMdfnwOaa2ZRyl0XHh7rk08xkMO+agehTrSEn1A/wIBXa720LSau5++g5AprwNgHg7YuO Nr0m3BfhtOKcdUoq3noLYsmI3OAxwSeNeAmaHEnaqMJHCs9dHfj1LCMYPItk3TX5NeRe81 12PQ5Y1h7hEFeS1oO1su7TWbiAzzqyc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-37-Q2mfz0NQOLCzNr_CMujkfA-1; Tue, 22 Nov 2022 17:37:03 -0500 X-MC-Unique: Q2mfz0NQOLCzNr_CMujkfA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02BBF1C05AB5 for ; Tue, 22 Nov 2022 22:37:03 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0A051121325; Tue, 22 Nov 2022 22:37:02 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] analyzer: fix ICE on 'bind(INT_CST, ...)' [PR107783] Date: Tue, 22 Nov 2022 17:36:59 -0500 Message-Id: <20221122223659.3308837-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r13-4248-g64fb291c5839e1. 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 --- 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 36cc7af7184..e56caaca6af 100644 --- a/gcc/testsuite/gcc.dg/analyzer/fd-accept.c +++ b/gcc/testsuite/gcc.dg/analyzer/fd-accept.c @@ -67,3 +67,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 6f91bc4b794..fa69ca4c0f8 100644 --- a/gcc/testsuite/gcc.dg/analyzer/fd-bind.c +++ b/gcc/testsuite/gcc.dg/analyzer/fd-bind.c @@ -72,3 +72,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 1ab54d01f36..5b1c335ba76 100644 --- a/gcc/testsuite/gcc.dg/analyzer/fd-connect.c +++ b/gcc/testsuite/gcc.dg/analyzer/fd-connect.c @@ -44,3 +44,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 1f54a8f2953..31eb90d6cb3 100644 --- a/gcc/testsuite/gcc.dg/analyzer/fd-listen.c +++ b/gcc/testsuite/gcc.dg/analyzer/fd-listen.c @@ -52,7 +52,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) @@ -61,3 +61,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); +} -- 2.26.3