]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/COFF/Error.h
Merge clang trunk r300422 and resolve conflicts.
[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 template <class T> T check(ErrorOr<T> EO) {
36   if (!EO)
37     fatal(EO.getError().message());
38   return std::move(*EO);
39 }
40
41 template <class T> T check(Expected<T> E) {
42   if (!E) {
43     std::string Buf;
44     llvm::raw_string_ostream OS(Buf);
45     logAllUnhandledErrors(E.takeError(), OS, "");
46     OS.flush();
47     fatal(Buf);
48   }
49   return std::move(*E);
50 }
51
52 } // namespace coff
53 } // namespace lld
54
55 #endif