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
10#include "clang-c/FatalErrorHandler.h"
11#include "llvm/Support/ErrorHandling.h"
12#include <stdio.h>
13#include <stdlib.h>
14
15static void aborting_fatal_error_handler(void *, const char *reason,
16 bool) {
17 // Write the result out to stderr avoiding errs() because raw_ostreams can
18 // call report_fatal_error.
19 fprintf(stderr, format: "LIBCLANG FATAL ERROR: %s\n", reason);
20 ::abort();
21}
22
23extern "C" {
24void clang_install_aborting_llvm_fatal_error_handler(void) {
25 llvm::remove_fatal_error_handler();
26 llvm::install_fatal_error_handler(handler: aborting_fatal_error_handler, user_data: nullptr);
27}
28
29void clang_uninstall_llvm_fatal_error_handler(void) {
30 llvm::remove_fatal_error_handler();
31}
32}
33

source code of clang/tools/libclang/FatalErrorHandler.cpp