This two-patch series adds support for the detection of uses of pointers invalidated as a result of the lifetime of the objects they point to having ended: either explicitly, after a call to a dynamic deallocation function, or implicitly, by virtue of an object with automatic storage duration having gone out of scope.
To minimize false positives the initial logic is very simple (even simplistic): the code only checks uses in basic blocks dominated by the invalidating calls (either calls to deallocation functions or GCC's clobbers). A more thorough checker is certainly possible and I'd say most desirable but will require a more sophisticated implementation and a better predicate analyzer than is available, and so will need to wait for GCC 13. Martin