Skip to content

[lldb] Fix FindDirectNestedType not working with class templates #81666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
}
Expand Down
17 changes: 17 additions & 0 deletions lldb/test/API/python_api/type/TestTypeList.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ def test(self):
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)
Expand Down
12 changes: 12 additions & 0 deletions lldb/test/API/python_api/type/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ class Task {
{}
};

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 {};
Expand Down Expand Up @@ -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
}