diff options
Diffstat (limited to 'lld/include/lld')
-rw-r--r-- | lld/include/lld/Common/ErrorHandler.h | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h index f43d4520ea9..5f544b88155 100644 --- a/lld/include/lld/Common/ErrorHandler.h +++ b/lld/include/lld/Common/ErrorHandler.h @@ -74,7 +74,7 @@ inline uint64_t errorCount() { return errorHandler().ErrorCount; } LLVM_ATTRIBUTE_NORETURN void exitLld(int Val); -// check() functions are convenient functions to strip errors +// check functions are convenient functions to strip errors // from error-or-value objects. template <class T> T check(ErrorOr<T> E) { if (auto EC = E.getError()) @@ -88,25 +88,27 @@ template <class T> T check(Expected<T> E) { return std::move(*E); } -template <class T> T check(ErrorOr<T> E, const Twine &Prefix) { +template <class T> +T check2(ErrorOr<T> E, llvm::function_ref<std::string()> Prefix) { if (auto EC = E.getError()) - fatal(Prefix + ": " + EC.message()); - return std::move(*E); -} - -template <class T> T check(Expected<T> E, const Twine &Prefix) { - if (!E) - fatal(Prefix + ": " + toString(E.takeError())); + fatal(Prefix() + ": " + EC.message()); return std::move(*E); } -// A lazy variant that only allocates error messages when there is an error. template <class T> -T checkLazy(Expected<T> E, llvm::function_ref<std::string()> getPrefix) { +T check2(Expected<T> E, llvm::function_ref<std::string()> Prefix) { if (!E) - fatal(getPrefix() + ": " + toString(E.takeError())); + fatal(Prefix() + ": " + toString(E.takeError())); return std::move(*E); } + +inline std::string checkToString(const Twine &S) { return S.str(); } +inline std::string checkToString(std::string S) { return S; } +inline std::string checkToString(const char *S) { return S; } + +// To evaluate the second argument lazily, we use C macro. +#define CHECK(E, S) check2(E, [&] { return checkToString(S); }) + } // namespace lld #endif |