Skip to content

Commit 337c87f

Browse files
committed
[cxx-interop] Fix debug-info round-tripping for class template specializations.
Use Swift (clang importer) lookup infra when looking up clang decls for debug info.
1 parent 03a3088 commit 337c87f

File tree

1 file changed

+14
-45
lines changed

1 file changed

+14
-45
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,53 +3033,22 @@ ClangNode ClangImporter::getEffectiveClangNode(const Decl *decl) const {
30333033
void ClangImporter::lookupTypeDecl(
30343034
StringRef rawName, ClangTypeKind kind,
30353035
llvm::function_ref<void(TypeDecl *)> receiver) {
3036-
clang::DeclarationName clangName(
3037-
&Impl.Instance->getASTContext().Idents.get(rawName));
3038-
3039-
SmallVector<clang::Sema::LookupNameKind, 1> lookupKinds;
3040-
switch (kind) {
3041-
case ClangTypeKind::Typedef:
3042-
lookupKinds.push_back(clang::Sema::LookupOrdinaryName);
3043-
break;
3044-
case ClangTypeKind::Tag:
3045-
lookupKinds.push_back(clang::Sema::LookupTagName);
3046-
lookupKinds.push_back(clang::Sema::LookupNamespaceName);
3047-
break;
3048-
case ClangTypeKind::ObjCProtocol:
3049-
lookupKinds.push_back(clang::Sema::LookupObjCProtocolName);
3050-
break;
3051-
}
3052-
3053-
// Perform name lookup into the global scope.
3054-
auto &sema = Impl.Instance->getSema();
3036+
auto &ctx = Impl.SwiftContext;
3037+
auto name = DeclName(ctx.getIdentifier(rawName));
30553038
bool foundViaClang = false;
3056-
3057-
for (auto lookupKind : lookupKinds) {
3058-
clang::LookupResult lookupResult(sema, clangName, clang::SourceLocation(),
3059-
lookupKind);
3060-
if (!Impl.DisableSourceImport &&
3061-
sema.LookupName(lookupResult, /*Scope=*/ sema.TUScope)) {
3062-
for (auto clangDecl : lookupResult) {
3063-
if (!isa<clang::TypeDecl>(clangDecl) &&
3064-
!isa<clang::NamespaceDecl>(clangDecl) &&
3065-
!isa<clang::ObjCContainerDecl>(clangDecl) &&
3066-
!isa<clang::ObjCCompatibleAliasDecl>(clangDecl)) {
3067-
continue;
3068-
}
3069-
Decl *imported = Impl.importDecl(clangDecl, Impl.CurrentVersion);
3070-
3071-
// Namespaces are imported as extensions for enums.
3072-
if (auto ext = dyn_cast_or_null<ExtensionDecl>(imported)) {
3073-
imported = ext->getExtendedNominal();
3074-
}
3075-
if (auto *importedType = dyn_cast_or_null<TypeDecl>(imported)) {
3076-
foundViaClang = true;
3077-
receiver(importedType);
3078-
}
3079-
}
3039+
auto consumer = makeDeclConsumer(
3040+
[&foundViaClang, receiver](Decl *found, DeclVisibilityKind) {
3041+
// Namespaces are imported as extensions for enums.
3042+
if (auto ext = dyn_cast_or_null<ExtensionDecl>(found)) {
3043+
found = ext->getExtendedNominal();
30803044
}
3081-
}
3082-
3045+
if (auto *importedType = dyn_cast_or_null<TypeDecl>(found)) {
3046+
foundViaClang = true;
3047+
receiver(importedType);
3048+
}
3049+
});
3050+
3051+
ctx.getClangModuleLoader()->lookupValue(name, consumer);
30833052
// If Clang couldn't find the type, query the DWARFImporterDelegate.
30843053
if (!foundViaClang)
30853054
Impl.lookupTypeDeclDWARF(rawName, kind, receiver);

0 commit comments

Comments
 (0)