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