19 #include "llvm/Config/config.h"
32 #if defined(HAVE_UNISTD_H)
48 #if LLVM_ENABLE_THREADS == 1
66 #if LLVM_ENABLE_THREADS == 1
75 #if LLVM_ENABLE_THREADS == 1
96 void* handlerData =
nullptr;
100 #if LLVM_ENABLE_THREADS == 1
108 handler(handlerData, Reason.
str(), GenCrashDiag);
115 OS <<
"LLVM ERROR: " << Reason <<
"\n";
131 #if LLVM_ENABLE_THREADS == 1
140 #if LLVM_ENABLE_THREADS == 1
149 void *HandlerData =
nullptr;
153 #if LLVM_ENABLE_THREADS == 1
161 Handler(HandlerData, Reason, GenCrashDiag);
165 #ifdef LLVM_ENABLE_EXCEPTIONS
167 throw std::bad_alloc();
171 char OOMMessage[] =
"LLVM ERROR: out of memory\n";
172 ssize_t written =
::write(2, OOMMessage, strlen(OOMMessage));
184 dbgs() << msg <<
"\n";
185 dbgs() <<
"UNREACHABLE executed";
187 dbgs() <<
" at " << file <<
":" << line;
190 #ifdef LLVM_BUILTIN_UNREACHABLE
193 LLVM_BUILTIN_UNREACHABLE;
198 bool gen_crash_diag) {
201 handler(reason.c_str());
215 #include <winerror.h>
218 #define MAP_ERR_TO_COND(x, y) \
220 return make_error_code(errc::y)
224 MAP_ERR_TO_COND(ERROR_ACCESS_DENIED, permission_denied);
225 MAP_ERR_TO_COND(ERROR_ALREADY_EXISTS, file_exists);
226 MAP_ERR_TO_COND(ERROR_BAD_UNIT, no_such_device);
227 MAP_ERR_TO_COND(ERROR_BUFFER_OVERFLOW, filename_too_long);
228 MAP_ERR_TO_COND(ERROR_BUSY, device_or_resource_busy);
229 MAP_ERR_TO_COND(ERROR_BUSY_DRIVE, device_or_resource_busy);
230 MAP_ERR_TO_COND(ERROR_CANNOT_MAKE, permission_denied);
231 MAP_ERR_TO_COND(ERROR_CANTOPEN, io_error);
232 MAP_ERR_TO_COND(ERROR_CANTREAD, io_error);
233 MAP_ERR_TO_COND(ERROR_CANTWRITE, io_error);
234 MAP_ERR_TO_COND(ERROR_CURRENT_DIRECTORY, permission_denied);
235 MAP_ERR_TO_COND(ERROR_DEV_NOT_EXIST, no_such_device);
236 MAP_ERR_TO_COND(ERROR_DEVICE_IN_USE, device_or_resource_busy);
237 MAP_ERR_TO_COND(ERROR_DIR_NOT_EMPTY, directory_not_empty);
238 MAP_ERR_TO_COND(ERROR_DIRECTORY, invalid_argument);
239 MAP_ERR_TO_COND(ERROR_DISK_FULL, no_space_on_device);
240 MAP_ERR_TO_COND(ERROR_FILE_EXISTS, file_exists);
241 MAP_ERR_TO_COND(ERROR_FILE_NOT_FOUND, no_such_file_or_directory);
242 MAP_ERR_TO_COND(ERROR_HANDLE_DISK_FULL, no_space_on_device);
243 MAP_ERR_TO_COND(ERROR_INVALID_ACCESS, permission_denied);
244 MAP_ERR_TO_COND(ERROR_INVALID_DRIVE, no_such_device);
245 MAP_ERR_TO_COND(ERROR_INVALID_FUNCTION, function_not_supported);
246 MAP_ERR_TO_COND(ERROR_INVALID_HANDLE, invalid_argument);
247 MAP_ERR_TO_COND(ERROR_INVALID_NAME, invalid_argument);
248 MAP_ERR_TO_COND(ERROR_LOCK_VIOLATION, no_lock_available);
249 MAP_ERR_TO_COND(ERROR_LOCKED, no_lock_available);
250 MAP_ERR_TO_COND(ERROR_NEGATIVE_SEEK, invalid_argument);
251 MAP_ERR_TO_COND(ERROR_NOACCESS, permission_denied);
252 MAP_ERR_TO_COND(ERROR_NOT_ENOUGH_MEMORY, not_enough_memory);
253 MAP_ERR_TO_COND(ERROR_NOT_READY, resource_unavailable_try_again);
254 MAP_ERR_TO_COND(ERROR_OPEN_FAILED, io_error);
255 MAP_ERR_TO_COND(ERROR_OPEN_FILES, device_or_resource_busy);
256 MAP_ERR_TO_COND(ERROR_OUTOFMEMORY, not_enough_memory);
257 MAP_ERR_TO_COND(ERROR_PATH_NOT_FOUND, no_such_file_or_directory);
258 MAP_ERR_TO_COND(ERROR_BAD_NETPATH, no_such_file_or_directory);
259 MAP_ERR_TO_COND(ERROR_READ_FAULT, io_error);
260 MAP_ERR_TO_COND(ERROR_RETRY, resource_unavailable_try_again);
261 MAP_ERR_TO_COND(ERROR_SEEK, io_error);
262 MAP_ERR_TO_COND(ERROR_SHARING_VIOLATION, permission_denied);
263 MAP_ERR_TO_COND(ERROR_TOO_MANY_OPEN_FILES, too_many_files_open);
264 MAP_ERR_TO_COND(ERROR_WRITE_FAULT, io_error);
265 MAP_ERR_TO_COND(ERROR_WRITE_PROTECT, permission_denied);
266 MAP_ERR_TO_COND(WSAEACCES, permission_denied);
267 MAP_ERR_TO_COND(WSAEBADF, bad_file_descriptor);
268 MAP_ERR_TO_COND(WSAEFAULT, bad_address);
269 MAP_ERR_TO_COND(WSAEINTR, interrupted);
270 MAP_ERR_TO_COND(WSAEINVAL, invalid_argument);
271 MAP_ERR_TO_COND(WSAEMFILE, too_many_files_open);
272 MAP_ERR_TO_COND(WSAENAMETOOLONG, filename_too_long);
274 return std::error_code(EV, std::system_category());
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
static void bindingsErrorHandler(void *user_data, const std::string &reason, bool gen_crash_diag)
A raw_ostream that writes to an SmallVector or SmallString.
void install_bad_alloc_error_handler(fatal_error_handler_t handler, void *user_data=nullptr)
Installs a new bad alloc error handler that should be used whenever a bad alloc error, e.g.
static void * ErrorHandlerUserData
std::string str() const
Return the twine contents as a std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void(* fatal_error_handler_t)(void *user_data, const std::string &reason, bool gen_crash_diag)
An error handler callback.
static fatal_error_handler_t ErrorHandler
void remove_fatal_error_handler()
Restores default error handling behaviour.
#define LLVM_EXTENSION
LLVM_EXTENSION - Support compilers where we have a keyword to suppress pedantic diagnostics.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
void remove_bad_alloc_error_handler()
Restores default bad alloc error handling behavior.
static void * BadAllocErrorHandlerUserData
void RunInterruptHandlers()
This function runs all the registered interrupt handlers, including the removal of files registered b...
std::error_code mapWindowsError(unsigned EV)
static std::mutex BadAllocErrorHandlerMutex
dot regions Print regions of function to dot file(with no function bodies)"
static void write(bool isBE, void *P, T V)
void report_bad_alloc_error(const char *Reason, bool GenCrashDiag=true)
Reports a bad alloc error, calling any user defined bad alloc error handler.
void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler)
Install a fatal error handler.
static fatal_error_handler_t BadAllocErrorHandler
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
StringRef str()
Return a StringRef for the vector contents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
llvm_unreachable("Unknown RegBank!")
LLVM_ATTRIBUTE_NORETURN void llvm_unreachable_internal(const char *msg=nullptr, const char *file=nullptr, unsigned line=0)
This function calls abort(), and prints the optional message to stderr.
void LLVMResetFatalErrorHandler()
Reset the fatal error handler.
static std::mutex ErrorHandlerMutex
void(* LLVMFatalErrorHandler)(const char *Reason)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef - Represent a constant reference to a string, i.e.
void install_fatal_error_handler(fatal_error_handler_t handler, void *user_data=nullptr)
install_fatal_error_handler - Installs a new error handler to be used whenever a serious (non-recover...