Michael137 created this revision. Michael137 added a reviewer: aprantl. Herald added a project: All. Michael137 requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
Currently all callsites already assume the pointer is non-null. This patch just asserts this assumption. This is practically enforced by `ModuleList::Append` which won't add `nullptr`s to `m_modules`. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D139082 Files: lldb/include/lldb/Core/ModuleList.h lldb/source/Core/ModuleList.cpp Index: lldb/source/Core/ModuleList.cpp =================================================================== --- lldb/source/Core/ModuleList.cpp +++ lldb/source/Core/ModuleList.cpp @@ -1067,9 +1067,10 @@ void ModuleList::ForEach( std::function<bool(const ModuleSP &module_sp)> const &callback) const { std::lock_guard<std::recursive_mutex> guard(m_modules_mutex); - for (const auto &module : m_modules) { + for (const auto &module_sp : m_modules) { + assert(module_sp != nullptr); // If the callback returns false, then stop iterating and break out - if (!callback(module)) + if (!callback(module_sp)) break; } } Index: lldb/include/lldb/Core/ModuleList.h =================================================================== --- lldb/include/lldb/Core/ModuleList.h +++ lldb/include/lldb/Core/ModuleList.h @@ -464,6 +464,12 @@ static bool RemoveSharedModuleIfOrphaned(const Module *module_ptr); + /// Applies 'callback' to each module in this ModuleList. + /// If 'callback' returns false, iteration terminates. + /// The 'module_sp' passed to 'callback' is guaranteed to + /// be non-null. + /// + /// This function is thread-safe. void ForEach(std::function<bool(const lldb::ModuleSP &module_sp)> const &callback) const;
Index: lldb/source/Core/ModuleList.cpp =================================================================== --- lldb/source/Core/ModuleList.cpp +++ lldb/source/Core/ModuleList.cpp @@ -1067,9 +1067,10 @@ void ModuleList::ForEach( std::function<bool(const ModuleSP &module_sp)> const &callback) const { std::lock_guard<std::recursive_mutex> guard(m_modules_mutex); - for (const auto &module : m_modules) { + for (const auto &module_sp : m_modules) { + assert(module_sp != nullptr); // If the callback returns false, then stop iterating and break out - if (!callback(module)) + if (!callback(module_sp)) break; } } Index: lldb/include/lldb/Core/ModuleList.h =================================================================== --- lldb/include/lldb/Core/ModuleList.h +++ lldb/include/lldb/Core/ModuleList.h @@ -464,6 +464,12 @@ static bool RemoveSharedModuleIfOrphaned(const Module *module_ptr); + /// Applies 'callback' to each module in this ModuleList. + /// If 'callback' returns false, iteration terminates. + /// The 'module_sp' passed to 'callback' is guaranteed to + /// be non-null. + /// + /// This function is thread-safe. void ForEach(std::function<bool(const lldb::ModuleSP &module_sp)> const &callback) const;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits