diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 29a25338a725d..d271d82a3364f 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -1878,7 +1878,7 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { continue; } - if (Importer.hasLLDBRedeclCompletion()) { + if (!Importer.hasLLDBRedeclCompletion()) { FieldDecl *FieldFrom = dyn_cast_or_null(From); Decl *ImportedDecl = *ImportedOrErr; FieldDecl *FieldTo = dyn_cast_or_null(ImportedDecl); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp index 723a4d0cfcabe..eabe8a1776ee9 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp @@ -824,23 +824,17 @@ bool ClangASTImporter::CompleteTagDecl(clang::TagDecl *decl) { if (!decl_origin.Valid()) return false; - ImporterDelegateSP delegate_sp( - GetDelegate(&decl->getASTContext(), decl_origin.ctx)); - - ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, - &decl->getASTContext()); - - if (!TypeSystemClang::UseRedeclCompletion()) { - if (!TypeSystemClang::GetCompleteDecl(decl_origin.ctx, decl_origin.decl)) - return false; - - if (delegate_sp) - delegate_sp->ImportDefinitionTo(decl, decl_origin.decl); - } else { + if (TypeSystemClang::UseRedeclCompletion()) { auto *origin_def = llvm::cast(decl_origin.decl)->getDefinition(); if (!origin_def) return false; + ImporterDelegateSP delegate_sp( + GetDelegate(&decl->getASTContext(), decl_origin.ctx)); + + ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, + &decl->getASTContext()); + // This is expected to pull in a definition for result_decl (if in redecl // completion mode) llvm::Expected result = delegate_sp->Import(origin_def); @@ -859,6 +853,18 @@ bool ClangASTImporter::CompleteTagDecl(clang::TagDecl *decl) { if (!decl->isThisDeclarationADefinition() && result_decl != decl) if (result_decl->getPreviousDecl() == nullptr) result_decl->setPreviousDecl(decl); + } else { + if (!TypeSystemClang::GetCompleteDecl(decl_origin.ctx, decl_origin.decl)) + return false; + + ImporterDelegateSP delegate_sp( + GetDelegate(&decl->getASTContext(), decl_origin.ctx)); + + ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, + &decl->getASTContext()); + + if (delegate_sp) + delegate_sp->ImportDefinitionTo(decl, decl_origin.decl); } return true; @@ -880,19 +886,7 @@ bool ClangASTImporter::CompleteObjCInterfaceDecl( if (!decl_origin.Valid()) return false; - ImporterDelegateSP delegate_sp( - GetDelegate(&interface_decl->getASTContext(), decl_origin.ctx)); - - if (!TypeSystemClang::UseRedeclCompletion()) { - if (!TypeSystemClang::GetCompleteDecl(decl_origin.ctx, decl_origin.decl)) - return false; - - if (delegate_sp) - delegate_sp->ImportDefinitionTo(interface_decl, decl_origin.decl); - - if (ObjCInterfaceDecl *super_class = interface_decl->getSuperClass()) - RequireCompleteType(clang::QualType(super_class->getTypeForDecl(), 0)); - } else { + if (TypeSystemClang::UseRedeclCompletion()) { ObjCInterfaceDecl *origin_decl = llvm::cast(decl_origin.decl); @@ -900,7 +894,7 @@ bool ClangASTImporter::CompleteObjCInterfaceDecl( if (!origin_decl) return false; - auto delegate_sp( + ImporterDelegateSP delegate_sp( GetDelegate(&interface_decl->getASTContext(), decl_origin.ctx)); llvm::Expected result = delegate_sp->Import(origin_decl); @@ -915,6 +909,18 @@ bool ClangASTImporter::CompleteObjCInterfaceDecl( return false; } + if (!TypeSystemClang::GetCompleteDecl(decl_origin.ctx, decl_origin.decl)) + return false; + + ImporterDelegateSP delegate_sp( + GetDelegate(&interface_decl->getASTContext(), decl_origin.ctx)); + + if (delegate_sp) + delegate_sp->ImportDefinitionTo(interface_decl, decl_origin.decl); + + if (ObjCInterfaceDecl *super_class = interface_decl->getSuperClass()) + RequireCompleteType(clang::QualType(super_class->getTypeForDecl(), 0)); + return true; } @@ -1204,8 +1210,6 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) { DeclContext::lookup_result lr = dc->lookup(*dn_or_err); for (clang::Decl *candidate : lr) { if (candidate->getKind() == From->getKind()) { - RegisterImportedDecl(From, candidate); - // If we're dealing with redecl chains. We want to find the definition, // so skip if the decl is actually just a forwad decl. if (TypeSystemClang::UseRedeclCompletion()) @@ -1213,6 +1217,7 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) { !tag_decl || !tag_decl->getDefinition()) continue; + RegisterImportedDecl(From, candidate); m_decls_to_ignore.insert(candidate); return candidate; } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h index b37cc0a60b3dc..7128befb62293 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h @@ -214,7 +214,7 @@ class ClangASTSource : public ImporterBackedASTSource, /// /// Clang AST contexts like to own their AST sources, so this is a state- /// free proxy object. - class ClangASTSourceProxy : public clang::ExternalASTSource { + class ClangASTSourceProxy : public ImporterBackedASTSource { public: ClangASTSourceProxy(ClangASTSource &original) : m_original(original) {} diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index a83a0e0de7c41..b430b59a9f12e 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -1788,6 +1788,8 @@ TypeSystemClang::CreateClassTemplateSpecializationDecl( static_cast(kind)); class_template_specialization_decl->setDeclContext(decl_ctx); class_template_specialization_decl->setInstantiationOf(class_template_decl); + if (TypeSystemClang::UseRedeclCompletion()) + ast.getTypeDeclType(class_template_specialization_decl, nullptr); class_template_specialization_decl->setTemplateArgs( TemplateArgumentList::CreateCopy(ast, args)); class_template_specialization_decl->setDeclName(