warn-access: wrong -Wdangling-pointer with labels [PR106080]
commitd482b20fd346482635a770281a164a09d608b058
authorMarek Polacek <polacek@redhat.com>
Tue, 14 Feb 2023 22:05:44 +0000 (14 17:05 -0500)
committerMarek Polacek <polacek@redhat.com>
Wed, 15 Feb 2023 13:53:44 +0000 (15 08:53 -0500)
tree897a39f43f2463b16356c01d500345598e220b74
parent81f0945cd97cf0645c56b14827abad63164bd80c
warn-access: wrong -Wdangling-pointer with labels [PR106080]

-Wdangling-pointer warns when the address of a label escapes.  This
causes grief in OCaml (<https://github.com/ocaml/ocaml/issues/11358>) as
well as in the kernel:
<https://bugzilla.kernel.org/show_bug.cgi?id=215851> because it uses

  #define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })

to get the PC.  -Wdangling-pointer is documented to warn about pointers
to objects.  However, it uses is_auto_decl which checks DECL_P, but DECL_P
is also true for a label/enumerator/function declaration, none of which is
an object.  Rather, it should use auto_var_p which correctly checks VAR_P
and PARM_DECL.

PR middle-end/106080

gcc/ChangeLog:

* gimple-ssa-warn-access.cc (is_auto_decl): Remove.  Use auto_var_p
instead.

gcc/testsuite/ChangeLog:

* c-c++-common/Wdangling-pointer-10.c: New test.
* c-c++-common/Wdangling-pointer-9.c: New test.
gcc/gimple-ssa-warn-access.cc
gcc/testsuite/c-c++-common/Wdangling-pointer-10.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wdangling-pointer-9.c [new file with mode: 0644]