Skip to content

Commit b8c6168

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

File tree

20 files changed

+214
-245
lines changed

20 files changed

+214
-245
lines changed

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

Lines changed: 10 additions & 21 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());
324325

325326
CompleteTagDeclsScope complete_scope(*this, &dst.getASTContext(),
326327
&src_ctxt->getASTContext());
@@ -377,8 +378,7 @@ 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)->getOriginalDecl();
382382
if (enum_decl) {
383383
if (GetDeclOrigin(enum_decl).Valid())
384384
return true;
@@ -414,12 +414,6 @@ bool ClangASTImporter::CanImport(const CompilerType &type) {
414414
->getDeducedType()
415415
.getAsOpaquePtr()));
416416

417-
case clang::Type::Elaborated:
418-
return CanImport(CompilerType(type.GetTypeSystem(),
419-
llvm::cast<clang::ElaboratedType>(qual_type)
420-
->getNamedType()
421-
.getAsOpaquePtr()));
422-
423417
case clang::Type::Paren:
424418
return CanImport(CompilerType(
425419
type.GetTypeSystem(),
@@ -452,7 +446,7 @@ bool ClangASTImporter::Import(const CompilerType &type) {
452446

453447
case clang::Type::Enum: {
454448
clang::EnumDecl *enum_decl =
455-
llvm::cast<clang::EnumType>(qual_type)->getDecl();
449+
llvm::cast<clang::EnumType>(qual_type)->getOriginalDecl();
456450
if (enum_decl) {
457451
if (GetDeclOrigin(enum_decl).Valid())
458452
return CompleteAndFetchChildren(qual_type);
@@ -488,12 +482,6 @@ bool ClangASTImporter::Import(const CompilerType &type) {
488482
->getDeducedType()
489483
.getAsOpaquePtr()));
490484

491-
case clang::Type::Elaborated:
492-
return Import(CompilerType(type.GetTypeSystem(),
493-
llvm::cast<clang::ElaboratedType>(qual_type)
494-
->getNamedType()
495-
.getAsOpaquePtr()));
496-
497485
case clang::Type::Paren:
498486
return Import(CompilerType(
499487
type.GetTypeSystem(),
@@ -597,7 +585,7 @@ bool ExtractBaseOffsets(const ASTRecordLayout &record_layout,
597585
return false;
598586

599587
DeclFromUser<RecordDecl> origin_base_record(
600-
origin_base_record_type->getDecl());
588+
origin_base_record_type->getOriginalDecl());
601589

602590
if (origin_base_record.IsInvalid())
603591
return false;
@@ -728,7 +716,8 @@ bool ClangASTImporter::importRecordLayoutFromOrigin(
728716

729717
QualType base_type = bi->getType();
730718
const RecordType *base_record_type = base_type->getAs<RecordType>();
731-
DeclFromParser<RecordDecl> base_record(base_record_type->getDecl());
719+
DeclFromParser<RecordDecl> base_record(
720+
base_record_type->getOriginalDecl());
732721
DeclFromParser<CXXRecordDecl> base_cxx_record =
733722
DynCast<CXXRecordDecl>(base_record);
734723

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

862851
if (const TagType *tag_type = type->getAs<TagType>()) {
863-
TagDecl *tag_decl = tag_type->getDecl();
852+
TagDecl *tag_decl = tag_type->getOriginalDecl();
864853

865854
DeclOrigin decl_origin = GetDeclOrigin(tag_decl);
866855

@@ -928,9 +917,9 @@ bool ClangASTImporter::RequireCompleteType(clang::QualType type) {
928917
return false;
929918

930919
if (const TagType *tag_type = type->getAs<TagType>()) {
931-
TagDecl *tag_decl = tag_type->getDecl();
920+
TagDecl *tag_decl = tag_type->getOriginalDecl();
932921

933-
if (tag_decl->getDefinition() || tag_decl->isBeingDefined())
922+
if (tag_decl->getDefinition())
934923
return true;
935924

936925
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/ClangPersistentVariables.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ ClangPersistentVariables::GetCompilerTypeFromPersistentDecl(
7979
if (p.m_decl == nullptr)
8080
return std::nullopt;
8181

82+
auto ctx = std::static_pointer_cast<TypeSystemClang>(p.m_context.lock());
8283
if (clang::TypeDecl *tdecl = llvm::dyn_cast<clang::TypeDecl>(p.m_decl)) {
83-
opaque_compiler_type_t t = static_cast<opaque_compiler_type_t>(
84-
const_cast<clang::Type *>(tdecl->getTypeForDecl()));
84+
opaque_compiler_type_t t =
85+
static_cast<opaque_compiler_type_t>(const_cast<clang::Type *>(
86+
ctx->getASTContext().getTypeDeclType(tdecl).getTypePtr()));
8587
return CompilerType(p.m_context, t);
8688
}
8789
return std::nullopt;

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)