@@ -1333,7 +1333,8 @@ bool AbstractStorageDecl::hasFixedLayout() const {
1333
1333
1334
1334
// Private and (unversioned) internal variables always have a
1335
1335
// fixed layout.
1336
- if (getEffectiveAccess () < Accessibility::Public)
1336
+ if (!getFormalAccessScope (/* useDC=*/ nullptr ,
1337
+ /* respectVersionedAttr=*/ true ).isPublic ())
1337
1338
return true ;
1338
1339
1339
1340
// Check for an explicit @_fixed_layout attribute.
@@ -1889,18 +1890,18 @@ SourceLoc ValueDecl::getAttributeInsertionLoc(bool forModifier) const {
1889
1890
1890
1891
// / Returns true if \p VD needs to be treated as publicly-accessible
1891
1892
// / at the SIL, LLVM, and machine levels due to being versioned.
1892
- static bool isVersionedInternalDecl (const ValueDecl *VD) {
1893
- assert (VD-> getFormalAccess () == Accessibility::Internal);
1893
+ bool ValueDecl:: isVersionedInternalDecl () const {
1894
+ assert (getFormalAccess () == Accessibility::Internal);
1894
1895
1895
- if (VD-> getAttrs ().hasAttribute <VersionedAttr>())
1896
+ if (getAttrs ().hasAttribute <VersionedAttr>())
1896
1897
return true ;
1897
1898
1898
- if (auto *FD = dyn_cast<FuncDecl>(VD ))
1899
+ if (auto *FD = dyn_cast<FuncDecl>(this ))
1899
1900
if (auto *ASD = FD->getAccessorStorageDecl ())
1900
1901
if (ASD->getAttrs ().hasAttribute <VersionedAttr>())
1901
1902
return true ;
1902
1903
1903
- if (auto *EED = dyn_cast<EnumElementDecl>(VD ))
1904
+ if (auto *EED = dyn_cast<EnumElementDecl>(this ))
1904
1905
if (EED->getParentEnum ()->getAttrs ().hasAttribute <VersionedAttr>())
1905
1906
return true ;
1906
1907
@@ -1927,21 +1928,17 @@ static Accessibility getTestableAccess(const ValueDecl *decl) {
1927
1928
}
1928
1929
1929
1930
Accessibility ValueDecl::getEffectiveAccess () const {
1930
- Accessibility effectiveAccess = getFormalAccess ();
1931
+ auto effectiveAccess = getFormalAccess (/* useDC=*/ nullptr ,
1932
+ /* respectVersionedAttr=*/ true );
1931
1933
1932
1934
// Handle @testable.
1933
1935
switch (effectiveAccess) {
1934
- case Accessibility::Public:
1935
- if (getModuleContext ()->isTestingEnabled ())
1936
- effectiveAccess = getTestableAccess (this );
1937
- break ;
1938
1936
case Accessibility::Open:
1939
1937
break ;
1938
+ case Accessibility::Public:
1940
1939
case Accessibility::Internal:
1941
1940
if (getModuleContext ()->isTestingEnabled ())
1942
1941
effectiveAccess = getTestableAccess (this );
1943
- else if (isVersionedInternalDecl (this ))
1944
- effectiveAccess = Accessibility::Public;
1945
1942
break ;
1946
1943
case Accessibility::FilePrivate:
1947
1944
break ;
@@ -1982,23 +1979,28 @@ Accessibility ValueDecl::getFormalAccessImpl(const DeclContext *useDC) const {
1982
1979
return getFormalAccess ();
1983
1980
}
1984
1981
1985
- AccessScope ValueDecl::getFormalAccessScope (const DeclContext *useDC) const {
1982
+ AccessScope ValueDecl::getFormalAccessScope (const DeclContext *useDC,
1983
+ bool respectVersionedAttr) const {
1986
1984
const DeclContext *result = getDeclContext ();
1987
- Accessibility access = getFormalAccess (useDC);
1985
+ Accessibility access = getFormalAccess (useDC, respectVersionedAttr );
1988
1986
1989
1987
while (!result->isModuleScopeContext ()) {
1990
1988
if (result->isLocalContext () || access == Accessibility::Private)
1991
1989
return AccessScope (result, true );
1992
1990
1993
1991
if (auto enclosingNominal = dyn_cast<NominalTypeDecl>(result)) {
1994
- access = std::min (access, enclosingNominal->getFormalAccess (useDC));
1992
+ access = std::min (access,
1993
+ enclosingNominal->getFormalAccess (useDC,
1994
+ respectVersionedAttr));
1995
1995
1996
1996
} else if (auto enclosingExt = dyn_cast<ExtensionDecl>(result)) {
1997
1997
// Just check the base type. If it's a constrained extension, Sema should
1998
1998
// have already enforced access more strictly.
1999
1999
if (auto extendedTy = enclosingExt->getExtendedType ()) {
2000
2000
if (auto nominal = extendedTy->getAnyNominal ()) {
2001
- access = std::min (access, nominal->getFormalAccess (useDC));
2001
+ access = std::min (access,
2002
+ nominal->getFormalAccess (useDC,
2003
+ respectVersionedAttr));
2002
2004
}
2003
2005
}
2004
2006
@@ -2050,7 +2052,8 @@ Type TypeDecl::getDeclaredInterfaceType() const {
2050
2052
bool NominalTypeDecl::hasFixedLayout () const {
2051
2053
// Private and (unversioned) internal types always have a
2052
2054
// fixed layout.
2053
- if (getEffectiveAccess () < Accessibility::Public)
2055
+ if (!getFormalAccessScope (/* useDC=*/ nullptr ,
2056
+ /* respectVersionedAttr=*/ true ).isPublic ())
2054
2057
return true ;
2055
2058
2056
2059
// Check for an explicit @_fixed_layout attribute.
0 commit comments