summaryrefslogtreecommitdiffstats
path: root/include/clang/Basic/Linkage.h
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-05-25 17:16:20 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-05-25 17:16:20 +0000
commita99ecbcc4c431d52df0b01539035ab5281d54656 (patch)
treed227893f1beb714e47a05479539968da1dee1ee6 /include/clang/Basic/Linkage.h
parent872db39510372c4acd8851a3b956e1a135cfcd41 (diff)
Fix linkage computation for derived types in inline functions.
John noticed that the fix for pr15930 (r181981) didn't handle indirect uses of local types. For example, a pointer to local struct, or a function that returns it. One way to implement this would be to recursively look for local types. This would look a lot like the linkage computation itself for types. To avoid code duplication and utilize the existing linkage cache, this patch just makes the computation of "type with no linkage but externally visible because it is from an inline function" part of the linkage computation itself. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182711 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/Linkage.h')
-rw-r--r--include/clang/Basic/Linkage.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/include/clang/Basic/Linkage.h b/include/clang/Basic/Linkage.h
index 13d2d24d8e..7f9ce6a909 100644
--- a/include/clang/Basic/Linkage.h
+++ b/include/clang/Basic/Linkage.h
@@ -37,6 +37,10 @@ enum Linkage {
/// point of view.
UniqueExternalLinkage,
+ /// \brief No linkage according to the standard, but is visible from other
+ /// translation units because of types defined in a inline function.
+ VisibleNoLinkage,
+
/// \brief External linkage, which indicates that the entity can
/// be referred to from other translation units.
ExternalLinkage
@@ -62,9 +66,24 @@ enum GVALinkage {
GVA_ExplicitTemplateInstantiation
};
-/// \brief Compute the minimum linkage given two linages.
+/// \brief Compute the minimum linkage given two linkages.
+///
+/// The linkage can be interpreted as a pair formed by the formal linkage and
+/// a boolean for external visibility. This is just what getFormalLinkage and
+/// isExternallyVisible return. We want the minimum of both components. The
+/// Linkage enum is defined in an order that makes this simple, we just need
+/// special cases for when VisibleNoLinkage would lose the visible bit and
+/// become NoLinkage.
inline Linkage minLinkage(Linkage L1, Linkage L2) {
- return L1 < L2? L1 : L2;
+ if (L2 == VisibleNoLinkage)
+ std::swap(L1, L2);
+ if (L1 == VisibleNoLinkage) {
+ if (L2 == InternalLinkage)
+ return NoLinkage;
+ if (L2 == UniqueExternalLinkage)
+ return NoLinkage;
+ }
+ return L1 < L2 ? L1 : L2;
}
} // end namespace clang