Skip to content

Commit

Permalink
[lldb][NFCI] TypeSystemClang::CreateStructForIdentifier should take a…
Browse files Browse the repository at this point in the history
… StringRef

This doesn't really use fast comparison or string uniqueness. In fact,
all of the current callers pass an empty string for type_name. The only
reason I don't remove it is because it looks like it is used downstream
for swift.

Differential Revision: https://reviews.llvm.org/D153810
  • Loading branch information
bulbazord authored and veselypeta committed Sep 3, 2024
2 parents 96730b8 + a2ff292 commit 5450a01
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ class BlockPointerSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
const char *const FuncPtr_name("__FuncPtr");

m_block_struct_type = clang_ast_context->CreateStructForIdentifier(
ConstString(), {{isa_name, isa_type},
{flags_name, flags_type},
{reserved_name, reserved_type},
{FuncPtr_name, function_pointer_type}});
llvm::StringRef(), {{isa_name, isa_type},
{flags_name, flags_type},
{reserved_name, reserved_type},
{FuncPtr_name, function_pointer_type}});
}

~BlockPointerSyntheticFrontEnd() override = default;
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ bool lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::Update() {
// +-----------------------------+
//
CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
ConstString(),
llvm::StringRef(),
{{"ptr0",
ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
{"ptr1",
Expand Down Expand Up @@ -503,7 +503,7 @@ bool lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd::
// +-----------------------------+
//
CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
ConstString(),
llvm::StringRef(),
{{"__next_",
ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
{"__hash_", ast_ctx->GetBasicType(lldb::eBasicTypeUnsignedLongLong)},
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ void lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetValueOffset(
if (!ast_ctx)
return;
CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
ConstString(),
llvm::StringRef(),
{{"ptr0", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
{"ptr1", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
{"ptr2", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ CompilerType PlatformFreeBSD::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_fault",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"_trapno", int_type},
}),
lldb::eAccessPublic, 0);

ast->AddFieldToRecordType(
union_type, "_timer",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"_timerid", int_type},
{"_overrun", int_type},
Expand All @@ -261,15 +261,15 @@ CompilerType PlatformFreeBSD::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_mesgq",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"_mqd", int_type},
}),
lldb::eAccessPublic, 0);

ast->AddFieldToRecordType(
union_type, "_poll",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"_band", long_type},
}),
Expand Down
21 changes: 11 additions & 10 deletions lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,14 @@ CompilerType PlatformLinux::GetSiginfoType(const llvm::Triple &triple) {
nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
clang::TTK_Union, lldb::eLanguageTypeC);
ast->StartTagDeclarationDefinition(sigfault_bounds_type);
ast->AddFieldToRecordType(sigfault_bounds_type, "_addr_bnd",
ast->CreateStructForIdentifier(ConstString(),
ast->AddFieldToRecordType(
sigfault_bounds_type, "_addr_bnd",
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"_lower", voidp_type},
{"_upper", voidp_type},
}),
lldb::eAccessPublic, 0);
lldb::eAccessPublic, 0);
ast->AddFieldToRecordType(sigfault_bounds_type, "_pkey", uint_type,
lldb::eAccessPublic, 0);
ast->CompleteTagDeclarationDefinition(sigfault_bounds_type);
Expand Down Expand Up @@ -404,7 +405,7 @@ CompilerType PlatformLinux::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_kill",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"si_pid", pid_type},
{"si_uid", uid_type},
Expand All @@ -413,7 +414,7 @@ CompilerType PlatformLinux::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_timer",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"si_tid", int_type},
{"si_overrun", int_type},
Expand All @@ -423,7 +424,7 @@ CompilerType PlatformLinux::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_rt",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"si_pid", pid_type},
{"si_uid", uid_type},
Expand All @@ -433,7 +434,7 @@ CompilerType PlatformLinux::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_sigchld",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"si_pid", pid_type},
{"si_uid", uid_type},
Expand All @@ -445,7 +446,7 @@ CompilerType PlatformLinux::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_sigfault",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"si_addr", voidp_type},
{"si_addr_lsb", short_type},
Expand All @@ -455,7 +456,7 @@ CompilerType PlatformLinux::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_sigpoll",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"si_band", band_type},
{"si_fd", int_type},
Expand All @@ -465,7 +466,7 @@ CompilerType PlatformLinux::GetSiginfoType(const llvm::Triple &triple) {
// NB: SIGSYS is not present on ia64 but we don't seem to support that
ast->AddFieldToRecordType(
union_type, "_sigsys",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"_call_addr", voidp_type},
{"_syscall", int_type},
Expand Down
12 changes: 6 additions & 6 deletions lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ CompilerType PlatformNetBSD::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_rt",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"_pid", pid_type},
{"_uid", uid_type},
Expand All @@ -287,7 +287,7 @@ CompilerType PlatformNetBSD::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_child",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"_pid", pid_type},
{"_uid", uid_type},
Expand All @@ -299,7 +299,7 @@ CompilerType PlatformNetBSD::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_fault",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"_addr", voidp_type},
{"_trap", int_type},
Expand All @@ -310,7 +310,7 @@ CompilerType PlatformNetBSD::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_poll",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"_band", long_type},
{"_fd", int_type},
Expand All @@ -319,7 +319,7 @@ CompilerType PlatformNetBSD::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(union_type, "_syscall",
ast->CreateStructForIdentifier(
ConstString(),
llvm::StringRef(),
{
{"_sysnum", int_type},
{"_retval", int_type.GetArrayType(2)},
Expand All @@ -330,7 +330,7 @@ CompilerType PlatformNetBSD::GetSiginfoType(const llvm::Triple &triple) {

ast->AddFieldToRecordType(
union_type, "_ptrace_state",
ast->CreateStructForIdentifier(ConstString(),
ast->CreateStructForIdentifier(llvm::StringRef(),
{
{"_pe_report_event", int_type},
{"_option", ptrace_option_type},
Expand Down
9 changes: 4 additions & 5 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2308,21 +2308,20 @@ CompilerType TypeSystemClang::CreateArrayType(const CompilerType &element_type,
}

CompilerType TypeSystemClang::CreateStructForIdentifier(
ConstString type_name,
llvm::StringRef type_name,
const std::initializer_list<std::pair<const char *, CompilerType>>
&type_fields,
bool packed) {
CompilerType type;
if (!type_name.IsEmpty() &&
if (!type_name.empty() &&
(type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name))
.IsValid()) {
lldbassert(0 && "Trying to create a type for an existing name");
return type;
}

type = CreateRecordType(nullptr, OptionalClangModuleID(), lldb::eAccessPublic,
type_name.GetCString(), clang::TTK_Struct,
lldb::eLanguageTypeC);
type_name, clang::TTK_Struct, lldb::eLanguageTypeC);
StartTagDeclarationDefinition(type);
for (const auto &field : type_fields)
AddFieldToRecordType(type, field.first, field.second, lldb::eAccessPublic,
Expand All @@ -2334,7 +2333,7 @@ CompilerType TypeSystemClang::CreateStructForIdentifier(
}

CompilerType TypeSystemClang::GetOrCreateStructForIdentifier(
ConstString type_name,
llvm::StringRef type_name,
const std::initializer_list<std::pair<const char *, CompilerType>>
&type_fields,
bool packed) {
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ class TypeSystemClang : public TypeSystem {
}

CompilerType CreateStructForIdentifier(
ConstString type_name,
llvm::StringRef type_name,
const std::initializer_list<std::pair<const char *, CompilerType>>
&type_fields,
bool packed = false);

CompilerType GetOrCreateStructForIdentifier(
ConstString type_name,
llvm::StringRef type_name,
const std::initializer_list<std::pair<const char *, CompilerType>>
&type_fields,
bool packed = false);
Expand Down

0 comments on commit 5450a01

Please sign in to comment.