public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/94295] New: use __builtin_operator_new and __builtin_operator_delete when available
@ 2020-03-23 23:16 richard-gccbugzilla at metafoo dot co.uk
  2020-03-24  7:04 ` [Bug libstdc++/94295] " glisse at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2020-03-23 23:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94295
           Summary: use __builtin_operator_new and
                    __builtin_operator_delete when available
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: richard-gccbugzilla at metafoo dot co.uk
  Target Milestone: ---

See https://bugs.llvm.org/show_bug.cgi?id=45287 for some background.

The C++ language rules do not permit optimization (eg, deletion) of direct
calls to 'operator new' and 'operator delete'. libstdc++ uses such calls to
implement std::allocator:

https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/ext/new_allocator.h#L112

As a consequence, allocations performed by libstdc++'s containers are not
optimizable.

Clang provides a pair of builtin functions to work around this issue:
https://clang.llvm.org/docs/LanguageExtensions.html#builtin-operator-new-and-builtin-operator-delete

__builtin_operator_new(args) is equivalent to ::operator new(args) except that
it permits optimizations.
__builtin_operator_delete(args) is equivalent to ::operator delete(args) except
that it permits optimizations.

You can detect support for these builtins with

#ifdef __has_builtin
#if __has_builtin(__builtin_operator_new) >= 201802L
// ...
#endif
#endif

(Note that __has_builtin(...) returned 1 for an older version of the builtins
that didn't support placement forms, and so couldn't be used for aligned
allocation and sized delete. It's probably not worth your time dealing with
those.)

This bug requests that libstdc++ uses these builtins when available.
(Separately, it'd be great if GCC considered supporting them too.)

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-07-22 13:44 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-23 23:16 [Bug libstdc++/94295] New: use __builtin_operator_new and __builtin_operator_delete when available richard-gccbugzilla at metafoo dot co.uk
2020-03-24  7:04 ` [Bug libstdc++/94295] " glisse at gcc dot gnu.org
2020-03-24 20:26 ` richard-gccbugzilla at metafoo dot co.uk
2020-03-24 20:44 ` pinskia at gcc dot gnu.org
2020-03-24 21:04 ` richard-gccbugzilla at metafoo dot co.uk
2020-03-24 21:34 ` glisse at gcc dot gnu.org
2020-03-24 21:58 ` richard-gccbugzilla at metafoo dot co.uk
2020-03-26 20:08 ` glisse at gcc dot gnu.org
2021-07-19 16:06 ` redi at gcc dot gnu.org
2021-07-20 18:58 ` richard-gccbugzilla at metafoo dot co.uk
2021-07-20 19:00 ` redi at gcc dot gnu.org
2021-07-20 19:31 ` jason at gcc dot gnu.org
2021-07-20 19:44 ` redi at gcc dot gnu.org
2021-07-22 13:43 ` cvs-commit at gcc dot gnu.org
2021-07-22 13:44 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).