[lldb] Unwrap the type when dereferencing the value
authorAndy Yankovsky <weratt@gmail.com>
Thu, 11 Nov 2021 14:39:49 +0000 (15:39 +0100)
committerAndy Yankovsky <weratt@gmail.com>
Mon, 15 Nov 2021 13:48:19 +0000 (14:48 +0100)
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

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
lldb/test/API/lang/cpp/dereferencing_references/main.cpp

index 077104b..b20ae32 100644 (file)
@@ -6492,7 +6492,8 @@ CompilerType TypeSystemClang::GetChildCompilerTypeAtIndex(
   case clang::Type::RValueReference:
     if (idx_is_valid) {
       const clang::ReferenceType *reference_type =
-          llvm::cast<clang::ReferenceType>(GetQualType(type).getTypePtr());
+          llvm::cast<clang::ReferenceType>(
+              RemoveWrappingTypes(GetQualType(type)).getTypePtr());
       CompilerType pointee_clang_type =
           GetType(reference_type->getPointeeType());
       if (transparent_pointers && pointee_clang_type.IsAggregateType()) {
index 994e26f..741fc6e 100644 (file)
@@ -21,3 +21,7 @@ class TestCase(TestBase):
         # 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")
index 8228dc4..b64978a 100644 (file)
@@ -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<TTT &&>(i);
+  // typedef of a reference
+  td_int_ref td_to_ref_type = i;
+
   return l_ref; // break here
 }