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