-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Implement dump() for MemberPointer APValues #136130
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
Conversation
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesPrint the member pointer decl and the path. Full diff: https://github.com/llvm/llvm-project/pull/136130.diff 3 Files Affected:
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index c8b459ee78e6b..89567425f0d5f 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -829,9 +829,21 @@ void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
return;
}
- case APValue::MemberPointer:
- OS << "MemberPointer <todo>";
+ case APValue::MemberPointer: {
+ OS << "MemberPointer ";
+ auto Path = Value.getMemberPointerPath();
+ for (const CXXRecordDecl *D : Path) {
+ {
+ ColorScope Color(OS, ShowColors, DeclNameColor);
+ OS << D->getDeclName();
+ }
+ OS << "::";
+ }
+
+ ColorScope Color(OS, ShowColors, DeclNameColor);
+ OS << Value.getMemberPointerDecl()->getDeclName();
return;
+ }
case APValue::AddrLabelDiff:
OS << "AddrLabelDiff <todo>";
return;
diff --git a/clang/test/AST/ast-dump-APValue-lvalue.cpp b/clang/test/AST/ast-dump-APValue-lvalue.cpp
index 333f7aa419377..51d22a5ba8b6d 100644
--- a/clang/test/AST/ast-dump-APValue-lvalue.cpp
+++ b/clang/test/AST/ast-dump-APValue-lvalue.cpp
@@ -27,6 +27,16 @@ namespace std {
class type_info;
}
+struct P {
+ int x;
+};
+struct Q {
+ float m;
+};
+struct MP : P, Q {
+ int i;
+};
+
void Test(int (&arr)[10]) {
constexpr int *pi = &i;
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pi 'int *const' constexpr cinit
@@ -53,6 +63,10 @@ void Test(int (&arr)[10]) {
// CHECK-NEXT: | |-value: LValue Base=null, Null=1, Offset=0, HasPath=1, PathLength=0, Path=()
constexpr const std::type_info* pti = &typeid(int);
- // CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pti 'const std::type_info *const' constexpr cinit
- // CHECK-NEXT: |-value: LValue Base=TypeInfoLValue typeid(int), Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
+ // CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pti 'const std::type_info *const' constexpr cinit
+ // CHECK-NEXT: | |-value: LValue Base=TypeInfoLValue typeid(int), Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
+
+ constexpr int(MP::*pmi) = (int MP::*)&P::x;
+ // CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pmi 'int (MP::*const)' constexpr cinit
+ // CHECK-NEXT: |-value: MemberPointer MP::x
}
diff --git a/clang/test/AST/ast-dump-APValue-todo.cpp b/clang/test/AST/ast-dump-APValue-todo.cpp
deleted file mode 100644
index acaa82ba53b6f..0000000000000
--- a/clang/test/AST/ast-dump-APValue-todo.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-// Test without serialization:
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 \
-// RUN: -ast-dump %s -ast-dump-filter Test \
-// RUN: | FileCheck --strict-whitespace --match-full-lines %s
-//
-// Test with serialization:
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 -emit-pch -o %t %s
-// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 \
-// RUN: -include-pch %t -ast-dump-all -ast-dump-filter Test /dev/null \
-// RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
-// RUN: | FileCheck --strict-whitespace --match-full-lines %s
-
-int i;
-struct S {
- int i;
-};
-
-void Test() {
- constexpr int(S::*pmi) = &S::i;
- // CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pmi 'int (S::*const)' constexpr cinit
- // CHECK-NEXT: |-value: MemberPointer <todo>
-}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do the JSONNodeDumper as well so the two stay somewhat in-sync?
Looks like that goes through |
Ah, good to know, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM assuming precommit CI is happy too.
Print the member pointer decl and the path.
Print the member pointer decl and the path.
Print the member pointer decl and the path.