@@ -977,6 +977,33 @@ typedef __char32_t char32_t;
977977# define _LIBCPP_NOINLINE
978978# endif
979979
980+ // Some functions, e.g. std::stacktrace::current, need to avoid being
981+ // tail-called by (and tail-calling other) functions, for proper enumeration of
982+ // call-stack frames.
983+ // clang-format off
984+
985+ // Disables tail-call optimization for "outbound" calls
986+ // performed in the function annotated with this attribute.
987+ # if __has_cpp_attribute(_Clang::__disable_tail_calls__)
988+ # define _LIBCPP_NO_TAIL_CALLS_OUT [[_Clang::__disable_tail_calls__]]
989+ # elif __has_cpp_attribute(__gnu__::__optimize__)
990+ # define _LIBCPP_NO_TAIL_CALLS_OUT [[__gnu__::__optimize__(" no-optimize-sibling-calls" )]]
991+ # else
992+ # define _LIBCPP_NO_TAIL_CALLS_OUT
993+ # endif
994+
995+ // Disables tail-call optimization for "inbound" calls -- that is,
996+ // calls from some other function calling the one having this attribute.
997+ # if __has_cpp_attribute(_Clang::__not_tail_called__)
998+ # define _LIBCPP_NO_TAIL_CALLS_IN [[_Clang::__not_tail_called__]]
999+ # else
1000+ # define _LIBCPP_NO_TAIL_CALLS_IN
1001+ # endif
1002+
1003+ // Disable TCO for calls into, and out from, the annotated function.
1004+ # define _LIBCPP_NO_TAIL_CALLS _LIBCPP_NO_TAIL_CALLS_IN _LIBCPP_NO_TAIL_CALLS_OUT
1005+ // clang-format on
1006+
9801007// We often repeat things just for handling wide characters in the library.
9811008// When wide characters are disabled, it can be useful to have a quick way of
9821009// disabling it without having to resort to #if-#endif, which has a larger
0 commit comments