[lldb][Expression][NFC] Make LoadAddressResolver::m_target a reference#149490
Merged
Conversation
The only place that passes a target to `LoadAddressResolver` already checks for pointer validity. And inside of the resolver we have been dereferencing the target anyway without nullptr checks. So codify the non-nullness of `m_target` by making it a reference.
Member
|
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesThe only place that passes a target to Full diff: https://github.com/llvm/llvm-project/pull/149490.diff 1 Files Affected:
diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp
index e445fa8833022..6f812b91a8b1d 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -700,7 +700,7 @@ void IRExecutionUnit::CollectCandidateCPlusPlusNames(
class LoadAddressResolver {
public:
- LoadAddressResolver(Target *target, bool &symbol_was_missing_weak)
+ LoadAddressResolver(Target &target, bool &symbol_was_missing_weak)
: m_target(target), m_symbol_was_missing_weak(symbol_was_missing_weak) {}
std::optional<lldb::addr_t> Resolve(SymbolContextList &sc_list) {
@@ -722,11 +722,11 @@ class LoadAddressResolver {
// First try the symbol.
if (candidate_sc.symbol) {
- load_address = candidate_sc.symbol->ResolveCallableAddress(*m_target);
+ load_address = candidate_sc.symbol->ResolveCallableAddress(m_target);
if (load_address == LLDB_INVALID_ADDRESS) {
Address addr = candidate_sc.symbol->GetAddress();
- load_address = m_target->GetProcessSP()
- ? addr.GetLoadAddress(m_target)
+ load_address = m_target.GetProcessSP()
+ ? addr.GetLoadAddress(&m_target)
: addr.GetFileAddress();
}
}
@@ -734,8 +734,8 @@ class LoadAddressResolver {
// If that didn't work, try the function.
if (load_address == LLDB_INVALID_ADDRESS && candidate_sc.function) {
Address addr = candidate_sc.function->GetAddress();
- load_address = m_target->GetProcessSP() ? addr.GetLoadAddress(m_target)
- : addr.GetFileAddress();
+ load_address = m_target.GetProcessSP() ? addr.GetLoadAddress(&m_target)
+ : addr.GetFileAddress();
}
// We found a load address.
@@ -766,7 +766,7 @@ class LoadAddressResolver {
}
private:
- Target *m_target;
+ Target &m_target;
bool &m_symbol_was_missing_weak;
lldb::addr_t m_best_internal_load_address = LLDB_INVALID_ADDRESS;
};
@@ -790,7 +790,7 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
for (size_t i = 0; i < m_preferred_modules.GetSize(); ++i)
non_local_images.Remove(m_preferred_modules.GetModuleAtIndex(i));
- LoadAddressResolver resolver(target, symbol_was_missing_weak);
+ LoadAddressResolver resolver(*target, symbol_was_missing_weak);
ModuleFunctionSearchOptions function_options;
function_options.include_symbols = true;
|
This was referenced Jul 23, 2025
Michael137
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Sep 2, 2025
llvm#149490) The only place that passes a target to `LoadAddressResolver` already checks for pointer validity. And inside of the resolver we have been dereferencing the target anyway without nullptr checks. So codify the non-nullness of `m_target` by making it a reference. (cherry picked from commit 03b7766)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The only place that passes a target to
LoadAddressResolveralready checks for pointer validity. And inside of the resolver we have been dereferencing the target anyway without nullptr checks. So codify the non-nullness ofm_targetby making it a reference.