summaryrefslogtreecommitdiffstats
path: root/lld/include
diff options
context:
space:
mode:
Diffstat (limited to 'lld/include')
-rw-r--r--lld/include/lld/Common/ErrorHandler.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h
index 86d1494932c..f43d4520ea9 100644
--- a/lld/include/lld/Common/ErrorHandler.h
+++ b/lld/include/lld/Common/ErrorHandler.h
@@ -30,6 +30,7 @@
#include "lld/Common/LLVM.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileOutputBuffer.h"
@@ -99,6 +100,13 @@ template <class T> T check(Expected<T> E, const Twine &Prefix) {
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) {
+ if (!E)
+ fatal(getPrefix() + ": " + toString(E.takeError()));
+ return std::move(*E);
+}
} // namespace lld
#endif
OpenPOWER on IntegriCloud