Author: YLChenZ Date: 2025-04-15T14:16:09+02:00 New Revision: 9a6c001b125d7d37b8f2c8b96461768c797c4e3f
URL: https://github.com/llvm/llvm-project/commit/9a6c001b125d7d37b8f2c8b96461768c797c4e3f DIFF: https://github.com/llvm/llvm-project/commit/9a6c001b125d7d37b8f2c8b96461768c797c4e3f.diff LOG: [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=() ``` Added: Modified: clang/lib/AST/TextNodeDumper.cpp clang/test/AST/ast-dump-APValue-lvalue.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp index b90f32389c897..c8b459ee78e6b 100644 --- a/clang/lib/AST/TextNodeDumper.cpp +++ b/clang/lib/AST/TextNodeDumper.cpp @@ -738,6 +738,14 @@ 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 (const auto BTI = B.dyn_cast<TypeInfoLValue>()) { + OS << "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 224caddb3eabe..333f7aa419377 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 typeid(int), Null=0, Offset=0, HasPath=1, PathLength=0, Path=() } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits