FatalErrorHandler.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. /*===-- clang-c/FatalErrorHandler.cpp - Fatal Error Handling ------*- C -*-===*\
  2. |* *|
  3. |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
  4. |* Exceptions. *|
  5. |* See https://llvm.org/LICENSE.txt for license information. *|
  6. |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
  7. |* *|
  8. \*===----------------------------------------------------------------------===*/
  9. #include "clang-c/FatalErrorHandler.h"
  10. #include "llvm/Support/ErrorHandling.h"
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. static void aborting_fatal_error_handler(void *, const char *reason,
  14. bool) {
  15. // Write the result out to stderr avoiding errs() because raw_ostreams can
  16. // call report_fatal_error.
  17. fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason);
  18. ::abort();
  19. }
  20. extern "C" {
  21. void clang_install_aborting_llvm_fatal_error_handler(void) {
  22. llvm::remove_fatal_error_handler();
  23. llvm::install_fatal_error_handler(aborting_fatal_error_handler, nullptr);
  24. }
  25. void clang_uninstall_llvm_fatal_error_handler(void) {
  26. llvm::remove_fatal_error_handler();
  27. }
  28. }