Skip to content

Commit 968ecb4

Browse files
committed
[PATCH 7/7] [clang] improve NestedNameSpecifier: LLDB changes
Patch series starting at #147835
1 parent 47b79ce commit 968ecb4

File tree

18 files changed

+201
-218
lines changed

18 files changed

+201
-218
lines changed

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

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ CompilerType ClangASTImporter::DeportType(TypeSystemClang &dst,
320320
DeclContextOverride decl_context_override;
321321

322322
if (auto *t = ClangUtil::GetQualType(src_type)->getAs<TagType>())
323-
decl_context_override.OverrideAllDeclsFromContainingFunction(t->getDecl());
323+
decl_context_override.OverrideAllDeclsFromContainingFunction(
324+
t->getOriginalDecl()->getDefinitionOrSelf());
324325

325326
CompleteTagDeclsScope complete_scope(*this, &dst.getASTContext(),
326327
&src_ctxt->getASTContext());
@@ -377,8 +378,9 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
377378
} break;
378379

379380
case clang::Type::Enum: {
380-
clang::EnumDecl *enum_decl =
381-
llvm::cast<clang::EnumType>(qual_type)->getDecl();
381+
auto *enum_decl = llvm::cast<clang::EnumType>(qual_type)
382+
->getOriginalDecl()
383+
->getDefinitionOrSelf();
382384
if (enum_decl) {
383385
if (GetDeclOrigin(enum_decl).Valid())
384386
return true;
@@ -414,12 +416,6 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
414416
->getDeducedType()
415417
.getAsOpaquePtr()));
416418

