Skip to content

Commit fc1cf3b

Browse files
committed
Replace clang::Decl::isHidden() with clang::Sema::isVisible().
clang::Decl::isHidden() is misleadingly named (see the associated FIXME comment) and doesn't do what we want when `-fmodules-local-submodule-visibility` is turned on. This change alone isn't unfortunately enough to make Swift work with `-fmodules-local-submodule-visibility`. For one thing, Clang's Objective-C component doesn't work correctly with `-fmodules-local-submodule-visibility`: https://bugs.llvm.org/show_bug.cgi?id=46248 However, in the meantime, we should still clean up our use of clang::Decl::isHidden().
1 parent d45047d commit fc1cf3b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,11 +2889,12 @@ void ClangModuleUnit::lookupValue(DeclName name, NLKind lookupKind,
28892889
bool ClangImporter::Implementation::isVisibleClangEntry(
28902890
const clang::NamedDecl *clangDecl) {
28912891
// For a declaration, check whether the declaration is hidden.
2892-
if (!clangDecl->isHidden()) return true;
2892+
clang::Sema &clangSema = getClangSema();
2893+
if (clangSema.isVisible(clangDecl)) return true;
28932894

28942895
// Is any redeclaration visible?
28952896
for (auto redecl : clangDecl->redecls()) {
2896-
if (!cast<clang::NamedDecl>(redecl)->isHidden()) return true;
2897+
if (clangSema.isVisible(cast<clang::NamedDecl>(redecl))) return true;
28972898
}
28982899

28992900
return false;
@@ -3004,8 +3005,10 @@ void ClangImporter::loadExtensions(NominalTypeDecl *nominal,
30043005
SmallVector<clang::NamedDecl *, 4> DelayedCategories;
30053006

30063007
// Simply importing the categories adds them to the list of extensions.
3007-
for (const auto *Cat : objcClass->visible_categories()) {
3008-
Impl.importDeclReal(Cat, Impl.CurrentVersion);
3008+
for (const auto *Cat : objcClass->known_categories()) {
3009+
if (getClangSema().isVisible(Cat)) {
3010+
Impl.importDeclReal(Cat, Impl.CurrentVersion);
3011+
}
30093012
}
30103013
}
30113014

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7131,9 +7131,12 @@ void SwiftDeclConverter::importMirroredProtocolMembers(
71317131
return;
71327132

71337133
bool inNearbyCategory =
7134-
std::any_of(interfaceDecl->visible_categories_begin(),
7135-
interfaceDecl->visible_categories_end(),
7134+
std::any_of(interfaceDecl->known_categories_begin(),
7135+
interfaceDecl->known_categories_end(),
71367136
[=](const clang::ObjCCategoryDecl *category) -> bool {
7137+
if (!Impl.getClangSema().isVisible(category)) {
7138+
return false;
7139+
}
71377140
if (category != decl) {
71387141
auto *categoryModule =
71397142
Impl.getClangModuleForDecl(category);

0 commit comments

Comments
 (0)