[PATCH] preserve integer value of local addresses returned from functions (PR 90737)

Martin Sebor msebor@gmail.com
Mon Jun 3 21:24:00 GMT 2019

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?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-90737.diff
Type: text/x-patch
Size: 4319 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190603/d9f2b0b0/attachment.bin>

More information about the Gcc-patches mailing list