From 47b76631e76810bfc6d91d534dc1b095e8058ff4 Mon Sep 17 00:00:00 2001 From: Joe Loser Date: Thu, 8 Sep 2022 09:05:04 -0600 Subject: [PATCH] [lldb] Use std::size instead of llvm::array_lengthof LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Differential Revision: https://reviews.llvm.org/D133501 --- lldb/source/DataFormatters/FormatManager.cpp | 2 +- lldb/source/Host/posix/MainLoopPosix.cpp | 2 +- lldb/source/Host/windows/ConnectionGenericFileWindows.cpp | 5 ++--- lldb/source/Interpreter/CommandInterpreter.cpp | 2 +- lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp | 5 ++--- lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp | 5 ++--- lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp | 5 ++--- lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp | 3 +-- lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp | 3 +-- lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp | 4 ++-- lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp | 3 +-- .../Darwin-Kernel/DynamicLoaderDarwinKernel.cpp | 2 +- .../Plugins/Instruction/ARM/EmulateInstructionARM.cpp | 4 ++-- .../Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp | 4 ++-- .../Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp | 4 ++-- .../ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp | 6 +++--- lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp | 2 +- lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp | 4 ++-- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp | 8 ++++---- .../Plugins/Process/Utility/RegisterContextDarwin_arm.cpp | 10 +++++----- .../Process/Utility/RegisterContextDarwin_arm64.cpp | 11 +++++------ .../Plugins/Process/Utility/RegisterContextDarwin_i386.cpp | 10 +++++----- .../Process/Utility/RegisterContextDarwin_x86_64.cpp | 10 +++++----- .../Process/Utility/RegisterContextWindows_i386.cpp | 4 ++-- .../Process/Utility/RegisterContextWindows_x86_64.cpp | 4 ++-- .../Windows/Common/NativeRegisterContextWindows_WoW64.cpp | 4 ++-- .../Windows/Common/NativeRegisterContextWindows_arm.cpp | 8 ++++---- .../Windows/Common/NativeRegisterContextWindows_arm64.cpp | 8 ++++---- .../Windows/Common/NativeRegisterContextWindows_i386.cpp | 4 ++-- .../Windows/Common/NativeRegisterContextWindows_x86_64.cpp | 8 ++++---- .../Windows/Common/arm/RegisterContextWindows_arm.cpp | 12 ++++++------ .../Windows/Common/arm64/RegisterContextWindows_arm64.cpp | 13 ++++++------- .../Windows/Common/x64/RegisterContextWindows_x64.cpp | 14 +++++++------- .../Windows/Common/x86/RegisterContextWindows_x86.cpp | 10 +++++----- .../Process/minidump/RegisterContextMinidump_ARM.cpp | 12 ++++++------ .../Process/minidump/RegisterContextMinidump_ARM64.cpp | 8 ++++---- lldb/source/Utility/ArchSpec.cpp | 12 ++++++------ lldb/unittests/Utility/StatusTest.cpp | 2 +- 38 files changed, 114 insertions(+), 123 deletions(-) diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index a81597f..70600a3 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -76,7 +76,7 @@ static_assert((sizeof(g_format_infos) / sizeof(g_format_infos[0])) == kNumFormats, "All formats must have a corresponding info entry."); -static uint32_t g_num_format_infos = llvm::array_lengthof(g_format_infos); +static uint32_t g_num_format_infos = std::size(g_format_infos); static bool GetFormatFromFormatChar(char format_char, Format &format) { for (uint32_t i = 0; i < g_num_format_infos; ++i) { diff --git a/lldb/source/Host/posix/MainLoopPosix.cpp b/lldb/source/Host/posix/MainLoopPosix.cpp index 1bbfad84..37d339d 100644 --- a/lldb/source/Host/posix/MainLoopPosix.cpp +++ b/lldb/source/Host/posix/MainLoopPosix.cpp @@ -81,7 +81,7 @@ Status MainLoopPosix::RunImpl::Poll() { EV_SET(&in_events[i++], fd.first, EVFILT_READ, EV_ADD, 0, 0, 0); num_events = kevent(loop.m_kqueue, in_events.data(), in_events.size(), - out_events, llvm::array_lengthof(out_events), nullptr); + out_events, std::size(out_events), nullptr); if (num_events < 0) { if (errno == EINTR) { diff --git a/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp b/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp index 0860e11..2db256a 100644 --- a/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp +++ b/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp @@ -188,9 +188,8 @@ size_t ConnectionGenericFile::Read(void *dst, size_t dst_len, ? std::chrono::duration_cast(*timeout) .count() : INFINITE; - DWORD wait_result = - ::WaitForMultipleObjects(llvm::array_lengthof(m_event_handles), - m_event_handles, FALSE, milliseconds); + DWORD wait_result = ::WaitForMultipleObjects( + std::size(m_event_handles), m_event_handles, FALSE, milliseconds); // All of the events are manual reset events, so make sure we reset them // to non-signalled. switch (wait_result) { diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 6ef209b..0596d85 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -561,7 +561,7 @@ void CommandInterpreter::LoadCommandDictionary() { "breakpoint set --name '%1'"}}; // clang-format on - size_t num_regexes = llvm::array_lengthof(break_regexes); + size_t num_regexes = std::size(break_regexes); std::unique_ptr break_regex_cmd_up( new CommandObjectRegexCommand( diff --git a/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp b/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp index a8d1cbc..0aa8430 100644 --- a/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp +++ b/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp @@ -1186,8 +1186,7 @@ static const RegisterInfo g_register_infos[] = { nullptr, }}; -static const uint32_t k_num_register_infos = - llvm::array_lengthof(g_register_infos); +static const uint32_t k_num_register_infos = std::size(g_register_infos); const lldb_private::RegisterInfo * ABIMacOSX_arm::GetRegisterInfoArray(uint32_t &count) { @@ -1235,7 +1234,7 @@ bool ABIMacOSX_arm::PrepareTrivialCall(Thread &thread, addr_t sp, llvm::ArrayRef::iterator ai = args.begin(), ae = args.end(); - for (size_t i = 0; i < llvm::array_lengthof(reg_names); ++i) { + for (size_t i = 0; i < std::size(reg_names); ++i) { if (ai == ae) break; diff --git a/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp b/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp index 9052f04..7112894 100644 --- a/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp +++ b/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp @@ -1189,8 +1189,7 @@ static const RegisterInfo g_register_infos[] = { nullptr, }}; -static const uint32_t k_num_register_infos = - llvm::array_lengthof(g_register_infos); +static const uint32_t k_num_register_infos = std::size(g_register_infos); const lldb_private::RegisterInfo * ABISysV_arm::GetRegisterInfoArray(uint32_t &count) { @@ -1240,7 +1239,7 @@ bool ABISysV_arm::PrepareTrivialCall(Thread &thread, addr_t sp, llvm::ArrayRef::iterator ai = args.begin(), ae = args.end(); - for (size_t i = 0; i < llvm::array_lengthof(reg_names); ++i) { + for (size_t i = 0; i < std::size(reg_names); ++i) { if (ai == ae) break; diff --git a/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp b/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp index c2b6ce1..c3fbdb1 100644 --- a/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp +++ b/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp @@ -503,8 +503,7 @@ static const RegisterInfo g_register_infos[] = { }, }; -static const uint32_t k_num_register_infos = - llvm::array_lengthof(g_register_infos); +static const uint32_t k_num_register_infos = std::size(g_register_infos); const lldb_private::RegisterInfo * ABISysV_mips::GetRegisterInfoArray(uint32_t &count) { @@ -560,7 +559,7 @@ bool ABISysV_mips::PrepareTrivialCall(Thread &thread, addr_t sp, llvm::ArrayRef::iterator ai = args.begin(), ae = args.end(); // Write arguments to registers - for (size_t i = 0; i < llvm::array_lengthof(reg_names); ++i) { + for (size_t i = 0; i < std::size(reg_names); ++i) { if (ai == ae) break; diff --git a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp index 24571ea..7c5bcaf 100644 --- a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp +++ b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp @@ -503,8 +503,7 @@ static const RegisterInfo g_register_infos_mips64[] = { }, }; -static const uint32_t k_num_register_infos = - llvm::array_lengthof(g_register_infos_mips64); +static const uint32_t k_num_register_infos = std::size(g_register_infos_mips64); const lldb_private::RegisterInfo * ABISysV_mips64::GetRegisterInfoArray(uint32_t &count) { diff --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp index 1ef3b8c..239901c 100644 --- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp +++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp @@ -204,8 +204,7 @@ static const RegisterInfo g_register_infos[] = { nullptr, }}; -static const uint32_t k_num_register_infos = - llvm::array_lengthof(g_register_infos); +static const uint32_t k_num_register_infos = std::size(g_register_infos); const lldb_private::RegisterInfo * ABISysV_ppc::GetRegisterInfoArray(uint32_t &count) { diff --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp index e6f0308..ec0c366 100644 --- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp +++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp @@ -53,10 +53,10 @@ LLDB_PLUGIN_DEFINE(ABISysV_ppc64) const lldb_private::RegisterInfo * ABISysV_ppc64::GetRegisterInfoArray(uint32_t &count) { if (GetByteOrder() == lldb::eByteOrderLittle) { - count = llvm::array_lengthof(g_register_infos_ppc64le); + count = std::size(g_register_infos_ppc64le); return g_register_infos_ppc64le; } else { - count = llvm::array_lengthof(g_register_infos_ppc64); + count = std::size(g_register_infos_ppc64); return g_register_infos_ppc64; } } diff --git a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp index f661431..e81f8ee 100644 --- a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp +++ b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp @@ -172,8 +172,7 @@ static const RegisterInfo g_register_infos[] = { DEFINE_REG(f15, 8, nullptr, LLDB_INVALID_REGNUM), }; -static const uint32_t k_num_register_infos = - llvm::array_lengthof(g_register_infos); +static const uint32_t k_num_register_infos = std::size(g_register_infos); const lldb_private::RegisterInfo * ABISysV_s390x::GetRegisterInfoArray(uint32_t &count) { diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp index 93f8f22..c76fb2a 100644 --- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp +++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp @@ -406,7 +406,7 @@ DynamicLoaderDarwinKernel::ReadMachHeader(addr_t addr, Process *process, llvm::M const uint32_t magicks[] = { llvm::MachO::MH_MAGIC_64, llvm::MachO::MH_MAGIC, llvm::MachO::MH_CIGAM, llvm::MachO::MH_CIGAM_64}; bool found_matching_pattern = false; - for (size_t i = 0; i < llvm::array_lengthof (magicks); i++) + for (size_t i = 0; i < std::size(magicks); i++) if (::memcmp (&header.magic, &magicks[i], sizeof (uint32_t)) == 0) found_matching_pattern = true; diff --git a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp index 103551d..0abfefa 100644 --- a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp +++ b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp @@ -13188,7 +13188,7 @@ EmulateInstructionARM::GetARMOpcodeForInstruction(const uint32_t opcode, &EmulateInstructionARM::EmulateRFE, "rfe{} {!}"} }; - static const size_t k_num_arm_opcodes = llvm::array_lengthof(g_arm_opcodes); + static const size_t k_num_arm_opcodes = std::size(g_arm_opcodes); for (size_t i = 0; i < k_num_arm_opcodes; ++i) { if ((g_arm_opcodes[i].mask & opcode) == g_arm_opcodes[i].value && @@ -13739,7 +13739,7 @@ EmulateInstructionARM::GetThumbOpcodeForInstruction(const uint32_t opcode, &EmulateInstructionARM::EmulateUXTH, "uxth.w ,{,}"}, }; - const size_t k_num_thumb_opcodes = llvm::array_lengthof(g_thumb_opcodes); + const size_t k_num_thumb_opcodes = std::size(g_thumb_opcodes); for (size_t i = 0; i < k_num_thumb_opcodes; ++i) { if ((g_thumb_opcodes[i].mask & opcode) == g_thumb_opcodes[i].value && (g_thumb_opcodes[i].variants & arm_isa) != 0) diff --git a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp index 80cee99..6ab77d3 100644 --- a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp +++ b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp @@ -52,7 +52,7 @@ using namespace lldb_private; LLDB_PLUGIN_DEFINE_ADV(EmulateInstructionARM64, InstructionARM64) static bool LLDBTableGetRegisterInfo(uint32_t reg_num, RegisterInfo ®_info) { - if (reg_num >= llvm::array_lengthof(g_register_infos_arm64_le)) + if (reg_num >= std::size(g_register_infos_arm64_le)) return false; reg_info = g_register_infos_arm64_le[reg_num]; return true; @@ -360,7 +360,7 @@ EmulateInstructionARM64::GetOpcodeForInstruction(const uint32_t opcode) { "TBNZ , #,