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: 24061 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1910533wrr; Mon, 21 Nov 2022 16:16:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf5vnAMmJ8VJkGrSS29YY51HZpSnOzRZM1CEXxEnJywgYBZTmUUsjYxPdq/1IG88ugz8MNre X-Received: by 2002:aa7:d408:0:b0:468:677a:877 with SMTP id z8-20020aa7d408000000b00468677a0877mr18458508edq.407.1669076215599; Mon, 21 Nov 2022 16:16:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669076215; cv=none; d=google.com; s=arc-20160816; b=NkJ2VcX8eIIpPYrm0UCUIuKjjqxX3UAwrtXrPsFGimq9JuVBpYKDo3SmoqKiZT0P09 VLgXtIxDz6PSzJkrOOD2czPg4TxuiWK6YIhXyffxEPMSauTxE6PwFbzH18CnrExI+lDx sOAUwMT5564Z3ngMEuMGom+8PghSuSfRrp1FzVP1PR/tSCnMQ7tOv9QFsm/uM4cSYMjs bMv4wss1Nqt4CeBA4Zkrqvx9xX/U4/CX4VhfgQ4j+91tcBMmBAVcCk9JBvqbU0RDU2q/ 2BVZu/s1RThVxGlxSFwUqQ01X0yIxrw03IIhLqjHeaQJKioz1CoGamJS6WcIw6dxm9dU H8OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=1LggxQZ+PJMBEILm12kNmOXDWfkKiWJNMonTwmlxzF0=; b=AQJivLMCsk1nMtuC6hklM+PQm8LViUtEJcmGfFlpaUNI6DXfuTcJD9oUHcsETeAv8o CphDrcb/G9tRJRjcGVBogGDaGC4EjW+FPsl6WJe8ZrN+0webBrgoImGYvU1UkMKFB9UG bjCeZPHslniCsR8peTd7CrB7q+yMHMphxcC3Ou961dy2h9S4rKKp2emLWIMxRHeSlxke I4NdcF0D+QiItKhM3TW6jtANej+xAVClJ9Y1QVPlHkwB2tWheZzlq3aX8nXzR51gswhf tCH7+xWxAS1n3G/or4Zl4zbN3qi/p5+yMuodSw3qxpa7RM6Bupz5etF9DUivs1L9zIai XcSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MxEWNTd+; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id js5-20020a17090797c500b007ad8bd5b636si10792158ejc.377.2022.11.21.16.16.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 16:16:55 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MxEWNTd+; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E0D438493C7 for ; Tue, 22 Nov 2022 00:16:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E0D438493C7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669076188; 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=MxEWNTd+ZRJE6nV/glgpQBwVRJEKK0n71exly2JO0Lf0n7pWXKgSWOVN/IJ0O6KIh QCB7eILXx7PZMGe7kwoGHg7TQhEFaLJLdwLqu/TN/Z7Cgbu6VTHnOggRb8CBV0QSSM nfkfyUyJ+EO9rk4gLGXyklkjyZ2//LEX97GEXFXY= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750153261804823401?= X-GMAIL-MSGID: =?utf-8?q?1750153261804823401?= 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'" } */ +}