@@ -6422,36 +6422,41 @@ QualType ASTContext::getPackIndexingType(QualType Pattern, Expr *IndexExpr,
64226422
64236423/// getUnaryTransformationType - We don't unique these, since the memory
64246424/// savings are minimal and these are rare.
6425- QualType ASTContext::getUnaryTransformType(QualType BaseType,
6426- QualType UnderlyingType,
6427- UnaryTransformType::UTTKind Kind)
6428- const {
6429- UnaryTransformType *ut = nullptr;
6430-
6431- if (BaseType->isDependentType()) {
6432- // Look in the folding set for an existing type.
6433- llvm::FoldingSetNodeID ID;
6434- DependentUnaryTransformType::Profile(ID, getCanonicalType(BaseType), Kind);
6425+ QualType
6426+ ASTContext::getUnaryTransformType(QualType BaseType, QualType UnderlyingType,
6427+ UnaryTransformType::UTTKind Kind) const {
64356428
6436- void *InsertPos = nullptr;
6437- DependentUnaryTransformType *Canon
6438- = DependentUnaryTransformTypes.FindNodeOrInsertPos(ID, InsertPos);
6429+ llvm::FoldingSetNodeID ID;
6430+ UnaryTransformType::Profile(ID, BaseType, UnderlyingType, Kind);
64396431
6440- if (!Canon) {
6441- // Build a new, canonical __underlying_type(type) type.
6442- Canon = new (*this, alignof(DependentUnaryTransformType ))
6443- DependentUnaryTransformType(*this, getCanonicalType(BaseType), Kind );
6444- DependentUnaryTransformTypes.InsertNode(Canon, InsertPos);
6445- }
6446- ut = new (*this, alignof(UnaryTransformType))
6447- UnaryTransformType(BaseType, QualType(), Kind, QualType(Canon, 0) );
6432+ void *InsertPos = nullptr;
6433+ if (UnaryTransformType *UT =
6434+ UnaryTransformTypes.FindNodeOrInsertPos(ID, InsertPos ))
6435+ return QualType(UT, 0 );
6436+
6437+ QualType CanonType;
6438+ if (!BaseType->isDependentType()) {
6439+ CanonType = UnderlyingType.getCanonicalType( );
64486440 } else {
6449- QualType CanonType = getCanonicalType(UnderlyingType);
6450- ut = new (*this, alignof(UnaryTransformType))
6451- UnaryTransformType(BaseType, UnderlyingType, Kind, CanonType);
6441+ assert(UnderlyingType.isNull() || BaseType == UnderlyingType);
6442+ UnderlyingType = QualType();
6443+ if (QualType CanonBase = BaseType.getCanonicalType();
6444+ BaseType != CanonBase) {
6445+ CanonType = getUnaryTransformType(CanonBase, QualType(), Kind);
6446+ assert(CanonType.isCanonical());
6447+
6448+ // Find the insertion position again.
6449+ [[maybe_unused]] UnaryTransformType *UT =
6450+ UnaryTransformTypes.FindNodeOrInsertPos(ID, InsertPos);
6451+ assert(!UT && "broken canonicalization");
6452+ }
64526453 }
6453- Types.push_back(ut);
6454- return QualType(ut, 0);
6454+
6455+ auto *UT = new (*this, alignof(UnaryTransformType))
6456+ UnaryTransformType(BaseType, UnderlyingType, Kind, CanonType);
6457+ UnaryTransformTypes.InsertNode(UT, InsertPos);
6458+ Types.push_back(UT);
6459+ return QualType(UT, 0);
64556460}
64566461
64576462QualType ASTContext::getAutoTypeInternal(
0 commit comments