[clang] [clang][ast]: Add DynamicAllocLValue and TypeInfoLValue support to APValue::dump(). (PR #135178)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 13 19:51:11 PDT 2025
https://github.com/YLChenZ updated https://github.com/llvm/llvm-project/pull/135178
>From 1119ecf764ecd94c12966758964cb486709a441d Mon Sep 17 00:00:00 2001
From: YLChenZ <chentongyongcz at gmail.com>
Date: Thu, 10 Apr 2025 21:20:58 +0800
Subject: [PATCH 1/2] [clang][ast]: Add DynamicAllocLValue and TypeInfoLValue
support to APValue::dump()
---
clang/lib/AST/TextNodeDumper.cpp | 4 ++++
clang/test/AST/ast-dump-APValue-lvalue.cpp | 12 ++++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index be8d609974d81..0849e5642f006 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -738,6 +738,10 @@ void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
else if (const auto *BE = B.dyn_cast<const Expr *>()) {
OS << BE->getStmtClassName() << ' ';
dumpPointer(BE);
+ } else if (B.is<TypeInfoLValue>()) {
+ OS << "TypeInfoLValue";
+ } else if (B.is<DynamicAllocLValue>()) {
+ OS << "DynamicAllocLValue";
} else {
const auto *VDB = B.get<const ValueDecl *>();
OS << VDB->getDeclKindName() << "Decl";
diff --git a/clang/test/AST/ast-dump-APValue-lvalue.cpp b/clang/test/AST/ast-dump-APValue-lvalue.cpp
index 224caddb3eabe..7e520254da41a 100644
--- a/clang/test/AST/ast-dump-APValue-lvalue.cpp
+++ b/clang/test/AST/ast-dump-APValue-lvalue.cpp
@@ -23,6 +23,10 @@ struct F {
};
F f;
+namespace std {
+ class type_info;
+}
+
void Test(int (&arr)[10]) {
constexpr int *pi = &i;
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pi 'int *const' constexpr cinit
@@ -45,6 +49,10 @@ void Test(int (&arr)[10]) {
// CHECK-NEXT: | |-value: LValue Base=VarDecl {{.*}}, Null=0, Offset=2, HasPath=1, PathLength=2, Path=({{.*}}, 2)
constexpr const int *n = nullptr;
- // CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} n 'const int *const' constexpr cinit
- // CHECK-NEXT: |-value: LValue Base=null, Null=1, Offset=0, HasPath=1, PathLength=0, Path=()
+ // CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} n 'const int *const' constexpr cinit
+ // 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, Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
}
>From 23d850d5833dd28293cb9bf4aff5e5b9dac7cc1d Mon Sep 17 00:00:00 2001
From: YLChenZ <chentongyongcz at gmail.com>
Date: Mon, 14 Apr 2025 10:47:50 +0800
Subject: [PATCH 2/2] print more information
---
clang/lib/AST/TextNodeDumper.cpp | 7 ++++++-
clang/test/AST/ast-dump-APValue-lvalue.cpp | 2 +-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 0849e5642f006..4c1091c29cb6b 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -739,9 +739,14 @@ void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
OS << BE->getStmtClassName() << ' ';
dumpPointer(BE);
} else if (B.is<TypeInfoLValue>()) {
- OS << "TypeInfoLValue";
+ OS << "TypeInfoLValue ";
+ const auto BTI = B.get<TypeInfoLValue>();
+ ColorScope Color(OS, ShowColors, TypeColor);
+ BTI.print(OS,PrintPolicy);
} else if (B.is<DynamicAllocLValue>()) {
OS << "DynamicAllocLValue";
+ auto BDA = B.getDynamicAllocType();
+ dumpType(BDA);
} else {
const auto *VDB = B.get<const ValueDecl *>();
OS << VDB->getDeclKindName() << "Decl";
diff --git a/clang/test/AST/ast-dump-APValue-lvalue.cpp b/clang/test/AST/ast-dump-APValue-lvalue.cpp
index 7e520254da41a..333f7aa419377 100644
--- a/clang/test/AST/ast-dump-APValue-lvalue.cpp
+++ b/clang/test/AST/ast-dump-APValue-lvalue.cpp
@@ -54,5 +54,5 @@ void Test(int (&arr)[10]) {
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, Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
+ // CHECK-NEXT: |-value: LValue Base=TypeInfoLValue typeid(int), Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
}
More information about the cfe-commits
mailing list