Author: Pavel Labath Date: 2024-05-09T08:37:48+02:00 New Revision: 042a0b000dfe602ee0432be5ff88c67f531791bc
URL: https://github.com/llvm/llvm-project/commit/042a0b000dfe602ee0432be5ff88c67f531791bc DIFF: https://github.com/llvm/llvm-project/commit/042a0b000dfe602ee0432be5ff88c67f531791bc.diff LOG: [lldb] Make SBType::GetDirectNestedType (mostly) work with typedefs (#91189) The implementation is straight-forward, but comes with a big disclaimer. See #91186 for details. Added: Modified: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp lldb/test/API/python_api/type/TestTypeList.py lldb/test/API/python_api/type/main.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index a771016039e85..d0033fcd9cdfc 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -7106,6 +7106,8 @@ TypeSystemClang::GetDirectNestedTypeWithName(lldb::opaque_compiler_type_t type, for (NamedDecl *decl : record_decl->lookup(decl_name)) { if (auto *tag_decl = dyn_cast<clang::TagDecl>(decl)) return GetType(getASTContext().getTagDeclType(tag_decl)); + if (auto *typedef_decl = dyn_cast<clang::TypedefNameDecl>(decl)) + return GetType(getASTContext().getTypedefType(typedef_decl)); } break; } diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py index 0498396903dcb..b028929eea442 100644 --- a/lldb/test/API/python_api/type/TestTypeList.py +++ b/lldb/test/API/python_api/type/TestTypeList.py @@ -273,6 +273,22 @@ def test(self): self.DebugSBType(int_enum_uchar) self.assertEqual(int_enum_uchar.GetName(), "unsigned char") + def test_nested_typedef(self): + """Exercise FindDirectNestedType for typedefs.""" + self.build() + target = self.dbg.CreateTarget(self.getBuildArtifact()) + self.assertTrue(target) + + with_nested_typedef = target.FindFirstType("WithNestedTypedef") + self.assertTrue(with_nested_typedef) + + # This is necessary to work around #91186 + self.assertTrue(target.FindFirstGlobalVariable("typedefed_value").GetType()) + + the_typedef = with_nested_typedef.FindDirectNestedType("TheTypedef") + self.assertTrue(the_typedef) + self.assertEqual(the_typedef.GetTypedefedType().GetName(), "int") + def test_GetByteAlign(self): """Exercise SBType::GetByteAlign""" self.build() diff --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp index 986ed3009a15f..6acde5bb666a6 100644 --- a/lldb/test/API/python_api/type/main.cpp +++ b/lldb/test/API/python_api/type/main.cpp @@ -53,6 +53,11 @@ enum class EnumUChar : unsigned char {}; struct alignas(128) OverAlignedStruct {}; OverAlignedStruct over_aligned_struct; +struct WithNestedTypedef { + typedef int TheTypedef; +}; +WithNestedTypedef::TheTypedef typedefed_value; + int main (int argc, char const *argv[]) { Task *task_head = new Task(-1, NULL); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits