Skip to content

Commit 95102b7

Browse files
committed
[lldb] Unwrap the type when dereferencing the value
The value type can be a typedef of a reference (e.g. `typedef int& myint`). In this case `GetQualType(type)` will return `clang::Typedef`, which cannot be casted to `clang::ReferenceType`. Fix a regression introduced in https://reviews.llvm.org/D103532. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D113673
1 parent 2a299e4 commit 95102b7

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6492,7 +6492,8 @@ CompilerType TypeSystemClang::GetChildCompilerTypeAtIndex(
64926492
case clang::Type::RValueReference:
64936493
if (idx_is_valid) {
64946494
const clang::ReferenceType *reference_type =
6495-
llvm::cast<clang::ReferenceType>(GetQualType(type).getTypePtr());
6495+
llvm::cast<clang::ReferenceType>(
6496+
RemoveWrappingTypes(GetQualType(type)).getTypePtr());
64966497
CompilerType pointee_clang_type =
64976498
GetType(reference_type->getPointeeType());
64986499
if (transparent_pointers && pointee_clang_type.IsAggregateType()) {

lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ def test(self):
2121
# Same as above for rvalue references.
2222
rref_val = self.expect_var_path("r_ref", type="TTT &&")
2323
self.assertEqual(rref_val.Dereference().GetType().GetName(), "TTT")
24+
25+
# Typedef to a reference should dereference to the underlying type.
26+
td_val = self.expect_var_path("td_to_ref_type", type="td_int_ref")
27+
self.assertEqual(td_val.Dereference().GetType().GetName(), "int")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
typedef int TTT;
2+
typedef int &td_int_ref;
23

34
int main() {
45
int i = 0;
6+
// references to typedefs
57
TTT &l_ref = i;
68
TTT &&r_ref = static_cast<TTT &&>(i);
9+
// typedef of a reference
10+
td_int_ref td_to_ref_type = i;
11+
712
return l_ref; // break here
813
}

0 commit comments

Comments
 (0)