Skip to content

Commit 6f806b4

Browse files
committed
Compare top-level modules when deciding visibility for redeclarations
When importing C declarations, one can come across a redeclaration due to two different clang modules textually including the same header. Previously, to decide visibility of a declaration from a particular module, the module in which it is redeclarated had to exactly match the one we saw before, so a struct defined in A.B.C might cause it to be hidden in A.X.Y, because we were already popping off submodule names on the "left hand side", so the module comparison was A != A.X.Y. If someone imports A.X.Y and expects that struct, they won't see it. Now, strip off submodules of the "right hand side", correctly comparing if the top-level modules match (A == A). This may have the effect of allowing more declarations to be visible than before but it prevents weird situations where struct typedefs can be hidden in overly complicated nested header includes normally found in OS system headers. rdar://problem/23588593
1 parent 1cc28c7 commit 6f806b4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,8 +2302,9 @@ static bool isVisibleFromModule(const ClangModuleUnit *ModuleFilter,
23022302
continue;
23032303
auto OwningClangModule = getClangOwningModule(Redeclaration,
23042304
ClangASTContext);
2305+
OwningClangModule = OwningClangModule->getTopLevelModule();
23052306

2306-
if (OwningClangModule == ModuleFilter->getClangModule())
2307+
if (OwningClangModule == ModuleFilter->getClangModule()->getTopLevelModule())
23072308
return true;
23082309
}
23092310
} else if (isa<clang::TagDecl>(D)) {
@@ -2314,8 +2315,9 @@ static bool isVisibleFromModule(const ClangModuleUnit *ModuleFilter,
23142315
continue;
23152316
auto OwningClangModule = getClangOwningModule(Redeclaration,
23162317
ClangASTContext);
2318+
OwningClangModule = OwningClangModule->getTopLevelModule();
23172319

2318-
if (OwningClangModule == ModuleFilter->getClangModule())
2320+
if (OwningClangModule == ModuleFilter->getClangModule()->getTopLevelModule())
23192321
return true;
23202322
}
23212323
}

0 commit comments

Comments
 (0)