[clang] e962306 - [clang] Fix printing null MemberPointer APValues (#149995)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 22 04:42:55 PDT 2025
Author: Timm Baeder
Date: 2025-07-22T13:42:51+02:00
New Revision: e96230607cad9d30670ce55ef1cb9dd3fe1e21d7
URL: https://github.com/llvm/llvm-project/commit/e96230607cad9d30670ce55ef1cb9dd3fe1e21d7
DIFF: https://github.com/llvm/llvm-project/commit/e96230607cad9d30670ce55ef1cb9dd3fe1e21d7.diff
LOG: [clang] Fix printing null MemberPointer APValues (#149995)
The decl can be null and this used to crash.
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 3d9397fb0b540..6b524cfcd2d71 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -843,7 +843,10 @@ void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
}
ColorScope Color(OS, ShowColors, DeclNameColor);
- OS << Value.getMemberPointerDecl()->getDeclName();
+ if (const ValueDecl *MemDecl = Value.getMemberPointerDecl())
+ OS << MemDecl->getDeclName();
+ else
+ OS << "null";
return;
}
case APValue::AddrLabelDiff:
diff --git a/clang/test/AST/ast-dump-APValue-lvalue.cpp b/clang/test/AST/ast-dump-APValue-lvalue.cpp
index 51d22a5ba8b6d..f4cf2f5291760 100644
--- a/clang/test/AST/ast-dump-APValue-lvalue.cpp
+++ b/clang/test/AST/ast-dump-APValue-lvalue.cpp
@@ -67,6 +67,10 @@ void Test(int (&arr)[10]) {
// 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
+ // CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pmi 'int (MP::*const)' constexpr cinit
+ // CHECK-NEXT: | |-value: MemberPointer MP::x
+
+ constexpr int(MP::*pmn) = (int MP::*)nullptr;
+ // CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pmn 'int (MP::*const)' constexpr cinit
+ // CHECK-NEXT: |-value: MemberPointer null
}
More information about the cfe-commits
mailing list