[clang] Make sure the same UsingType is searched and inserted (#79182)
When creating a new UsingType, the underlying type may change if it is a
declaration. This creates an inconsistency between the type searched and
type created. Update member and non-member Profile functions so that
they return the same ID.
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ea42579..3d41105 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4729,13 +4729,12 @@
bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
void Profile(llvm::FoldingSetNodeID &ID) {
- Profile(ID, Found, typeMatchesDecl() ? QualType() : getUnderlyingType());
+ Profile(ID, Found, getUnderlyingType());
}
static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found,
QualType Underlying) {
ID.AddPointer(Found);
- if (!Underlying.isNull())
- Underlying.Profile(ID);
+ Underlying.Profile(ID);
}
static bool classof(const Type *T) { return T->getTypeClass() == Using; }
};
diff --git a/clang/test/AST/ast-dump-using.cpp b/clang/test/AST/ast-dump-using.cpp
index c007ecd..5a4e910 100644
--- a/clang/test/AST/ast-dump-using.cpp
+++ b/clang/test/AST/ast-dump-using.cpp
@@ -12,7 +12,13 @@
typedef S f; // to dump the introduced type
// CHECK: TypedefDecl
// CHECK-NEXT: `-ElaboratedType {{.*}} 'S' sugar
-// CHECK-NEXT: `-UsingType {{.*}} 'a::S' sugar
-// CHECK-NEXT: |-UsingShadow {{.*}} 'S'
+// CHECK-NEXT: `-UsingType [[TYPE_ADDR:.*]] 'a::S' sugar
+// CHECK-NEXT: |-UsingShadow [[SHADOW_ADDR:.*]] 'S'
+// CHECK-NEXT: `-RecordType {{.*}} 'a::S'
+typedef S e; // check the same UsingType is reused.
+// CHECK: TypedefDecl
+// CHECK-NEXT: `-ElaboratedType {{.*}} 'S' sugar
+// CHECK-NEXT: `-UsingType [[TYPE_ADDR]] 'a::S' sugar
+// CHECK-NEXT: |-UsingShadow [[SHADOW_ADDR]] 'S'
// CHECK-NEXT: `-RecordType {{.*}} 'a::S'
}