[PATCH v2 2/2] add -Wdangling-pointer [PR #63272]

Martin Sebor msebor@gmail.com
Tue Nov 30 22:55:04 GMT 2021

Attached is a revision of this patch with adjustments for
the changes to the prerequisite patch 1 in the series and
a couple of minor simplifications and slightly improved
test coverage, rested on x86_64-linux.

On 11/1/21 4:18 PM, Martin Sebor wrote:
> Patch 2 in this series adds support for detecting the uses of
> dangling pointers: those to auto objects that have gone out of
> scope.  Like patch 1, to minimize false positives this detection
> is very simplistic.  However, thanks to the more deterministic
> nature of the problem (all local objects go out of scope) is able
> to detect more instances of it.  The approach I used is to simply
> search the IL for clobbers that dominate uses of pointers to
> the clobbered objects.  If such a use is found that's not
> followed by a clobber of the same object the warning triggers.
> Similar to -Wuse-after-free, the new -Wdangling-pointer option
> has multiple levels: level 1 to detect unconditional uses and
> level 2 to flag conditional ones.  Unlike with -Wuse-after-free
> there is no use case for testing dangling pointers for
> equality, so there is no level 3.
> Tested on x86_64-linux and  by building Glibc and Binutils/GDB.
> It found no problems outside of the GCC test suite.
> As with the first patch in this series, the tests contain a number
> of xfails due to known limitations marked with pr??????.  I'll
> open bugs for them before committing the patch if I don't resolve
> them first in a followup.
> Martin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-63272-2.diff
Type: text/x-patch
Size: 58985 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20211130/0bdafb29/attachment-0001.bin>

More information about the Gcc-patches mailing list