Skip to content

Commit 82dbf4d

Browse files
authored
Merge pull request #8660 from Michael137/bugfix/lldb/type-completion/crash-fixes-to-next
[lldb][Type Completion] Fix various redecl-completion issues that stem from the UseRedeclCompletion setting split Debugging larger programs with the redecl-completion setting enabled was causing various crashes. This patch series resolves these. All of them were caused by either missed cherry-picks or incorrect UseRedeclCompletion guards. Follow-ups from #8222
2 parents 31d6301 + 9dbe7e9 commit 82dbf4d

File tree

4 files changed

+39
-32
lines changed

4 files changed

+39
-32
lines changed

clang/lib/AST/ASTImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2055,7 +2055,7 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
20552055
continue;
20562056
}
20572057

2058-
if (Importer.hasLLDBRedeclCompletion()) {
2058+
if (!Importer.hasLLDBRedeclCompletion()) {
20592059
FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
20602060
Decl *ImportedDecl = *ImportedOrErr;
20612061
FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);

lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -824,23 +824,17 @@ bool ClangASTImporter::CompleteTagDecl(clang::TagDecl *decl) {
824824
if (!decl_origin.Valid())
825825
return false;
826826

827-
ImporterDelegateSP delegate_sp(
828-
GetDelegate(&decl->getASTContext(), decl_origin.ctx));
829-
830-
ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp,
831-
&decl->getASTContext());
832-
833-
if (!TypeSystemClang::UseRedeclCompletion()) {
834-
if (!TypeSystemClang::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
835-
return false;
836-
837-
if (delegate_sp)
838-
delegate_sp->ImportDefinitionTo(decl, decl_origin.decl);
839-
} else {
827+
if (TypeSystemClang::UseRedeclCompletion()) {
840828
auto *origin_def = llvm::cast<TagDecl>(decl_origin.decl)->getDefinition();
841829
if (!origin_def)
842830
return false;
843831

832+
ImporterDelegateSP delegate_sp(
833+
GetDelegate(&decl->getASTContext(), decl_origin.ctx));
834+
835+
ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp,
836+
&decl->getASTContext());
837+
844838
// This is expected to pull in a definition for result_decl (if in redecl
845839
// completion mode)
846840
llvm::Expected<Decl *> result = delegate_sp->Import(origin_def);
@@ -859,6 +853,18 @@ bool ClangASTImporter::CompleteTagDecl(clang::TagDecl *decl) {
859853
if (!decl->isThisDeclarationADefinition() && result_decl != decl)
860854
if (result_decl->getPreviousDecl() == nullptr)
861855
result_decl->setPreviousDecl(decl);
856+
} else {
857+
if (!TypeSystemClang::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
858+
return false;
859+
860+
ImporterDelegateSP delegate_sp(
861+
GetDelegate(&decl->getASTContext(), decl_origin.ctx));
862+
863+
ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp,
864+
&decl->getASTContext());
865+
866+
if (delegate_sp)
867+
delegate_sp->ImportDefinitionTo(decl, decl_origin.decl);
862868
}
863869

864870
return true;
@@ -880,27 +886,15 @@ bool ClangASTImporter::CompleteObjCInterfaceDecl(
880886
if (!decl_origin.Valid())
881887
return false;
882888

883-
ImporterDelegateSP delegate_sp(
884-
GetDelegate(&interface_decl->getASTContext(), decl_origin.ctx));
885-
886-
if (!TypeSystemClang::UseRedeclCompletion()) {
887-
if (!TypeSystemClang::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
888-
return false;
889-
890-
if (delegate_sp)
891-
delegate_sp->ImportDefinitionTo(interface_decl, decl_origin.decl);
892-
893-
if (ObjCInterfaceDecl *super_class = interface_decl->getSuperClass())
894-
RequireCompleteType(clang::QualType(super_class->getTypeForDecl(), 0));
895-
} else {
889+
if (TypeSystemClang::UseRedeclCompletion()) {
896890
ObjCInterfaceDecl *origin_decl =
897891
llvm::cast<ObjCInterfaceDecl>(decl_origin.decl);
898892

899893
origin_decl = origin_decl->getDefinition();
900894
if (!origin_decl)
901895
return false;
902896

903-
auto delegate_sp(
897+
ImporterDelegateSP delegate_sp(
904898
GetDelegate(&interface_decl->getASTContext(), decl_origin.ctx));
905899

906900
llvm::Expected<Decl *> result = delegate_sp->Import(origin_decl);
@@ -915,6 +909,18 @@ bool ClangASTImporter::CompleteObjCInterfaceDecl(
915909
return false;
916910
}
917911

912+
if (!TypeSystemClang::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
913+
return false;
914+
915+
ImporterDelegateSP delegate_sp(
916+
GetDelegate(&interface_decl->getASTContext(), decl_origin.ctx));
917+
918+
if (delegate_sp)
919+
delegate_sp->ImportDefinitionTo(interface_decl, decl_origin.decl);
920+
921+
if (ObjCInterfaceDecl *super_class = interface_decl->getSuperClass())
922+
RequireCompleteType(clang::QualType(super_class->getTypeForDecl(), 0));
923+
918924
return true;
919925
}
920926

@@ -1204,15 +1210,14 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) {
12041210
DeclContext::lookup_result lr = dc->lookup(*dn_or_err);
12051211
for (clang::Decl *candidate : lr) {
12061212
if (candidate->getKind() == From->getKind()) {
1207-
RegisterImportedDecl(From, candidate);
1208-
1209-
// If we're dealing with redecl chains. We want to find the definition,
1213+
// If we're dealing with redecl chains, we want to find the definition,
12101214
// so skip if the decl is actually just a forwad decl.
12111215
if (TypeSystemClang::UseRedeclCompletion())
12121216
if (auto *tag_decl = llvm::dyn_cast<TagDecl>(candidate);
12131217
!tag_decl || !tag_decl->getDefinition())
12141218
continue;
12151219

1220+
RegisterImportedDecl(From, candidate);
12161221
m_decls_to_ignore.insert(candidate);
12171222
return candidate;
12181223
}

lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class ClangASTSource : public ImporterBackedASTSource,
214214
///
215215
/// Clang AST contexts like to own their AST sources, so this is a state-
216216
/// free proxy object.
217-
class ClangASTSourceProxy : public clang::ExternalASTSource {
217+
class ClangASTSourceProxy : public ImporterBackedASTSource {
218218
public:
219219
ClangASTSourceProxy(ClangASTSource &original) : m_original(original) {}
220220

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,8 @@ TypeSystemClang::CreateClassTemplateSpecializationDecl(
17321732
static_cast<TagDecl::TagKind>(kind));
17331733
class_template_specialization_decl->setDeclContext(decl_ctx);
17341734
class_template_specialization_decl->setInstantiationOf(class_template_decl);
1735+
if (TypeSystemClang::UseRedeclCompletion())
1736+
ast.getTypeDeclType(class_template_specialization_decl, nullptr);
17351737
class_template_specialization_decl->setTemplateArgs(
17361738
TemplateArgumentList::CreateCopy(ast, args));
17371739
class_template_specialization_decl->setDeclName(

0 commit comments

Comments
 (0)