Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
Error.h
Go to the documentation of this file.
1//===- llvm/Support/Error.h - Recoverable error handling --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines an API used to report recoverable errors.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_SUPPORT_ERROR_H
14#define LLVM_SUPPORT_ERROR_H
15
16#include "llvm-c/Error.h"
17#include "llvm/ADT/Twine.h"
18#include "llvm/Config/abi-breaking.h"
19#include "llvm/Support/AlignOf.h"
20#include "llvm/Support/Compiler.h"
21#include "llvm/Support/Debug.h"
22#include "llvm/Support/ErrorHandling.h"
23#include "llvm/Support/ErrorOr.h"
24#include "llvm/Support/Format.h"
25#include "llvm/Support/raw_ostream.h"
26#include <cassert>
27#include <cstdint>
28#include <cstdlib>
29#include <functional>
30#include <memory>
31#include <new>
32#include <optional>
33#include <string>
34#include <system_error>
35#include <type_traits>
36#include <utility>
37#include <vector>
38
39namespacellvm {
40
41classErrorSuccess;
42
43/// Base class for error info classes. Do not extend this directly: Extend
44/// the ErrorInfo template subclass instead.
45classErrorInfoBase {
46public:
47virtual~ErrorInfoBase() =default;
48
49 /// Print an error message to an output stream.
50virtualvoidlog(raw_ostream &OS)const = 0;
51
52 /// Return the error message as a string.
53virtual std::stringmessage() const{
54 std::string Msg;
55raw_string_ostreamOS(Msg);
56log(OS);
57return Msg;
58 }
59
60 /// Convert this error to a std::error_code.
61 ///
62 /// This is a temporary crutch to enable interaction with code still
63 /// using std::error_code. It will be removed in the future.
64virtual std::error_codeconvertToErrorCode()const = 0;
65
66// Returns the class ID for this type.
67staticconstvoid *classID() {return &ID; }
68
69// Returns the class ID for the dynamic type of this ErrorInfoBase instance.
70virtualconstvoid *dynamicClassID()const = 0;
71
72// Check whether this instance is a subclass of the class identified by
73// ClassID.
74virtualboolisA(constvoid *const ClassID) const{
75return ClassID ==classID();
76 }
77
78// Check whether this instance is a subclass of ErrorInfoT.
79template <typename ErrorInfoT>boolisA() const{
80returnisA(ErrorInfoT::classID());
81 }
82
83private:
84virtualvoid anchor();
85
86staticcharID;
87};
88
89/// Lightweight error class with error context and mandatory checking.
90///
91/// Instances of this class wrap a ErrorInfoBase pointer. Failure states
92/// are represented by setting the pointer to a ErrorInfoBase subclass
93/// instance containing information describing the failure. Success is
94/// represented by a null pointer value.
95///
96/// Instances of Error also contains a 'Checked' flag, which must be set
97/// before the destructor is called, otherwise the destructor will trigger a
98/// runtime error. This enforces at runtime the requirement that all Error
99/// instances be checked or returned to the caller.
100///
101/// There are two ways to set the checked flag, depending on what state the
102/// Error instance is in. For Error instances indicating success, it
103/// is sufficient to invoke the boolean conversion operator. E.g.:
104///
105/// @code{.cpp}
106/// Error foo(<...>);
107///
108/// if (auto E = foo(<...>))
109/// return E; // <- Return E if it is in the error state.
110/// // We have verified that E was in the success state. It can now be safely
111/// // destroyed.
112/// @endcode
113///
114/// A success value *can not* be dropped. For example, just calling 'foo(<...>)'
115/// without testing the return value will raise a runtime error, even if foo
116/// returns success.
117///
118/// For Error instances representing failure, you must use either the
119/// handleErrors or handleAllErrors function with a typed handler. E.g.:
120///
121/// @code{.cpp}
122/// class MyErrorInfo : public ErrorInfo<MyErrorInfo> {
123/// // Custom error info.
124/// };
125///
126/// Error foo(<...>) { return make_error<MyErrorInfo>(...); }
127///
128/// auto E = foo(<...>); // <- foo returns failure with MyErrorInfo.
129/// auto NewE =
130/// handleErrors(std::move(E),
131/// [](const MyErrorInfo &M) {
132/// // Deal with the error.
133/// },
134/// [](std::unique_ptr<OtherError> M) -> Error {
135/// if (canHandle(*M)) {
136/// // handle error.
137/// return Error::success();
138/// }
139/// // Couldn't handle this error instance. Pass it up the stack.
140/// return Error(std::move(M));
141/// });
142/// // Note - The error passed to handleErrors will be marked as checked. If
143/// // there is no matched handler, a new error with the same payload is
144/// // created and returned.
145/// // The handlers take the error checked by handleErrors as an argument,
146/// // which can be used to retrieve more information. If a new error is
147/// // created by a handler, it will be passed back to the caller of
148/// // handleErrors and needs to be checked or return up to the stack.
149/// // Otherwise, the passed-in error is considered consumed.
150/// @endcode
151///
152/// The handleAllErrors function is identical to handleErrors, except
153/// that it has a void return type, and requires all errors to be handled and
154/// no new errors be returned. It prevents errors (assuming they can all be
155/// handled) from having to be bubbled all the way to the top-level.
156///
157/// *All* Error instances must be checked before destruction, even if
158/// they're moved-assigned or constructed from Success values that have already
159/// been checked. This enforces checking through all levels of the call stack.
160class[[nodiscard]]Error {
161// ErrorList needs to be able to yank ErrorInfoBase pointers out of Errors
162// to add to the error list. It can't rely on handleErrors for this, since
163// handleErrors does not support ErrorList handlers.
164friendclassErrorList;
165
166// handleErrors needs to be able to set the Checked flag.
167template <typename... HandlerTs>
168friendErrorhandleErrors(ErrorE, HandlerTs &&... Handlers);
169// visitErrors needs direct access to the payload.
170template <typename HandlerT>
171friendvoidvisitErrors(constError &E, HandlerTH);
172
173// Expected<T> needs to be able to steal the payload when constructed from an
174// error.
175template <typename T>friendclassExpected;
176
177// wrap needs to be able to steal the payload.
178friendLLVMErrorRefwrap(Error);
179
180protected:
181 /// Create a success value. Prefer using 'Error::success()' for readability
182Error() {
183 setPtr(nullptr);
184 setChecked(false);
185 }
186
187public:
188 /// Create a success value.
189staticErrorSuccesssuccess();
190
191// Errors are not copy-constructable.
192Error(constError &Other) =delete;
193
194 /// Move-construct an error value. The newly constructed error is considered
195 /// unchecked, even if the source error had been checked. The original error
196 /// becomes a checked Success value, regardless of its original state.
197Error(Error &&Other) {
198 setChecked(true);
199 *this = std::move(Other);
200 }
201
202 /// Create an error value. Prefer using the 'make_error' function, but
203 /// this constructor can be useful when "re-throwing" errors from handlers.
204Error(std::unique_ptr<ErrorInfoBase> Payload) {
205 setPtr(Payload.release());
206 setChecked(false);
207 }
208
209// Errors are not copy-assignable.
210Error &operator=(constError &Other) =delete;
211
212 /// Move-assign an error value. The current error must represent success, you
213 /// you cannot overwrite an unhandled error. The current error is then
214 /// considered unchecked. The source error becomes a checked success value,
215 /// regardless of its original state.
216Error &operator=(Error &&Other) {
217// Don't allow overwriting of unchecked values.
218 assertIsChecked();
219 setPtr(Other.getPtr());
220
221// This Error is unchecked, even if the source error was checked.
222 setChecked(false);
223
224// Null out Other's payload and set its checked bit.
225Other.setPtr(nullptr);
226Other.setChecked(true);
227
228return *this;
229 }
230
231 /// Destroy a Error. Fails with a call to abort() if the error is
232 /// unchecked.
233~Error() {
234 assertIsChecked();
235deletegetPtr();
236 }
237
238 /// Bool conversion. Returns true if this Error is in a failure state,
239 /// and false if it is in an accept state. If the error is in a Success state
240 /// it will be considered checked.
241explicitoperatorbool() {
242 setChecked(getPtr() ==nullptr);
243returngetPtr() !=nullptr;
244 }
245
246 /// Check whether one error is a subclass of another.
247template <typename ErrT>boolisA() const{
248returngetPtr() &&getPtr()->isA(ErrT::classID());
249 }
250
251 /// Returns the dynamic class id of this error, or null if this is a success
252 /// value.
253constvoid*dynamicClassID() const{
254if (!getPtr())
255returnnullptr;
256returngetPtr()->dynamicClassID();
257 }
258
259private:
260#if LLVM_ENABLE_ABI_BREAKING_CHECKS
261// assertIsChecked() happens very frequently, but under normal circumstances
262// is supposed to be a no-op. So we want it to be inlined, but having a bunch
263// of debug prints can cause the function to be too large for inlining. So
264// it's important that we define this function out of line so that it can't be
265// inlined.
266 [[noreturn]]void fatalUncheckedError()const;
267#endif
268
269void assertIsChecked() {
270#if LLVM_ENABLE_ABI_BREAKING_CHECKS
271if (LLVM_UNLIKELY(!getChecked() ||getPtr()))
272 fatalUncheckedError();
273#endif
274 }
275
276 ErrorInfoBase *getPtr() const{
277#if LLVM_ENABLE_ABI_BREAKING_CHECKS
278returnreinterpret_cast<ErrorInfoBase*>(
279reinterpret_cast<uintptr_t>(Payload) &
280 ~static_cast<uintptr_t>(0x1));
281#else
282return Payload;
283#endif
284 }
285
286void setPtr(ErrorInfoBase *EI) {
287#if LLVM_ENABLE_ABI_BREAKING_CHECKS
288 Payload =reinterpret_cast<ErrorInfoBase*>(
289 (reinterpret_cast<uintptr_t>(EI) &
290 ~static_cast<uintptr_t>(0x1)) |
291 (reinterpret_cast<uintptr_t>(Payload) & 0x1));
292#else
293 Payload = EI;
294#endif
295 }
296
297bool getChecked() const{
298#if LLVM_ENABLE_ABI_BREAKING_CHECKS
299return (reinterpret_cast<uintptr_t>(Payload) & 0x1) == 0;
300#else
301returntrue;
302#endif
303 }
304
305void setChecked(bool V) {
306#if LLVM_ENABLE_ABI_BREAKING_CHECKS
307 Payload =reinterpret_cast<ErrorInfoBase*>(
308 (reinterpret_cast<uintptr_t>(Payload) &
309 ~static_cast<uintptr_t>(0x1)) |
310 (V ? 0 : 1));
311#endif
312 }
313
314 std::unique_ptr<ErrorInfoBase> takePayload() {
315 std::unique_ptr<ErrorInfoBase> Tmp(getPtr());
316 setPtr(nullptr);
317 setChecked(true);
318return Tmp;
319 }
320
321friendraw_ostream &operator<<(raw_ostream &OS,constError &E) {
322if (auto *P =E.getPtr())
323P->log(OS);
324else
325OS <<"success";
326returnOS;
327 }
328
329ErrorInfoBase *Payload =nullptr;
330};
331
332/// Subclass of Error for the sole purpose of identifying the success path in
333/// the type system. This allows to catch invalid conversion to Expected<T> at
334/// compile time.
335classErrorSuccess final :publicError {};
336
337inlineErrorSuccessError::success() {returnErrorSuccess(); }
338
339/// Make a Error instance representing failure using the given error info
340/// type.
341template <typename ErrT,typename... ArgTs>Errormake_error(ArgTs &&... Args) {
342returnError(std::make_unique<ErrT>(std::forward<ArgTs>(Args)...));
343}
344
345/// Base class for user error types. Users should declare their error types
346/// like:
347///
348/// class MyError : public ErrorInfo<MyError> {
349/// ....
350/// };
351///
352/// This class provides an implementation of the ErrorInfoBase::kind
353/// method, which is used by the Error RTTI system.
354template <typename ThisErrT,typename ParentErrT = ErrorInfoBase>
355classErrorInfo :public ParentErrT {
356public:
357usingParentErrT::ParentErrT;// inherit constructors
358
359staticconstvoid *classID() {return &ThisErrT::ID; }
360
361constvoid *dynamicClassID() const override{return &ThisErrT::ID; }
362
363boolisA(constvoid *const ClassID) const override{
364return ClassID ==classID() || ParentErrT::isA(ClassID);
365 }
366};
367
368/// Special ErrorInfo subclass representing a list of ErrorInfos.
369/// Instances of this class are constructed by joinError.
370classErrorList final :publicErrorInfo<ErrorList> {
371// handleErrors needs to be able to iterate the payload list of an
372// ErrorList.
373template <typename... HandlerTs>
374friendErrorhandleErrors(ErrorE, HandlerTs &&... Handlers);
375// visitErrors needs to be able to iterate the payload list of an
376// ErrorList.
377template <typename HandlerT>
378friendvoidvisitErrors(constError &E, HandlerTH);
379
380// joinErrors is implemented in terms of join.
381friendErrorjoinErrors(Error,Error);
382
383public:
384voidlog(raw_ostream &OS) const override{
385OS <<"Multiple errors:\n";
386for (constauto &ErrPayload : Payloads) {
387 ErrPayload->log(OS);
388OS <<"\n";
389 }
390 }
391
392 std::error_codeconvertToErrorCode()const override;
393
394// Used by ErrorInfo::classID.
395staticcharID;
396
397private:
398ErrorList(std::unique_ptr<ErrorInfoBase> Payload1,
399 std::unique_ptr<ErrorInfoBase> Payload2) {
400assert(!Payload1->isA<ErrorList>() && !Payload2->isA<ErrorList>() &&
401"ErrorList constructor payloads should be singleton errors");
402 Payloads.push_back(std::move(Payload1));
403 Payloads.push_back(std::move(Payload2));
404 }
405
406staticError join(Error E1,Error E2) {
407if (!E1)
408return E2;
409if (!E2)
410return E1;
411if (E1.isA<ErrorList>()) {
412auto &E1List =static_cast<ErrorList &>(*E1.getPtr());
413if (E2.isA<ErrorList>()) {
414auto E2Payload = E2.takePayload();
415auto &E2List =static_cast<ErrorList &>(*E2Payload);
416for (auto &Payload : E2List.Payloads)
417 E1List.Payloads.push_back(std::move(Payload));
418 }else
419 E1List.Payloads.push_back(E2.takePayload());
420
421return E1;
422 }
423if (E2.isA<ErrorList>()) {
424auto &E2List =static_cast<ErrorList &>(*E2.getPtr());
425 E2List.Payloads.insert(E2List.Payloads.begin(), E1.takePayload());
426return E2;
427 }
428returnError(std::unique_ptr<ErrorList>(
429new ErrorList(E1.takePayload(), E2.takePayload())));
430 }
431
432 std::vector<std::unique_ptr<ErrorInfoBase>> Payloads;
433};
434
435/// Concatenate errors. The resulting Error is unchecked, and contains the
436/// ErrorInfo(s), if any, contained in E1, followed by the
437/// ErrorInfo(s), if any, contained in E2.
438inlineErrorjoinErrors(Error E1,Error E2) {
439return ErrorList::join(std::move(E1), std::move(E2));
440}
441
442/// Tagged union holding either a T or a Error.
443///
444/// This class parallels ErrorOr, but replaces error_code with Error. Since
445/// Error cannot be copied, this class replaces getError() with
446/// takeError(). It also adds an bool errorIsA<ErrT>() method for testing the
447/// error class type.
448///
449/// Example usage of 'Expected<T>' as a function return type:
450///
451/// @code{.cpp}
452/// Expected<int> myDivide(int A, int B) {
453/// if (B == 0) {
454/// // return an Error
455/// return createStringError(inconvertibleErrorCode(),
456/// "B must not be zero!");
457/// }
458/// // return an integer
459/// return A / B;
460/// }
461/// @endcode
462///
463/// Checking the results of to a function returning 'Expected<T>':
464/// @code{.cpp}
465/// if (auto E = Result.takeError()) {
466/// // We must consume the error. Typically one of:
467/// // - return the error to our caller
468/// // - toString(), when logging
469/// // - consumeError(), to silently swallow the error
470/// // - handleErrors(), to distinguish error types
471/// errs() << "Problem with division " << toString(std::move(E)) << "\n";
472/// return;
473/// }
474/// // use the result
475/// outs() << "The answer is " << *Result << "\n";
476/// @endcode
477///
478/// For unit-testing a function returning an 'Expected<T>', see the
479/// 'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
480
481template <class T>class[[nodiscard]]Expected {
482template <class T1>friendclassExpectedAsOutParameter;
483template <class OtherT>friendclassExpected;
484
485staticconstexprbool isRef = std::is_reference_v<T>;
486
487usingwrap = std::reference_wrapper<std::remove_reference_t<T>>;
488
489usingerror_type = std::unique_ptr<ErrorInfoBase>;
490
491public:
492usingstorage_type = std::conditional_t<isRef, wrap, T>;
493usingvalue_type =T;
494
495private:
496usingreference = std::remove_reference_t<T> &;
497usingconst_reference =const std::remove_reference_t<T> &;
498usingpointer = std::remove_reference_t<T> *;
499usingconst_pointer =const std::remove_reference_t<T> *;
500
501public:
502 /// Create an Expected<T> error value from the given Error.
503Expected(Error &&Err)
504 : HasError(true)
505#if LLVM_ENABLE_ABI_BREAKING_CHECKS
506// Expected is unchecked upon construction in Debug builds.
507 ,Unchecked(true)
508#endif
509 {
510assert(Err &&"Cannot create Expected<T> from Error success value.");
511new (getErrorStorage()) error_type(Err.takePayload());
512 }
513
514 /// Forbid to convert from Error::success() implicitly, this avoids having
515 /// Expected<T> foo() { return Error::success(); } which compiles otherwise
516 /// but triggers the assertion above.
517Expected(ErrorSuccess) =delete;
518
519 /// Create an Expected<T> success value from the given OtherT value, which
520 /// must be convertible to T.
521template <typename OtherT>
522Expected(OtherT &&Val,
523 std::enable_if_t<std::is_convertible_v<OtherT, T>> * =nullptr)
524 : HasError(false)
525#if LLVM_ENABLE_ABI_BREAKING_CHECKS
526// Expected is unchecked upon construction in Debug builds.
527 ,
528Unchecked(true)
529#endif
530 {
531new (getStorage())storage_type(std::forward<OtherT>(Val));
532 }
533
534 /// Move construct an Expected<T> value.
535Expected(Expected &&Other) { moveConstruct(std::move(Other)); }
536
537 /// Move construct an Expected<T> value from an Expected<OtherT>, where OtherT
538 /// must be convertible to T.
539template <class OtherT>
540Expected(Expected<OtherT> &&Other,
541 std::enable_if_t<std::is_convertible_v<OtherT, T>> * =nullptr) {
542 moveConstruct(std::move(Other));
543 }
544
545 /// Move construct an Expected<T> value from an Expected<OtherT>, where OtherT
546 /// isn't convertible to T.
547template <class OtherT>
548explicitExpected(
549Expected<OtherT> &&Other,
550 std::enable_if_t<!std::is_convertible_v<OtherT, T>> * =nullptr) {
551 moveConstruct(std::move(Other));
552 }
553
554 /// Move-assign from another Expected<T>.
555Expected &operator=(Expected &&Other) {
556 moveAssign(std::move(Other));
557return *this;
558 }
559
560 /// Destroy an Expected<T>.
561~Expected() {
562 assertIsChecked();
563if (!HasError)
564 getStorage()->~storage_type();
565else
566 getErrorStorage()->~error_type();
567 }
568
569 /// Return false if there is an error.
570explicitoperatorbool() {
571#if LLVM_ENABLE_ABI_BREAKING_CHECKS
572Unchecked = HasError;
573#endif
574return !HasError;
575 }
576
577 /// Returns a reference to the stored T value.
578 referenceget() {
579 assertIsChecked();
580return *getStorage();
581 }
582
583 /// Returns a const reference to the stored T value.
584 const_referenceget() const{
585 assertIsChecked();
586returnconst_cast<Expected<T> *>(this)->get();
587 }
588
589 /// Returns \a takeError() after moving the held T (if any) into \p V.
590template <class OtherT>
591ErrormoveInto(
592 OtherT &Value,
593 std::enable_if_t<std::is_assignable_v<OtherT &, T &&>> * =nullptr) && {
594if (*this)
595Value = std::move(get());
596return takeError();
597 }
598
599 /// Check that this Expected<T> is an error of type ErrT.
600template <typename ErrT>boolerrorIsA() const{
601return HasError && (*getErrorStorage())->template isA<ErrT>();
602 }
603
604 /// Take ownership of the stored error.
605 /// After calling this the Expected<T> is in an indeterminate state that can
606 /// only be safely destructed. No further calls (beside the destructor) should
607 /// be made on the Expected<T> value.
608ErrortakeError() {
609#if LLVM_ENABLE_ABI_BREAKING_CHECKS
610Unchecked =false;
611#endif
612return HasError ?Error(std::move(*getErrorStorage())) : Error::success();
613 }
614
615 /// Returns a pointer to the stored T value.
616 pointeroperator->() {
617 assertIsChecked();
618return toPointer(getStorage());
619 }
620
621 /// Returns a const pointer to the stored T value.
622 const_pointeroperator->() const{
623 assertIsChecked();
624return toPointer(getStorage());
625 }
626
627 /// Returns a reference to the stored T value.
628 referenceoperator*() {
629 assertIsChecked();
630return *getStorage();
631 }
632
633 /// Returns a const reference to the stored T value.
634 const_referenceoperator*() const{
635 assertIsChecked();
636return *getStorage();
637 }
638
639private:
640template <class T1>
641staticbool compareThisIfSameType(constT1 &a,constT1 &b) {
642return &a == &b;
643 }
644
645template <class T1,class T2>
646staticbool compareThisIfSameType(constT1 &,const T2 &) {
647returnfalse;
648 }
649
650template <class OtherT>void moveConstruct(Expected<OtherT> &&Other) {
651 HasError =Other.HasError;
652#if LLVM_ENABLE_ABI_BREAKING_CHECKS
653Unchecked =true;
654Other.Unchecked =false;
655#endif
656
657if (!HasError)
658new (getStorage()) storage_type(std::move(*Other.getStorage()));
659else
660new (getErrorStorage()) error_type(std::move(*Other.getErrorStorage()));
661 }
662
663template <class OtherT>void moveAssign(Expected<OtherT> &&Other) {
664 assertIsChecked();
665
666if (compareThisIfSameType(*this,Other))
667return;
668
669 this->~Expected();
670new (this) Expected(std::move(Other));
671 }
672
673 pointer toPointer(pointer Val) {return Val; }
674
675 const_pointer toPointer(const_pointer Val) const{return Val; }
676
677 pointer toPointer(wrap *Val) {return &Val->get(); }
678
679 const_pointer toPointer(constwrap *Val) const{return &Val->get(); }
680
681 storage_type *getStorage() {
682assert(!HasError &&"Cannot get value when an error exists!");
683returnreinterpret_cast<storage_type *>(&TStorage);
684 }
685
686const storage_type *getStorage() const{
687assert(!HasError &&"Cannot get value when an error exists!");
688returnreinterpret_cast<conststorage_type *>(&TStorage);
689 }
690
691 error_type *getErrorStorage() {
692assert(HasError &&"Cannot get error when a value exists!");
693returnreinterpret_cast<error_type *>(&ErrorStorage);
694 }
695
696const error_type *getErrorStorage() const{
697assert(HasError &&"Cannot get error when a value exists!");
698returnreinterpret_cast<consterror_type *>(&ErrorStorage);
699 }
700
701// Used by ExpectedAsOutParameter to reset the checked flag.
702void setUnchecked() {
703#if LLVM_ENABLE_ABI_BREAKING_CHECKS
704Unchecked =true;
705#endif
706 }
707
708#if LLVM_ENABLE_ABI_BREAKING_CHECKS
709 [[noreturn]]LLVM_ATTRIBUTE_NOINLINEvoid fatalUncheckedExpected() const{
710dbgs() <<"Expected<T> must be checked before access or destruction.\n";
711if (HasError) {
712dbgs() <<"Unchecked Expected<T> contained error:\n";
713 (*getErrorStorage())->log(dbgs());
714 }else
715dbgs() <<"Expected<T> value was in success state. (Note: Expected<T> "
716"values in success mode must still be checked prior to being "
717"destroyed).\n";
718 abort();
719 }
720#endif
721
722void assertIsChecked() const{
723#if LLVM_ENABLE_ABI_BREAKING_CHECKS
724if (LLVM_UNLIKELY(Unchecked))
725 fatalUncheckedExpected();
726#endif
727 }
728
729union{
730AlignedCharArrayUnion<storage_type>TStorage;
731AlignedCharArrayUnion<error_type>ErrorStorage;
732 };
733bool HasError : 1;
734#if LLVM_ENABLE_ABI_BREAKING_CHECKS
735boolUnchecked : 1;
736#endif
737};
738
739/// Report a serious error, calling any installed error handler. See
740/// ErrorHandling.h.
741[[noreturn]]voidreport_fatal_error(Error Err,bool gen_crash_diag =true);
742
743/// Report a fatal error if Err is a failure value.
744///
745/// This function can be used to wrap calls to fallible functions ONLY when it
746/// is known that the Error will always be a success value. E.g.
747///
748/// @code{.cpp}
749/// // foo only attempts the fallible operation if DoFallibleOperation is
750/// // true. If DoFallibleOperation is false then foo always returns
751/// // Error::success().
752/// Error foo(bool DoFallibleOperation);
753///
754/// cantFail(foo(false));
755/// @endcode
756inlinevoidcantFail(Error Err,constchar *Msg =nullptr) {
757if (Err) {
758if (!Msg)
759 Msg ="Failure value returned from cantFail wrapped call";
760#ifndef NDEBUG
761 std::string Str;
762raw_string_ostreamOS(Str);
763OS << Msg <<"\n" << Err;
764 Msg = Str.c_str();
765#endif
766llvm_unreachable(Msg);
767 }
768}
769
770/// Report a fatal error if ValOrErr is a failure value, otherwise unwraps and
771/// returns the contained value.
772///
773/// This function can be used to wrap calls to fallible functions ONLY when it
774/// is known that the Error will always be a success value. E.g.
775///
776/// @code{.cpp}
777/// // foo only attempts the fallible operation if DoFallibleOperation is
778/// // true. If DoFallibleOperation is false then foo always returns an int.
779/// Expected<int> foo(bool DoFallibleOperation);
780///
781/// int X = cantFail(foo(false));
782/// @endcode
783template <typename T>
784TcantFail(Expected<T> ValOrErr,constchar *Msg =nullptr) {
785if (ValOrErr)
786return std::move(*ValOrErr);
787else {
788if (!Msg)
789 Msg ="Failure value returned from cantFail wrapped call";
790#ifndef NDEBUG
791 std::string Str;
792raw_string_ostreamOS(Str);
793autoE = ValOrErr.takeError();
794OS << Msg <<"\n" <<E;
795 Msg = Str.c_str();
796#endif
797llvm_unreachable(Msg);
798 }
799}
800
801/// Report a fatal error if ValOrErr is a failure value, otherwise unwraps and
802/// returns the contained reference.
803///
804/// This function can be used to wrap calls to fallible functions ONLY when it
805/// is known that the Error will always be a success value. E.g.
806///
807/// @code{.cpp}
808/// // foo only attempts the fallible operation if DoFallibleOperation is
809/// // true. If DoFallibleOperation is false then foo always returns a Bar&.
810/// Expected<Bar&> foo(bool DoFallibleOperation);
811///
812/// Bar &X = cantFail(foo(false));
813/// @endcode
814template <typename T>
815T&cantFail(Expected<T&> ValOrErr,constchar *Msg =nullptr) {
816if (ValOrErr)
817return *ValOrErr;
818else {
819if (!Msg)
820 Msg ="Failure value returned from cantFail wrapped call";
821#ifndef NDEBUG
822 std::string Str;
823raw_string_ostreamOS(Str);
824autoE = ValOrErr.takeError();
825OS << Msg <<"\n" <<E;
826 Msg = Str.c_str();
827#endif
828llvm_unreachable(Msg);
829 }
830}
831
832/// Helper for testing applicability of, and applying, handlers for
833/// ErrorInfo types.
834template <typename HandlerT>
835classErrorHandlerTraits
836 :publicErrorHandlerTraits<
837 decltype(&std::remove_reference_t<HandlerT>::operator())> {};
838
839// Specialization functions of the form 'Error (const ErrT&)'.
840template <typename ErrT>classErrorHandlerTraits<Error (&)(ErrT &)> {
841public:
842staticboolappliesTo(constErrorInfoBase &E) {
843returnE.template isA<ErrT>();
844 }
845
846template <typename HandlerT>
847staticErrorapply(HandlerT &&H, std::unique_ptr<ErrorInfoBase>E) {
848assert(appliesTo(*E) &&"Applying incorrect handler");
849returnH(static_cast<ErrT &>(*E));
850 }
851};
852
853// Specialization functions of the form 'void (const ErrT&)'.
854template <typename ErrT>classErrorHandlerTraits<void (&)(ErrT &)> {
855public:
856staticboolappliesTo(constErrorInfoBase &E) {
857returnE.template isA<ErrT>();
858 }
859
860template <typename HandlerT>
861staticErrorapply(HandlerT &&H, std::unique_ptr<ErrorInfoBase>E) {
862assert(appliesTo(*E) &&"Applying incorrect handler");
863H(static_cast<ErrT &>(*E));
864returnError::success();
865 }
866};
867
868/// Specialization for functions of the form 'Error (std::unique_ptr<ErrT>)'.
869template <typename ErrT>
870classErrorHandlerTraits<Error (&)(std::unique_ptr<ErrT>)> {
871public:
872staticboolappliesTo(constErrorInfoBase &E) {
873returnE.template isA<ErrT>();
874 }
875
876template <typename HandlerT>
877staticErrorapply(HandlerT &&H, std::unique_ptr<ErrorInfoBase>E) {
878assert(appliesTo(*E) &&"Applying incorrect handler");
879 std::unique_ptr<ErrT> SubE(static_cast<ErrT *>(E.release()));
880returnH(std::move(SubE));
881 }
882};
883
884/// Specialization for functions of the form 'void (std::unique_ptr<ErrT>)'.
885template <typename ErrT>
886classErrorHandlerTraits<void (&)(std::unique_ptr<ErrT>)> {
887public:
888staticboolappliesTo(constErrorInfoBase &E) {
889returnE.template isA<ErrT>();
890 }
891
892template <typename HandlerT>
893staticErrorapply(HandlerT &&H, std::unique_ptr<ErrorInfoBase>E) {
894assert(appliesTo(*E) &&"Applying incorrect handler");
895 std::unique_ptr<ErrT> SubE(static_cast<ErrT *>(E.release()));
896H(std::move(SubE));
897returnError::success();
898 }
899};
900
901// Specialization for member functions of the form 'RetT (const ErrT&)'.
902template <typename C,typename RetT,typename ErrT>
903classErrorHandlerTraits<RetT (C::*)(ErrT &)>
904 :publicErrorHandlerTraits<RetT (&)(ErrT &)> {};
905
906// Specialization for member functions of the form 'RetT (const ErrT&) const'.
907template <typename C,typename RetT,typename ErrT>
908classErrorHandlerTraits<RetT (C::*)(ErrT &)const>
909 :publicErrorHandlerTraits<RetT (&)(ErrT &)> {};
910
911// Specialization for member functions of the form 'RetT (const ErrT&)'.
912template <typename C,typename RetT,typename ErrT>
913classErrorHandlerTraits<RetT (C::*)(const ErrT &)>
914 :publicErrorHandlerTraits<RetT (&)(ErrT &)> {};
915
916// Specialization for member functions of the form 'RetT (const ErrT&) const'.
917template <typename C,typename RetT,typename ErrT>
918classErrorHandlerTraits<RetT (C::*)(const ErrT &)const>
919 :publicErrorHandlerTraits<RetT (&)(ErrT &)> {};
920
921/// Specialization for member functions of the form
922/// 'RetT (std::unique_ptr<ErrT>)'.
923template <typename C,typename RetT,typename ErrT>
924classErrorHandlerTraits<RetT (C::*)(std::unique_ptr<ErrT>)>
925 :publicErrorHandlerTraits<RetT (&)(std::unique_ptr<ErrT>)> {};
926
927/// Specialization for member functions of the form
928/// 'RetT (std::unique_ptr<ErrT>) const'.
929template <typename C,typename RetT,typename ErrT>
930classErrorHandlerTraits<RetT (C::*)(std::unique_ptr<ErrT>)const>
931 :publicErrorHandlerTraits<RetT (&)(std::unique_ptr<ErrT>)> {};
932
933inlineErrorhandleErrorImpl(std::unique_ptr<ErrorInfoBase> Payload) {
934returnError(std::move(Payload));
935}
936
937template <typename HandlerT,typename... HandlerTs>
938ErrorhandleErrorImpl(std::unique_ptr<ErrorInfoBase> Payload,
939 HandlerT &&Handler, HandlerTs &&... Handlers) {
940if (ErrorHandlerTraits<HandlerT>::appliesTo(*Payload))
941returnErrorHandlerTraits<HandlerT>::apply(std::forward<HandlerT>(Handler),
942 std::move(Payload));
943returnhandleErrorImpl(std::move(Payload),
944 std::forward<HandlerTs>(Handlers)...);
945}
946
947/// Pass the ErrorInfo(s) contained in E to their respective handlers. Any
948/// unhandled errors (or Errors returned by handlers) are re-concatenated and
949/// returned.
950/// Because this function returns an error, its result must also be checked
951/// or returned. If you intend to handle all errors use handleAllErrors
952/// (which returns void, and will abort() on unhandled errors) instead.
953template <typename... HandlerTs>
954ErrorhandleErrors(ErrorE, HandlerTs &&... Hs) {
955if (!E)
956returnError::success();
957
958 std::unique_ptr<ErrorInfoBase> Payload =E.takePayload();
959
960if (Payload->isA<ErrorList>()) {
961ErrorList &List =static_cast<ErrorList &>(*Payload);
962Error R;
963for (auto &P :List.Payloads)
964 R = ErrorList::join(
965 std::move(R),
966handleErrorImpl(std::move(P), std::forward<HandlerTs>(Hs)...));
967return R;
968 }
969
970returnhandleErrorImpl(std::move(Payload), std::forward<HandlerTs>(Hs)...);
971}
972
973/// Behaves the same as handleErrors, except that by contract all errors
974/// *must* be handled by the given handlers (i.e. there must be no remaining
975/// errors after running the handlers, or llvm_unreachable is called).
976template <typename... HandlerTs>
977voidhandleAllErrors(ErrorE, HandlerTs &&... Handlers) {
978cantFail(handleErrors(std::move(E), std::forward<HandlerTs>(Handlers)...));
979}
980
981/// Check that E is a non-error, then drop it.
982/// If E is an error, llvm_unreachable will be called.
983inlinevoidhandleAllErrors(ErrorE) {
984cantFail(std::move(E));
985}
986
987/// Visit all the ErrorInfo(s) contained in E by passing them to the respective
988/// handler, without consuming the error.
989template <typename HandlerT>voidvisitErrors(constError &E, HandlerTH) {
990constErrorInfoBase *Payload =E.getPtr();
991if (!Payload)
992return;
993
994if (Payload->isA<ErrorList>()) {
995constErrorList &List =static_cast<constErrorList &>(*Payload);
996for (constauto &P :List.Payloads)
997H(*P);
998return;
999 }
1000
1001returnH(*Payload);
1002}
1003
1004/// Handle any errors (if present) in an Expected<T>, then try a recovery path.
1005///
1006/// If the incoming value is a success value it is returned unmodified. If it
1007/// is a failure value then it the contained error is passed to handleErrors.
1008/// If handleErrors is able to handle the error then the RecoveryPath functor
1009/// is called to supply the final result. If handleErrors is not able to
1010/// handle all errors then the unhandled errors are returned.
1011///
1012/// This utility enables the follow pattern:
1013///
1014/// @code{.cpp}
1015/// enum FooStrategy { Aggressive, Conservative };
1016/// Expected<Foo> foo(FooStrategy S);
1017///
1018/// auto ResultOrErr =
1019/// handleExpected(
1020/// foo(Aggressive),
1021/// []() { return foo(Conservative); },
1022/// [](AggressiveStrategyError&) {
1023/// // Implicitly conusme this - we'll recover by using a conservative
1024/// // strategy.
1025/// });
1026///
1027/// @endcode
1028template <typenameT,typename RecoveryFtor,typename... HandlerTs>
1029Expected<T>handleExpected(Expected<T> ValOrErr, RecoveryFtor &&RecoveryPath,
1030 HandlerTs &&... Handlers) {
1031if (ValOrErr)
1032return ValOrErr;
1033
1034if (auto Err =handleErrors(ValOrErr.takeError(),
1035 std::forward<HandlerTs>(Handlers)...))
1036return std::move(Err);
1037
1038return RecoveryPath();
1039}
1040
1041/// Log all errors (if any) in E to OS. If there are any errors, ErrorBanner
1042/// will be printed before the first one is logged. A newline will be printed
1043/// after each error.
1044///
1045/// This function is compatible with the helpers from Support/WithColor.h. You
1046/// can pass any of them as the OS. Please consider using them instead of
1047/// including 'error: ' in the ErrorBanner.
1048///
1049/// This is useful in the base level of your program to allow clean termination
1050/// (allowing clean deallocation of resources, etc.), while reporting error
1051/// information to the user.
1052voidlogAllUnhandledErrors(ErrorE, raw_ostream &OS, Twine ErrorBanner = {});
1053
1054/// Write all error messages (if any) in E to a string. The newline character
1055/// is used to separate error messages.
1056std::stringtoString(ErrorE);
1057
1058/// Like toString(), but does not consume the error. This can be used to print
1059/// a warning while retaining the original error object.
1060std::stringtoStringWithoutConsuming(const Error &E);
1061
1062/// Consume a Error without doing anything. This method should be used
1063/// only where an error can be considered a reasonable and expected return
1064/// value.
1065///
1066/// Uses of this method are potentially indicative of design problems: If it's
1067/// legitimate to do nothing while processing an "error", the error-producer
1068/// might be more clearly refactored to return an std::optional<T>.
1069inlinevoidconsumeError(Error Err) {
1070handleAllErrors(std::move(Err), [](constErrorInfoBase &) {});
1071}
1072
1073/// Convert an Expected to an Optional without doing anything. This method
1074/// should be used only where an error can be considered a reasonable and
1075/// expected return value.
1076///
1077/// Uses of this method are potentially indicative of problems: perhaps the
1078/// error should be propagated further, or the error-producer should just
1079/// return an Optional in the first place.
1080template <typename T> std::optional<T>expectedToOptional(Expected<T> &&E) {
1081if (E)
1082return std::move(*E);
1083consumeError(E.takeError());
1084return std::nullopt;
1085}
1086
1087template <typename T> std::optional<T>expectedToStdOptional(Expected<T> &&E) {
1088if (E)
1089return std::move(*E);
1090consumeError(E.takeError());
1091return std::nullopt;
1092}
1093
1094/// Helper for converting an Error to a bool.
1095///
1096/// This method returns true if Err is in an error state, or false if it is
1097/// in a success state. Puts Err in a checked state in both cases (unlike
1098/// Error::operator bool(), which only does this for success states).
1099inlineboolerrorToBool(Error Err) {
1100bool IsError =static_cast<bool>(Err);
1101if (IsError)
1102consumeError(std::move(Err));
1103return IsError;
1104}
1105
1106/// Helper for Errors used as out-parameters.
1107///
1108/// This helper is for use with the Error-as-out-parameter idiom, where an error
1109/// is passed to a function or method by reference, rather than being returned.
1110/// In such cases it is helpful to set the checked bit on entry to the function
1111/// so that the error can be written to (unchecked Errors abort on assignment)
1112/// and clear the checked bit on exit so that clients cannot accidentally forget
1113/// to check the result. This helper performs these actions automatically using
1114/// RAII:
1115///
1116/// @code{.cpp}
1117/// Result foo(Error &Err) {
1118/// ErrorAsOutParameter ErrAsOutParam(&Err); // 'Checked' flag set
1119/// // <body of foo>
1120/// // <- 'Checked' flag auto-cleared when ErrAsOutParam is destructed.
1121/// }
1122/// @endcode
1123///
1124/// ErrorAsOutParameter takes an Error* rather than Error& so that it can be
1125/// used with optional Errors (Error pointers that are allowed to be null). If
1126/// ErrorAsOutParameter took an Error reference, an instance would have to be
1127/// created inside every condition that verified that Error was non-null. By
1128/// taking an Error pointer we can just create one instance at the top of the
1129/// function.
1130classErrorAsOutParameter {
1131public:
1132
1133ErrorAsOutParameter(Error *Err) : Err(Err) {
1134// Raise the checked bit if Err is success.
1135if (Err)
1136 (void)!!*Err;
1137 }
1138
1139ErrorAsOutParameter(Error &Err) : Err(&Err) {
1140 (void)!!Err;
1141 }
1142
1143~ErrorAsOutParameter() {
1144// Clear the checked bit.
1145if (Err && !*Err)
1146 *Err =Error::success();
1147 }
1148
1149private:
1150Error *Err;
1151};
1152
1153/// Helper for Expected<T>s used as out-parameters.
1154///
1155/// See ErrorAsOutParameter.
1156template <typename T>
1157classExpectedAsOutParameter {
1158public:
1159ExpectedAsOutParameter(Expected<T> *ValOrErr)
1160 : ValOrErr(ValOrErr) {
1161if (ValOrErr)
1162 (void)!!*ValOrErr;
1163 }
1164
1165~ExpectedAsOutParameter() {
1166if (ValOrErr)
1167 ValOrErr->setUnchecked();
1168 }
1169
1170private:
1171Expected<T> *ValOrErr;
1172};
1173
1174/// This class wraps a std::error_code in a Error.
1175///
1176/// This is useful if you're writing an interface that returns a Error
1177/// (or Expected) and you want to call code that still returns
1178/// std::error_codes.
1179classECError :publicErrorInfo<ECError> {
1180friendErrorerrorCodeToError(std::error_code);
1181
1182void anchor()override;
1183
1184public:
1185voidsetErrorCode(std::error_codeEC) { this->EC =EC; }
1186 std::error_codeconvertToErrorCode() const override{returnEC; }
1187voidlog(raw_ostream &OS) const override{OS <<EC.message(); }
1188
1189// Used by ErrorInfo::classID.
1190staticcharID;
1191
1192protected:
1193ECError() =default;
1194ECError(std::error_codeEC) :EC(EC) {}
1195
1196 std::error_codeEC;
1197};
1198
1199/// The value returned by this function can be returned from convertToErrorCode
1200/// for Error values where no sensible translation to std::error_code exists.
1201/// It should only be used in this situation, and should never be used where a
1202/// sensible conversion to std::error_code is available, as attempts to convert
1203/// to/from this error will result in a fatal error. (i.e. it is a programmatic
1204/// error to try to convert such a value).
1205std::error_codeinconvertibleErrorCode();
1206
1207/// Helper for converting an std::error_code to a Error.
1208ErrorerrorCodeToError(std::error_code EC);
1209
1210/// Helper for converting an ECError to a std::error_code.
1211///
1212/// This method requires that Err be Error() or an ECError, otherwise it
1213/// will trigger a call to abort().
1214std::error_codeerrorToErrorCode(Error Err);
1215
1216/// Helper to get errno as an std::error_code.
1217///
1218/// errno should always be represented using the generic category as that's what
1219/// both libc++ and libstdc++ do. On POSIX systems you can also represent them
1220/// using the system category, however this makes them compare differently for
1221/// values outside of those used by `std::errc` if one is generic and the other
1222/// is system.
1223///
1224/// See the libc++ and libstdc++ implementations of `default_error_condition` on
1225/// the system category for more details on what the difference is.
1226inline std::error_codeerrnoAsErrorCode() {
1227return std::error_code(errno, std::generic_category());
1228}
1229
1230/// Convert an ErrorOr<T> to an Expected<T>.
1231template <typename T>Expected<T>errorOrToExpected(ErrorOr<T> &&EO) {
1232if (auto EC = EO.getError())
1233returnerrorCodeToError(EC);
1234return std::move(*EO);
1235}
1236
1237/// Convert an Expected<T> to an ErrorOr<T>.
1238template <typename T>ErrorOr<T>expectedToErrorOr(Expected<T> &&E) {
1239if (auto Err =E.takeError())
1240returnerrorToErrorCode(std::move(Err));
1241return std::move(*E);
1242}
1243
1244/// This class wraps a string in an Error.
1245///
1246/// StringError is useful in cases where the client is not expected to be able
1247/// to consume the specific error message programmatically (for example, if the
1248/// error message is to be presented to the user).
1249///
1250/// StringError can also be used when additional information is to be printed
1251/// along with a error_code message. Depending on the constructor called, this
1252/// class can either display:
1253/// 1. the error_code message (ECError behavior)
1254/// 2. a string
1255/// 3. the error_code message and a string
1256///
1257/// These behaviors are useful when subtyping is required; for example, when a
1258/// specific library needs an explicit error type. In the example below,
1259/// PDBError is derived from StringError:
1260///
1261/// @code{.cpp}
1262/// Expected<int> foo() {
1263/// return llvm::make_error<PDBError>(pdb_error_code::dia_failed_loading,
1264/// "Additional information");
1265/// }
1266/// @endcode
1267///
1268classStringError :publicErrorInfo<StringError> {
1269public:
1270staticcharID;
1271
1272StringError(std::string &&S, std::error_code EC,bool PrintMsgOnly);
1273 /// Prints EC + S and converts to EC.
1274StringError(std::error_code EC,constTwine &S =Twine());
1275 /// Prints S and converts to EC.
1276StringError(constTwine &S, std::error_code EC);
1277
1278voidlog(raw_ostream &OS)const override;
1279 std::error_codeconvertToErrorCode()const override;
1280
1281const std::string &getMessage() const{return Msg; }
1282
1283private:
1284 std::string Msg;
1285 std::error_code EC;
1286constbool PrintMsgOnly =false;
1287};
1288
1289/// Create formatted StringError object.
1290template <typename... Ts>
1291inlineErrorcreateStringError(std::error_code EC,charconst *Fmt,
1292const Ts &... Vals) {
1293 std::string Buffer;
1294raw_string_ostream(Buffer) <<format(Fmt, Vals...);
1295return make_error<StringError>(Buffer, EC);
1296}
1297
1298ErrorcreateStringError(std::string &&Msg, std::error_code EC);
1299
1300inlineErrorcreateStringError(std::error_code EC,constchar *S) {
1301returncreateStringError(std::string(S), EC);
1302}
1303
1304inlineErrorcreateStringError(std::error_code EC,constTwine &S) {
1305returncreateStringError(S.str(), EC);
1306}
1307
1308/// Create a StringError with an inconvertible error code.
1309inlineErrorcreateStringError(constTwine &S) {
1310returncreateStringError(llvm::inconvertibleErrorCode(), S);
1311}
1312
1313template <typename... Ts>
1314inlineErrorcreateStringError(charconst *Fmt,const Ts &...Vals) {
1315returncreateStringError(llvm::inconvertibleErrorCode(), Fmt, Vals...);
1316}
1317
1318template <typename... Ts>
1319inlineErrorcreateStringError(std::errc EC,charconst *Fmt,
1320const Ts &... Vals) {
1321returncreateStringError(std::make_error_code(EC), Fmt, Vals...);
1322}
1323
1324/// This class wraps a filename and another Error.
1325///
1326/// In some cases, an error needs to live along a 'source' name, in order to
1327/// show more detailed information to the user.
1328classFileError final :publicErrorInfo<FileError> {
1329
1330friendErrorcreateFileError(constTwine &,Error);
1331friendErrorcreateFileError(constTwine &,size_t,Error);
1332
1333public:
1334voidlog(raw_ostream &OS) const override{
1335assert(Err &&"Trying to log after takeError().");
1336OS <<"'" << FileName <<"': ";
1337if (Line)
1338OS <<"line " << *Line <<": ";
1339 Err->log(OS);
1340 }
1341
1342 std::stringmessageWithoutFileInfo() const{
1343 std::string Msg;
1344raw_string_ostreamOS(Msg);
1345 Err->log(OS);
1346return Msg;
1347 }
1348
1349StringRefgetFileName() const{return FileName; }
1350
1351ErrortakeError() {returnError(std::move(Err)); }
1352
1353 std::error_codeconvertToErrorCode()const override;
1354
1355// Used by ErrorInfo::classID.
1356staticcharID;
1357
1358private:
1359FileError(constTwine &F, std::optional<size_t> LineNum,
1360 std::unique_ptr<ErrorInfoBase>E) {
1361assert(E &&"Cannot create FileError from Error success value.");
1362 FileName =F.str();
1363 Err = std::move(E);
1364 Line = std::move(LineNum);
1365 }
1366
1367staticError build(constTwine &F, std::optional<size_t> Line,ErrorE) {
1368 std::unique_ptr<ErrorInfoBase> Payload;
1369handleAllErrors(std::move(E),
1370 [&](std::unique_ptr<ErrorInfoBase> EIB) ->Error {
1371 Payload = std::move(EIB);
1372returnError::success();
1373 });
1374return Error(
1375 std::unique_ptr<FileError>(new FileError(F, Line, std::move(Payload))));
1376 }
1377
1378 std::string FileName;
1379 std::optional<size_t>Line;
1380 std::unique_ptr<ErrorInfoBase> Err;
1381};
1382
1383/// Concatenate a source file path and/or name with an Error. The resulting
1384/// Error is unchecked.
1385inlineErrorcreateFileError(constTwine &F,ErrorE) {
1386return FileError::build(F, std::optional<size_t>(), std::move(E));
1387}
1388
1389/// Concatenate a source file path and/or name with line number and an Error.
1390/// The resulting Error is unchecked.
1391inlineErrorcreateFileError(constTwine &F,size_t Line,ErrorE) {
1392return FileError::build(F, std::optional<size_t>(Line), std::move(E));
1393}
1394
1395/// Concatenate a source file path and/or name with a std::error_code
1396/// to form an Error object.
1397inlineErrorcreateFileError(constTwine &F, std::error_code EC) {
1398returncreateFileError(F,errorCodeToError(EC));
1399}
1400
1401/// Concatenate a source file path and/or name with line number and
1402/// std::error_code to form an Error object.
1403inlineErrorcreateFileError(constTwine &F,size_t Line, std::error_code EC) {
1404returncreateFileError(F, Line,errorCodeToError(EC));
1405}
1406
1407ErrorcreateFileError(constTwine &F,ErrorSuccess) =delete;
1408
1409/// Helper for check-and-exit error handling.
1410///
1411/// For tool use only. NOT FOR USE IN LIBRARY CODE.
1412///
1413classExitOnError {
1414public:
1415 /// Create an error on exit helper.
1416ExitOnError(std::string Banner ="",int DefaultErrorExitCode = 1)
1417 : Banner(std::move(Banner)),
1418 GetExitCode([=](constError &) {return DefaultErrorExitCode; }) {}
1419
1420 /// Set the banner string for any errors caught by operator().
1421voidsetBanner(std::string Banner) { this->Banner = std::move(Banner); }
1422
1423 /// Set the exit-code mapper function.
1424voidsetExitCodeMapper(std::function<int(constError &)> GetExitCode) {
1425 this->GetExitCode = std::move(GetExitCode);
1426 }
1427
1428 /// Check Err. If it's in a failure state log the error(s) and exit.
1429voidoperator()(Error Err) const{ checkError(std::move(Err)); }
1430
1431 /// Check E. If it's in a success state then return the contained value. If
1432 /// it's in a failure state log the error(s) and exit.
1433template <typename T>Toperator()(Expected<T> &&E) const{
1434 checkError(E.takeError());
1435return std::move(*E);
1436 }
1437
1438 /// Check E. If it's in a success state then return the contained reference. If
1439 /// it's in a failure state log the error(s) and exit.
1440template <typename T>T&operator()(Expected<T&> &&E) const{
1441 checkError(E.takeError());
1442return *E;
1443 }
1444
1445private:
1446void checkError(Error Err) const{
1447if (Err) {
1448int ExitCode = GetExitCode(Err);
1449logAllUnhandledErrors(std::move(Err),errs(), Banner);
1450 exit(ExitCode);
1451 }
1452 }
1453
1454 std::string Banner;
1455 std::function<int(const Error &)> GetExitCode;
1456};
1457
1458/// Conversion from Error to LLVMErrorRef for C error bindings.
1459inlineLLVMErrorRefwrap(Error Err) {
1460returnreinterpret_cast<LLVMErrorRef>(Err.takePayload().release());
1461}
1462
1463/// Conversion from LLVMErrorRef to Error for C error bindings.
1464inlineErrorunwrap(LLVMErrorRef ErrRef) {
1465returnError(std::unique_ptr<ErrorInfoBase>(
1466reinterpret_cast<ErrorInfoBase *>(ErrRef)));
1467}
1468
1469}// end namespace llvm
1470
1471#endif// LLVM_SUPPORT_ERROR_H
Unchecked
@ Unchecked
Definition:AArch64AsmPrinter.cpp:72
const
aarch64 promote const
Definition:AArch64PromoteConstant.cpp:230
AlignOf.h
true
basic Basic Alias true
Definition:BasicAliasAnalysis.cpp:1981
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Compiler.h
LLVM_UNLIKELY
#define LLVM_UNLIKELY(EXPR)
Definition:Compiler.h:320
LLVM_ATTRIBUTE_NOINLINE
#define LLVM_ATTRIBUTE_NOINLINE
LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, mark a method "not for inl...
Definition:Compiler.h:330
Debug.h
Other
std::optional< std::vector< StOtherPiece > > Other
Definition:ELFYAML.cpp:1315
ErrorOr.h
Provides ErrorOr<T> smart pointer.
wrap
static LLVMTargetMachineRef wrap(const TargetMachine *P)
Definition:ExecutionEngineBindings.cpp:33
Format.h
F
#define F(x, y, z)
Definition:MD5.cpp:55
H
#define H(x, y, z)
Definition:MD5.cpp:57
getPtr
static const char * getPtr(const MachOObjectFile &O, size_t Offset, size_t MachOFilesetEntryOffset=0)
Definition:MachOObjectFile.cpp:111
T
#define T
Definition:Mips16ISelLowering.cpp:341
T1
#define T1
Definition:Mips16ISelLowering.cpp:340
P
#define P(N)
if
if(PassOpts->AAPipeline)
Definition:PassBuilderBindings.cpp:64
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
Twine.h
T
bool
llvm::ECError
This class wraps a std::error_code in a Error.
Definition:Error.h:1179
llvm::ECError::ECError
ECError()=default
llvm::ECError::EC
std::error_code EC
Definition:Error.h:1196
llvm::ECError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition:Error.h:1186
llvm::ECError::ECError
ECError(std::error_code EC)
Definition:Error.h:1194
llvm::ECError::errorCodeToError
friend Error errorCodeToError(std::error_code)
Helper for converting an std::error_code to a Error.
Definition:Error.cpp:111
llvm::ECError::setErrorCode
void setErrorCode(std::error_code EC)
Definition:Error.h:1185
llvm::ECError::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition:Error.h:1187
llvm::ECError::ID
static char ID
Definition:Error.h:1190
llvm::ErrorAsOutParameter
Helper for Errors used as out-parameters.
Definition:Error.h:1130
llvm::ErrorAsOutParameter::ErrorAsOutParameter
ErrorAsOutParameter(Error *Err)
Definition:Error.h:1133
llvm::ErrorAsOutParameter::ErrorAsOutParameter
ErrorAsOutParameter(Error &Err)
Definition:Error.h:1139
llvm::ErrorAsOutParameter::~ErrorAsOutParameter
~ErrorAsOutParameter()
Definition:Error.h:1143
llvm::ErrorHandlerTraits< Error(&)(ErrT &)>::appliesTo
static bool appliesTo(const ErrorInfoBase &E)
Definition:Error.h:842
llvm::ErrorHandlerTraits< Error(&)(ErrT &)>::apply
static Error apply(HandlerT &&H, std::unique_ptr< ErrorInfoBase > E)
Definition:Error.h:847
llvm::ErrorHandlerTraits< Error(&)(std::unique_ptr< ErrT >)>::apply
static Error apply(HandlerT &&H, std::unique_ptr< ErrorInfoBase > E)
Definition:Error.h:877
llvm::ErrorHandlerTraits< Error(&)(std::unique_ptr< ErrT >)>::appliesTo
static bool appliesTo(const ErrorInfoBase &E)
Definition:Error.h:872
llvm::ErrorHandlerTraits< void(&)(ErrT &)>::appliesTo
static bool appliesTo(const ErrorInfoBase &E)
Definition:Error.h:856
llvm::ErrorHandlerTraits< void(&)(ErrT &)>::apply
static Error apply(HandlerT &&H, std::unique_ptr< ErrorInfoBase > E)
Definition:Error.h:861
llvm::ErrorHandlerTraits< void(&)(std::unique_ptr< ErrT >)>::appliesTo
static bool appliesTo(const ErrorInfoBase &E)
Definition:Error.h:888
llvm::ErrorHandlerTraits< void(&)(std::unique_ptr< ErrT >)>::apply
static Error apply(HandlerT &&H, std::unique_ptr< ErrorInfoBase > E)
Definition:Error.h:893
llvm::ErrorHandlerTraits
Helper for testing applicability of, and applying, handlers for ErrorInfo types.
Definition:Error.h:837
llvm::ErrorInfoBase
Base class for error info classes.
Definition:Error.h:45
llvm::ErrorInfoBase::~ErrorInfoBase
virtual ~ErrorInfoBase()=default
llvm::ErrorInfoBase::message
virtual std::string message() const
Return the error message as a string.
Definition:Error.h:53
llvm::ErrorInfoBase::classID
static const void * classID()
Definition:Error.h:67
llvm::ErrorInfoBase::isA
bool isA() const
Definition:Error.h:79
llvm::ErrorInfoBase::dynamicClassID
virtual const void * dynamicClassID() const =0
llvm::ErrorInfoBase::isA
virtual bool isA(const void *const ClassID) const
Definition:Error.h:74
llvm::ErrorInfoBase::convertToErrorCode
virtual std::error_code convertToErrorCode() const =0
Convert this error to a std::error_code.
llvm::ErrorInfoBase::log
virtual void log(raw_ostream &OS) const =0
Print an error message to an output stream.
llvm::ErrorInfo
Base class for user error types.
Definition:Error.h:355
llvm::ErrorInfo::isA
bool isA(const void *const ClassID) const override
Definition:Error.h:363
llvm::ErrorInfo::dynamicClassID
const void * dynamicClassID() const override
Definition:Error.h:361
llvm::ErrorInfo::classID
static const void * classID()
Definition:Error.h:359
llvm::ErrorList
Special ErrorInfo subclass representing a list of ErrorInfos.
Definition:Error.h:370
llvm::ErrorList::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition:Error.cpp:93
llvm::ErrorList::handleErrors
friend Error handleErrors(Error E, HandlerTs &&... Handlers)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Definition:Error.h:954
llvm::ErrorList::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition:Error.h:384
llvm::ErrorList::ID
static char ID
Definition:Error.h:395
llvm::ErrorList::joinErrors
friend Error joinErrors(Error, Error)
Concatenate errors.
Definition:Error.h:438
llvm::ErrorList::visitErrors
friend void visitErrors(const Error &E, HandlerT H)
Visit all the ErrorInfo(s) contained in E by passing them to the respective handler,...
Definition:Error.h:989
llvm::ErrorOr
Represents either an error or a value T.
Definition:ErrorOr.h:56
llvm::ErrorSuccess
Subclass of Error for the sole purpose of identifying the success path in the type system.
Definition:Error.h:335
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Error::Error
Error(Error &&Other)
Move-construct an error value.
Definition:Error.h:197
llvm::Error::~Error
~Error()
Destroy a Error.
Definition:Error.h:233
llvm::Error::dynamicClassID
const void * dynamicClassID() const
Returns the dynamic class id of this error, or null if this is a success value.
Definition:Error.h:253
llvm::Error::operator<<
friend raw_ostream & operator<<(raw_ostream &OS, const Error &E)
Definition:Error.h:321
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition:Error.h:337
llvm::Error::Error
Error(std::unique_ptr< ErrorInfoBase > Payload)
Create an error value.
Definition:Error.h:204
llvm::Error::operator=
Error & operator=(const Error &Other)=delete
llvm::Error::Error
Error()
Create a success value. Prefer using 'Error::success()' for readability.
Definition:Error.h:182
llvm::Error::Error
Error(const Error &Other)=delete
llvm::Error::operator=
Error & operator=(Error &&Other)
Move-assign an error value.
Definition:Error.h:216
llvm::Error::isA
bool isA() const
Check whether one error is a subclass of another.
Definition:Error.h:247
llvm::ExitOnError
Helper for check-and-exit error handling.
Definition:Error.h:1413
llvm::ExitOnError::setBanner
void setBanner(std::string Banner)
Set the banner string for any errors caught by operator().
Definition:Error.h:1421
llvm::ExitOnError::ExitOnError
ExitOnError(std::string Banner="", int DefaultErrorExitCode=1)
Create an error on exit helper.
Definition:Error.h:1416
llvm::ExitOnError::operator()
T operator()(Expected< T > &&E) const
Check E.
Definition:Error.h:1433
llvm::ExitOnError::operator()
T & operator()(Expected< T & > &&E) const
Check E.
Definition:Error.h:1440
llvm::ExitOnError::operator()
void operator()(Error Err) const
Check Err. If it's in a failure state log the error(s) and exit.
Definition:Error.h:1429
llvm::ExitOnError::setExitCodeMapper
void setExitCodeMapper(std::function< int(const Error &)> GetExitCode)
Set the exit-code mapper function.
Definition:Error.h:1424
llvm::ExpectedAsOutParameter
Helper for Expected<T>s used as out-parameters.
Definition:Error.h:1157
llvm::ExpectedAsOutParameter::~ExpectedAsOutParameter
~ExpectedAsOutParameter()
Definition:Error.h:1165
llvm::ExpectedAsOutParameter::ExpectedAsOutParameter
ExpectedAsOutParameter(Expected< T > *ValOrErr)
Definition:Error.h:1159
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::Expected::operator*
const_reference operator*() const
Returns a const reference to the stored T value.
Definition:Error.h:634
llvm::Expected::Expected
Expected(Expected< OtherT > &&Other, std::enable_if_t<!std::is_convertible_v< OtherT, T > > *=nullptr)
Move construct an Expected<T> value from an Expected<OtherT>, where OtherT isn't convertible to T.
Definition:Error.h:548
llvm::Expected::moveInto
Error moveInto(OtherT &Value, std::enable_if_t< std::is_assignable_v< OtherT &, T && > > *=nullptr) &&
Returns takeError() after moving the held T (if any) into V.
Definition:Error.h:591
llvm::Expected::operator->
pointer operator->()
Returns a pointer to the stored T value.
Definition:Error.h:616
llvm::Expected::operator*
reference operator*()
Returns a reference to the stored T value.
Definition:Error.h:628
llvm::Expected::Expected
Expected(OtherT &&Val, std::enable_if_t< std::is_convertible_v< OtherT, T > > *=nullptr)
Create an Expected<T> success value from the given OtherT value, which must be convertible to T.
Definition:Error.h:522
llvm::Expected::~Expected
~Expected()
Destroy an Expected<T>.
Definition:Error.h:561
llvm::Expected::get
const_reference get() const
Returns a const reference to the stored T value.
Definition:Error.h:584
llvm::Expected::errorIsA
bool errorIsA() const
Check that this Expected<T> is an error of type ErrT.
Definition:Error.h:600
llvm::Expected::Expected
Expected(ErrorSuccess)=delete
Forbid to convert from Error::success() implicitly, this avoids having Expected<T> foo() { return Err...
llvm::Expected::Expected
Expected(Error &&Err)
Create an Expected<T> error value from the given Error.
Definition:Error.h:503
llvm::Expected::TStorage
AlignedCharArrayUnion< storage_type > TStorage
Definition:Error.h:730
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition:Error.h:608
llvm::Expected::operator->
const_pointer operator->() const
Returns a const pointer to the stored T value.
Definition:Error.h:622
llvm::Expected::operator=
Expected & operator=(Expected &&Other)
Move-assign from another Expected<T>.
Definition:Error.h:555
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition:Error.h:578
llvm::Expected::ErrorStorage
AlignedCharArrayUnion< error_type > ErrorStorage
Definition:Error.h:731
llvm::Expected::storage_type
std::conditional_t< isRef, wrap, T > storage_type
Definition:Error.h:492
llvm::Expected::Expected
Expected(Expected &&Other)
Move construct an Expected<T> value.
Definition:Error.h:535
llvm::Expected::Expected
Expected(Expected< OtherT > &&Other, std::enable_if_t< std::is_convertible_v< OtherT, T > > *=nullptr)
Move construct an Expected<T> value from an Expected<OtherT>, where OtherT must be convertible to T.
Definition:Error.h:540
llvm::FileError
This class wraps a filename and another Error.
Definition:Error.h:1328
llvm::FileError::takeError
Error takeError()
Definition:Error.h:1351
llvm::FileError::ID
static char ID
Definition:Error.h:1356
llvm::FileError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition:Error.cpp:103
llvm::FileError::messageWithoutFileInfo
std::string messageWithoutFileInfo() const
Definition:Error.h:1342
llvm::FileError::getFileName
StringRef getFileName() const
Definition:Error.h:1349
llvm::FileError::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition:Error.h:1334
llvm::FileError::createFileError
friend Error createFileError(const Twine &, Error)
Concatenate a source file path and/or name with an Error.
Definition:Error.h:1385
llvm::StringError
This class wraps a string in an Error.
Definition:Error.h:1268
llvm::StringError::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition:Error.cpp:149
llvm::StringError::getMessage
const std::string & getMessage() const
Definition:Error.h:1281
llvm::StringError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition:Error.cpp:159
llvm::StringError::ID
static char ID
Definition:Error.h:1270
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::Twine::str
std::string str() const
Return the twine contents as a std::string.
Definition:Twine.cpp:17
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition:raw_ostream.h:661
unsigned
LLVMErrorRef
struct LLVMOpaqueError * LLVMErrorRef
Opaque reference to an error instance.
Definition:Error.h:33
Error.h
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
false
Definition:StackSlotColoring.cpp:193
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::lltok::Error
@ Error
Definition:LLToken.h:21
llvm::logicalview::LVSortMode::Line
@ Line
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::errorToBool
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
Definition:Error.h:1099
llvm::logAllUnhandledErrors
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Definition:Error.cpp:65
llvm::visitErrors
void visitErrors(const Error &E, HandlerT H)
Visit all the ErrorInfo(s) contained in E by passing them to the respective handler,...
Definition:Error.h:989
llvm::createFileError
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition:Error.h:1385
llvm::expectedToStdOptional
std::optional< T > expectedToStdOptional(Expected< T > &&E)
Definition:Error.h:1087
llvm::handleAllErrors
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Definition:Error.h:977
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition:Error.cpp:98
llvm::handleErrors
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Definition:Error.h:954
llvm::expectedToErrorOr
ErrorOr< T > expectedToErrorOr(Expected< T > &&E)
Convert an Expected<T> to an ErrorOr<T>.
Definition:Error.h:1238
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition:Error.h:1291
llvm::expectedToOptional
std::optional< T > expectedToOptional(Expected< T > &&E)
Convert an Expected to an Optional without doing anything.
Definition:Error.h:1080
llvm::toStringWithoutConsuming
std::string toStringWithoutConsuming(const Error &E)
Like toString(), but does not consume the error.
Definition:Error.cpp:85
llvm::joinErrors
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition:Error.h:438
llvm::get
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Definition:PointerIntPair.h:270
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::handleExpected
Expected< T > handleExpected(Expected< T > ValOrErr, RecoveryFtor &&RecoveryPath, HandlerTs &&... Handlers)
Handle any errors (if present) in an Expected<T>, then try a recovery path.
Definition:Error.h:1029
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition:Format.h:125
llvm::handleErrorImpl
Error handleErrorImpl(std::unique_ptr< ErrorInfoBase > Payload)
Definition:Error.h:933
llvm::make_error
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition:Error.h:341
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition:raw_ostream.cpp:907
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition:Error.h:756
llvm::unwrap
Attribute unwrap(LLVMAttributeRef Attr)
Definition:Attributes.h:335
llvm::errorOrToExpected
Expected< T > errorOrToExpected(ErrorOr< T > &&EO)
Convert an ErrorOr<T> to an Expected<T>.
Definition:Error.h:1231
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1873
llvm::wrap
LLVMAttributeRef wrap(Attribute Attr)
Definition:Attributes.h:330
llvm::BasicBlockSection::List
@ List
llvm::toString
const char * toString(DWARFSectionKind Kind)
Definition:DWARFUnitIndex.h:67
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition:Error.cpp:111
llvm::errnoAsErrorCode
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.
Definition:Error.h:1226
llvm::success
LogicalResult success(bool IsSuccess=true)
Utility function to generate a LogicalResult.
Definition:LogicalResult.h:55
llvm::errorToErrorCode
std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
Definition:Error.cpp:117
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition:Error.h:1069
std
Implement std::hash so that hash_code can be used in STL containers.
Definition:BitVector.h:858
raw_ostream.h
llvm::AlignedCharArrayUnion
A suitably aligned and sized character array member which can hold elements of any type.
Definition:AlignOf.h:27

Generated on Thu Jul 17 2025 10:23:34 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp