[Bug c/67618] malloc+memset optimization breaks code

glisse at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Sep 17 20:13:00 GMT 2015


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

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |c

--- Comment #7 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Daniel Gutson from comment #4)
> The optimization ignores the 'if' statement (just comment that line and
> see), so if malloc() returns NULL, memset is called unconditionally and will
> try to write to address NULL.

Ah, you are saying that calling memset on a null pointer is not undefined
behavior, that it generates an observable trap, and that the transformation
should be protected by -fdelete-null-pointer-checks?



More information about the Gcc-bugs mailing list