[Lldb-commits] [lldb] 3abd063 - [lldb] Make TypeSystemClang::GetFullyUnqualifiedType work for constant arrays
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 29 02:14:14 PDT 2021
Author: Pavel Labath
Date: 2021-10-29T11:13:59+02:00
New Revision: 3abd063fc793d2d56fc78287c61b73b2d7843bc5
URL: https://github.com/llvm/llvm-project/commit/3abd063fc793d2d56fc78287c61b73b2d7843bc5
DIFF: https://github.com/llvm/llvm-project/commit/3abd063fc793d2d56fc78287c61b73b2d7843bc5.diff
LOG: [lldb] Make TypeSystemClang::GetFullyUnqualifiedType work for constant arrays
Unqualify (constant) arrays recursively, just like we do for pointers.
This allows for better pretty printer matching.
Differential Revision: https://reviews.llvm.org/D112708
Added:
Modified:
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/test/API/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py
lldb/test/API/functionalities/data-formatter/data-formatter-advanced/main.cpp
lldb/unittests/Symbol/TestTypeSystemClang.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 00daaad41a6e1..aa0a8086cb28c 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -4238,7 +4238,13 @@ static clang::QualType GetFullyUnqualifiedType_Impl(clang::ASTContext *ast,
if (qual_type->isPointerType())
qual_type = ast->getPointerType(
GetFullyUnqualifiedType_Impl(ast, qual_type->getPointeeType()));
- else
+ else if (const ConstantArrayType *arr =
+ ast->getAsConstantArrayType(qual_type)) {
+ qual_type = ast->getConstantArrayType(
+ GetFullyUnqualifiedType_Impl(ast, arr->getElementType()),
+ arr->getSize(), arr->getSizeExpr(), arr->getSizeModifier(),
+ arr->getIndexTypeQualifiers().getAsOpaqueValue());
+ } else
qual_type = qual_type.getUnqualifiedType();
qual_type.removeLocalConst();
qual_type.removeLocalRestrict();
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py b/lldb/test/API/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py
index 3906e48368054..f089038280e52 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py
@@ -65,10 +65,12 @@ def cleanup():
self.runCmd("type summary clear")
self.runCmd(
- "type summary add --summary-string \"${var[]}\" -x \"int\\[[0-9]\\]")
+ "type summary add --summary-string \"${var[]}\" -x \"^int\\[[0-9]\\]")
self.expect("frame variable int_array",
substrs=['1,2,3,4,5'])
+ self.expect("frame variable const_int_array",
+ substrs=['11,12,13,14,15'])
# this will fail if we don't do [] as regex correctly
self.runCmd(
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-advanced/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-advanced/main.cpp
index 857e2493e1a2d..e7a52fe73bd4c 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-advanced/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-advanced/main.cpp
@@ -144,7 +144,8 @@ int main (int argc, const char * argv[])
cool_array[2].character = 'Q';
int int_array[] = {1,2,3,4,5};
-
+ const int const_int_array[] = {11, 12, 13, 14, 15};
+
IWrapPointers wrapper;
*int_array = -1;
diff --git a/lldb/unittests/Symbol/TestTypeSystemClang.cpp b/lldb/unittests/Symbol/TestTypeSystemClang.cpp
index 21ae5b01b0cc9..5b1154d2cd8b9 100644
--- a/lldb/unittests/Symbol/TestTypeSystemClang.cpp
+++ b/lldb/unittests/Symbol/TestTypeSystemClang.cpp
@@ -912,6 +912,32 @@ TEST_F(TestTypeSystemClang, AddMethodToObjCObjectType) {
EXPECT_EQ(method->getDeclName().getObjCSelector().getAsString(), "foo");
}
+TEST_F(TestTypeSystemClang, GetFullyUnqualifiedType) {
+ CompilerType bool_ = m_ast->GetBasicType(eBasicTypeBool);
+ CompilerType cv_bool = bool_.AddConstModifier().AddVolatileModifier();
+
+ // const volatile bool -> bool
+ EXPECT_EQ(bool_, cv_bool.GetFullyUnqualifiedType());
+
+ // const volatile bool[47] -> bool[47]
+ EXPECT_EQ(bool_.GetArrayType(47),
+ cv_bool.GetArrayType(47).GetFullyUnqualifiedType());
+
+ // const volatile bool[47][42] -> bool[47][42]
+ EXPECT_EQ(
+ bool_.GetArrayType(42).GetArrayType(47),
+ cv_bool.GetArrayType(42).GetArrayType(47).GetFullyUnqualifiedType());
+
+ // const volatile bool * -> bool *
+ EXPECT_EQ(bool_.GetPointerType(),
+ cv_bool.GetPointerType().GetFullyUnqualifiedType());
+
+ // const volatile bool *[47] -> bool *[47]
+ EXPECT_EQ(
+ bool_.GetPointerType().GetArrayType(47),
+ cv_bool.GetPointerType().GetArrayType(47).GetFullyUnqualifiedType());
+}
+
TEST(TestScratchTypeSystemClang, InferSubASTFromLangOpts) {
LangOptions lang_opts;
EXPECT_EQ(
More information about the lldb-commits
mailing list