public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-8282] middle-end/104492 - avoid all equality compare dangling pointer diags
@ 2022-04-27 10:03 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-04-27 10:03 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9aaaae7edb781867797d0a553a7db99d52ecd5e1

commit r12-8282-g9aaaae7edb781867797d0a553a7db99d52ecd5e1
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Apr 25 10:46:16 2022 +0200

    middle-end/104492 - avoid all equality compare dangling pointer diags
    
    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.
    
    2022-04-25  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/104492
            * gimple-ssa-warn-access.cc
            (pass_waccess::warn_invalid_pointer): Exclude equality compare
            diagnostics for all kind of invalidations.
            (pass_waccess::check_dangling_uses): Fix post-dominator query.
            (pass_waccess::check_pointer_uses): Likewise.

Diff:
---
 gcc/gimple-ssa-warn-access.cc | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 879dbcc1e52..39aa8186de6 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -3923,7 +3923,8 @@ pass_waccess::warn_invalid_pointer (tree ref, gimple *use_stmt,
       return;
     }
 
-  if ((maybe && warn_dangling_pointer < 2)
+  if (equality
+      || (maybe && warn_dangling_pointer < 2)
       || warning_suppressed_p (use_stmt, OPT_Wdangling_pointer_))
     return;
 
@@ -4241,7 +4242,7 @@ pass_waccess::check_pointer_uses (gimple *stmt, tree ptr,
 	      basic_block use_bb = gimple_bb (use_stmt);
 	      bool this_maybe
 		= (maybe
-		   || !dominated_by_p (CDI_POST_DOMINATORS, use_bb, stmt_bb));
+		   || !dominated_by_p (CDI_POST_DOMINATORS, stmt_bb, use_bb));
 	      warn_invalid_pointer (*use_p->use, use_stmt, stmt, var,
 				    this_maybe, equality);
 	      continue;
@@ -4486,7 +4487,7 @@ pass_waccess::check_dangling_uses (tree var, tree decl, bool maybe /* = false */
 
   basic_block use_bb = gimple_bb (use_stmt);
   basic_block clob_bb = gimple_bb (*pclob);
-  maybe = maybe || !dominated_by_p (CDI_POST_DOMINATORS, use_bb, clob_bb);
+  maybe = maybe || !dominated_by_p (CDI_POST_DOMINATORS, clob_bb, use_bb);
   warn_invalid_pointer (var, use_stmt, *pclob, decl, maybe, false);
 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-27 10:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 10:03 [gcc r12-8282] middle-end/104492 - avoid all equality compare dangling pointer diags 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).