On Tue, Feb 14, 2023 at 10:48:15PM -0500, Marek Polacek via Gcc-patches wrote:
> -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.

and RESULT_DECL ;)

> Bootstrapped/regtested on ppc64le-pc-linux-gnu, ok for trunk and 12?
> 
>       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.

> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/Wdangling-pointer-9.c
> @@ -0,0 +1,9 @@
> +/* PR middle-end/106080 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -Wdangling-pointer" } */
> +
> +void
> +foo (void **failaddr)
> +{
> +  *failaddr = ({ __label__ __here; __here: &&__here; });
> +}

Perhaps add dg-bogus above just to make it more clear what
we are testing in the test?

Otherwise LGTM.

        Jakub

Reply via email to