]> git.ipfire.org Git - people/ms/gcc.git/commitdiff
Avoid duplicate diagnostic in g++.dg/warn/Wuse-after-free3.C
authorRichard Biener <rguenther@suse.de>
Wed, 15 Mar 2023 13:48:57 +0000 (14:48 +0100)
committerRichard Biener <rguenther@suse.de>
Wed, 15 Mar 2023 14:30:49 +0000 (15:30 +0100)
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.

* 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
gcc/testsuite/g++.dg/warn/Wuse-after-free3.C

index 8b1c1cc019e3a52ea09fb5d3c15628f05c38589b..019c110041054609a0f9640933351a5b05582a12 100644 (file)
@@ -4194,6 +4194,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
index 1862ac8b09d9b8037a902689d4a62acd369a445a..e5b157865bf6e35ab72b98cef0164f6c4031375a 100644 (file)
@@ -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" }
+}