diff options
author | Rui Ueyama <ruiu@google.com> | 2017-12-06 22:08:17 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2017-12-06 22:08:17 +0000 |
commit | bdc5150984c695439f728aeae55e95fad0409bb1 (patch) | |
tree | 0c3378289e8a14e4df8e44d12d3f334b0ff403ea /lld/include | |
parent | 0969462c52802b17175736061abbc71ea30ec8bc (diff) | |
download | bcm5719-llvm-bdc5150984c695439f728aeae55e95fad0409bb1.tar.gz bcm5719-llvm-bdc5150984c695439f728aeae55e95fad0409bb1.zip |
Always evaluate the second argument for CHECK() lazily.
This patch is to rename check CHECK and make it a C macro, so that
we can evaluate the second argument lazily.
Differential Revision: https://reviews.llvm.org/D40915
llvm-svn: 319974
Diffstat (limited to 'lld/include')
-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 |