[Lldb-commits] [PATCH] D113673: [lldb] Unwrap the type when dereferencing the value

Andy Yankovsky via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 11 06:40:09 PST 2021


werat created this revision.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113673

Files:
  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: lldb/test/API/lang/cpp/dereferencing_references/main.cpp
===================================================================
--- lldb/test/API/lang/cpp/dereferencing_references/main.cpp
+++ 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<TTT &&>(i);
+  // typedef of a reference
+  td_int_ref td = i;
+
   return l_ref; // break here
 }
Index: lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
===================================================================
--- lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
+++ lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
@@ -21,3 +21,7 @@
         # 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", type="td_int_ref")
+        self.assertEqual(td_val.Dereference().GetType().GetName(), "int")
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===================================================================
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -6492,7 +6492,8 @@
   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()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113673.386500.patch
Type: text/x-patch
Size: 2028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211111/b78d1c90/attachment.bin>


More information about the lldb-commits mailing list