[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

Wei Wang via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 20:00:56 PST 2024


apolloww wrote:

> The change is correct. The problem is subtle though. It comes from the difference in behavior between the member and non-member Profile functions.
> 
> I think we could do better instead with a change which makes it harder to trip on this.
> 
> I think a simplification like this should work (untested):
> 
> ```
> diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
> index ea425791fc97..3d411051084c 100644
> --- a/clang/include/clang/AST/Type.h
> +++ b/clang/include/clang/AST/Type.h
> @@ -4729,13 +4729,12 @@ public:
>    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; }
>  };
> ```

Thanks. This works and looks better. 

https://github.com/llvm/llvm-project/pull/79182


More information about the cfe-commits mailing list