1 //===- llvm/Support/ErrorHandling.h - Callbacks for errors ------*- C++ -*-===//
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 error conditions.
11 // Callbacks can be registered for these errors through this API.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_ERRORHANDLING_H
16 #define LLVM_SUPPORT_ERRORHANDLING_H
18 #include "llvm/Support/Compiler.h"
24 /// An error handler callback.
25 typedef void (*llvm_error_handler_t)(void *user_data,
26 const std::string& reason);
28 /// llvm_instal_error_handler - Installs a new error handler to be used
29 /// whenever a serious (non-recoverable) error is encountered by LLVM.
31 /// If you are using llvm_start_multithreaded, you should register the handler
32 /// before doing that.
34 /// If no error handler is installed the default is to print the error message
35 /// to stderr, and call exit(1). If an error handler is installed then it is
36 /// the handler's responsibility to log the message, it will no longer be
37 /// printed to stderr. If the error handler returns, then exit(1) will be
40 /// It is dangerous to naively use an error handler which throws an exception.
41 /// Even though some applications desire to gracefully recover from arbitrary
42 /// faults, blindly throwing exceptions through unfamiliar code isn't a way to
45 /// \param user_data - An argument which will be passed to the install error
47 void llvm_install_error_handler(llvm_error_handler_t handler,
50 /// Restores default error handling behaviour.
51 /// This must not be called between llvm_start_multithreaded() and
52 /// llvm_stop_multithreaded().
53 void llvm_remove_error_handler();
55 /// Reports a serious error, calling any installed error handler. These
56 /// functions are intended to be used for error conditions which are outside
57 /// the control of the compiler (I/O errors, invalid user input, etc.)
59 /// If no error handler is installed the default is to print the message to
60 /// standard error, followed by a newline.
61 /// After the error handler is called this function will call exit(1), it
63 NORETURN void llvm_report_error(const char *reason);
64 NORETURN void llvm_report_error(const std::string &reason);
65 NORETURN void llvm_report_error(const Twine &reason);
67 /// This function calls abort(), and prints the optional message to stderr.
68 /// Use the llvm_unreachable macro (that adds location info), instead of
69 /// calling this function directly.
70 NORETURN void llvm_unreachable_internal(const char *msg=0,
71 const char *file=0, unsigned line=0);
74 /// Prints the message and location info to stderr in !NDEBUG builds.
75 /// This is intended to be used for "impossible" situations that imply
76 /// a bug in the compiler.
78 /// In NDEBUG mode it only prints "UNREACHABLE executed".
79 /// Use this instead of assert(0), so that the compiler knows this path
80 /// is not reachable even for NDEBUG builds.
82 #define llvm_unreachable(msg) \
83 ::llvm::llvm_unreachable_internal(msg, __FILE__, __LINE__)
85 #define llvm_unreachable(msg) ::llvm::llvm_unreachable_internal()