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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It is extremely important optimization and is done only if new/delete is used,
not when one calls these operators.  While when one calls the operator by hand,
the C++ standard doesn't give the possibility of optimizing away e.g. a pair of
operator delete (operator new (23)), when delete new int; is used, it can be
optimized away.  With reading and modification of the global state, sure, under
the hood the function will need to read and store some global state, but the
point is that typically that state doesn't include anything that the callers
care about.  It is similar to malloc, if one defines in C or C++ malloc and
uses variables the callers of malloc set or read in the malloc implementation,
it will not work properly.  We have a -fno-builtin-malloc or -fno-builtin-free
for that case though, so people that want to do weird things can at the expense
of massive code penalization get what they want (better is to use some compiler
barriers for such state).  For the operator new/delete I think we don't have a
switch, maybe it should be added.  But it certainly should default to the
current state.

Reply via email to