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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Mathias Stearn from comment #0)
> https://godbolt.org/z/svjPzrf5z Shows the impact on codegen by making
> __GLIBCXX_NORETURN imply cold in addition to noreturn. This seemed like the
> easiest way to demonstrate this. It also might be worth considering since
> noreturn functions tend to be cold ones. We have noreturn imply cold in our
> codebase, FWIW.

These are the other uses of _GLIBCXX_NORETURN:

include/c_global/cstdlib:  extern "C" void abort(void) _GLIBCXX_NOTHROW
_GLIBCXX_NORETURN;
include/c_global/cstdlib:  extern "C" void exit(int) _GLIBCXX_NOTHROW
_GLIBCXX_NORETURN;
include/c_global/cstdlib:  extern "C" void quick_exit(int) _GLIBCXX_NOTHROW
_GLIBCXX_NORETURN;
include/c_global/cstdlib:  extern "C" void _Exit(int) _GLIBCXX_NOTHROW
_GLIBCXX_NORETURN;
include/c_global/cstdlib:  extern "C" void (_Exit)(int) _GLIBCXX_NOTHROW
_GLIBCXX_NORETURN;
include/c_std/cstdlib:  extern "C" void abort(void) throw () _GLIBCXX_NORETURN;
include/c_std/cstdlib:  extern "C" void exit(int) throw () _GLIBCXX_NORETURN;
include/c_std/cstdlib:  extern "C" void quick_exit(int) throw()
_GLIBCXX_NORETURN;
include/c_std/cstdlib:  extern "C" void (_Exit)(int) throw ()
_GLIBCXX_NORETURN;
include/debug/formatter.h:    _GLIBCXX_NORETURN void

The last one is __gnu_debug::_Error_formatter::_M_error, which should
definitely be cold.

I'm less sure about the libc functions. Glibc doesn't mark them as cold.

I think for now I'll just explicitly add __attribute__((__cold__)) to
__glibcxx_assert_fail and _Error_formatter::_M_error.

We also have a few uses of __noreturn__ directly, without the macro (both as
__attribute__((__noreturn__)) and oddly, [[__noreturn__]] which could just be
[[noreturn]] because that was in C++11.

Reply via email to