diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2017-12-06 18:52:13 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2017-12-06 18:52:13 +0000 |
commit | 9ffa988b5d07625958d21d27dda8a2fab4f18e7f (patch) | |
tree | 77fa5626aa65b275cc39faec5700791086a07faf /lld/include/lld | |
parent | 7724b03cdef46cd775606cd2d854a1754c8c8504 (diff) | |
download | bcm5719-llvm-9ffa988b5d07625958d21d27dda8a2fab4f18e7f.tar.gz bcm5719-llvm-9ffa988b5d07625958d21d27dda8a2fab4f18e7f.zip |
Add a checkLazy error checking variant.
This avoids allocating the error message when there is no error that
check requires.
It avoids the code duplication of inlining check.
llvm-svn: 319922
Diffstat (limited to 'lld/include/lld')
-rw-r--r-- | lld/include/lld/Common/ErrorHandler.h | 8 |
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 |