diff options
author | Vlad Serebrennikov <serebrennikov.vladislav@gmail.com> | 2024-02-16 20:40:27 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-16 20:40:27 +0400 |
commit | 7b7d411de9f731d2bcf6b093f6cee2cf57a5196e (patch) | |
tree | a07aa206f2ea80a443885e6fbfc1007a9368b82e /lldb | |
parent | dfae16277329011aa5f1e41ecd06b9db75a0c374 (diff) | |
download | llvm-7b7d411de9f731d2bcf6b093f6cee2cf57a5196e.zip llvm-7b7d411de9f731d2bcf6b093f6cee2cf57a5196e.tar.gz llvm-7b7d411de9f731d2bcf6b093f6cee2cf57a5196e.tar.bz2 |
[lldb] Fix `FindDirectNestedType` not working with class templates (#81666)
This patch attempts to fix lookup in class template specialization.
The first fixed problem is that during type lookup `DeclContextGetName`
have been dropping template arguments. So when such a name was compared
against a name in `DW_AT_name`, which contains template arguments, false
mismatches have been occurring.
The second fixed problem is that LLDB's printing policy hasn't been
matching Clang's printing policy when it comes to integral non-type
template arguments. This again caused some false mismatches during type
lookup, because Clang puts e.g. `3U` in debug info for class
specializations, but LLDB has been expecting just `3`. This patch brings
printing policy in line with what Clang does.
Diffstat (limited to 'lldb')
-rw-r--r-- | lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 10 | ||||
-rw-r--r-- | lldb/test/API/python_api/type/TestTypeList.py | 17 | ||||
-rw-r--r-- | lldb/test/API/python_api/type/main.cpp | 12 |
3 files changed, 37 insertions, 2 deletions
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index a41e2c6..0652ac0 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -2165,6 +2165,7 @@ PrintingPolicy TypeSystemClang::GetTypePrintingPolicy() { // (and we then would have suppressed them from the type name) and also setups // where LLDB wasn't able to reconstruct the default arguments. printing_policy.SuppressDefaultTemplateArgs = false; + printing_policy.AlwaysIncludeTypeForTemplateArgument = true; return printing_policy; } @@ -9265,8 +9266,13 @@ ConstString TypeSystemClang::DeclContextGetName(void *opaque_decl_ctx) { if (opaque_decl_ctx) { clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx); - if (named_decl) - return ConstString(named_decl->getName()); + if (named_decl) { + std::string name; + llvm::raw_string_ostream stream{name}; + named_decl->getNameForDiagnostic(stream, GetTypePrintingPolicy(), + /*qualified=*/false); + return ConstString(name); + } } return ConstString(); } diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py index c267def..63ab958 100644 --- a/lldb/test/API/python_api/type/TestTypeList.py +++ b/lldb/test/API/python_api/type/TestTypeList.py @@ -150,6 +150,23 @@ class TypeAndTypeListTestCase(TestBase): invalid_type = task_type.FindDirectNestedType(None) self.assertFalse(invalid_type) + # Check that FindDirectNestedType works with types from AST + pointer = frame0.FindVariable("pointer") + pointer_type = pointer.GetType() + self.assertTrue(pointer_type) + self.DebugSBType(pointer_type) + pointer_info_type = pointer_type.template_args[1] + self.assertTrue(pointer_info_type) + self.DebugSBType(pointer_info_type) + + pointer_masks1_type = pointer_info_type.FindDirectNestedType("Masks1") + self.assertTrue(pointer_masks1_type) + self.DebugSBType(pointer_masks1_type) + + pointer_masks2_type = pointer_info_type.FindDirectNestedType("Masks2") + self.assertTrue(pointer_masks2_type) + self.DebugSBType(pointer_masks2_type) + # We'll now get the child member 'id' from 'task_head'. id = task_head.GetChildMemberWithName("id") self.DebugSBValue(id) diff --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp index 98de970..391f58e 100644 --- a/lldb/test/API/python_api/type/main.cpp +++ b/lldb/test/API/python_api/type/main.cpp @@ -34,6 +34,14 @@ public: {} }; +template <unsigned Value> struct PointerInfo { + enum Masks1 { pointer_mask }; + enum class Masks2 { pointer_mask }; +}; + +template <unsigned Value, typename InfoType = PointerInfo<Value>> +struct Pointer {}; + enum EnumType {}; enum class ScopedEnumType {}; enum class EnumUChar : unsigned char {}; @@ -71,5 +79,9 @@ int main (int argc, char const *argv[]) ScopedEnumType scoped_enum_type; EnumUChar scoped_enum_type_uchar; + Pointer<3> pointer; + PointerInfo<3>::Masks1 mask1 = PointerInfo<3>::Masks1::pointer_mask; + PointerInfo<3>::Masks2 mask2 = PointerInfo<3>::Masks2::pointer_mask; + return 0; // Break at this line } |