Coverage Report

Created: 2017-09-19 22:28

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/ELF/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/raw_ostream.h"
17
#include <mutex>
18
19
#if !defined(_MSC_VER) && !defined(__MINGW32__)
20
#include <unistd.h>
21
#endif
22
23
using namespace llvm;
24
25
using namespace lld;
26
using namespace lld::elf;
27
28
uint64_t elf::ErrorCount;
29
raw_ostream *elf::ErrorOS;
30
31
// The functions defined in this file can be called from multiple threads,
32
// but outs() or errs() are not thread-safe. We protect them using a mutex.
33
static std::mutex Mu;
34
35
// Prints "\n" or does nothing, depending on Msg contents of
36
// the previous call of this function.
37
600
static void newline(const Twine &Msg) {
38
600
  // True if the previous error message contained "\n".
39
600
  // We want to separate multi-line error messages with a newline.
40
600
  static bool Flag;
41
600
42
600
  if (Flag)
43
60
    *ErrorOS << "\n";
44
600
  Flag = StringRef(Msg.str()).contains('\n');
45
600
}
46
47
588
static void print(StringRef S, raw_ostream::Colors C) {
48
588
  *ErrorOS << Config->Argv[0] << ": ";
49
588
  if (
Config->ColorDiagnostics588
) {
50
6
    ErrorOS->changeColor(C, true);
51
6
    *ErrorOS << S;
52
6
    ErrorOS->resetColor();
53
588
  } else {
54
582
    *ErrorOS << S;
55
582
  }
56
588
}
57
58
2.97k
void elf::log(const Twine &Msg) {
59
2.97k
  if (
Config->Verbose2.97k
) {
60
65
    std::lock_guard<std::mutex> Lock(Mu);
61
65
    outs() << Config->Argv[0] << ": " << Msg << "\n";
62
65
    outs().flush();
63
65
  }
64
2.97k
}
65
66
78
void elf::message(const Twine &Msg) {
67
78
  std::lock_guard<std::mutex> Lock(Mu);
68
78
  outs() << Msg << "\n";
69
78
  outs().flush();
70
78
}
71
72
140
void elf::warn(const Twine &Msg) {
73
140
  if (
Config->FatalWarnings140
) {
74
1
    error(Msg);
75
1
    return;
76
1
  }
77
139
78
139
  std::lock_guard<std::mutex> Lock(Mu);
79
139
  newline(Msg);
80
139
  print("warning: ", raw_ostream::MAGENTA);
81
139
  *ErrorOS << Msg << "\n";
82
139
}
83
84
461
void elf::error(const Twine &Msg) {
85
461
  std::lock_guard<std::mutex> Lock(Mu);
86
461
  newline(Msg);
87
461
88
461
  if (
Config->ErrorLimit == 0 || 461
ErrorCount < Config->ErrorLimit438
) {
89
446
    print("error: ", raw_ostream::RED);
90
446
    *ErrorOS << Msg << "\n";
91
461
  } else 
if (15
ErrorCount == Config->ErrorLimit15
) {
92
3
    print("error: ", raw_ostream::RED);
93
3
    *ErrorOS << "too many errors emitted, stopping now"
94
3
             << " (use -error-limit=0 to see all errors)\n";
95
3
    if (Config->ExitEarly)
96
0
      exitLld(1);
97
461
  }
98
461
99
461
  ++ErrorCount;
100
461
}
101
102
0
void elf::exitLld(int Val) {
103
0
  // Dealloc/destroy ManagedStatic variables before calling
104
0
  // _exit(). In a non-LTO build, this is a nop. In an LTO
105
0
  // build allows us to get the output of -time-passes.
106
0
  llvm_shutdown();
107
0
108
0
  outs().flush();
109
0
  errs().flush();
110
0
  _exit(Val);
111
0
}
112
113
0
void elf::fatal(const Twine &Msg) {
114
0
  error(Msg);
115
0
  exitLld(1);
116
0
}