Skip to content

Commit e962306

Browse files
authored
[clang] Fix printing null MemberPointer APValues (#149995)
The decl can be null and this used to crash.
1 parent a807e8e commit e962306

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,10 @@ void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
843843
}
844844

845845
ColorScope Color(OS, ShowColors, DeclNameColor);
846-
OS << Value.getMemberPointerDecl()->getDeclName();
846+
if (const ValueDecl *MemDecl = Value.getMemberPointerDecl())
847+
OS << MemDecl->getDeclName();
848+
else
849+
OS << "null";
847850
return;
848851
}
849852
case APValue::AddrLabelDiff:

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ void Test(int (&arr)[10]) {
6767
// CHECK-NEXT: | |-value: LValue Base=TypeInfoLValue typeid(int), Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
6868

6969
constexpr int(MP::*pmi) = (int MP::*)&P::x;
70-
// CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pmi 'int (MP::*const)' constexpr cinit
71-
// CHECK-NEXT: |-value: MemberPointer MP::x
70+
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pmi 'int (MP::*const)' constexpr cinit
71+
// CHECK-NEXT: | |-value: MemberPointer MP::x
72+
73+
constexpr int(MP::*pmn) = (int MP::*)nullptr;
74+
// CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pmn 'int (MP::*const)' constexpr cinit
75+
// CHECK-NEXT: |-value: MemberPointer null
7276
}

0 commit comments

Comments
 (0)