@@ -1516,16 +1516,6 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
15161516 MSGuidTagDecl = buildImplicitRecord("_GUID");
15171517 getTranslationUnitDecl()->addDecl(MSGuidTagDecl);
15181518 }
1519-
1520- // size_t (C99TC3 6.5.3.4), signed size_t (C++23 5.13.2) and
1521- // ptrdiff_t (C99TC3 6.5.6) Although these types are not built-in, they are
1522- // part of the core language and are widely used.
1523- // Using PredefinedSugarType makes these types as named sugar types rather
1524- // than standard integer types, enabling better hints and diagnostics.
1525- using Kind = PredefinedSugarType::Kind;
1526- SizeType = getPredefinedSugarType(Kind::SizeT);
1527- SignedSizeType = getPredefinedSugarType(Kind::SignedSizeT);
1528- PtrdiffType = getPredefinedSugarType(Kind::PtrdiffT);
15291519}
15301520
15311521DiagnosticsEngine &ASTContext::getDiagnostics() const {
@@ -5232,24 +5222,27 @@ QualType ASTContext::getDependentBitIntType(bool IsUnsigned,
52325222
52335223QualType
52345224ASTContext::getPredefinedSugarType(PredefinedSugarType::Kind KD) const {
5235- llvm::FoldingSetNodeID ID;
5236- PredefinedSugarType::Profile(ID, llvm::to_underlying(KD));
52375225
5238- void *InsertPos = nullptr;
5239- if (PredefinedSugarType *Existing =
5240- PredefinedSugarTypes.FindNodeOrInsertPos(ID, InsertPos))
5241- return QualType(Existing, 0);
5226+ auto Target = PredefinedSugarTypes[llvm::to_underlying(KD)];
5227+ if (Target != nullptr)
5228+ return QualType(Target, 0);
52425229
52435230 using Kind = PredefinedSugarType::Kind;
52445231
52455232 auto getCanonicalType = [](const ASTContext &Ctx, Kind KDI) -> QualType {
52465233 switch (KDI) {
5234+ // size_t (C99TC3 6.5.3.4), signed size_t (C++23 5.13.2) and
5235+ // ptrdiff_t (C99TC3 6.5.6) Although these types are not built-in, they
5236+ // are part of the core language and are widely used. Using
5237+ // PredefinedSugarType makes these types as named sugar types rather than
5238+ // standard integer types, enabling better hints and diagnostics.
52475239 case Kind::SizeT:
52485240 return Ctx.getFromTargetType(Ctx.Target->getSizeType());
52495241 case Kind::SignedSizeT:
52505242 return Ctx.getFromTargetType(Ctx.Target->getSignedSizeType());
52515243 case Kind::PtrdiffT:
52525244 return Ctx.getFromTargetType(Ctx.Target->getPtrDiffType(LangAS::Default));
5245+ case Kind::Max:;
52535246 }
52545247 llvm_unreachable("unexpected kind");
52555248 };
@@ -5258,7 +5251,7 @@ ASTContext::getPredefinedSugarType(PredefinedSugarType::Kind KD) const {
52585251 PredefinedSugarType(KD, &Idents.get(PredefinedSugarType::getName(KD)),
52595252 getCanonicalType(*this, static_cast<Kind>(KD)));
52605253 Types.push_back(New);
5261- PredefinedSugarTypes.InsertNode(New, InsertPos) ;
5254+ Target = New ;
52625255 return QualType(New, 0);
52635256}
52645257
@@ -6842,19 +6835,25 @@ QualType ASTContext::getTagDeclType(const TagDecl *Decl) const {
68426835/// getSizeType - Return the unique type for "size_t" (C99 7.17), the result
68436836/// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and
68446837/// needs to agree with the definition in <stddef.h>.
6845- QualType ASTContext::getSizeType() const { return SizeType; }
6838+ QualType ASTContext::getSizeType() const {
6839+ return getPredefinedSugarType(PredefinedSugarType::Kind::SizeT);
6840+ }
68466841
68476842CanQualType ASTContext::getCanonicalSizeType() const {
68486843 return getFromTargetType(Target->getSizeType());
68496844}
68506845
68516846/// Return the unique signed counterpart of the integer type
68526847/// corresponding to size_t.
6853- QualType ASTContext::getSignedSizeType() const { return SignedSizeType; }
6848+ QualType ASTContext::getSignedSizeType() const {
6849+ return getPredefinedSugarType(PredefinedSugarType::Kind::SignedSizeT);
6850+ }
68546851
68556852/// getPointerDiffType - Return the unique type for "ptrdiff_t" (C99 7.17)
68566853/// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
6857- QualType ASTContext::getPointerDiffType() const { return PtrdiffType; }
6854+ QualType ASTContext::getPointerDiffType() const {
6855+ return getPredefinedSugarType(PredefinedSugarType::Kind::PtrdiffT);
6856+ }
68586857
68596858/// Return the unique unsigned counterpart of "ptrdiff_t"
68606859/// integer type. The standard (C11 7.21.6.1p7) refers to this type
0 commit comments