-Wdangling-pointer: fix MEM_REF handling [PR109514]
authorJason Merrill <jason@redhat.com>
Fri, 14 Apr 2023 17:37:16 +0000 (13:37 -0400)
committerJason Merrill <jason@redhat.com>
Sat, 15 Apr 2023 01:34:14 +0000 (21:34 -0400)
commit9964df74a9e99e850bf9b0b6ff5c47133f846db8
tree44bb6e88aecdd16b93b79a03cdc89149e5aaf76f
parent1aee19f9b57caef2a600968807ecaa13bac2d2f8
-Wdangling-pointer: fix MEM_REF handling [PR109514]

Here we hit the MEM_REF case, with its arg an ADDR_EXPR, but had no handling
for that and wrongly assumed it would be a reference to a local variable.
This patch overhauls the logic for deciding whether the target is something
to warn about so that we only warn if we specifically recognize the target
as non-local.  None of the existing tests regress as a result.

PR c++/109514

gcc/ChangeLog:

* gimple-ssa-warn-access.cc (pass_waccess::check_dangling_stores):
Overhaul lhs_ref.ref analysis.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wdangling-pointer-6.C: New test.
gcc/gimple-ssa-warn-access.cc
gcc/testsuite/g++.dg/warn/Wdangling-pointer-6.C [new file with mode: 0644]