diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp @@ -881,8 +881,8 @@ std::string uname = std::string(DropNameScope(udt.Name)); - CompilerType ct = m_clang.CreateTypedefType(ToCompilerType(qt), uname.c_str(), - ToCompilerDeclContext(*scope), 0); + CompilerType ct = ToCompilerType(qt).CreateTypedef( + uname.c_str(), ToCompilerDeclContext(*scope), 0); clang::TypedefNameDecl *tnd = m_clang.GetAsTypedefDecl(ct); DeclStatus status; status.resolved = true; diff --git a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp --- a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp +++ b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp @@ -550,8 +550,8 @@ if (!ast_typedef.IsValid()) { CompilerType target_ast_type = target_type->GetFullCompilerType(); - ast_typedef = m_ast.CreateTypedefType( - target_ast_type, name.c_str(), m_ast.CreateDeclContext(decl_ctx), 0); + ast_typedef = target_ast_type.CreateTypedef( + name.c_str(), m_ast.CreateDeclContext(decl_ctx), 0); if (!ast_typedef) return nullptr; diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -665,14 +665,6 @@ // Creating related types - /// Using the current type, create a new typedef to that type using - /// "typedef_name" as the name and "decl_ctx" as the decl context. - /// \param opaque_payload is an opaque TypePayloadClang. - static CompilerType - CreateTypedefType(const CompilerType &type, const char *typedef_name, - const CompilerDeclContext &compiler_decl_ctx, - uint32_t opaque_payload); - CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) override; @@ -720,6 +712,9 @@ CompilerType AddRestrictModifier(lldb::opaque_compiler_type_t type) override; + /// Using the current type, create a new typedef to that type using + /// "typedef_name" as the name and "decl_ctx" as the decl context. + /// \param opaque_payload is an opaque TypePayloadClang. CompilerType CreateTypedef(lldb::opaque_compiler_type_t type, const char *name, const CompilerDeclContext &decl_ctx, diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -4402,39 +4402,6 @@ return CompilerType(); } -CompilerType TypeSystemClang::CreateTypedefType( - const CompilerType &type, const char *typedef_name, - const CompilerDeclContext &compiler_decl_ctx, uint32_t payload) { - if (type && typedef_name && typedef_name[0]) { - TypeSystemClang *ast = - llvm::dyn_cast(type.GetTypeSystem()); - if (!ast) - return CompilerType(); - clang::ASTContext &clang_ast = ast->getASTContext(); - clang::QualType qual_type(ClangUtil::GetQualType(type)); - - clang::DeclContext *decl_ctx = - TypeSystemClang::DeclContextGetAsDeclContext(compiler_decl_ctx); - if (!decl_ctx) - decl_ctx = ast->getASTContext().getTranslationUnitDecl(); - - clang::TypedefDecl *decl = - clang::TypedefDecl::CreateDeserialized(clang_ast, 0); - decl->setDeclContext(decl_ctx); - decl->setDeclName(&clang_ast.Idents.get(typedef_name)); - decl->setTypeSourceInfo(clang_ast.getTrivialTypeSourceInfo(qual_type)); - - SetOwningModule(decl, TypePayloadClang(payload).GetOwningModule()); - decl->setAccess(clang::AS_public); // TODO respect proper access specifier - - decl_ctx->addDecl(decl); - - // Get a uniqued clang::QualType for the typedef decl type - return ast->GetType(clang_ast.getTypedefType(decl)); - } - return CompilerType(); -} - CompilerType TypeSystemClang::GetPointeeType(lldb::opaque_compiler_type_t type) { if (type) { @@ -4516,7 +4483,7 @@ CompilerType TypeSystemClang::CreateTypedef( lldb::opaque_compiler_type_t type, const char *typedef_name, const CompilerDeclContext &compiler_decl_ctx, uint32_t payload) { - if (type) { + if (type && typedef_name && typedef_name[0]) { clang::ASTContext &clang_ast = getASTContext(); clang::QualType qual_type(GetQualType(type)); @@ -4525,10 +4492,11 @@ if (!decl_ctx) decl_ctx = getASTContext().getTranslationUnitDecl(); - clang::TypedefDecl *decl = clang::TypedefDecl::Create( - clang_ast, decl_ctx, clang::SourceLocation(), clang::SourceLocation(), - &clang_ast.Idents.get(typedef_name), - clang_ast.getTrivialTypeSourceInfo(qual_type)); + clang::TypedefDecl *decl = + clang::TypedefDecl::CreateDeserialized(clang_ast, 0); + decl->setDeclContext(decl_ctx); + decl->setDeclName(&clang_ast.Idents.get(typedef_name)); + decl->setTypeSourceInfo(clang_ast.getTrivialTypeSourceInfo(qual_type)); decl_ctx->addDecl(decl); SetOwningModule(decl, TypePayloadClang(payload).GetOwningModule()); diff --git a/lldb/unittests/Symbol/TestTypeSystemClang.cpp b/lldb/unittests/Symbol/TestTypeSystemClang.cpp --- a/lldb/unittests/Symbol/TestTypeSystemClang.cpp +++ b/lldb/unittests/Symbol/TestTypeSystemClang.cpp @@ -482,9 +482,8 @@ m_ast->CompleteTagDeclarationDefinition(type); // typedef foo foo_def; - CompilerType typedef_type = m_ast->CreateTypedefType( - type, "foo_def", - m_ast->CreateDeclContext(m_ast->GetTranslationUnitDecl()), 0); + CompilerType typedef_type = type.CreateTypedef( + "foo_def", m_ast->CreateDeclContext(m_ast->GetTranslationUnitDecl()), 0); CompilerType auto_type( m_ast.get(),