From e494ec070367ab5759031e718657dc0f9bdf065e Mon Sep 17 00:00:00 2001 From: Andy Yankovsky Date: Thu, 11 Nov 2021 15:39:49 +0100 Subject: [PATCH] [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 (cherry picked from commit 95102b7dc3c1b5b3f1b688221d9aa28cb1e17974) --- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 3 ++- .../TestCPPDereferencingReferences.py | 4 ++++ lldb/test/API/lang/cpp/dereferencing_references/main.cpp | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 01efb7d7fbfdae..c2696f7a4aa349 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -6519,7 +6519,8 @@ CompilerType TypeSystemClang::GetChildCompilerTypeAtIndex( case clang::Type::RValueReference: if (idx_is_valid) { const clang::ReferenceType *reference_type = - llvm::cast(GetQualType(type).getTypePtr()); + llvm::cast( + RemoveWrappingTypes(GetQualType(type)).getTypePtr()); CompilerType pointee_clang_type = GetType(reference_type->getPointeeType()); if (transparent_pointers && pointee_clang_type.IsAggregateType()) { diff --git a/lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py b/lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py index 994e26f0e91e8b..741fc6ed85e018 100644 --- a/lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py +++ b/lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py @@ -21,3 +21,7 @@ def test(self): # Same as above for rvalue references. rref_val = self.expect_var_path("r_ref", type="TTT &&") self.assertEqual(rref_val.Dereference().GetType().GetName(), "TTT") + + # 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") diff --git a/lldb/test/API/lang/cpp/dereferencing_references/main.cpp b/lldb/test/API/lang/cpp/dereferencing_references/main.cpp index 8228dc41132054..b64978a9029f81 100644 --- a/lldb/test/API/lang/cpp/dereferencing_references/main.cpp +++ b/lldb/test/API/lang/cpp/dereferencing_references/main.cpp @@ -1,8 +1,13 @@ typedef int TTT; +typedef int &td_int_ref; int main() { int i = 0; + // references to typedefs TTT &l_ref = i; TTT &&r_ref = static_cast(i); + // typedef of a reference + td_int_ref td_to_ref_type = i; + return l_ref; // break here }