417-
case clang::Type::Elaborated:
418-
return CanImport(CompilerType(type.GetTypeSystem(),
419-
llvm::cast<clang::ElaboratedType>(qual_type)
420-
->getNamedType()
421-
.getAsOpaquePtr()));
422-
423419
case clang::Type::Paren:
424420
return CanImport(CompilerType(
425421
type.GetTypeSystem(),
@@ -451,8 +447,9 @@ bool ClangASTImporter::Import(const CompilerType &type) {
451447
} break;
452448

453449
case clang::Type::Enum: {
454-
clang::EnumDecl *enum_decl =
455-
llvm::cast<clang::EnumType>(qual_type)->getDecl();
450+
clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)
451+
->getOriginalDecl()
452+
->getDefinitionOrSelf();
456453
if (enum_decl) {
457454
if (GetDeclOrigin(enum_decl).Valid())
458455
return CompleteAndFetchChildren(qual_type);
@@ -488,12 +485,6 @@ bool ClangASTImporter::Import(const CompilerType &type) {
488485
->getDeducedType()
489486
.getAsOpaquePtr()));
490487

491-
case clang::Type::Elaborated:
492-
return Import(CompilerType(type.GetTypeSystem(),
493-
llvm::cast<clang::ElaboratedType>(qual_type)
494-
->getNamedType()
495-
.getAsOpaquePtr()));
496-
497488
case clang::Type::Paren:
498489
return Import(CompilerType(
499490
type.GetTypeSystem(),
@@ -597,7 +588,7 @@ bool ExtractBaseOffsets(const ASTRecordLayout &record_layout,
597588
return false;
598589

599590
DeclFromUser<RecordDecl> origin_base_record(
600-
origin_base_record_type->getDecl());
591+
origin_base_record_type->getOriginalDecl()->getDefinitionOrSelf());
601592

602593
if (origin_base_record.IsInvalid())
603594
return false;
@@ -728,7 +719,8 @@ bool ClangASTImporter::importRecordLayoutFromOrigin(
728719

729720
QualType base_type = bi->getType();
730721
const RecordType *base_record_type = base_type->getAs<RecordType>();
731-
DeclFromParser<RecordDecl> base_record(base_record_type->getDecl());
722+
DeclFromParser<RecordDecl> base_record(
723+
base_record_type->getOriginalDecl()->getDefinitionOrSelf());
732724
DeclFromParser<CXXRecordDecl> base_cxx_record =
733725
DynCast<CXXRecordDecl>(base_record);
734726

@@ -860,7 +852,7 @@ bool ClangASTImporter::CompleteAndFetchChildren(clang::QualType type) {
860852
Log *log = GetLog(LLDBLog::Expressions);
861853

862854
if (const TagType *tag_type = type->getAs<TagType>()) {
863-
TagDecl *tag_decl = tag_type->getDecl();
855+
TagDecl *tag_decl = tag_type->getOriginalDecl()->getDefinitionOrSelf();
864856

865857
DeclOrigin decl_origin = GetDeclOrigin(tag_decl);
866858

@@ -928,9 +920,9 @@ bool ClangASTImporter::RequireCompleteType(clang::QualType type) {
928920
return false;
929921

930922
if (const TagType *tag_type = type->getAs<TagType>()) {
931-
TagDecl *tag_decl = tag_type->getDecl();
923+
TagDecl *tag_decl = tag_type->getOriginalDecl();
932924

933-
if (tag_decl->getDefinition() || tag_decl->isBeingDefined())
925+
if (tag_decl->getDefinition())
934926
return true;
935927

936928
return CompleteTagDecl(tag_decl);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ TagDecl *ClangASTSource::FindCompleteType(const TagDecl *decl) {
223223
continue;
224224

225225
TagDecl *candidate_tag_decl =
226-
const_cast<TagDecl *>(tag_type->getDecl());
226+
tag_type->getOriginalDecl()->getDefinitionOrSelf();
227227

228228
if (TypeSystemClang::GetCompleteDecl(
229229
&candidate_tag_decl->getASTContext(), candidate_tag_decl))
@@ -250,7 +250,8 @@ TagDecl *ClangASTSource::FindCompleteType(const TagDecl *decl) {
250250
if (!tag_type)
251251
continue;
252252

253-
TagDecl *candidate_tag_decl = const_cast<TagDecl *>(tag_type->getDecl());
253+
TagDecl *candidate_tag_decl =
254+
tag_type->getOriginalDecl()->getDefinitionOrSelf();
254255

255256
if (TypeSystemClang::GetCompleteDecl(&candidate_tag_decl->getASTContext(),
256257
candidate_tag_decl))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ void ClangExpressionDeclMap::LookUpLldbClass(NameSearchContext &context) {
839839

840840
clang::CXXRecordDecl *class_decl = method_decl->getParent();
841841

842-
QualType class_qual_type(class_decl->getTypeForDecl(), 0);
842+
QualType class_qual_type = m_ast_context->getCanonicalTagType(class_decl);
843843

844844
TypeFromUser class_user_type(
845845
class_qual_type.getAsOpaquePtr(),
@@ -1561,7 +1561,7 @@ ClangExpressionDeclMap::AddExpressionVariable(NameSearchContext &context,
15611561

15621562
if (const clang::Type *parser_type = parser_opaque_type.getTypePtr()) {
15631563
if (const TagType *tag_type = dyn_cast<TagType>(parser_type))
1564-
CompleteType(tag_type->getDecl());
1564+
CompleteType(tag_type->getOriginalDecl()->getDefinitionOrSelf());
15651565
if (const ObjCObjectPointerType *objc_object_ptr_type =
15661566
dyn_cast<ObjCObjectPointerType>(parser_type))
15671567
CompleteType(objc_object_ptr_type->getInterfaceDecl());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ NameSearchContext::AddTypeDecl(const CompilerType &clang_type) {
153153

154154
return (NamedDecl *)typedef_name_decl;
155155
} else if (const TagType *tag_type = qual_type->getAs<TagType>()) {
156-
TagDecl *tag_decl = tag_type->getDecl();
156+
TagDecl *tag_decl = tag_type->getOriginalDecl()->getDefinitionOrSelf();
157157

158158
m_decls.push_back(tag_decl);
159159

lldb/source/Plugins/Language/ObjC/NSDictionary.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ static CompilerType GetLLDBNSPairType(TargetSP target_sp) {
7373

7474
static constexpr llvm::StringLiteral g_lldb_autogen_nspair("__lldb_autogen_nspair");
7575

76-
compiler_type = scratch_ts_sp->GetTypeForIdentifier<clang::CXXRecordDecl>(g_lldb_autogen_nspair);
76+
compiler_type = scratch_ts_sp->GetTypeForIdentifier<clang::CXXRecordDecl>(
77+
scratch_ts_sp->getASTContext(), g_lldb_autogen_nspair);
7778

7879
if (!compiler_type) {
7980
compiler_type = scratch_ts_sp->CreateRecordType(

lldb/source/Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ CompilerType RegisterTypeBuilderClang::GetRegisterType(
4747
// See if we have made this type before and can reuse it.
4848
CompilerType fields_type =
4949
type_system->GetTypeForIdentifier<clang::CXXRecordDecl>(
50-
register_type_name);
50+
type_system->getASTContext(), register_type_name);
5151

5252
if (!fields_type) {
5353
// In most ABI, a change of field type means a change in storage unit.
@@ -83,7 +83,7 @@ CompilerType RegisterTypeBuilderClang::GetRegisterType(
8383
// may have built this one already.
8484
CompilerType field_enum_type =
8585
type_system->GetTypeForIdentifier<clang::EnumDecl>(
86-
enum_type_name);
86+
type_system->getASTContext(), enum_type_name);
8787

8888
if (field_enum_type)
8989
field_type = field_enum_type;

lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ bool PdbAstBuilder::CompleteTagDecl(clang::TagDecl &tag) {
449449
->GetIndex();
450450
lldbassert(IsTagRecord(type_id, index.tpi()));
451451

452-
clang::QualType tag_qt = m_clang.getASTContext().getTypeDeclType(&tag);
452+
clang::QualType tag_qt = m_clang.getASTContext().getCanonicalTagType(&tag);
453453
TypeSystemClang::SetHasExternalStorage(tag_qt.getAsOpaquePtr(), false);
454454

455455
TypeIndex tag_ti = type_id.index;
@@ -562,7 +562,8 @@ clang::QualType PdbAstBuilder::CreatePointerType(const PointerRecord &pointer) {
562562
m_clang.getASTContext(), spelling));
563563
}
564564
return m_clang.getASTContext().getMemberPointerType(
565-
pointee_type, /*Qualifier=*/nullptr, class_type->getAsCXXRecordDecl());
565+
pointee_type, /*Qualifier=*/std::nullopt,
566+
class_type->getAsCXXRecordDecl());
566567
}
567568

568569
clang::QualType pointer_type;
@@ -859,9 +860,9 @@ PdbAstBuilder::CreateFunctionDecl(PdbCompilandSymId func_id,
859860
SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
860861
m_clang.GetSymbolFile()->GetBackingSymbolFile());
861862
PdbIndex &index = pdb->GetIndex();
862-
clang::QualType parent_qt = llvm::cast<clang::TypeDecl>(parent)
863-
->getTypeForDecl()
864-
->getCanonicalTypeInternal();
863+
clang::CanQualType parent_qt =
864+
m_clang.getASTContext().getCanonicalTypeDeclType(
865+
llvm::cast<clang::TypeDecl>(parent));
865866
lldb::opaque_compiler_type_t parent_opaque_ty =
866867
ToCompilerType(parent_qt).GetOpaqueQualType();
867868
// FIXME: Remove this workaround.

lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
407407
// symbols in PDB for types with const or volatile modifiers, but we need
408408
// to create only one declaration for them all.
409409
Type::ResolveState type_resolve_state;
410-
CompilerType clang_type =
411-
m_ast.GetTypeForIdentifier<clang::CXXRecordDecl>(name, decl_context);
410+
CompilerType clang_type = m_ast.GetTypeForIdentifier<clang::CXXRecordDecl>(
411+
m_ast.getASTContext(), name, decl_context);
412412
if (!clang_type.IsValid()) {
413413
auto access = GetAccessibilityForUdt(*udt);
414414

@@ -479,8 +479,8 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
479479
uint64_t bytes = enum_type->getLength();
480480

481481
// Check if such an enum already exists in the current context
482-
CompilerType ast_enum =
483-
m_ast.GetTypeForIdentifier<clang::EnumDecl>(name, decl_context);
482+
CompilerType ast_enum = m_ast.GetTypeForIdentifier<clang::EnumDecl>(
483+
m_ast.getASTContext(), name, decl_context);
484484
if (!ast_enum.IsValid()) {
485485
auto underlying_type_up = enum_type->getUnderlyingType();
486486
if (!underlying_type_up)
@@ -557,7 +557,8 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
557557

558558
// Check if such a typedef already exists in the current context
559559
CompilerType ast_typedef =
560-
m_ast.GetTypeForIdentifier<clang::TypedefNameDecl>(name, decl_ctx);
560+
m_ast.GetTypeForIdentifier<clang::TypedefNameDecl>(
561+
m_ast.getASTContext(), name, decl_ctx);
561562
if (!ast_typedef.IsValid()) {
562563
CompilerType target_ast_type = target_type->GetFullCompilerType();
563564

0 commit comments

Comments
 (0)