* [PATCH] Avoid duplicate diagnostic in g++.dg/warn/Wuse-after-free3.C
@ 2023-03-15 13:53 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-03-15 13:53 UTC (permalink / raw)
To: gcc-patches; +Cc: Jakub Jelinek
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" }
+}
--
2.35.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-15 13:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15 13:53 [PATCH] Avoid duplicate diagnostic in g++.dg/warn/Wuse-after-free3.C Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).