From patchwork Tue Nov 22 00:14:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 60953 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B67F384F6CB for ; Tue, 22 Nov 2022 00:16:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B67F384F6CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669076173; bh=1LggxQZ+PJMBEILm12kNmOXDWfkKiWJNMonTwmlxzF0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=xrSNjjq+TZhGh3v1PWaZ/nAiFkUyy7MIRYvVknEJ1TD250zhbzd6W86nyGwIipRmh jpYobw8YGrRnKU0MoLwPkhcTtPc4PxXZtIqJGJ2ygdumso4BORhywbJcYLzpt85DMF DME0wPKhhJF4/an2gw9dAcj2l8/w/KaHaCDtbas4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C1EF3384F4B3 for ; Tue, 22 Nov 2022 00:14:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C1EF3384F4B3 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-114-ThBsQH5lPi-f2RTvZqLg0g-1; Mon, 21 Nov 2022 19:14:50 -0500 X-MC-Unique: ThBsQH5lPi-f2RTvZqLg0g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1753833AEC for ; Tue, 22 Nov 2022 00:14:49 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFB1D1410DD9; Tue, 22 Nov 2022 00:14:49 +0000 (UTC) To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] analyzer: fix ICE on 'bind' with non-pointer arg [P107783] Date: Mon, 21 Nov 2022 19:14:46 -0500 Message-Id: <20221122001446.3254636-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r13-4220-g12a4785c9120be. 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 --- 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(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/fd-bind-pr107783.c 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'" } */ +}