[Lldb-commits] [lldb] cb0ffa5 - [lldb] Fix simple template names and template params with scope qualifiers
Arthur Eubanks via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 15 17:07:25 PST 2022
Author: Arthur Eubanks
Date: 2022-11-15T16:52:34-08:00
New Revision: cb0ffa529a0f7f907fd89587fc2ab4f6ffd57cf5
URL: https://github.com/llvm/llvm-project/commit/cb0ffa529a0f7f907fd89587fc2ab4f6ffd57cf5
DIFF: https://github.com/llvm/llvm-project/commit/cb0ffa529a0f7f907fd89587fc2ab4f6ffd57cf5.diff
LOG: [lldb] Fix simple template names and template params with scope qualifiers
Followup to D134378.
With PrintingPolicy::SuppressScope, we'd also not print the scope in template params. The intention was only to skip the scope for the class because we expect template params to be fully qualified when comparing them for simple template names.
Instead, use `NamedDecl::getNameForDiagnostic` if we're dealing with a tag, which is what we actually use when emitting debug info in clang. That already has an option to suppress the scope on the base name.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D137583
Added:
Modified:
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes2.py
lldb/test/API/lang/cpp/unique-types2/main.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index cd142b73ab824..a868abb46a73a 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2131,11 +2131,12 @@ PrintingPolicy TypeSystemClang::GetTypePrintingPolicy() {
return printing_policy;
}
-std::string TypeSystemClang::GetTypeNameForDecl(const NamedDecl *named_decl) {
+std::string TypeSystemClang::GetTypeNameForDecl(const NamedDecl *named_decl,
+ bool qualified) {
clang::PrintingPolicy printing_policy = GetTypePrintingPolicy();
std::string result;
llvm::raw_string_ostream os(result);
- named_decl->printQualifiedName(os, printing_policy);
+ named_decl->getNameForDiagnostic(os, printing_policy, qualified);
return result;
}
@@ -3768,7 +3769,7 @@ bool TypeSystemClang::GetCompleteType(lldb::opaque_compiler_type_t type) {
}
ConstString TypeSystemClang::GetTypeName(lldb::opaque_compiler_type_t type,
- bool BaseOnly) {
+ bool base_only) {
if (!type)
return ConstString();
@@ -3790,9 +3791,13 @@ ConstString TypeSystemClang::GetTypeName(lldb::opaque_compiler_type_t type,
return ConstString(GetTypeNameForDecl(typedef_decl));
}
- clang::PrintingPolicy printing_policy(GetTypePrintingPolicy());
- printing_policy.SuppressScope = BaseOnly;
- return ConstString(qual_type.getAsString(printing_policy));
+ // For consistency, this follows the same code path that clang uses to emit
+ // debug info. This also handles when we don't want any scopes preceding the
+ // name.
+ if (auto *named_decl = qual_type->getAsTagDecl())
+ return ConstString(GetTypeNameForDecl(named_decl, !base_only));
+
+ return ConstString(qual_type.getAsString(GetTypePrintingPolicy()));
}
ConstString
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index a56c5f27850c7..1c0e120aadbfe 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -644,7 +644,7 @@ class TypeSystemClang : public TypeSystem {
// Accessors
ConstString GetTypeName(lldb::opaque_compiler_type_t type,
- bool BaseOnly) override;
+ bool base_only) override;
ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type) override;
@@ -1051,7 +1051,8 @@ class TypeSystemClang : public TypeSystem {
clang::PrintingPolicy GetTypePrintingPolicy();
/// Returns the internal type name for the given NamedDecl using the
/// type printing policy.
- std::string GetTypeNameForDecl(const clang::NamedDecl *named_decl);
+ std::string GetTypeNameForDecl(const clang::NamedDecl *named_decl,
+ bool qualified = true);
const clang::ClassTemplateSpecializationDecl *
GetAsTemplateSpecialization(lldb::opaque_compiler_type_t type);
diff --git a/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes2.py b/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes2.py
index 0fe078b2d1e3a..b0105a3994f89 100644
--- a/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes2.py
+++ b/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes2.py
@@ -36,6 +36,7 @@ def do_test(self, debug_flags):
self.expect("image lookup -A -t 'Foo<int>::Nested<int>'", DATA_TYPES_DISPLAYED_CORRECTLY, error=True)
self.expect("image lookup -A -t 'Nested<char>'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
self.expect("image lookup -A -t '::Nested<char>'", DATA_TYPES_DISPLAYED_CORRECTLY, error=True)
+ self.expect("image lookup -A -t 'Foo<int>::Nested<ns::Bar>'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
self.expect_expr("t1", result_type="Foo<char>")
self.expect_expr("t1", result_type="Foo<char>")
@@ -49,6 +50,7 @@ def do_test(self, debug_flags):
self.expect_expr("p6", result_type="FooPack<int, int>")
self.expect_expr("p7", result_type="FooPack<int, int, int>")
self.expect_expr("n1", result_type="Foo<int>::Nested<char>")
+ self.expect_expr("n2", result_type="Foo<int>::Nested<ns::Bar>")
@skipIf(compiler=no_match("clang"))
@skipIf(compiler_version=["<", "15.0"])
diff --git a/lldb/test/API/lang/cpp/unique-types2/main.cpp b/lldb/test/API/lang/cpp/unique-types2/main.cpp
index e980af1718015..0b858f52d91ce 100644
--- a/lldb/test/API/lang/cpp/unique-types2/main.cpp
+++ b/lldb/test/API/lang/cpp/unique-types2/main.cpp
@@ -1,3 +1,7 @@
+namespace ns {
+struct Bar {};
+} // namespace ns
+
template <class T> struct Foo {
T t;
template <class U> class Nested {
@@ -23,5 +27,6 @@ int main() {
FooPack<int, int, int> p7;
Foo<int>::Nested<char> n1;
+ Foo<int>::Nested<ns::Bar> n2;
// Set breakpoint here
}
More information about the lldb-commits
mailing list