[clang] [clang-tools-extra] [libcxx] [Clang] Make the SizeType, SignedSizeType and PtrdiffType be named sugar types instead of built-in types (PR #143653)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 28 13:33:56 PDT 2025
================
@@ -1516,6 +1516,23 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
MSGuidTagDecl = buildImplicitRecord("_GUID");
getTranslationUnitDecl()->addDecl(MSGuidTagDecl);
}
+
+ // size_t (C99TC3 6.5.3.4), signed size_t (C++23 5.13.2) and
+ // ptrdiff_t (C99TC3 6.5.6) Although these types are not built-in, they are
+ // part of the core language and are widely used.
+ if (!LangOpts.HLSL) {
+ // Using PredefinedSugarType makes these types as named sugar types rather
+ // than standard integer types, enabling better hints and diagnostics.
+ using Kind = PredefinedSugarType::Kind;
+ SizeType = getPredefinedSugarType(llvm::to_underlying(Kind::SizeT));
+ SignedSizeType =
+ getPredefinedSugarType(llvm::to_underlying(Kind::SignedSizeT));
+ PtrdiffType = getPredefinedSugarType(llvm::to_underlying(Kind::PtrdiffT));
+ } else {
+ SizeType = getFromTargetType(Target.getSizeType());
+ SignedSizeType = getFromTargetType(Target.getSignedSizeType());
+ PtrdiffType = getFromTargetType(Target.getPtrDiffType(LangAS::Default));
+ }
----------------
YexuanXiao wrote:
I have restored HLSL support, and the tests now pass.
https://github.com/llvm/llvm-project/pull/143653
More information about the cfe-commits
mailing list