On 6/3/19 3:24 PM, Martin Sebor wrote:
> While testing a different -Wreturn-local-addr bug fix/enhancement
> I noticed that in functions that return integers as opposed to
> pointers such as:
>
> intptr_t f (int i) { return (intptr_t)&i; }
>
> the converted address is folded to zero. This can be detected
> by strictly conforming programs so it's not really correct.
> Such statements also trigger the warning.
>
> The attached patch adjusts the C and C++ front-ends to avoid
> the folding.
>
> The patch also avoids the warning but I'm on the fence about that.
> There is some value in diagnosing it since it could be masking
> a bug. Would anyone like to argue in favor of keeping it?
>
> Martin
>
> gcc-90737.diff
>
> PR c/90737 - [8/9/10 Regression] inconsistent address of a local converted to
> intptr_t between callee and caller
>
> gcc/c/ChangeLog:
>
> PR c/90737
> * c-typeck.c (c_finish_return): Only consider functions returning
> pointers as candidates for -Wreturn-local-addr.
>
> gcc/cp/ChangeLog:
>
> PR c/90737
> * typeck.c (maybe_warn_about_returning_address_of_local): Only
> consider functions returning pointers as candidates for
> -Wreturn-local-addr.
>
> gcc/testsuite/ChangeLog:
>
> PR c/90737
> * c-c++-common/Wreturn-local-addr.c: New test.
> * g++.dg/warn/Wreturn-local-addr-6.C: New test.
OK
jeff