[Bug c/123001] Assignments to globally allocated struct fields removed with -O1.
rguenth at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Dec 4 13:46:51 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123001
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Likely buffer_alloc is marked with the malloc attribute and since the
pointer does not escape the function it is dead (leaked) memory and
GCC elides stores to it.
return p - (p_instr *)buffer_ptr(&instrbuf);
does not constitute an escape point since without 'p' escaping itself
p cannot be reconstructed (as random address) from just
buffer_ptr(&instrbuf).
I assume buffer_alloc allocates from the storage of 'instrbuf' itself
or storage pointed to by it. But the malloc attribute assures that
no other pointer to *p exists in the program [or can be constructed
by means of offsetting].
So I think this is INVALID.
More information about the Gcc-bugs
mailing list