Coverage Report

Created: 2019-07-24 05:18

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