@@ -4946,11 +4946,12 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
49464946
49474947 // Find the results that are actually a member of "recordDecl".
49484948 TinyPtrVector<ValueDecl *> result;
4949+ ClangModuleLoader *clangModuleLoader = ctx.getClangModuleLoader ();
49494950 for (auto found : allResults) {
49504951 auto named = found.get <clang::NamedDecl *>();
49514952 if (dyn_cast<clang::Decl>(named->getDeclContext ()) ==
49524953 recordDecl->getClangDecl ()) {
4953- if (auto import = ctx. getClangModuleLoader () ->importDeclDirectly (named))
4954+ if (auto import = clangModuleLoader ->importDeclDirectly (named))
49544955 result.push_back (cast<ValueDecl>(import ));
49554956 }
49564957 }
@@ -4966,16 +4967,32 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
49664967 continue ;
49674968
49684969 auto *baseRecord = baseType->getAs <clang::RecordType>()->getDecl ();
4969- if (auto import =
4970- ctx.getClangModuleLoader ()->importDeclDirectly (baseRecord)) {
4970+ if (auto import = clangModuleLoader->importDeclDirectly (baseRecord)) {
49714971 // If we are looking up the base class, go no further. We will have
49724972 // already found it during the other lookup.
49734973 if (cast<ValueDecl>(import )->getName () == name)
49744974 continue ;
49754975
4976- auto baseResults = cast<NominalTypeDecl>(import )->lookupDirect (name);
4976+ // Add Clang members that are imported lazily.
4977+ auto baseResults = evaluateOrDefault (
4978+ ctx.evaluator ,
4979+ ClangRecordMemberLookup ({cast<NominalTypeDecl>(import ), name}), {});
4980+ // Add members that are synthesized eagerly, such as subscripts.
4981+ for (auto member :
4982+ cast<NominalTypeDecl>(import )->getCurrentMembersWithoutLoading ()) {
4983+ if (auto namedMember = dyn_cast<ValueDecl>(member)) {
4984+ if (namedMember->hasName () &&
4985+ namedMember->getName ().getBaseName () == name &&
4986+ // Make sure we don't add duplicate entries, as that would
4987+ // wrongly imply that lookup is ambiguous.
4988+ !llvm::is_contained (baseResults, namedMember)) {
4989+ baseResults.push_back (namedMember);
4990+ }
4991+ }
4992+ }
49774993 for (auto foundInBase : baseResults) {
4978- if (auto newDecl = cloneBaseMemberDecl (foundInBase, recordDecl)) {
4994+ if (auto newDecl = clangModuleLoader->importBaseMemberDecl (
4995+ foundInBase, recordDecl)) {
49794996 result.push_back (newDecl);
49804997 }
49814998 }
@@ -5772,6 +5789,18 @@ Decl *ClangImporter::importDeclDirectly(const clang::NamedDecl *decl) {
57725789 return Impl.importDecl (decl, Impl.CurrentVersion );
57735790}
57745791
5792+ ValueDecl *ClangImporter::importBaseMemberDecl (ValueDecl *decl,
5793+ DeclContext *newContext) {
5794+ // Make sure we don't clone the decl again for this class, as that would
5795+ // result in multiple definitions of the same symbol.
5796+ std::pair<ValueDecl *, DeclContext *> key = {decl, newContext};
5797+ if (!Impl.clonedBaseMembers .count (key)) {
5798+ ValueDecl *cloned = cloneBaseMemberDecl (decl, newContext);
5799+ Impl.clonedBaseMembers [key] = cloned;
5800+ }
5801+ return Impl.clonedBaseMembers [key];
5802+ }
5803+
57755804void ClangImporter::diagnoseTopLevelValue (const DeclName &name) {
57765805 Impl.diagnoseTopLevelValue (name);
57775806}
0 commit comments