Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/Linkage.h
Line
Count
Source (jump to first uncovered line)
1
//===- Linkage.h - Linkage enumeration and utilities ------------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
/// \file
11
/// Defines the Linkage enumeration and various utility functions.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_BASIC_LINKAGE_H
16
#define LLVM_CLANG_BASIC_LINKAGE_H
17
18
#include <utility>
19
20
namespace clang {
21
22
/// Describes the different kinds of linkage
23
/// (C++ [basic.link], C99 6.2.2) that an entity may have.
24
enum Linkage : unsigned char {
25
  /// No linkage, which means that the entity is unique and
26
  /// can only be referred to from within its scope.
27
  NoLinkage = 0,
28
29
  /// Internal linkage, which indicates that the entity can
30
  /// be referred to from within the translation unit (but not other
31
  /// translation units).
32
  InternalLinkage,
33
34
  /// External linkage within a unique namespace.
35
  ///
36
  /// From the language perspective, these entities have external
37
  /// linkage. However, since they reside in an anonymous namespace,
38
  /// their names are unique to this translation unit, which is
39
  /// equivalent to having internal linkage from the code-generation
40
  /// point of view.
41
  UniqueExternalLinkage,
42
43
  /// No linkage according to the standard, but is visible from other
44
  /// translation units because of types defined in a inline function.
45
  VisibleNoLinkage,
46
47
  /// Internal linkage according to the Modules TS, but can be referred
48
  /// to from other translation units indirectly through inline functions and
49
  /// templates in the module interface.
50
  ModuleInternalLinkage,
51
52
  /// Module linkage, which indicates that the entity can be referred
53
  /// to from other translation units within the same module, and indirectly
54
  /// from arbitrary other translation units through inline functions and
55
  /// templates in the module interface.
56
  ModuleLinkage,
57
58
  /// External linkage, which indicates that the entity can
59
  /// be referred to from other translation units.
60
  ExternalLinkage
61
};
62
63
/// Describes the different kinds of language linkage
64
/// (C++ [dcl.link]) that an entity may have.
65
enum LanguageLinkage {
66
  CLanguageLinkage,
67
  CXXLanguageLinkage,
68
  NoLanguageLinkage
69
};
70
71
/// A more specific kind of linkage than enum Linkage.
72
///
73
/// This is relevant to CodeGen and AST file reading.
74
enum GVALinkage {
75
  GVA_Internal,
76
  GVA_AvailableExternally,
77
  GVA_DiscardableODR,
78
  GVA_StrongExternal,
79
  GVA_StrongODR
80
};
81
82
5.29M
inline bool isDiscardableGVALinkage(GVALinkage L) {
83
5.29M
  return L <= GVA_DiscardableODR;
84
5.29M
}
85
86
37.4M
inline bool isExternallyVisible(Linkage L) {
87
37.4M
  return L >= VisibleNoLinkage;
88
37.4M
}
89
90
28.5M
inline Linkage getFormalLinkage(Linkage L) {
91
28.5M
  switch (L) {
92
28.5M
  case UniqueExternalLinkage:
93
11.2k
    return ExternalLinkage;
94
28.5M
  case VisibleNoLinkage:
95
10.0k
    return NoLinkage;
96
28.5M
  case ModuleInternalLinkage:
97
290
    return InternalLinkage;
98
28.5M
  default:
99
28.4M
    return L;
100
28.5M
  }
101
28.5M
}
102
103
21.3M
inline bool isExternalFormalLinkage(Linkage L) {
104
21.3M
  return getFormalLinkage(L) == ExternalLinkage;
105
21.3M
}
106
107
/// Compute the minimum linkage given two linkages.
108
///
109
/// The linkage can be interpreted as a pair formed by the formal linkage and
110
/// a boolean for external visibility. This is just what getFormalLinkage and
111
/// isExternallyVisible return. We want the minimum of both components. The
112
/// Linkage enum is defined in an order that makes this simple, we just need
113
/// special cases for when VisibleNoLinkage would lose the visible bit and
114
/// become NoLinkage.
115
8.73M
inline Linkage minLinkage(Linkage L1, Linkage L2) {
116
8.73M
  if (L2 == VisibleNoLinkage)
117
3.30k
    std::swap(L1, L2);
118
8.73M
  if (L1 == VisibleNoLinkage) {
119
3.83k
    if (L2 == InternalLinkage)
120
4
      return NoLinkage;
121
3.82k
    if (L2 == UniqueExternalLinkage)
122
0
      return NoLinkage;
123
8.73M
  }
124
8.73M
  return L1 < L2 ? 
L14.54k
:
L28.73M
;
125
8.73M
}
126
127
} // namespace clang
128
129
#endif // LLVM_CLANG_BASIC_LINKAGE_H