Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/include/lld/Core/Atom.h
Line
Count
Source (jump to first uncovered line)
1
//===- Core/Atom.h - A node in linking graph --------------------*- 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_CORE_ATOM_H
11
#define LLD_CORE_ATOM_H
12
13
#include "lld/Core/LLVM.h"
14
#include "llvm/ADT/StringRef.h"
15
16
namespace lld {
17
18
class File;
19
20
template<typename T>
21
class OwningAtomPtr;
22
23
///
24
/// The linker has a Graph Theory model of linking. An object file is seen
25
/// as a set of Atoms with References to other Atoms.  Each Atom is a node
26
/// and each Reference is an edge. An Atom can be a DefinedAtom which has
27
/// content or a UndefinedAtom which is a placeholder and represents an
28
/// undefined symbol (extern declaration).
29
///
30
class Atom {
31
  template<typename T> friend class OwningAtomPtr;
32
33
public:
34
  /// Whether this atom is defined or a proxy for an undefined symbol
35
  enum Definition {
36
    definitionRegular,      ///< Normal C/C++ function or global variable.
37
    definitionAbsolute,     ///< Asm-only (foo = 10). Not tied to any content.
38
    definitionUndefined,    ///< Only in .o files to model reference to undef.
39
    definitionSharedLibrary ///< Only in shared libraries to model export.
40
  };
41
42
  /// The scope in which this atom is acessible to other atoms.
43
  enum Scope {
44
    scopeTranslationUnit,  ///< Accessible only to atoms in the same translation
45
                           ///  unit (e.g. a C static).
46
    scopeLinkageUnit,      ///< Accessible to atoms being linked but not visible
47
                           ///  to runtime loader (e.g. visibility=hidden).
48
    scopeGlobal            ///< Accessible to all atoms and visible to runtime
49
                           ///  loader (e.g. visibility=default).
50
  };
51
52
  /// file - returns the File that produced/owns this Atom
53
  virtual const File& file() const = 0;
54
55
  /// name - The name of the atom. For a function atom, it is the (mangled)
56
  /// name of the function.
57
  virtual StringRef name() const = 0;
58
59
  /// definition - Whether this atom is a definition or represents an undefined
60
  /// symbol.
61
6.52k
  Definition definition() const { return _definition; }
62
63
0
  static bool classof(const Atom *a) { return true; }
64
65
protected:
66
  /// Atom is an abstract base class.  Only subclasses can access constructor.
67
1.71k
  explicit Atom(Definition def) : _definition(def) {}
68
69
  /// The memory for Atom objects is always managed by the owning File
70
  /// object.  Therefore, no one but the owning File object should call
71
  /// delete on an Atom.  In fact, some File objects may bulk allocate
72
  /// an array of Atoms, so they cannot be individually deleted by anyone.
73
1.87k
  virtual ~Atom() = default;
74
75
private:
76
  Definition _definition;
77
};
78
79
/// Class which owns an atom pointer and runs the atom destructor when the
80
/// owning pointer goes out of scope.
81
template<typename T>
82
class OwningAtomPtr {
83
private:
84
  OwningAtomPtr(const OwningAtomPtr &) = delete;
85
  void operator=(const OwningAtomPtr &) = delete;
86
87
public:
88
71
  OwningAtomPtr() = default;
lld::OwningAtomPtr<lld::DefinedAtom>::OwningAtomPtr()
Line
Count
Source
88
58
  OwningAtomPtr() = default;
lld::OwningAtomPtr<lld::UndefinedAtom>::OwningAtomPtr()
Line
Count
Source
88
7
  OwningAtomPtr() = default;
lld::OwningAtomPtr<lld::SharedLibraryAtom>::OwningAtomPtr()
Line
Count
Source
88
6
  OwningAtomPtr() = default;
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::OwningAtomPtr()
89
3.48k
  OwningAtomPtr(T *atom) : atom(atom) { }
lld::OwningAtomPtr<lld::Atom>::OwningAtomPtr(lld::Atom*)
Line
Count
Source
89
1.23k
  OwningAtomPtr(T *atom) : atom(atom) { }
lld::OwningAtomPtr<lld::UndefinedAtom>::OwningAtomPtr(lld::UndefinedAtom*)
Line
Count
Source
89
375
  OwningAtomPtr(T *atom) : atom(atom) { }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::OwningAtomPtr(lld::SharedLibraryAtom*)
Line
Count
Source
89
302
  OwningAtomPtr(T *atom) : atom(atom) { }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::OwningAtomPtr(lld::AbsoluteAtom*)
lld::OwningAtomPtr<lld::DefinedAtom>::OwningAtomPtr(lld::DefinedAtom*)
Line
Count
Source
89
1.58k
  OwningAtomPtr(T *atom) : atom(atom) { }
90
91
13.9k
  ~OwningAtomPtr() {
92
13.9k
    if (atom)
93
1.13k
      runDestructor(atom);
94
13.9k
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::~OwningAtomPtr()
lld::OwningAtomPtr<lld::Atom>::~OwningAtomPtr()
Line
Count
Source
91
3.94k
  ~OwningAtomPtr() {
92
3.94k
    if (atom)
93
99
      runDestructor(atom);
94
3.94k
  }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::~OwningAtomPtr()
Line
Count
Source
91
645
  ~OwningAtomPtr() {
92
645
    if (atom)
93
138
      runDestructor(atom);
94
645
  }
lld::OwningAtomPtr<lld::UndefinedAtom>::~OwningAtomPtr()
Line
Count
Source
91
1.18k
  ~OwningAtomPtr() {
92
1.18k
    if (atom)
93
45
      runDestructor(atom);
94
1.18k
  }
lld::OwningAtomPtr<lld::DefinedAtom>::~OwningAtomPtr()
Line
Count
Source
91
8.17k
  ~OwningAtomPtr() {
92
8.17k
    if (atom)
93
855
      runDestructor(atom);
94
8.17k
  }
95
96
1.39k
  void runDestructor(Atom *atom) {
97
1.39k
    atom->~Atom();
98
1.39k
  }
lld::OwningAtomPtr<lld::Atom>::runDestructor(lld::Atom*)
Line
Count
Source
96
323
  void runDestructor(Atom *atom) {
97
323
    atom->~Atom();
98
323
  }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::runDestructor(lld::Atom*)
Line
Count
Source
96
138
  void runDestructor(Atom *atom) {
97
138
    atom->~Atom();
98
138
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::runDestructor(lld::Atom*)
lld::OwningAtomPtr<lld::DefinedAtom>::runDestructor(lld::Atom*)
Line
Count
Source
96
887
  void runDestructor(Atom *atom) {
97
887
    atom->~Atom();
98
887
  }
lld::OwningAtomPtr<lld::UndefinedAtom>::runDestructor(lld::Atom*)
Line
Count
Source
96
45
  void runDestructor(Atom *atom) {
97
45
    atom->~Atom();
98
45
  }
99
100
10.3k
  OwningAtomPtr(OwningAtomPtr &&ptr) : atom(ptr.atom) {
101
10.3k
    ptr.atom = nullptr;
102
10.3k
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::OwningAtomPtr(lld::OwningAtomPtr<lld::AbsoluteAtom>&&)
lld::OwningAtomPtr<lld::UndefinedAtom>::OwningAtomPtr(lld::OwningAtomPtr<lld::UndefinedAtom>&&)
Line
Count
Source
100
803
  OwningAtomPtr(OwningAtomPtr &&ptr) : atom(ptr.atom) {
101
803
    ptr.atom = nullptr;
102
803
  }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::OwningAtomPtr(lld::OwningAtomPtr<lld::SharedLibraryAtom>&&)
Line
Count
Source
100
337
  OwningAtomPtr(OwningAtomPtr &&ptr) : atom(ptr.atom) {
101
337
    ptr.atom = nullptr;
102
337
  }
lld::OwningAtomPtr<lld::DefinedAtom>::OwningAtomPtr(lld::OwningAtomPtr<lld::DefinedAtom>&&)
Line
Count
Source
100
6.53k
  OwningAtomPtr(OwningAtomPtr &&ptr) : atom(ptr.atom) {
101
6.53k
    ptr.atom = nullptr;
102
6.53k
  }
lld::OwningAtomPtr<lld::Atom>::OwningAtomPtr(lld::OwningAtomPtr<lld::Atom>&&)
Line
Count
Source
100
2.70k
  OwningAtomPtr(OwningAtomPtr &&ptr) : atom(ptr.atom) {
101
2.70k
    ptr.atom = nullptr;
102
2.70k
  }
103
104
2.51k
  void operator=(OwningAtomPtr&& ptr) {
105
2.51k
    if (atom)
106
256
      runDestructor(atom);
107
2.51k
    atom = ptr.atom;
108
2.51k
    ptr.atom = nullptr;
109
2.51k
  }
lld::OwningAtomPtr<lld::DefinedAtom>::operator=(lld::OwningAtomPtr<lld::DefinedAtom>&&)
Line
Count
Source
104
1.91k
  void operator=(OwningAtomPtr&& ptr) {
105
1.91k
    if (atom)
106
32
      runDestructor(atom);
107
1.91k
    atom = ptr.atom;
108
1.91k
    ptr.atom = nullptr;
109
1.91k
  }
lld::OwningAtomPtr<lld::Atom>::operator=(lld::OwningAtomPtr<lld::Atom>&&)
Line
Count
Source
104
597
  void operator=(OwningAtomPtr&& ptr) {
105
597
    if (atom)
106
224
      runDestructor(atom);
107
597
    atom = ptr.atom;
108
597
    ptr.atom = nullptr;
109
597
  }
110
111
9.98k
  T *const &get() const {
112
9.98k
    return atom;
113
9.98k
  }
lld::OwningAtomPtr<lld::DefinedAtom>::get() const
Line
Count
Source
111
8.33k
  T *const &get() const {
112
8.33k
    return atom;
113
8.33k
  }
lld::OwningAtomPtr<lld::UndefinedAtom>::get() const
Line
Count
Source
111
93
  T *const &get() const {
112
93
    return atom;
113
93
  }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::get() const
Line
Count
Source
111
204
  T *const &get() const {
112
204
    return atom;
113
204
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::get() const
lld::OwningAtomPtr<lld::Atom>::get() const
Line
Count
Source
111
1.35k
  T *const &get() const {
112
1.35k
    return atom;
113
1.35k
  }
114
115
6.67k
  T *&get() {
116
6.67k
    return atom;
117
6.67k
  }
lld::OwningAtomPtr<lld::DefinedAtom>::get()
Line
Count
Source
115
3.55k
  T *&get() {
116
3.55k
    return atom;
117
3.55k
  }
lld::OwningAtomPtr<lld::Atom>::get()
Line
Count
Source
115
2.13k
  T *&get() {
116
2.13k
    return atom;
117
2.13k
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::get()
lld::OwningAtomPtr<lld::UndefinedAtom>::get()
Line
Count
Source
115
657
  T *&get() {
116
657
    return atom;
117
657
  }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::get()
Line
Count
Source
115
324
  T *&get() {
116
324
    return atom;
117
324
  }
118
119
2.13k
  T *release() {
120
2.13k
    auto *v = atom;
121
2.13k
    atom = nullptr;
122
2.13k
    return v;
123
2.13k
  }
lld::OwningAtomPtr<lld::Atom>::release()
Line
Count
Source
119
908
  T *release() {
120
908
    auto *v = atom;
121
908
    atom = nullptr;
122
908
    return v;
123
908
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::release()
lld::OwningAtomPtr<lld::SharedLibraryAtom>::release()
Line
Count
Source
119
142
  T *release() {
120
142
    auto *v = atom;
121
142
    atom = nullptr;
122
142
    return v;
123
142
  }
lld::OwningAtomPtr<lld::DefinedAtom>::release()
Line
Count
Source
119
752
  T *release() {
120
752
    auto *v = atom;
121
752
    atom = nullptr;
122
752
    return v;
123
752
  }
lld::OwningAtomPtr<lld::UndefinedAtom>::release()
Line
Count
Source
119
337
  T *release() {
120
337
    auto *v = atom;
121
337
    atom = nullptr;
122
337
    return v;
123
337
  }
124
125
private:
126
  T *atom = nullptr;
127
};
128
129
} // end namespace lld
130
131
#endif // LLD_CORE_ATOM_H