[libcxx-commits] [libcxx] Add C++23 stacktrace (P0881R7) (PR #136528)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 1 01:29:57 PDT 2025


================
@@ -965,6 +965,33 @@ typedef __char32_t char32_t;
 #    define _LIBCPP_NOINLINE
 #  endif
 
+// Some functions, e.g. std::stacktrace::current, need to avoid being
+// tail-called by (and tail-calling other) functions, for proper enumeration of
+// call-stack frames.
+// clang-format off
+
+// Disables tail-call optimization for "outbound" calls
+// performed in the function annotated with this attribute.
+#  if __has_cpp_attribute(_Clang::__disable_tail_calls__)
+#    define _LIBCPP_NO_TAIL_CALLS_OUT [[_Clang::__disable_tail_calls__]]
+#  elif __has_cpp_attribute(__gnu__::__optimize__)
+#    define _LIBCPP_NO_TAIL_CALLS_OUT [[__gnu__::__optimize__("no-optimize-sibling-calls")]]
+#  else
+#    define _LIBCPP_NO_TAIL_CALLS_OUT
+#  endif
+
+// Disables tail-call optimization for "inbound" calls -- that is,
+// calls from some other function calling the one having this attribute.
+#  if __has_cpp_attribute(_Clang::__not_tail_called__)
+#    define _LIBCPP_NO_TAIL_CALLS_IN [[_Clang::__not_tail_called__]]
+#  else
+#    define _LIBCPP_NO_TAIL_CALLS_IN
+#  endif
+
+// Disable TCO for calls into, and out from, the annotated function.
+#  define _LIBCPP_NO_TAIL_CALLS _LIBCPP_NO_TAIL_CALLS_IN _LIBCPP_NO_TAIL_CALLS_OUT
+// clang-format on
----------------
philnik777 wrote:

IMO it would be better if we go the other way around and add `[[gnu::always_inline, gnu::nodebug]]`. I'm pretty sure people don't care about the `stacktrace::current()` at the top of the trace.

https://github.com/llvm/llvm-project/pull/136528


More information about the libcxx-commits mailing list