/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/COFF/Error.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- Error.cpp ----------------------------------------------------------===// |
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 | | #include "Error.h" |
11 | | #include "Config.h" |
12 | | |
13 | | #include "llvm/ADT/Twine.h" |
14 | | #include "llvm/Support/Error.h" |
15 | | #include "llvm/Support/ManagedStatic.h" |
16 | | #include "llvm/Support/Process.h" |
17 | | #include "llvm/Support/raw_ostream.h" |
18 | | #include <mutex> |
19 | | |
20 | | #if !defined(_MSC_VER) && !defined(__MINGW32__) |
21 | | #include <unistd.h> |
22 | | #endif |
23 | | |
24 | | using namespace llvm; |
25 | | |
26 | | namespace lld { |
27 | | // The functions defined in this file can be called from multiple threads, |
28 | | // but outs() or errs() are not thread-safe. We protect them using a mutex. |
29 | | static std::mutex Mu; |
30 | | |
31 | | namespace coff { |
32 | | uint64_t ErrorCount; |
33 | | raw_ostream *ErrorOS; |
34 | | |
35 | 0 | static LLVM_ATTRIBUTE_NORETURN void exitLld(int Val) { |
36 | 0 | // Dealloc/destroy ManagedStatic variables before calling |
37 | 0 | // _exit(). In a non-LTO build, this is a nop. In an LTO |
38 | 0 | // build allows us to get the output of -time-passes. |
39 | 0 | llvm_shutdown(); |
40 | 0 |
|
41 | 0 | outs().flush(); |
42 | 0 | errs().flush(); |
43 | 0 | _exit(Val); |
44 | 0 | } |
45 | | |
46 | 19 | static void print(StringRef S, raw_ostream::Colors C) { |
47 | 19 | *ErrorOS << Config->Argv[0] << ": "; |
48 | 19 | if (Config->ColorDiagnostics19 ) { |
49 | 0 | ErrorOS->changeColor(C, true); |
50 | 0 | *ErrorOS << S; |
51 | 0 | ErrorOS->resetColor(); |
52 | 19 | } else { |
53 | 19 | *ErrorOS << S; |
54 | 19 | } |
55 | 19 | } |
56 | | |
57 | 812 | void log(const Twine &Msg) { |
58 | 812 | if (Config->Verbose812 ) { |
59 | 78 | std::lock_guard<std::mutex> Lock(Mu); |
60 | 78 | outs() << Config->Argv[0] << ": " << Msg << "\n"; |
61 | 78 | outs().flush(); |
62 | 78 | } |
63 | 812 | } |
64 | | |
65 | 4 | void message(const Twine &Msg) { |
66 | 4 | std::lock_guard<std::mutex> Lock(Mu); |
67 | 4 | outs() << Msg << "\n"; |
68 | 4 | outs().flush(); |
69 | 4 | } |
70 | | |
71 | 11 | void error(const Twine &Msg) { |
72 | 11 | std::lock_guard<std::mutex> Lock(Mu); |
73 | 11 | |
74 | 11 | if (Config->ErrorLimit == 0 || 11 ErrorCount < Config->ErrorLimit11 ) { |
75 | 11 | print("error: ", raw_ostream::RED); |
76 | 11 | *ErrorOS << Msg << "\n"; |
77 | 11 | } else if (0 ErrorCount == Config->ErrorLimit0 ) { |
78 | 0 | print("error: ", raw_ostream::RED); |
79 | 0 | *ErrorOS << "too many errors emitted, stopping now" |
80 | 0 | << " (use /ERRORLIMIT:0 to see all errors)\n"; |
81 | 0 | exitLld(1); |
82 | 0 | } |
83 | 11 | |
84 | 11 | ++ErrorCount; |
85 | 11 | } |
86 | | |
87 | 0 | void fatal(const Twine &Msg) { |
88 | 0 | if (Config->ColorDiagnostics0 ) { |
89 | 0 | errs().changeColor(raw_ostream::RED, /*bold=*/true); |
90 | 0 | errs() << "error: "; |
91 | 0 | errs().resetColor(); |
92 | 0 | } else { |
93 | 0 | errs() << "error: "; |
94 | 0 | } |
95 | 0 | errs() << Msg << "\n"; |
96 | 0 | exitLld(1); |
97 | 0 | } |
98 | | |
99 | 0 | void fatal(std::error_code EC, const Twine &Msg) { |
100 | 0 | fatal(Msg + ": " + EC.message()); |
101 | 0 | } |
102 | | |
103 | 0 | void fatal(llvm::Error &Err, const Twine &Msg) { |
104 | 0 | fatal(errorToErrorCode(std::move(Err)), Msg); |
105 | 0 | } |
106 | | |
107 | 8 | void warn(const Twine &Msg) { |
108 | 8 | std::lock_guard<std::mutex> Lock(Mu); |
109 | 8 | print("warning: ", raw_ostream::MAGENTA); |
110 | 8 | *ErrorOS << Msg << "\n"; |
111 | 8 | } |
112 | | |
113 | | } // namespace coff |
114 | | } // namespace lld |