https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/136130
Print the member pointer decl and the path. >From ae8fac6c80a757a5ee3a0fa6e59d7546f71ce116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Thu, 17 Apr 2025 13:44:50 +0200 Subject: [PATCH] [clang] Implement dump() for MemberPointer APValues --- clang/lib/AST/TextNodeDumper.cpp | 16 ++++++++++++++-- clang/test/AST/ast-dump-APValue-lvalue.cpp | 18 ++++++++++++++++-- clang/test/AST/ast-dump-APValue-todo.cpp | 22 ---------------------- 3 files changed, 30 insertions(+), 26 deletions(-) delete mode 100644 clang/test/AST/ast-dump-APValue-todo.cpp 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> -} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits