https://github.com/YLChenZ created https://github.com/llvm/llvm-project/pull/135178
Closes #134996. The crash about `TypeInfoLValue` is https://godbolt.org/z/73WY31s55. The crash about `DynamicAllocLValue` I don't know how to reproduce it yet. Before the patch: ``` ...... `-VarDecl 0x118857f0 <<source>:3:1, col:50> col:33 val 'const std::type_info *const' constexpr cinit |-value: LValue Base= clang++: /root/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From&) [with To = const clang::ValueDecl*; From = llvm::PointerUnion<const clang::ValueDecl*, const clang::Expr*, clang::TypeInfoLValue, clang::DynamicAllocLValue>]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed. ``` After the patch: ``` ...... `-VarDecl 0x55b81259b750 <test.cpp:3:1, col:50> col:33 val 'const std::type_info *const' constexpr cinit |-value: LValue Base=TypeInfoLValue, Null=0, Offset=0, HasPath=1, PathLength=0, Path=() `-UnaryOperator 0x55b81259b7f0 <col:39, col:50> 'const std::type_info *' prefix '&' cannot overflow `-CXXTypeidExpr 0x55b81259b7d0 <col:40, col:50> 'const std::type_info' lvalue ``` >From 6368e470bbefc66369128c13b41c33e75c8b31a1 Mon Sep 17 00:00:00 2001 From: YLChenZ <chentongyon...@gmail.com> Date: Thu, 10 Apr 2025 21:20:58 +0800 Subject: [PATCH] [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=() } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits