https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90737

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #5)

Returning a pointer to a local and converting it to an integer in the caller is
undefined because the pointer is indeterminate.
If there is no cast to an integer in the return statement in the callee but the
pointer is tested for equality to NULL both in the caller and the callee, the
behavior of the test in the caller is also undefined.
If a pointer is converted to an integer, returned, and then cast back to a
pointer in the caller, the behavior (of the cast) is implementation defined
(opinions might vary here whether that could include undefined since the result
is indeterminate).

What is well-defined is storing the pointer in some integer X, and b) returning
the pointer as an integer R, and the comparing X == R: the result must be true.

I see the transformation to null as helpful in avoiding accidentally accessing
some other function's stack (not so much as an optimization).

Reply via email to