summaryrefslogtreecommitdiff
path: root/lld/include
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-12-06 22:08:17 +0000
committerRui Ueyama <ruiu@google.com>2017-12-06 22:08:17 +0000
commitde42122e33e5a159a660ae3443b227e5d9c517b4 (patch)
treec4e6e955405972d163300b532826f0d61414bb39 /lld/include
parent8abf53067ab526587d84731679a26b009b3ba57b (diff)
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
Diffstat (limited to 'lld/include')
-rw-r--r--lld/include/lld/Common/ErrorHandler.h26
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