Skip to content

Commit 9a6c001

Browse files
authored
[clang][ast]: Add DynamicAllocLValue and TypeInfoLValue support to APValue::dump(). (#135178)
Closes #134996. The crash about `TypeInfoLValue` is https://godbolt.org/z/73WY31s55. After the patch: ```cpp //test.cpp #include <typeinfo> constexpr const std::type_info* val = &typeid(int); ``` ``` lambda@ubuntu22:~/test$ clang++ -std=c++20 -Xclang -ast-dump -fsyntax-only test.cpp LValue Base=TypeInfoLValue typeid(int), Null=0, Offset=0, HasPath=1, PathLength=0, Path=() ``` ```cpp //DAtest.cpp constexpr int *m = new int(42); ``` ``` lambda@ubuntu22:~/test$ clang++ -std=c++20 -Xclang -ast-dump -fsyntax-only DAtest.cpp LValue Base=DynamicAllocLValue 'int', Null=0, Offset=0, HasPath=1, PathLength=0, Path=() ```
1 parent 38faf32 commit 9a6c001

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

clang/lib/AST/TextNodeDumper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,14 @@ void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
738738
else if (const auto *BE = B.dyn_cast<const Expr *>()) {
739739
OS << BE->getStmtClassName() << ' ';
740740
dumpPointer(BE);
741+
} else if (const auto BTI = B.dyn_cast<TypeInfoLValue>()) {
742+
OS << "TypeInfoLValue ";
743+
ColorScope Color(OS, ShowColors, TypeColor);
744+
BTI.print(OS, PrintPolicy);
745+
} else if (B.is<DynamicAllocLValue>()) {
746+
OS << "DynamicAllocLValue";
747+
auto BDA = B.getDynamicAllocType();
748+
dumpType(BDA);
741749
} else {
742750
const auto *VDB = B.get<const ValueDecl *>();
743751
OS << VDB->getDeclKindName() << "Decl";

clang/test/AST/ast-dump-APValue-lvalue.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ struct F {
2323
};
2424
F f;
2525

26+
namespace std {
27+
class type_info;
28+
}
29+
2630
void Test(int (&arr)[10]) {
2731
constexpr int *pi = &i;
2832
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pi 'int *const' constexpr cinit
@@ -45,6 +49,10 @@ void Test(int (&arr)[10]) {
4549
// CHECK-NEXT: | |-value: LValue Base=VarDecl {{.*}}, Null=0, Offset=2, HasPath=1, PathLength=2, Path=({{.*}}, 2)
4650

4751
constexpr const int *n = nullptr;
48-
// CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} n 'const int *const' constexpr cinit
49-
// CHECK-NEXT: |-value: LValue Base=null, Null=1, Offset=0, HasPath=1, PathLength=0, Path=()
52+
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} n 'const int *const' constexpr cinit
53+
// CHECK-NEXT: | |-value: LValue Base=null, Null=1, Offset=0, HasPath=1, PathLength=0, Path=()
54+
55+
constexpr const std::type_info* pti = &typeid(int);
56+
// CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pti 'const std::type_info *const' constexpr cinit
57+
// CHECK-NEXT: |-value: LValue Base=TypeInfoLValue typeid(int), Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
5058
}

0 commit comments

Comments
 (0)