Coverage Report

Created: 2018-01-17 21:32

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/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/Common/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
3.16k
  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
798
  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
879
  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
38
  OwningAtomPtr() = default;
lld::OwningAtomPtr<lld::DefinedAtom>::OwningAtomPtr()
Line
Count
Source
88
33
  OwningAtomPtr() = default;
lld::OwningAtomPtr<lld::UndefinedAtom>::OwningAtomPtr()
Line
Count
Source
88
3
  OwningAtomPtr() = default;
lld::OwningAtomPtr<lld::SharedLibraryAtom>::OwningAtomPtr()
Line
Count
Source
88
2
  OwningAtomPtr() = default;
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::OwningAtomPtr()
89
1.64k
  OwningAtomPtr(T *atom) : atom(atom) { }
lld::OwningAtomPtr<lld::DefinedAtom>::OwningAtomPtr(lld::DefinedAtom*)
Line
Count
Source
89
733
  OwningAtomPtr(T *atom) : atom(atom) { }
lld::OwningAtomPtr<lld::UndefinedAtom>::OwningAtomPtr(lld::UndefinedAtom*)
Line
Count
Source
89
185
  OwningAtomPtr(T *atom) : atom(atom) { }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::OwningAtomPtr(lld::SharedLibraryAtom*)
Line
Count
Source
89
146
  OwningAtomPtr(T *atom) : atom(atom) { }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::OwningAtomPtr(lld::AbsoluteAtom*)
lld::OwningAtomPtr<lld::Atom>::OwningAtomPtr(lld::Atom*)
Line
Count
Source
89
582
  OwningAtomPtr(T *atom) : atom(atom) { }
90
91
6.55k
  ~OwningAtomPtr() {
92
6.55k
    if (atom)
93
546
      runDestructor(atom);
94
6.55k
  }
lld::OwningAtomPtr<lld::DefinedAtom>::~OwningAtomPtr()
Line
Count
Source
91
3.83k
  ~OwningAtomPtr() {
92
3.83k
    if (atom)
93
401
      runDestructor(atom);
94
3.83k
  }
lld::OwningAtomPtr<lld::UndefinedAtom>::~OwningAtomPtr()
Line
Count
Source
91
578
  ~OwningAtomPtr() {
92
578
    if (atom)
93
22
      runDestructor(atom);
94
578
  }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::~OwningAtomPtr()
