Skip to content

[lldb][Type Completion] Fix various redecl-completion issues that stem from the UseRedeclCompletion setting split #8660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,7 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
continue;
}

if (Importer.hasLLDBRedeclCompletion()) {
if (!Importer.hasLLDBRedeclCompletion()) {
FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
Decl *ImportedDecl = *ImportedOrErr;
FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
Expand Down
65 changes: 35 additions & 30 deletions lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TagDecl>(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<Decl *> result = delegate_sp->Import(origin_def);
Expand All @@ -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;
Expand All @@ -880,27 +886,15 @@ 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<ObjCInterfaceDecl>(decl_origin.decl);

origin_decl = origin_decl->getDefinition();
if (!origin_decl)
return false;

auto delegate_sp(
ImporterDelegateSP delegate_sp(
GetDelegate(&interface_decl->getASTContext(), decl_origin.ctx));

llvm::Expected<Decl *> result = delegate_sp->Import(origin_decl);
Expand All @@ -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;
}

Expand Down Expand Up @@ -1204,15 +1210,14 @@ 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,
// 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())
if (auto *tag_decl = llvm::dyn_cast<TagDecl>(candidate);
!tag_decl || !tag_decl->getDefinition())
continue;

RegisterImportedDecl(From, candidate);
m_decls_to_ignore.insert(candidate);
return candidate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,8 @@ TypeSystemClang::CreateClassTemplateSpecializationDecl(
static_cast<TagDecl::TagKind>(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(
Expand Down