1 //===- lib/Support/ErrorHandling.cpp - Callbacks for errors ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines an API used to indicate fatal error conditions. Non-fatal
11 // errors (most of them) should be handled through LLVMContext.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/Support/Debug.h"
17 #include "llvm/Support/ErrorHandling.h"
18 #include "llvm/Support/raw_ostream.h"
19 #include "llvm/System/Threading.h"
25 static fatal_error_handler_t ErrorHandler = 0;
26 static void *ErrorHandlerUserData = 0;
28 void llvm::install_fatal_error_handler(fatal_error_handler_t handler,
30 assert(!llvm_is_multithreaded() &&
31 "Cannot register error handlers after starting multithreaded mode!\n");
32 assert(!ErrorHandler && "Error handler already registered!\n");
33 ErrorHandler = handler;
34 ErrorHandlerUserData = user_data;
37 void llvm::remove_fatal_error_handler() {
41 void llvm::report_fatal_error(const char *reason) {
42 report_fatal_error(Twine(reason));
45 void llvm::report_fatal_error(const std::string &reason) {
46 report_fatal_error(Twine(reason));
49 void llvm::report_fatal_error(const Twine &reason) {
51 errs() << "LLVM ERROR: " << reason << "\n";
53 ErrorHandler(ErrorHandlerUserData, reason.str());
58 void llvm::llvm_unreachable_internal(const char *msg, const char *file,
60 // This code intentionally doesn't call the ErrorHandler callback, because
61 // llvm_unreachable is intended to be used to indicate "impossible"
62 // situations, and not legitimate runtime errors.
64 dbgs() << msg << "\n";
65 dbgs() << "UNREACHABLE executed";
67 dbgs() << " at " << file << ":" << line;