check_internal.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "common/check_internal.h"
  5. namespace Carbon::Internal {
  6. // Prints the buffered message.
  7. auto PrintAfterStackTrace(void* str) -> void {
  8. llvm::errs() << reinterpret_cast<char*>(str);
  9. }
  10. ExitingStream::~ExitingStream() {
  11. llvm_unreachable(
  12. "Exiting streams should only be constructed by check.h macros that "
  13. "ensure the special operator| exits the program prior to their "
  14. "destruction!");
  15. }
  16. auto ExitingStream::Done() -> void {
  17. buffer_ << "\n";
  18. // Register another signal handler to print the buffered message. This is
  19. // because we want it at the bottom of output, after LLVM's builtin stack
  20. // output, rather than the top.
  21. llvm::sys::AddSignalHandler(PrintAfterStackTrace,
  22. const_cast<char*>(buffer_str_.c_str()));
  23. // It's useful to exit the program with `std::abort()` for integration with
  24. // debuggers and other tools. We also assume LLVM's exit handling is
  25. // installed, which will stack trace on `std::abort()`.
  26. std::abort();
  27. }
  28. } // namespace Carbon::Internal