[clang] 2e52e13 - [clang] Make sure the same UsingType is searched and inserted (#79182)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 24 11:06:24 PST 2024
Author: Wei Wang
Date: 2024-01-24T11:06:20-08:00
New Revision: 2e52e13c1e7e9a41d47b808fc5d668b7b738b94c
URL: https://github.com/llvm/llvm-project/commit/2e52e13c1e7e9a41d47b808fc5d668b7b738b94c
DIFF: https://github.com/llvm/llvm-project/commit/2e52e13c1e7e9a41d47b808fc5d668b7b738b94c.diff
LOG: [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.
Added:
Modified:
clang/include/clang/AST/Type.h
clang/test/AST/ast-dump-using.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ea425791fc97f05..3d411051084c71b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4729,13 +4729,12 @@ class UsingType final : public Type,
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 c007ecd8bda5839..5a4e910ffb8654e 100644
--- a/clang/test/AST/ast-dump-using.cpp
+++ b/clang/test/AST/ast-dump-using.cpp
@@ -12,7 +12,13 @@ using a::S;
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'
}
More information about the cfe-commits
mailing list