From 9aaaae7edb781867797d0a553a7db99d52ecd5e1 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 25 Apr 2022 10:46:16 +0200 Subject: [PATCH] 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 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. --- 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 879dbcc..39aa818 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); } -- 2.7.4