]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/COFF/Error.h
Merge bmake-20161212
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / COFF / Error.h
1 //===- Error.h --------------------------------------------------*- C++ -*-===//
2 //
3 //                             The LLVM Linker
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLD_COFF_ERROR_H
11 #define LLD_COFF_ERROR_H
12
13 #include "lld/Core/LLVM.h"
14 #include "llvm/Support/Error.h"
15
16 namespace lld {
17 namespace coff {
18
19 LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg);
20 LLVM_ATTRIBUTE_NORETURN void fatal(std::error_code EC, const Twine &Prefix);
21 LLVM_ATTRIBUTE_NORETURN void fatal(llvm::Error &Err, const Twine &Prefix);
22
23 template <class T> T check(ErrorOr<T> &&V, const Twine &Prefix) {
24   if (auto EC = V.getError())
25     fatal(EC, Prefix);
26   return std::move(*V);
27 }
28
29 template <class T> T check(Expected<T> E, const Twine &Prefix) {
30   if (llvm::Error Err = E.takeError())
31     fatal(Err, Prefix);
32   return std::move(*E);
33 }
34
35 } // namespace coff
36 } // namespace lld
37
38 #endif