Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pointer to reference type #113596

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lldb/source/Core/ValueObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2911,6 +2911,15 @@ ValueObjectSP ValueObject::AddressOf(Status &error) {

AddressType address_type = eAddressTypeInvalid;
const bool scalar_is_load_address = false;

// For reference type we need to get the address of the object that
// it refers to.
if (GetCompilerType().IsReferenceType()) {
ValueObjectSP deref_obj = Dereference(error);
if (error.Fail() || !deref_obj)
return ValueObjectSP();
return deref_obj->AddressOf(error);
}
addr_t addr = GetAddressOf(scalar_is_load_address, &address_type);
error.Clear();
if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,24 @@ def test(self):
# Typedef to a reference should dereference to the underlying type.
td_val = self.expect_var_path("td_to_ref_type", type="td_int_ref")
self.assertEqual(td_val.Dereference().GetType().GetName(), "int")

def test_take_address_of_reference(self):
"""Tests taking address of lvalue/rvalue references in lldb works correctly."""
self.build()
lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.cpp")
)

plref_val_from_code = self.expect_var_path("pl_ref", type="TTT *")
plref_val_from_expr_path = self.expect_var_path("&l_ref", type="TTT *")
self.assertEqual(
plref_val_from_code.GetValueAsAddress(),
plref_val_from_expr_path.GetValueAsAddress(),
)

prref_val_from_code = self.expect_var_path("pr_ref", type="TTT *")
prref_val_from_expr_path = self.expect_var_path("&r_ref", type="TTT *")
self.assertEqual(
prref_val_from_code.GetValueAsAddress(),
prref_val_from_expr_path.GetValueAsAddress(),
)
2 changes: 2 additions & 0 deletions lldb/test/API/lang/cpp/dereferencing_references/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ int main() {
// typedef of a reference
td_int_ref td_to_ref_type = i;

TTT *pl_ref = &l_ref;
TTT *pr_ref = &r_ref;
return l_ref; // break here
}
Loading