[Bug c/67316] Address local variable returned as 0x0
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Aug 22 04:10:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67316
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is undefined behavior. Returning the address of a local variable is
undefined.
If you want to trick the compiler though here is a better solution (than just
moving the address taking out of the return):
ptr_t GC_approx_sp2(void)
{
volatile word dummy;
dummy = 42;
ptr_t ret = (ptr_t)&dummy;
asm("":"+r"(ret));
return ret;
}
More information about the Gcc-bugs
mailing list