From patchwork Wed Mar 15 13:53:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 70233 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2342199wrd; Wed, 15 Mar 2023 06:54:02 -0700 (PDT) X-Google-Smtp-Source: AK7set9DSO78FthM1V0IWnZOtkhn3GjfovSNYwSVLqMLMsBZ6ybAWk1jFJOKcKc6IVbiEanbN6hO X-Received: by 2002:a17:906:b7d8:b0:924:44b9:e485 with SMTP id fy24-20020a170906b7d800b0092444b9e485mr6342062ejb.58.1678888442585; Wed, 15 Mar 2023 06:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678888442; cv=none; d=google.com; s=arc-20160816; b=DiT5+AEhtLRsJ6T8pzbcuNCS7ceSnaEmyTmygOha3JiU81ZPSgdv5lfdey7e1PYAHV oW+kiL+UbB2T1AWu/FHxD8xz6DNJ6+mQ3mJCpU1i8KM65cjpMv0YUAXskbJJLBUc7yIw gxTkrv8IaALpJ2ulXIWS6+IzOXZKfIFL93LyhM6/FQIIG8q+8Gzc6FSbyTEZzBd+K4LJ kupyBfugNidI9A0I+8mzuDVpVUnpTdc3xRBVnjQG/Chy+JfbQOgzvFrKTbd0RxqFJETL IKtUp/llS5yTFISChC0NkLiv52DeYToBgHCgzobIxwj118drtT/6apBgHqsZz05XNMIK o53Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=5o91ls8UeBrlsqx+R7LRay7xlLWpX31LA5uE0vnfNbw=; b=tBKjjVDSWxT9HtFcqBdH5rR+olFPTTbpZsl+OqSR3hlSMBuxT487vb5PMEIv+x4bAq yAgtAkbqrRxFSQQp0y57uqBwfiWuYwTo8KI5KBXTuVmYdEPor3Ap717BLXb4qL12zW55 PQaDEDBJTJcn/BDeODDnDzIfkdhbKxtXuup2QIY/49aWBFEyIvQYHKzP8b/haEn5HT96 dpK5tIzeR790FaF0/PfU8p6b+OBoTFZ139Q02CXpgTN7FT7OKOVu8FsIzT14/E1G3/ry Da41/oeLbzrJNjU0ek1Q827G6W+owIa+niyrgwRCrbB1rabUtFQGgPXIwb0r9IQTFhMS 6WEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WmpAy6eb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dv6-20020a170906b80600b008cd04d9ea72si5741353ejb.847.2023.03.15.06.54.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 06:54:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WmpAy6eb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 3DE153858017 for ; Wed, 15 Mar 2023 13:53:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DE153858017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678888438; bh=5o91ls8UeBrlsqx+R7LRay7xlLWpX31LA5uE0vnfNbw=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=WmpAy6eb5IDvt7dcaWUGWotr8L9SGQ5VNgcNhbEoUXuZiqoAL7dkblOZRBGLOC5Zb Ud57Km/TlbWJyRNUXhD26d+p7D8Y4UPF2HpcoUW/la9daBgb27bGCnuNVO7XM9eX5E nw7R4aJBGp6zjzKCr07Oo6meRSd2r1q1tIHqDfqQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 3870C3858D39 for ; Wed, 15 Mar 2023 13:53:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3870C3858D39 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0F6F51FD78; Wed, 15 Mar 2023 13:53:15 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id D2A3E2C141; Wed, 15 Mar 2023 13:53:14 +0000 (UTC) Date: Wed, 15 Mar 2023 13:53:14 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] Avoid duplicate diagnostic in g++.dg/warn/Wuse-after-free3.C User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230315135358.3DE153858017@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760442127520274181?= X-GMAIL-MSGID: =?utf-8?q?1760442127520274181?= We are diagnosing operator delete (this_3(D)); A::f (this_3(D)); *this_3(D) ={v} CLOBBER; where the CLOBBER appears at the end of the DTOR for C++11 and later. The following avoids this by simply never diagnosing clobbers as use-after-free. Bootstrap and regtest running on x86_64-unknown-linux-gnu, I'm going to push this if it succeeds. Richard. * gimple-ssa-warn-access.cc (pass_waccess::check_pointer_uses): Do not diagnose clobbers. * g++.dg/warn/Wuse-after-free3.C: Remove expected duplicate diagnostic. --- gcc/gimple-ssa-warn-access.cc | 4 ++++ gcc/testsuite/g++.dg/warn/Wuse-after-free3.C | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc index ed5499ca7fb..88d44690ade 100644 --- a/gcc/gimple-ssa-warn-access.cc +++ b/gcc/gimple-ssa-warn-access.cc @@ -4189,6 +4189,10 @@ pass_waccess::check_pointer_uses (gimple *stmt, tree ptr, if (use_stmt == stmt || is_gimple_debug (use_stmt)) continue; + /* A clobber isn't a use. */ + if (gimple_clobber_p (use_stmt)) + continue; + if (realloc_lhs) { /* Check to see if USE_STMT is a mismatched deallocation diff --git a/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C b/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C index 1862ac8b09d..e5b157865bf 100644 --- a/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C +++ b/gcc/testsuite/g++.dg/warn/Wuse-after-free3.C @@ -1,7 +1,6 @@ // PR target/104213 // { dg-do compile } // { dg-options "-Wuse-after-free" } -// FIXME: We should not output the warning twice. struct A { @@ -13,4 +12,4 @@ A::~A () { operator delete (this); f (); // { dg-warning "used after" } -} // { dg-warning "used after" } +}