Skip to content

Commit 2e52e13

Browse files
authored
[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.
1 parent 123c83d commit 2e52e13

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

clang/include/clang/AST/Type.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4729,13 +4729,12 @@ class UsingType final : public Type,
47294729
bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
47304730

47314731
void Profile(llvm::FoldingSetNodeID &ID) {
4732-
Profile(ID, Found, typeMatchesDecl() ? QualType() : getUnderlyingType());
4732+
Profile(ID, Found, getUnderlyingType());
47334733
}
47344734
static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found,
47354735
QualType Underlying) {
47364736
ID.AddPointer(Found);
4737-
if (!Underlying.isNull())
4738-
Underlying.Profile(ID);
4737+
Underlying.Profile(ID);
47394738
}
47404739
static bool classof(const Type *T) { return T->getTypeClass() == Using; }
47414740
};

clang/test/AST/ast-dump-using.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ using a::S;
1212
typedef S f; // to dump the introduced type
1313
// CHECK: TypedefDecl
1414
// CHECK-NEXT: `-ElaboratedType {{.*}} 'S' sugar
15-
// CHECK-NEXT: `-UsingType {{.*}} 'a::S' sugar
16-
// CHECK-NEXT: |-UsingShadow {{.*}} 'S'
15+
// CHECK-NEXT: `-UsingType [[TYPE_ADDR:.*]] 'a::S' sugar
16+
// CHECK-NEXT: |-UsingShadow [[SHADOW_ADDR:.*]] 'S'
17+
// CHECK-NEXT: `-RecordType {{.*}} 'a::S'
18+
typedef S e; // check the same UsingType is reused.
19+
// CHECK: TypedefDecl
20+
// CHECK-NEXT: `-ElaboratedType {{.*}} 'S' sugar
21+
// CHECK-NEXT: `-UsingType [[TYPE_ADDR]] 'a::S' sugar
22+
// CHECK-NEXT: |-UsingShadow [[SHADOW_ADDR]] 'S'
1723
// CHECK-NEXT: `-RecordType {{.*}} 'a::S'
1824
}

0 commit comments

Comments
 (0)