Skip to content

Commit 7d3d4de

Browse files
committed
Fixup IdentifierInfo Key Confusion
Clang has two sources of IdentifierInfo pointers: the ASTContext and the Preprocessor. Even though the keys from each can be used to index into the other's tables, doing so has detrimental effects on the Clang Importer. At the very least, it will cause the Clang Importer to re-load modules that should have already been cached down by implicit module builds. This is because the module will build itself against a properly interned key from the Preprocessor, but be looked up by a key from the ASTContext after the next time. Once in a blue moon, this may even allow Clang to return garbage to us, though I'm still verifying that. For now, let's patch up this mess by using the right source of keys.
1 parent fcb0b2b commit 7d3d4de

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,6 @@ bool ClangImporter::canImportModule(Located<Identifier> moduleID) {
17141714

17151715
ModuleDecl *ClangImporter::Implementation::loadModuleClang(
17161716
SourceLoc importLoc, ArrayRef<Located<Identifier>> path) {
1717-
auto &clangContext = getClangASTContext();
17181717
auto &clangHeaderSearch = getClangPreprocessor().getHeaderSearchInfo();
17191718

17201719
// Look up the top-level module first, to see if it exists at all.
@@ -1728,8 +1727,9 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
17281727
SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>, 4>
17291728
clangPath;
17301729
for (auto component : path) {
1731-
clangPath.push_back({&clangContext.Idents.get(component.Item.str()),
1732-
exportSourceLoc(component.Loc)});
1730+
clangPath.emplace_back(
1731+
getClangPreprocessor().getIdentifierInfo(component.Item.str()),
1732+
exportSourceLoc(component.Loc));
17331733
}
17341734

17351735
auto &rawDiagClient = Instance->getDiagnosticClient();

0 commit comments

Comments
 (0)