From patchwork Mon Apr 25 09:54:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 53171 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 94F78385843E for ; Mon, 25 Apr 2022 09:55:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 94F78385843E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1650880505; bh=36YVENPF1oEZmn5kGbQF4a7tdmK6Kg6W7e59whZTRz8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=GbtTh8hpbHlh/ZVfXRsvIGZWW5pgPBb+5Hv7Y+HZWYGjgcBvoRAaMTh1eBKUFZMo4 2btlIiqudiUa/ZBPPkn/Ixs7kHrtxeMhLpQHbLWvAdW162OpaRsW0j5A68RmqQOd5h 9/mYEbo2J4QYKEoVqFPL+j+IhD8lkAIitWbBhJ4Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 83D123858D28 for ; Mon, 25 Apr 2022 09:54:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 83D123858D28 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3B629210E7; Mon, 25 Apr 2022 09:54:35 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 226C013AE1; Mon, 25 Apr 2022 09:54:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AH9SB9tvZmL/JQAAMHmgww (envelope-from ); Mon, 25 Apr 2022 09:54:35 +0000 Date: Mon, 25 Apr 2022 11:54:34 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/104492 - avoid all equality compare dangling pointer diags MIME-Version: 1.0 Message-Id: <20220425095435.226C013AE1@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Cc: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following extends the equality compare dangling pointer diagnostics suppression for uses following free or realloc to also cover those following invalidation of auto variables via CLOBBERs. That avoids diagnosing idioms like return std::find(std::begin(candidates), std::end(candidates), s) != std::end(candidates); for auto candidates which are prone to forwarding of the final comparison across the storage invalidation as then seen by the late run access warning pass. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK for trunk? Thanks, Richard. 2022-04-25 Richard Biener PR middle-end/104492 * gimple-ssa-warn-access.cc (pass_waccess::warn_invalid_pointer): Exclude equality compare diagnostics for all kind of invalidations. * c-c++-common/Wdangling-pointer.c: Adjust for changed suppression. * c-c++-common/Wdangling-pointer-2.c: Likewise. --- gcc/gimple-ssa-warn-access.cc | 14 +++++--------- gcc/testsuite/c-c++-common/Wdangling-pointer-2.c | 4 ++-- gcc/testsuite/c-c++-common/Wdangling-pointer.c | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc index 879dbcc1e52..6c404f18db7 100644 --- a/gcc/gimple-ssa-warn-access.cc +++ b/gcc/gimple-ssa-warn-access.cc @@ -3896,13 +3896,13 @@ pass_waccess::warn_invalid_pointer (tree ref, gimple *use_stmt, return; } + if ((equality && warn_use_after_free < 3) + || (maybe && warn_use_after_free < 2) + || warning_suppressed_p (use_stmt, OPT_Wuse_after_free)) + return; + if (is_gimple_call (inval_stmt)) { - if ((equality && warn_use_after_free < 3) - || (maybe && warn_use_after_free < 2) - || warning_suppressed_p (use_stmt, OPT_Wuse_after_free)) - return; - const tree inval_decl = gimple_call_fndecl (inval_stmt); if ((ref && warning_at (use_loc, OPT_Wuse_after_free, @@ -3923,10 +3923,6 @@ pass_waccess::warn_invalid_pointer (tree ref, gimple *use_stmt, return; } - if ((maybe && warn_dangling_pointer < 2) - || warning_suppressed_p (use_stmt, OPT_Wdangling_pointer_)) - return; - if (DECL_NAME (var)) { if ((ref diff --git a/gcc/testsuite/c-c++-common/Wdangling-pointer-2.c b/gcc/testsuite/c-c++-common/Wdangling-pointer-2.c index 20f11b227d6..11c939cb086 100644 --- a/gcc/testsuite/c-c++-common/Wdangling-pointer-2.c +++ b/gcc/testsuite/c-c++-common/Wdangling-pointer-2.c @@ -356,7 +356,7 @@ NOIPA void warn_cond_if_else (int i) } else { - int b[] = { 3, 4 }; // { dg-message "'b' declared" "pr??????" { xfail *-*-* } } + int b[] = { 3, 4 }; // { dg-message "'b' declared" } sink (b); p = b; } @@ -365,7 +365,7 @@ NOIPA void warn_cond_if_else (int i) because after the first diagnostic the code suppresses subsequent ones for the same use. This needs to be fixed. */ sink (p); // { dg-warning "dangling pointer 'p' to 'a' may be used" } - // { dg-warning "dangling pointer 'p' to 'b' may be used" "pr??????" { xfail *-*-* } .-1 } + // { dg-warning "dangling pointer 'p' to 'b' may be used" "" { target *-*-* } .-1 } } diff --git a/gcc/testsuite/c-c++-common/Wdangling-pointer.c b/gcc/testsuite/c-c++-common/Wdangling-pointer.c index 0a18c3c8249..09e4036a4dd 100644 --- a/gcc/testsuite/c-c++-common/Wdangling-pointer.c +++ b/gcc/testsuite/c-c++-common/Wdangling-pointer.c @@ -370,7 +370,7 @@ void warn_cond_if_else (int i) } else { - int b[] = { 3, 4 }; // { dg-message "'b' declared" "note" { xfail *-*-* } } + int b[] = { 3, 4 }; // { dg-message "'b' declared" "note" } sink (b); p = b; } @@ -379,7 +379,7 @@ void warn_cond_if_else (int i) because after the first diagnostic the code suppresses subsequent ones for the same use. This needs to be fixed. */ sink (p); // { dg-warning "dangling pointer 'p' to 'a' may be used" } - // { dg-warning "dangling pointer 'p' to 'b' may be used" "pr??????" { xfail *-*-* } .-1 } + // { dg-warning "dangling pointer 'p' to 'b' may be used" "" { target *-*-* } .-1 } }