Line
Count
Source
91
296
  ~OwningAtomPtr() {
92
296
    if (atom)
93
64
      runDestructor(atom);
94
296
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::~OwningAtomPtr()
lld::OwningAtomPtr<lld::Atom>::~OwningAtomPtr()
Line
Count
Source
91
1.85k
  ~OwningAtomPtr() {
92
1.85k
    if (atom)
93
59
      runDestructor(atom);
94
1.85k
  }
95
96
665
  void runDestructor(Atom *atom) {
97
665
    atom->~Atom();
98
665
  }
lld::OwningAtomPtr<lld::DefinedAtom>::runDestructor(lld::Atom*)
Line
Count
Source
96
417
  void runDestructor(Atom *atom) {
97
417
    atom->~Atom();
98
417
  }
lld::OwningAtomPtr<lld::UndefinedAtom>::runDestructor(lld::Atom*)
Line
Count
Source
96
22
  void runDestructor(Atom *atom) {
97
22
    atom->~Atom();
98
22
  }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::runDestructor(lld::Atom*)
Line
Count
Source
96
64
  void runDestructor(Atom *atom) {
97
64
    atom->~Atom();
98
64
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::runDestructor(lld::Atom*)
lld::OwningAtomPtr<lld::Atom>::runDestructor(lld::Atom*)
Line
Count
Source
96
162
  void runDestructor(Atom *atom) {
97
162
    atom->~Atom();
98
162
  }
99
100
4.87k
  OwningAtomPtr(OwningAtomPtr &&ptr) : atom(ptr.atom) {
101
4.87k
    ptr.atom = nullptr;
102
4.87k
  }
lld::OwningAtomPtr<lld::DefinedAtom>::OwningAtomPtr(lld::OwningAtomPtr<lld::DefinedAtom>&&)
Line
Count
Source
100
3.06k
  OwningAtomPtr(OwningAtomPtr &&ptr) : atom(ptr.atom) {
101
3.06k
    ptr.atom = nullptr;
102
3.06k
  }
lld::OwningAtomPtr<lld::UndefinedAtom>::OwningAtomPtr(lld::OwningAtomPtr<lld::UndefinedAtom>&&)
Line
Count
Source
100
390
  OwningAtomPtr(OwningAtomPtr &&ptr) : atom(ptr.atom) {
101
390
    ptr.atom = nullptr;
102
390
  }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::OwningAtomPtr(lld::OwningAtomPtr<lld::SharedLibraryAtom>&&)
Line
Count
Source
100
148
  OwningAtomPtr(OwningAtomPtr &&ptr) : atom(ptr.atom) {
101
148
    ptr.atom = nullptr;
102
148
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::OwningAtomPtr(lld::OwningAtomPtr<lld::AbsoluteAtom>&&)
lld::OwningAtomPtr<lld::Atom>::OwningAtomPtr(lld::OwningAtomPtr<lld::Atom>&&)
Line
Count
Source
100
1.26k
  OwningAtomPtr(OwningAtomPtr &&ptr) : atom(ptr.atom) {
101
1.26k
    ptr.atom = nullptr;
102
1.26k
  }
103
104
1.20k
  void operator=(OwningAtomPtr&& ptr) {
105
1.20k
    if (atom)
106
119
      runDestructor(atom);
107
1.20k
    atom = ptr.atom;
108
1.20k
    ptr.atom = nullptr;
109
1.20k
  }
lld::OwningAtomPtr<lld::DefinedAtom>::operator=(lld::OwningAtomPtr<lld::DefinedAtom>&&)
Line
Count
Source
104
911
  void operator=(OwningAtomPtr&& ptr) {
105
911
    if (atom)
106
16
      runDestructor(atom);
107
911
    atom = ptr.atom;
108
911
    ptr.atom = nullptr;
109
911
  }
lld::OwningAtomPtr<lld::Atom>::operator=(lld::OwningAtomPtr<lld::Atom>&&)
Line
Count
Source
104
294
  void operator=(OwningAtomPtr&& ptr) {
105
294
    if (atom)
106
103
      runDestructor(atom);
107
294
    atom = ptr.atom;
108
294
    ptr.atom = nullptr;
109
294
  }
110
111
4.73k
  T *const &get() const {
112
4.73k
    return atom;
113
4.73k
  }
lld::OwningAtomPtr<lld::DefinedAtom>::get() const
Line
Count
Source
111
3.92k
  T *const &get() const {
112
3.92k
    return atom;
113
3.92k
  }
lld::OwningAtomPtr<lld::UndefinedAtom>::get() const
Line
Count
Source
111
46
  T *const &get() const {
112
46
    return atom;
113
46
  }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::get() const
Line
Count
Source
111
94
  T *const &get() const {
112
94
    return atom;
113
94
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::get() const
lld::OwningAtomPtr<lld::Atom>::get() const
Line
Count
Source
111
674
  T *const &get() const {
112
674
    return atom;
113
674
  }
114
115
3.11k
  T *&get() {
116
3.11k
    return atom;
117
3.11k
  }
lld::OwningAtomPtr<lld::DefinedAtom>::get()
Line
Count
Source
115
1.64k
  T *&get() {
116
1.64k
    return atom;
117
1.64k
  }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::get()
Line
Count
Source
115
154
  T *&get() {
116
154
    return atom;
117
154
  }
lld::OwningAtomPtr<lld::UndefinedAtom>::get()
Line
Count
Source
115
322
  T *&get() {
116
322
    return atom;
117
322
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::get()
lld::OwningAtomPtr<lld::Atom>::get()
Line
Count
Source
115
1.00k
  T *&get() {
116
1.00k
    return atom;
117
1.00k
  }
118
119
1.00k
  T *release() {
120
1.00k
    auto *v = atom;
121
1.00k
    atom = nullptr;
122
1.00k
    return v;
123
1.00k
  }
lld::OwningAtomPtr<lld::UndefinedAtom>::release()
Line
Count
Source
119
166
  T *release() {
120
166
    auto *v = atom;
121
166
    atom = nullptr;
122
166
    return v;
123
166
  }
lld::OwningAtomPtr<lld::DefinedAtom>::release()
Line
Count
Source
119
349
  T *release() {
120
349
    auto *v = atom;
121
349
    atom = nullptr;
122
349
    return v;
123
349
  }
lld::OwningAtomPtr<lld::SharedLibraryAtom>::release()
Line
Count
Source
119
67
  T *release() {
120
67
    auto *v = atom;
121
67
    atom = nullptr;
122
67
    return v;
123
67
  }
Unexecuted instantiation: lld::OwningAtomPtr<lld::AbsoluteAtom>::release()
lld::OwningAtomPtr<lld::Atom>::release()
Line
Count
Source
119
420
  T *release() {
120
420
    auto *v = atom;
121
420
    atom = nullptr;
122
420
    return v;
123
420
  }
124
125
private:
126
  T *atom = nullptr;
127
};
128
129
} // end namespace lld
130
131
#endif // LLD_CORE_ATOM_H