Skip to content

Commit 89cfeeb

Browse files
authored
[clang] fix structural comparison for dependent class member pointer (#133343)
Fixes a regression introduced in #130537 and reported here #133144 This fixes a crash in ASTStructuralEquivalence where the non-null precondition for IsStructurallyEquivalent would be violated, when comparing member pointers with a dependent class. This also drive-by fixes the ast node traverser for member pointers so it doesn't traverse into the qualifier in case it's not a type, or the class declaration in case it would be equivalent to what the qualifier refers. This avoids printing of `<<<NULL>>>` on the text node dumper, which is redundant. No release notes since the regression was never released. Fixes #133144
1 parent d443cd6 commit 89cfeeb

File tree

5 files changed

+381
-318
lines changed

5 files changed

+381
-318
lines changed

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,13 @@ class ASTNodeTraverser
394394
}
395395
void VisitMemberPointerType(const MemberPointerType *T) {
396396
// FIXME: Provide a NestedNameSpecifier visitor.
397-
Visit(T->getQualifier()->getAsType());
398-
Visit(T->getMostRecentCXXRecordDecl());
397+
NestedNameSpecifier *Qualifier = T->getQualifier();
398+
if (NestedNameSpecifier::SpecifierKind K = Qualifier->getKind();
399+
K == NestedNameSpecifier::TypeSpec ||
400+
K == NestedNameSpecifier::TypeSpecWithTemplate)
401+
Visit(Qualifier->getAsType());
402+
if (T->isSugared())
403+
Visit(T->getMostRecentCXXRecordDecl()->getTypeForDecl());
399404
Visit(T->getPointeeType());
400405
}
401406
void VisitArrayType(const ArrayType *T) { Visit(T->getElementType()); }

clang/lib/AST/ASTStructuralEquivalence.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,9 +897,11 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
897897
if (!IsStructurallyEquivalent(Context, MemPtr1->getQualifier(),
898898
MemPtr2->getQualifier()))
899899
return false;
900-
if (!IsStructurallyEquivalent(Context,
901-
MemPtr1->getMostRecentCXXRecordDecl(),
902-
MemPtr2->getMostRecentCXXRecordDecl()))
900+
CXXRecordDecl *D1 = MemPtr1->getMostRecentCXXRecordDecl(),
901+
*D2 = MemPtr2->getMostRecentCXXRecordDecl();
902+
if (D1 == D2)
903+
break;
904+
if (!D1 || !D2 || !IsStructurallyEquivalent(Context, D1, D2))
903905
return false;
904906
break;
905907
}

clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,9 +2452,6 @@ int main()
24522452
// CHECK-NEXT: }
24532453
// CHECK-NEXT: },
24542454
// CHECK-NEXT: {
2455-
// CHECK-NEXT: "id": "0x0"
2456-
// CHECK-NEXT: },
2457-
// CHECK-NEXT: {
24582455
// CHECK-NEXT: "id": "0x{{.*}}",
24592456
// CHECK-NEXT: "kind": "TemplateTypeParmType",
24602457
// CHECK-NEXT: "type": {

0 commit comments

Comments
 (0)