Skip to content

Commit 722247c

Browse files
committed
[lldb] Unify the two CreateTypedef implementations in TypeSystemClang
To get LLDB one step closer to fulfil the software redundancy requirements of modern aircrafts, we apparently decided to have two separately maintained implementations of `CreateTypedef` in TypeSystemClang. Let's pass on the idea of an LLDB-powered jetliner and deleted one implementation. On a more serious note: This function got duplicated a long time ago when the idea of CompilerType with a backing TypeSystemClang subclass happened (56939cb). One implementation was supposed to be called from CompilerType::CreateTypedef and the other has just always been around to create typedefs. By accident one of the implementations is only used by the PDB parser while the CompilerType::CreateTypedef backend is used by the rest of LLDB. We also had some patches over the year that only fixed one of the two functions (D18099 for example only fixed up the CompilerType::CreateTypedef implementation). D51162 and D86140 both fixed the same missing `addDecl` call for one of the two implementations. This patch: * deletes the `CreateTypedefType` function as its only used by the PDB parser and the `CreateTypedef` implementation is anyway needed as it's the backend implementation of CompilerType. * replaces the calls in the PDB parser by just calling the CompilerType wrapper. * moves the documentation to the remaining function. * moves the check for empty typedef names that was only in the deleted implementation to the other (I don't think this fixes anything as I believe all callers are already doing the same check). I'll fix up the usual stuff (not using StringRef, not doing early exit) in a NFC follow-up. This patch is not NFC as the PDB parser now calls the function that has the fix from D18099. Reviewed By: labath, JDevlieghere Differential Revision: https://reviews.llvm.org/D93382
1 parent a4e47cd commit 722247c

File tree

5 files changed

+15
-53
lines changed

5 files changed

+15
-53
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,8 @@ PdbAstBuilder::GetOrCreateTypedefDecl(PdbGlobalSymId id) {
881881

882882
std::string uname = std::string(DropNameScope(udt.Name));
883883

884-
CompilerType ct = m_clang.CreateTypedefType(ToCompilerType(qt), uname.c_str(),
885-
ToCompilerDeclContext(*scope), 0);
884+
CompilerType ct = ToCompilerType(qt).CreateTypedef(
885+
uname.c_str(), ToCompilerDeclContext(*scope), 0);
886886
clang::TypedefNameDecl *tnd = m_clang.GetAsTypedefDecl(ct);
887887
DeclStatus status;
888888
status.resolved = true;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
550550
if (!ast_typedef.IsValid()) {
551551
CompilerType target_ast_type = target_type->GetFullCompilerType();
552552

553-
ast_typedef = m_ast.CreateTypedefType(
554-
target_ast_type, name.c_str(), m_ast.CreateDeclContext(decl_ctx), 0);
553+
ast_typedef = target_ast_type.CreateTypedef(
554+
name.c_str(), m_ast.CreateDeclContext(decl_ctx), 0);
555555
if (!ast_typedef)
556556
return nullptr;
557557

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

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4402,39 +4402,6 @@ TypeSystemClang::GetNonReferenceType(lldb::opaque_compiler_type_t type) {
44024402
return CompilerType();
44034403
}
44044404

4405-
CompilerType TypeSystemClang::CreateTypedefType(
4406-
const CompilerType &type, const char *typedef_name,
4407-
const CompilerDeclContext &compiler_decl_ctx, uint32_t payload) {
4408-
if (type && typedef_name && typedef_name[0]) {
4409-
TypeSystemClang *ast =
4410-
llvm::dyn_cast<TypeSystemClang>(type.GetTypeSystem());
4411-
if (!ast)
4412-
return CompilerType();
4413-
clang::ASTContext &clang_ast = ast->getASTContext();
4414-
clang::QualType qual_type(ClangUtil::GetQualType(type));
4415-
4416-
clang::DeclContext *decl_ctx =
4417-
TypeSystemClang::DeclContextGetAsDeclContext(compiler_decl_ctx);
4418-
if (!decl_ctx)
4419-
decl_ctx = ast->getASTContext().getTranslationUnitDecl();
4420-
4421-
clang::TypedefDecl *decl =
4422-
clang::TypedefDecl::CreateDeserialized(clang_ast, 0);
4423-
decl->setDeclContext(decl_ctx);
4424-
decl->setDeclName(&clang_ast.Idents.get(typedef_name));
4425-
decl->setTypeSourceInfo(clang_ast.getTrivialTypeSourceInfo(qual_type));
4426-
4427-
SetOwningModule(decl, TypePayloadClang(payload).GetOwningModule());
4428-
decl->setAccess(clang::AS_public); // TODO respect proper access specifier
4429-
4430-
decl_ctx->addDecl(decl);
4431-
4432-
// Get a uniqued clang::QualType for the typedef decl type
4433-
return ast->GetType(clang_ast.getTypedefType(decl));
4434-
}
4435-
return CompilerType();
4436-
}
4437-
44384405
CompilerType
44394406
TypeSystemClang::GetPointeeType(lldb::opaque_compiler_type_t type) {
44404407
if (type) {
@@ -4516,7 +4483,7 @@ TypeSystemClang::AddRestrictModifier(lldb::opaque_compiler_type_t type) {
45164483
CompilerType TypeSystemClang::CreateTypedef(
45174484
lldb::opaque_compiler_type_t type, const char *typedef_name,
45184485
const CompilerDeclContext &compiler_decl_ctx, uint32_t payload) {
4519-
if (type) {
4486+
if (type && typedef_name && typedef_name[0]) {
45204487
clang::ASTContext &clang_ast = getASTContext();
45214488
clang::QualType qual_type(GetQualType(type));
45224489

@@ -4525,10 +4492,11 @@ CompilerType TypeSystemClang::CreateTypedef(
45254492
if (!decl_ctx)
45264493
decl_ctx = getASTContext().getTranslationUnitDecl();
45274494

4528-
clang::TypedefDecl *decl = clang::TypedefDecl::Create(
4529-
clang_ast, decl_ctx, clang::SourceLocation(), clang::SourceLocation(),
4530-
&clang_ast.Idents.get(typedef_name),
4531-
clang_ast.getTrivialTypeSourceInfo(qual_type));
4495+
clang::TypedefDecl *decl =
4496+
clang::TypedefDecl::CreateDeserialized(clang_ast, 0);
4497+
decl->setDeclContext(decl_ctx);
4498+
decl->setDeclName(&clang_ast.Idents.get(typedef_name));
4499+
decl->setTypeSourceInfo(clang_ast.getTrivialTypeSourceInfo(qual_type));
45324500
decl_ctx->addDecl(decl);
45334501
SetOwningModule(decl, TypePayloadClang(payload).GetOwningModule());
45344502

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -665,14 +665,6 @@ class TypeSystemClang : public TypeSystem {
665665

666666
// Creating related types
667667

668-
/// Using the current type, create a new typedef to that type using
669-
/// "typedef_name" as the name and "decl_ctx" as the decl context.
670-
/// \param opaque_payload is an opaque TypePayloadClang.
671-
static CompilerType
672-
CreateTypedefType(const CompilerType &type, const char *typedef_name,
673-
const CompilerDeclContext &compiler_decl_ctx,
674-
uint32_t opaque_payload);
675-
676668
CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type,
677669
ExecutionContextScope *exe_scope) override;
678670

@@ -720,6 +712,9 @@ class TypeSystemClang : public TypeSystem {
720712

721713
CompilerType AddRestrictModifier(lldb::opaque_compiler_type_t type) override;
722714

715+
/// Using the current type, create a new typedef to that type using
716+
/// "typedef_name" as the name and "decl_ctx" as the decl context.
717+
/// \param opaque_payload is an opaque TypePayloadClang.
723718
CompilerType CreateTypedef(lldb::opaque_compiler_type_t type,
724719
const char *name,
725720
const CompilerDeclContext &decl_ctx,

lldb/unittests/Symbol/TestTypeSystemClang.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,8 @@ TEST_F(TestTypeSystemClang, TemplateArguments) {
482482
m_ast->CompleteTagDeclarationDefinition(type);
483483

484484
// typedef foo<int, 47> foo_def;
485-
CompilerType typedef_type = m_ast->CreateTypedefType(
486-
type, "foo_def",
487-
m_ast->CreateDeclContext(m_ast->GetTranslationUnitDecl()), 0);
485+
CompilerType typedef_type = type.CreateTypedef(
486+
"foo_def", m_ast->CreateDeclContext(m_ast->GetTranslationUnitDecl()), 0);
488487

489488
CompilerType auto_type(
490489
m_ast.get(),

0 commit comments

Comments
 (0)