14#include <system_error>
20enum class ErrorErrorCode :
int {
29class ErrorErrorCategory :
public std::error_category {
31 const char *
name()
const noexcept
override {
return "Error"; }
33 std::string message(
int condition)
const override {
34 switch (
static_cast<ErrorErrorCode
>(condition)) {
35 case ErrorErrorCode::MultipleErrors:
36 return "Multiple errors";
37 case ErrorErrorCode::InconvertibleError:
38 return "Inconvertible error value. An error has occurred that could not "
39 "be converted to a known std::error_code. Please file a bug.";
40 case ErrorErrorCode::FileError:
41 return "A file error occurred.";
49 static ErrorErrorCategory ErrorErrorCat;
53void ErrorInfoBase::anchor() {}
54char ErrorInfoBase::ID = 0;
56void ECError::anchor() {}
90 return std::error_code(
static_cast<int>(ErrorErrorCode::MultipleErrors),
95 return std::error_code(
static_cast<int>(ErrorErrorCode::InconvertibleError),
100 std::error_code NestedEC = Err->convertToErrorCode();
102 return std::error_code(
static_cast<int>(ErrorErrorCode::FileError),
110 return Error(std::make_unique<ECError>(
ECError(EC)));
123#if LLVM_ENABLE_ABI_BREAKING_CHECKS
124void Error::fatalUncheckedError()
const {
125 dbgs() <<
"Program aborted due to an unhandled Error:\n";
130 dbgs() <<
"Error value was Success. (Note: Success values must still be "
131 "checked prior to being destroyed).\n";
137 : Msg(S.str()),
EC(
EC) {}
140 : Msg(S.str()),
EC(
EC), PrintMsgOnly(
true) {}
143 : Msg(
std::
move(S)),
EC(
EC), PrintMsgOnly(PrintMsgOnly) {}
164 assert(Err &&
"report_fatal_error called with success value");
182 return reinterpret_cast<ErrorInfoBase *
>(Err)->dynamicClassID();
193 char *ErrMsg =
new char[Tmp.size() + 1];
194 memcpy(ErrMsg, Tmp.data(), Tmp.size());
195 ErrMsg[Tmp.size()] =
'\0';
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static LLVMTargetMachineRef wrap(const TargetMachine *P)
static const char * toString(MIToken::TokenKind TokenKind)
static const char * getPtr(const MachOObjectFile &O, size_t Offset, size_t MachOFilesetEntryOffset=0)
SymbolStringPoolEntryUnsafe unwrap(LLVMOrcSymbolStringPoolEntryRef E)
This file defines the SmallVector class.
static ErrorErrorCategory & getErrorErrorCat()
This class wraps a std::error_code in a Error.
Base class for error info classes.
virtual std::string message() const
Return the error message as a string.
virtual std::error_code convertToErrorCode() const =0
Convert this error to a std::error_code.
virtual void log(raw_ostream &OS) const =0
Print an error message to an output stream.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
static ErrorSuccess success()
Create a success value.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
StringError(std::string &&S, std::error_code EC, bool PrintMsgOnly)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
LLVM_C_ABI void LLVMCantFail(LLVMErrorRef Err)
Report a fatal error if Err is a failure value.
LLVM_C_ABI char * LLVMGetErrorMessage(LLVMErrorRef Err)
Returns the given string's error message.
LLVM_C_ABI LLVMErrorRef LLVMCreateStringError(const char *ErrMsg)
Create a StringError.
LLVM_C_ABI void LLVMConsumeError(LLVMErrorRef Err)
Dispose of the given error without handling it.
LLVM_C_ABI LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err)
Returns the type id for the given error instance, which must be a failure value (i....
LLVM_C_ABI void LLVMDisposeErrorMessage(char *ErrMsg)
Dispose of the given error message.
const void * LLVMErrorTypeId
Error type identifier.
struct LLVMOpaqueError * LLVMErrorRef
Opaque reference to an error instance.
LLVM_C_ABI LLVMErrorTypeId LLVMGetStringErrorTypeId(void)
Returns the type id for llvm StringError.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
void visitErrors(const Error &E, HandlerT H)
Visit all the ErrorInfo(s) contained in E by passing them to the respective handler,...
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
LLVM_ABI std::string toStringWithoutConsuming(const Error &E)
Like toString(), but does not consume the error.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
LLVM_ABI std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
void consumeError(Error Err)
Consume a Error without doing anything.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Implement std::hash so that hash_code can be used in STL containers.