On Wed, 27 Apr 2022, Jakub Jelinek wrote: > On Mon, Apr 25, 2022 at 11:54:34AM +0200, Richard Biener wrote: > > 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 <rguent...@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. > > > > * c-c++-common/Wdangling-pointer.c: Adjust for changed > > suppression. > > * c-c++-common/Wdangling-pointer-2.c: Likewise. > > I spoke with Martin on IRC and his comment was that this is ok > but should be accompanied with a doc/invoke.texi change that clarifies > that behavior in the documentation. > I think that is a reasonable request.
Like so? diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 07b440190c3..4decbf84a43 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -8642,8 +8642,10 @@ Warn about uses of pointers (or C++ references) to objects with automatic storage duration after their lifetime has ended. This includes local variables declared in nested blocks, compound literals and other unnamed temporary objects. In addition, warn about storing the address of such -objects in escaped pointers. The warning is enabled at all optimization -levels but may yield different results with optimization than without. +objects in escaped pointers. As exception we do not warn when pointers +are used in equality compares after the lifetime of the storage they point +to ended. The warning is enabled at all optimization levels but may yield +different results with optimization than without. @table @gcctabopt @item -Wdangling-pointer=1