[Bug tree-optimization/82946] member pointer defeats strlen optimization involving a string literal

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Nov 13 16:54:00 GMT 2017


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

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #3)

As I explained in comment #0, a_5(D)->d can safely be assumed not to point to
itself as a result of the subsequent access to what it points to in strlen, and
thanks to the fact that a string literal is never a valid representation of a
pointer.

Joseph's bare metal case of strlen (((struct A*)"123")->d) from comment #2
could be handled either by detecting and warning about it, or accommodated
under -ffreestanding or some new option to disable the optimization.


More information about the Gcc-bugs mailing list