xref: /netbsd-src/external/apache2/llvm/dist/clang/tools/libclang/FatalErrorHandler.cpp (revision e038c9c4676b0f19b1b7dd08a940c6ed64a6d5ae)
17330f729Sjoerg /*===-- clang-c/FatalErrorHandler.cpp - Fatal Error Handling ------*- C -*-===*\
27330f729Sjoerg |*                                                                            *|
37330f729Sjoerg |* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
47330f729Sjoerg |* Exceptions.                                                                *|
57330f729Sjoerg |* See https://llvm.org/LICENSE.txt for license information.                  *|
67330f729Sjoerg |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
77330f729Sjoerg |*                                                                            *|
87330f729Sjoerg \*===----------------------------------------------------------------------===*/
97330f729Sjoerg 
107330f729Sjoerg #include "clang-c/FatalErrorHandler.h"
117330f729Sjoerg #include "llvm/Support/ErrorHandling.h"
12*e038c9c4Sjoerg #include <stdlib.h>
137330f729Sjoerg 
aborting_fatal_error_handler(void *,const std::string & reason,bool)147330f729Sjoerg static void aborting_fatal_error_handler(void *, const std::string &reason,
157330f729Sjoerg                                          bool) {
167330f729Sjoerg   // Write the result out to stderr avoiding errs() because raw_ostreams can
177330f729Sjoerg   // call report_fatal_error.
187330f729Sjoerg   fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason.c_str());
197330f729Sjoerg   ::abort();
207330f729Sjoerg }
217330f729Sjoerg 
227330f729Sjoerg extern "C" {
clang_install_aborting_llvm_fatal_error_handler(void)237330f729Sjoerg void clang_install_aborting_llvm_fatal_error_handler(void) {
247330f729Sjoerg   llvm::remove_fatal_error_handler();
257330f729Sjoerg   llvm::install_fatal_error_handler(aborting_fatal_error_handler, nullptr);
267330f729Sjoerg }
277330f729Sjoerg 
clang_uninstall_llvm_fatal_error_handler(void)287330f729Sjoerg void clang_uninstall_llvm_fatal_error_handler(void) {
297330f729Sjoerg   llvm::remove_fatal_error_handler();
307330f729Sjoerg }
317330f729Sjoerg }
32