Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/lib/Core/Error.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Error.cpp - system_error extensions for lld --------------*- 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
#include "lld/Core/Error.h"
11
#include "llvm/ADT/Twine.h"
12
#include "llvm/Support/ErrorHandling.h"
13
#include <mutex>
14
#include <string>
15
#include <vector>
16
17
using namespace lld;
18
19
namespace {
20
class _YamlReaderErrorCategory : public std::error_category {
21
public:
22
0
  const char* name() const noexcept override {
23
0
    return "lld.yaml.reader";
24
0
  }
25
26
6
  std::string message(int ev) const override {
27
6
    switch (static_cast<YamlReaderError>(ev)) {
28
0
    case YamlReaderError::unknown_keyword:
29
0
      return "Unknown keyword found in yaml file";
30
6
    case YamlReaderError::illegal_value:
31
6
      return "Bad value found in yaml file";
32
0
    }
33
0
    
llvm_unreachable0
("An enumerator of YamlReaderError does not have a "
34
0
                     "message defined.");
35
0
  }
36
};
37
} // end anonymous namespace
38
39
6
const std::error_category &lld::YamlReaderCategory() {
40
6
  static _YamlReaderErrorCategory o;
41
6
  return o;
42
6
}
43
44
namespace lld {
45
46
/// Temporary class to enable make_dynamic_error_code() until
47
/// llvm::ErrorOr<> is updated to work with error encapsulations
48
/// other than error_code.
49
class dynamic_error_category : public std::error_category {
50
public:
51
2.35k
  ~dynamic_error_category() override = default;
52
53
0
  const char *name() const noexcept override {
54
0
    return "lld.dynamic_error";
55
0
  }
56
57
0
  std::string message(int ev) const override {
58
0
    assert(ev >= 0);
59
0
    assert(ev < (int)_messages.size());
60
0
    // The value is an index into the string vector.
61
0
    return _messages[ev];
62
0
  }
63
64
0
  int add(std::string msg) {
65
0
    std::lock_guard<std::recursive_mutex> lock(_mutex);
66
0
    // Value zero is always the successs value.
67
0
    if (_messages.empty())
68
0
      _messages.push_back("Success");
69
0
    _messages.push_back(msg);
70
0
    // Return the index of the string just appended.
71
0
    return _messages.size() - 1;
72
0
  }
73
74
private:
75
  std::vector<std::string> _messages;
76
  std::recursive_mutex _mutex;
77
};
78
79
static dynamic_error_category categorySingleton;
80
81
0
std::error_code make_dynamic_error_code(StringRef msg) {
82
0
  return std::error_code(categorySingleton.add(msg), categorySingleton);
83
0
}
84
85
char GenericError::ID = 0;
86
87
11
GenericError::GenericError(Twine Msg) : Msg(Msg.str()) { }
88
89
10
void GenericError::log(raw_ostream &OS) const {
90
10
  OS << Msg;
91
10
}
92
93
} // namespace lld